|
Luc, thanks. That sounds promising. Would you be able to provide some code for and example
Dale
|
|
|
|
|
Hi,
I don't do examples normally, I'll make an exception this once, without warranties, without
service, this is old code, to be taken as is; I use it on a daily basis though.
Class LP_File will not be provided, as far as this method is involved
it just encapsulates simple File methods.
public static bool IsPrintableFile(string filename, byte[] accept, out long nonPrintables) {
bool printable=true;
bool firstRead=true;
long chars=0;
int logged=0;
nonPrintables=0;
if (accept==null) accept=new byte[0];
using (LP_File f=new LP_File(filename)) {
try {
f.OpenBinaryReader();
byte[] buffer=new byte[512];
for ( ; ; ) {
int len=f.ReadBinary(buffer);
if (len<=0) break;
if (firstRead) {
firstRead=false;
if (len>=2) {
byte c0=buffer[0];
byte c1=buffer[1];
if (c0==0xFF && c1==0xFE) return true;
if (c0==0xFE && c1==0xFF) return true;
if (len>=3) {
byte c2=buffer[2];
if (c0==0xEF && c1==0xBB && c2==0xBF) return true;
}
}
}
for (int j=0 ; j< len ; j++) {
byte c=buffer[j];
chars++;
if (c>=0x20 && c<=0x7F) continue;
if (c=='\t' || c==0x0A || c==0x0D) continue;
bool acceptable=false;
for (int i=0 ; i< accept.Length ; i++) {
if (c==accept[i]) acceptable=true;
}
if (!acceptable) {
logged++;
if (logged<20) {
int i=(int)c;
Console.WriteLine("Bad character ("+i.ToString("X2")+
") in "+filename);
}
nonPrintables++;
}
}
}
f.CloseBinaryReader();
if (logged!=0) Console.WriteLine(logged+" bad chars");
} catch (Exception exc) {
env.error("IO error on "+filename+": "+exc);
}
}
if (nonPrintables>(chars/64)) printable=false;
return printable;
}
I wish tabs were less than 8 positions on CP!
Nowadays I probably would add a few more printable chars such as copyright, euro, and
e with some accents.
|
|
|
|
|
Nice Snippet, Going to insert it into my archives for referencing
|
|
|
|
|
Try indenting with SPACEs.
|
|
|
|
|
PIEBALDconsult wrote: Try indenting with SPACEs
Nooo way. All those spaces would take too much space on disk as you recently admitted yourself.
|
|
|
|
|
But it's Chris' disk, not yours.
|
|
|
|
|
I would like to update the field of a database with the maximum value + 1. The following code doesn't compile because I get an error, so I must be doing something wrong.
//@Task_ref = MAX(Task_ref from database) + 1
string _getMaxTaskRef = @"SELECT MAX([task_ref])
FROM [teamwiki].[dbo].[task]";
SqlCommand cmdGetMaxTaskRef = new SqlCommand(_getMaxTaskRef, conAppDB);
cmdGetMaxTaskRef.ExecuteScalar();
if (_getMaxTaskRef != null)
{
SqlDbType.BigInt _nextRef = (SqlDbType.BigInt) _getMaxTaskRef.
+ 1;
Error:
Error 1 'System.Data.SqlDbType.BigInt' is a 'field' but is used like a 'type' c:\inetpub\wwwroot\TaskEntry\TaskEntry.aspx.cs 100 31 http://localhost/TaskEntry/
Jon
|
|
|
|
|
The SQL types are only for passing in to DBs. you'll want to cast this to int or long instead.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello everyone,
I have a managed console application which invokes both managed DLL and native COM (by using COM interop). I am using VSTS 2008 and Windows Server 2003 x64 edition.
My question is, I want to measure a specifc function call performance, e.g. from calling a function of managed console application, to managed DLL and to native COM. I also want to get the execution elapsed time for each function call stack from the top managed code level to bottom native level.
Are there any tools or solutions? It is great if I only get the specific function call performance for each stack, overall performance is not needed.
thanks in advance,
George
|
|
|
|
|
You'll need a profiling tool to do this. Compuware has a good one, and Red-Gate has its ANTS profiler. There are others, but those two I can recommend.
|
|
|
|
|
Thanks Dave!
1.
"Compuware has a good one" -- what is the name? I need the name to do some search.
2.
No .Net or VSTS built-in tool?
regards,
George
|
|
|
|
|
George_George wrote: what is the name? I need the name to do some search
Oops. DevPartner Profiler.
George_George wrote: No .Net or VSTS built-in tool?
Nope. Maybe in VS2010, though I haven't poked around in it very much.
|
|
|
|
|
Good one is also JetBrains dotTrace.
Regards
Sebastian
|
|
|
|
|
It is not free?
regards,
George
|
|
|
|
|
No it is not...
I think the Visual Studio Team Suite Edition has a built-in profiler...
|
|
|
|
|
i want to change the size of page of rdlc report.. like change to A4 or anyother..
show me the way..
|
|
|
|
|
|
hello friends
i'm converting a c program to c#...
i need to use the header file content from tat program...
pls help me out wit an idea how to use those declarations and functions in c# from c header files
im aware that c# doesnt support header files....help me out wit any alternate idea
the quieter u become more u hear
|
|
|
|
|
simple. Just put your declarations and functions in your main class.
if you need access by multiple classes then use a static class as a kind of 'header' class
|
|
|
|
|
There is no way to use those files. You simply have to rewrite the declarations in C# code in an appropriate place in your project.
|
|
|
|
|
wit is not a word. And, it sounds like you need to learn C#. C# doesn't need headers, it auto includes everything.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
You couldn't figure that out on your own?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Simple; put an # include directive in your C# and run it through a C pre-processor.
|
|
|
|
|
Good Day Everybody....
i've been trying to move a value to a textbox control from another thread... I tried so many things but it doesn't work. Anybody who can help me, i really need it badly. Thnx n advance to kind people who r ready to share thier knowledge.
below are my coding:
-------------------
form1.cs
------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace webbrowser
{
public partial class WebBrowser : Form
{
public delegate void DisplayHandler(string stringMessage);
public event DisplayMessage;
public WebBrowser()
{
InitializeComponent();
}
private void WebBrowser_Load(object sender, EventArgs e)
{
Thread threadSocket = new Thread(new ThreadStart(StartSocket));
threadSocket.Start();
}
public static void StartSocket()
{
SocketServer mySocket = new SocketServer();
mySocket.SocketDataArrival += new SocketServer.SocketServerHandler(ShowDataArrival);
mySocket.InititateServer();
}
void DisplayMessage(string stringMessage)
{
TxtBoxMsg.Text = stringMessage;
}
static void ShowDataArrival(object a, SocketServerArgs e)
{
DisplayHandler d = new DisplayHandler();
d.Invoke(e.Message);
}
}
}
---------------------------
Class1.cs
-----------
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace webbrowser
{
public class SocketServer
{
public delegate void SocketServerHandler(object myObject, SocketServerArgs myArgs);
public event SocketServerHandler SocketDataArrival;
public void InititateServer()
{
StreamWriter streamWriter;
StreamReader streamReader;
NetworkStream networkStream;
TcpListener tcpListener = new TcpListener(8000);
tcpListener.Start();
Socket serverSocket = tcpListener.AcceptSocket();
try
{
if (serverSocket.Connected)
{
networkStream = new NetworkStream(serverSocket);
streamWriter = new StreamWriter(networkStream);
streamReader = new StreamReader(networkStream);
SocketServerArgs myArgs = new SocketServerArgs(streamReader.ReadLine());
SocketDataArrival(this, myArgs);
}
}
catch (SocketException ex)
{
Console.WriteLine(ex);
}
}
public SocketServer()
{
}
}
public class SocketServerArgs : EventArgs
{
private string message;
public SocketServerArgs(string message)
{
this.message = message;
}
public string Message
{
get
{
return message;
}
}
}
}
xxx
|
|
|
|
|