|
If the distribution is good, you can just use any 32 bits from the 128 bits.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
Two more questions,
1.
"distribution is good" -- distribution of string to hash or distribution of MD5 result?
2.
"distribution is good" -- how do you define good generally?
regards,
George
|
|
|
|
|
Is there something wrong with the GetHashCode method in the string class?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
It's not enterprisey.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: It's not enterprisey.
Oh. I thought that it perhaps was too NIH.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
NIH is short for?
regards,
George
|
|
|
|
|
Not Invented Here
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Ok, Guffa!
Any existing technologies is fine. Any solution you could provide to me for my original question?
regards,
George
|
|
|
|
|
Can you speak in some other words? My English is not good, sorry. "enterprisey" you mean?
regards,
George
|
|
|
|
|
Genrally that means overly complicated.
As there is a built-in method in the string class that does what you ask for, you should obviously look at that before you look for anything "better".
As it turns out, the built-in method doesn't fulfill all your requirements, but it sure fulfills all the requirements that you mentioned in your original post.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
The "built-in method" -- you mean GetHashCode?
regards,
George
|
|
|
|
|
Yes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Cool, Guffa!
regards,
George
|
|
|
|
|
Probably not, but George like to know his limits
|
|
|
|
|
Yeah its kinda crap
Well... its very very fast, uses some sort of parity method. You get collisions all the time though in fairly general usage.
|
|
|
|
|
Hi Mark,
Sorry I lost your context. Do you mean GetHashCode method?
regards,
George
|
|
|
|
|
Yep. GetHashCode is designed to be very fast. Tradeoff is that its also weak, poor dispersion, and not guaranteed to give you the same value over different versions of the framework.
It's basically for sorting keys into buckets for hashtables and that sort of thing.
|
|
|
|
|
Hi Mark!
1.
"not guaranteed to give you the same value over different versions of the framework" -- I think it is the main issue. Suppose we have hash value data generated by .Net 2.0 and then upgrade to 3.5, we need to upgrade both code and data. Correct?
2.
"not guaranteed to give you the same value over different versions of the framework." -- are there any official documents? I can not find any. It is appreciated if you could refer some.
regards,
George
|
|
|
|
|
Hi Guffa!
My concerns,
1. GetHashCode is random enough?
2. GetHashCode is not language independent and C# version independent? I want to find some standard way, which is platform/language independent, like CRC32, MD5 or something.
Any comments?
regards,
George
|
|
|
|
|
When maximize Form - i want to save the place and make them bigger
( proportionally ) - how can i do it in most easy way ??
|
|
|
|
|
Set the anchor properties of your controls to size as you want
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I set the anchor properties already - but first .. .its not working and the controls have any effect - and second ... when i comeback to check the anchor properties after running my application - then its come back the the value that was before i change it and i don't know why.
|
|
|
|
|
Try to Use "FlowLayOutPanel"
ToolBox ->Container
|
|
|
|
|
Hi.
I've found a ping example which I've been tryig do expand with a database etc, but I have one question:
When using the code below, I cant seem to get it to continue pinging - it just stops when "a host is not there".
Can anyone see how I can make it continue and just add the data "DNS Error" to the database?
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
namespace printHosts
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
}
SqlConnection oconn;
SqlCommand ocomm;
string sSql = "";
int ID = 0;
string address = "";
oconn = new SqlConnection(@"server=server;database=database;user id=user; password=password");
sSql = "SELECT hostname FROM Hostinfo";
ocomm = new SqlCommand(sSql);
SqlDataAdapter myapdater = new SqlDataAdapter(sSql, oconn);
DataSet ds = new DataSet("Hostinfo");
DataTable dataTable = ds.Tables["Hostinfo"];
myapdater.Fill(ds, "Hostinfo");
foreach (DataRow row in ds.Tables[0].Rows)
{
address = row["hostname"].ToString();
Console.WriteLine(address);
try
{
sSql = "SELECT COUNT(*) FROM Hostinfo WHERE hostname ='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
if (Convert.ToInt32(ocomm.ExecuteScalar()) == 0)
{
sSql = "INSERT INTO Hostinfo (hostname, currentPingTime) values "
+ "('" + row["hostname"].ToString() + "', '"
+ DateTime.Now + "', '"
+ "')";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
}
else
{
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
sSql = "UPDATE Hostinfo SET "
+ "', LastPingTime ='" + ""
+ " WHERE id=" + ID;
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
catch
{
oconn.Open();
DateTime LastUpdatedPingTime = DateTime.Now;
sSql = "SELECT COUNT(*) FROM Hostinfo WHERE hostname ='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
if (Convert.ToInt32(ocomm.ExecuteScalar()) == 0)
{
sSql = "INSERT INTO Hostinfo (hostname, currentPingTime, repley) values"
+ "('" + row["hostname"].ToString() + "', '"
+ DateTime.Now + "', '"
+ address + "', '"
+ "')";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
}
else
{
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
sSql = "UPDATE Hostinfo SET "
+ " currentPingTime ='" + DateTime.Now
+ "', repley ='" + address
+ "' WHERE id= '" + ID + "'"; ;
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
if (IsOffline())
{
return;
}
IPAddress ip = null;
try
{
ip = Dns.GetHostEntry(address).AddressList[0];
}
catch (System.Net.Sockets.SocketException ex)
{
Console.WriteLine("DNS Error: {0}", ex.Message);
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
return;
}
//Console.WriteLine("Pinging {0} [{1}] with 32 bytes of data:", address, ip.ToString());
Console.WriteLine();
Thread pingThread = new Thread(new ParameterizedThreadStart(StartPing));
pingThread.Start(ip);
pingThread.Join();
}
}
[Flags]
enum ConnectionState : int
{
INTERNET_CONNECTION_MODEM = 0x1,
INTERNET_CONNECTION_LAN = 0x2,
INTERNET_CONNECTION_PROXY = 0x4,
INTERNET_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
}
[DllImport("wininet", CharSet = CharSet.Auto)]
static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);
static bool IsOffline()
{
ConnectionState state = 0;
InternetGetConnectedState(ref state, 0);
if (((int)ConnectionState.INTERNET_CONNECTION_OFFLINE & (int)state) != 0)
{
return true;
}
return false;
}
static void StartPing(object argument)
{
SqlConnection oconn;
SqlCommand ocomm;
string sSql = "";
int ID = 0;
string address = "";
try
{
oconn = new SqlConnection("server=sqlserver;database=audit_data;uid=user;pwd=password;");
oconn.Open();
sSql = "SELECT Hostname from hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
{
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
catch (Exception e)
{
}
IPAddress ip = (IPAddress)argument;
//set options ttl=128 and no fragmentation
PingOptions options = new PingOptions(128, true);
//create a Ping object
Ping ping = new Ping();
//32 empty bytes buffer
byte[] data = new byte[32];
int received = 0;
List<long> responseTimes = new List<long>();
//ping 4 times
for (int i = 0; i < 1; i++)
{
PingReply reply = ping.Send(ip, 1000, data, options);
if (reply != null)
{
switch (reply.Status)
{
case IPStatus.Success:
Console.WriteLine("Reply from {0}",
reply.Address, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl);
received++;
responseTimes.Add(reply.RoundtripTime);
break;
case IPStatus.TimedOut:
Console.WriteLine("Request timed out.");
break;
default:
Console.WriteLine("Ping failed {0}", reply.Status.ToString());
break;
}
}
else
{
Console.WriteLine("Ping failed for an unknown reason");
}
}
}
}
}
Thanks Jan.
|
|
|
|
|
While put Code please use proper format [ InlineCode ] and [Code Block]
that will be more understandable by all.
Thanks
|
|
|
|
|