|
you may use a few chars from a guid.
Calin
|
|
|
|
|
Just create a loop that creates random characters from 0-9 and a-z and A-Z. Then combine them for the specified length.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
|
I would imagine that 3Ie7Y3GHayk may resolve into something less than random.
Could just be base 26 or 52 integers.
45789521012586410=368I5E292I426
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Having also numbers, I guess it's a base-62 number.
Making some calculation, 11 base-62 digits are roughly equivalent to 64 base-2 digits.
So I guess that a code like 3Ie7Y3GHayk is a base-62 encoded Int64 value.
A guid is 128 bits, so, if you want to generate this code starting from a Guid you must use half of it. I'm not sure that doing so introduces the risk of conflicting ids.
If you want something quick&dirty, you could try the following code (I used base64 that is directly provided by the framework, but keep in mind that the resulting string can containg characters like '/' or '+' that might cause problems when put in urls). Otherwise you must write your own encoding algorithm.
Guid guid = Guid.NewGuid();
byte[] guidArray = guid.ToByteArray();
byte[] halfArray = new byte[8];
Array.Copy(guidArray, halfArray, halfArray.Length);
string id = Convert.ToBase64String(halfArray).Substring(0, 11);
|
|
|
|
|
The problem with the grid is scalability from the randomness. That is why I suggested they probably aren't using a random number.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Yes, probably is a database index encoded in string format.
|
|
|
|
|
A guid has a specific format; I wouldn't call the code that youtube uses a "guid", even though they use it for identification.
You can use the random-function to create a random string with a given length, store it in a database, and make sure that you don't issue a double. Would that suffice for identification?
I are troll
|
|
|
|
|
Hi, is possible to get the ThreadId of the window if i know the IdProcess?
thanks. Bye Bye
|
|
|
|
|
Hi,
well...based on the processId you can get the Process , by using Process.GetProcessById(idProcess) . Then, use Threads property of the process object to get all the ProcessThread 's.
Calin
|
|
|
|
|
ok I have understood, but at the moment of lunch Process (Process.Start()), i can get the process id, but not the specific ThreadId of the window. There are many threadId when i call ProcessThread's...how can i find the ThreadId of the window?
thank you Calin.
|
|
|
|
|
May I ask you what do you want achieve with that thread?
Calin
|
|
|
|
|
Ok i try to explain my problem...
I made a sample application: with a button open a folder
(sorry for italian comment but i'm italian)
if (!IdProcessoCartellaDati.HasValue)
{
if (Processo == null)
{
// istanzia il processo
Processo = new Process();
// nome del processo
Processo.StartInfo.FileName = "explorer.exe";
// la cartella da aprire
Processo.StartInfo.Arguments = "C:\\Temp\\Log";
// controllo di eventuali errori
Processo.StartInfo.ErrorDialog = true;
Processo.StartInfo.ErrorDialogParentHandle = Handle;
Processo.StartInfo.UseShellExecute = true;
try
{
// esegue l'apertura della cartella
Processo.Start();
// memorizza l'id del processo
IdProcessoCartellaDati = Processo.Id;
}
catch (Exception)
{
// gli errori sono gestiti da Windows
}
// rilascia le risorse
Processo.Dispose();
}
}
else
{
Processo = Process.GetProcessById(IdProcessoCartellaDati.Value);
// ripristina la finestra (dimensioni)
ShowWindow(Processo.MainWindowHandle, SW_RESTORE);
// e la porta in primo piano
BringWindowToTop(Processo.MainWindowHandle);
}
This solution it's ok, but if i close the application with a explorer open on the specific folder, if i execute the appication again at the first click event Vista open another explorer window (and it's correct) but if i click again ,Vista open another window, and another...
I hope that you have understand my problem.
Thank you.
Bye Bye
|
|
|
|
|
|
|
We have a Database forum - your question has nothing to do with C#
|
|
|
|
|
hello......
i have a datagridview of like 2 coloums and i need to paste the tab seperated data into it the data is like
user address
a b
c d
and i need to copy the above nad paste in thte datagridview. when i copy al this and paste its pasting in a single cell. is there any modification to be done for this to be possible or any other ways of doing this .. thank you.
|
|
|
|
|
there are so many child nodes in parent node. i want on the selection of child node the another form must be open.how can I do this?
|
|
|
|
|
you may use NodeMouseClick to handle the selection event.
Calin
|
|
|
|
|
hello every body,
is there any mechanism in visual studio 2005 and c# to copy the remote server table and update the local database table with that copied table,
please guide me in this topic, step by step to accomplish it
i have sql server 2005 database at local and remote server.
|
|
|
|
|
use bulk copy facility provided by c#.net.
|
|
|
|
|
you could use a datastructure in the client and the server that maps the data and convert to bytes and then decode that data again on the another side . the datastructure may contain the database table coloum names if the both tables on the two sides are same...
|
|
|
|
|
Hey, first post here so sorry if im all over the place here. my previous experience is VB6 and picaxe chips! (lol: "goto main")
I have started my C# (2008) project and made some progress. At the minute i have 3 main classes: Program.cs, SerPort.cs (essentially input into the program) and Output.cs (output from the program). I can deal will the input and output alright, i have an event in serport.cs when data arrives, it grabs the data and sends it to a method in my output.cs that deals with it.
I started this project as a blank C# project as i dont need a form most of the time. I have added code into Program.cs to stick a notify icon in the notify area, fine. The right click menu of this notify icon has 'Exit' and 'Settings'. I have coded the exit event fine, but am having trouble with settings. I need it to open a form which i have made but i need it to do it so the user can only open it once (try right clicking the system clock and clicking properties twice - i want it to work like that)
im pretty new to C# and im picking up as i go along and the problem with showing the form seems to be that the method for the event is a static one (whatever static means), if i try and make it not static, i get an error in my Main method(which is also static), if i try and make my Main method not static it says there isnt a valid static main entry point - GRRR :P
im using this command at the minute: Form Setting = new Settings(); Setting.ShowDialog(); i understand that if i use this in the brackets of showdialog, it should make it modal, but for that my method needs to be non-static. basically i have nothing to own the form, so i can just open as many as i like!
my program is started by "Application.Run();" at the minute, should i make it like a project would be if it were started as a windows forms project and use "Application.Run(form);" and define my notify icon within the form, then hide the form until someone hits the "settings" button? is this bad practise to have the form sat there all the time it isnt being used? should i just stick an if statement before the ShowDialog command to check if the form is already there and activate it if it is (is this what happens when you right click the clock and click properties?)
thanks so much for any help and im sorry this is such an essay, ive just got so many questions and i dont know the conventions. after this is sorted i should be able to deal with the settings (so long as they work in a similar way to VB6 lol) and finish everything off
thanks, Sam
here is my current program.cs, (MediaCenterController is my output.cs):
namespace Video_Duke_Box
{
class Program
{
public Thread trd;
static void Main()
{
if (SerPort.OpenPort())
{
icn = new NotifyIcon();
ContextMenuStrip menu = new ContextMenuStrip();
icn.ContextMenuStrip = menu;
ToolStripMenuItem COMMenuItem = new ToolStripMenuItem("COM Port", null, new EventHandler(COMMenuItem_Click));
ToolStripMenuItem ExitMenuItem = new ToolStripMenuItem("Exit", null, new EventHandler(ExitMenuItem_Click));
ToolStripSeparator separator = new ToolStripSeparator();
menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { COMMenuItem, separator, ExitMenuItem });
icn.Visible = true;
icn.Icon = Properties.Resources.ehshell_IDI_APP1;
icn.ShowBalloonTip(3000, "Connected", "Duke Box is Connected", ToolTipIcon.Info);
MediaCenterController MCC = new MediaCenterController();
MCC.MediaStateChange += new MediaCenterController.MediaCenterHandler(SerPort.MediaCenter_Running);
MCC.MediaStateChange += new MediaCenterController.MediaCenterHandler(MediaCenter_Running);
Thread trd = new Thread(new ThreadStart(MCC.MediaCenterRunning));
trd.IsBackground = true;
trd.Start();
Application.Run();
}
else
{
}
}
static public void MediaCenter_Running(object MCRObject, MediaCenterEventArg state)
{
if (state.on)
{ icn.Icon = Properties.Resources.ehshell_IDI_APP2; }
else
{ icn.Icon = Properties.Resources.ehshell_IDI_APP1; }
}
static void COMMenuItem_Click(object sender, EventArgs e)
{
Form Setting = new Settings();
Setting.ShowDialog();
}
static void ExitMenuItem_Click(object sender, EventArgs e)
{
icn.Dispose();
SerPort.comport.Close();
Application.Exit();
}
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem cOMPOrtToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
public ContextMenuStrip menu;
class ControlContainer : IContainer
{
ComponentCollection _components;
public ControlContainer()
{
_components = new ComponentCollection(new IComponent[] { });
}
public void Add(IComponent component)
{ }
public void Add(IComponent component, string Name)
{ }
public void Remove(IComponent component)
{ }
public ComponentCollection Components
{
get { return _components; }
}
public void Dispose()
{
_components = null;
}
}
public static NotifyIcon icn;
}
}
|
|
|
|
|
Ok then, I think I understood some of that
I think there's a keyword in VB 'shared' which means the same as static. Static means things belong to the class rather than to instances of it.
What this means is that anything which is static can only refer to other static things - because you don't have any reference to a particular instance of the class.
As a suggestion to get you going, change all your methods to be non-static and rename the Main to something else. Then create a new static main, and in there instantiate the Program class, then call your old main function - does that make sense? Something like this:
static void Main()
{
Program program = new Program();
program.OldMainFunction();
}
Then you'll be working with an instance of a Program rather than class level...
Regards,
Rob Philpott.
|
|
|
|
|
sweet!
thanks, looks like a bit of work, but i was thinking that i needed to ditch the static at some point, just wasnt sure how :P
so you dont think i need to restructure it? having the form created only when the user presses the button is the right thing to do?
ill have a go at that now, and thanks for taking the time to understand my ramblings!
another problem im going to have when i have finished it all is making the installable, i would love to include some drivers in the install, is this hard to do? (drivers werent written by me)
cheers
sam
|
|
|
|