
Jibrohni
Avatar/Signature-
Posts
28 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by Jibrohni
-
SOLVED: var Index = from LinkIcon in xmlDoc.Descendants("LinkIcon") where (string)LinkIcon.Parent.Attribute("ID").Value == item.LinkID.ToString() select LinkIcon.Attribute("Index").Value; item.IconIndex = Index.First<string>(); var Path = from LinkCollection in xmlDoc.Descendants("LinkIcon") where (string)LinkCollection.Parent.Attribute("ID").Value == item.LinkID.ToString() select LinkCollection.Attribute("Path").Value; item.IconPath = Path.First<string>();
-
Hi all, I'm trying to retrieve some specific data from an XML file I have attached. The data is in <LinkCollection> I have a semi populated class object that contains an ID that directly relates to the LinkItem ID. Matching these values I then want to populate the rest of the class with the other data - Path, Index and any DescriptiveText held under that ID. My attempt is here but I'm returning dodgy string values and getting nowhere slowly. //gets icon path and index foreach (LinkItem item in linkItems) { var Index = from LinkIcon in xmlDoc.Descendants("LinkIcon") where (string)LinkIcon.Parent.Attribute("ID") == item.LinkID select LinkIcon.Attribute("Index").Value; item.IconIndex = Index.ToString(); var Path = from LinkCollection in xmlDoc.Descendants("LinkItem") where LinkCollection.Attribute("ID").Value == item.LinkID select LinkCollection.Descendants("LinkIcon").Attributes("Path"); item.IconPath = Path.ToString(); } example.txt
-
Good day one and all, Apologies if I'm not in the most suitable topic area for this. Can someone tell me why I'm getting a bad data error when I try using this decryption method? The encryption part works fine, but when decrypting the file I get the error: CryptographicExcpetion was unhandled Bad Data on the line fsDecrypted.Write(sr.ReadToEnd()) please see the code I'm trying to use: /// <summary> /// Encrypts a file - Not implemented /// </summary> /// <param name="sInputFilename">File to encrypt</param> /// <param name="sOutputFilename">Encrypted file name</param> /// <param name="sKey">Encryption Key</param> private void EncryptFile(string sInputFilename, string sOutputFilename, string sKey) { FileStream fsInput = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read); FileStream fsEncrypted = new FileStream(sOutputFilename, FileMode.Create, FileAccess.Write); DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey); ICryptoTransform desencrypt = DES.CreateEncryptor(); CryptoStream cryptostream = new CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write); byte[] bytearrayinput = new byte[fsInput.Length - 1]; fsInput.Read(bytearrayinput, 0, bytearrayinput.Length); cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length); fsEncrypted.Close(); } /// <summary> /// Decrypts a file - Not implemented /// </summary> /// <param name="sInputFilename">File to decrypt</param> /// <param name="sOutputFilename">Decrypted file name</param> /// <param name="sKey">Decryption Key</param> static void DecryptFile(string sInputFilename, string sOutputFilename, string sKey) { DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); //A 64 bit key and IV is required for this provider. //Set secret key For DES algorithm. DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //Set initialization vector. DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey); //Create a file stream to read the encrypted file back. FileStream fsread = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read); //Create a DES decryptor from the DES instance. ICryptoTransform desdecrypt = DES.CreateDecryptor(); //Create crypto stream set to read and do a //DES decryption transform on incoming bytes. CryptoStream cryptostreamDecr = new CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read); StreamReader sr = new StreamReader(cryptostreamDecr); //Print the contents of the decrypted file. StreamWriter fsDecrypted = new StreamWriter(sOutputFilename); fsDecrypted.Write(sr.ReadToEnd()); fsDecrypted.Flush(); fsDecrypted.Close(); } I'm using the same key for both "m43%gj&^", and the fact that it encrypts suggests that that is fine to use. Thanks in advance for your time. Jib
-
Well to be honest the actual target application is likely to change a lot more than Calc, so it will be a life's work once I get to that point. I'll be running it on my computer to start with, so there will be less variables, however I hope to run it elsewhere eventually. I just want to take a robust approach that requires as few alterations to the code as possible really.
-
Hmm, perhaps Calc isn't the best starter project. I'm using Windows Detective and it's results are somewhat irregular. Sometimes the buttons appear with WindowText such as "2", other times they contain nothing. I'm automating an application and need to reproduce mouse clicks and text entries. I can do this by taking a screen dump and mapping out the button positions dependant on a pre-known pixel set. I thought the window-handle approach might be a little more robust though..?
-
Anyone?
-
Hey all, I'm trying to use FindWindowEx() to get a handle to the Calculator buttons. I'm using this code to drill down through the levels, which works fine until I get to the button level: hwndFrame = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "CalcFrame", ""); hwndDialog = FindWindowEx(hwndFrame, IntPtr.Zero, "#32770", ""); hwndButton = FindWindowEx(hwndDialog, IntPtr.Zero, "Button", "2"); The top two lines populate the handles just fine, but the third does not. Anyone got a clue as to why it's returning nothing for the button handle? I'm using Window Detective to obtain the UI information and it lists "Button" as the class type, however it doesn't list anything for WindowTitle. I've tried it with "" and "2". I've seen "2" in a supposedly working example on the net. My declaration is: [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle); Help, thanks. Jib.
-
Indeed it does - thank you. Slowly getting the hang of this...
-
Hey there, I'm using API's to get the handle to a specific button in an external app. How can I derive the screen position of this child window in order to direct a send click there? Thanks, Jib.
-
Hi all, I'm hoping someone can point me in the direction of a good place to start learning about API calls using C#. I want to work towards obtaining handles to external programs and retrieving various bits of information. Ideally I want to be able to watch a window and act everytime a WM_PAINT message is triggered. I'm just finding it a tough topic for a beginner to understand with all the complex looking parameters and all. Any good advice is welcomed. Jib.
-
That's what I was doing before - but the change frequency of my seed value was lower than my random number iteration frequency - therefore it was repeating the same deck of cards 5 or 6 times before the seed value had a chance to change. Using the high resolution timer meant that the seed value I was using was changing much more rapidly, beating the next iteration of my algorithm, and thus providing a completely new random deck. Basically the tick rate was moving at a slower pace than my iterating algorithm.
-
Ok guys, so I've managed to solve the problem by incorporating a high performance/high resolution timer. I used the class at the destination below: http://www.codeproject.com/KB/cs/highperformancetimercshar.aspx I then took the .Duration value after starting the timer and used a Right function to take the 7 digits (the farthest right being the numbers changing most frequently). I then used these as my seed value. HiPerfTimer ht = new HiPerfTimer(); ht.Start(); Random rnd = new Random(Convert.ToInt32(Right(ht.Duration.ToString(),7))); I hope this helps others out. Thanks again!
-
Well I have a Deck class that gets instantiated at the beginning of each iteration. I then use the Shuffle() method to randomize each deck: /// <summary> /// method to shuffle the deck /// </summary> public void shuffle(int seed) { Random rnd = new Random(seed); int sort1; int sort2; Card tmpcard = new Card(); for (int ctr = 0; ctr < 100; ctr++) { sort1 = (int)((rnd.NextDouble() * 52) + 1); sort2 = (int)((rnd.NextDouble() * 52) + 1); tmpcard = this.Cards[sort1]; this.Cards[sort1] = this.Cards[sort2]; this.Cards[sort2] = tmpcard; } this.next = 1; //reset pointer to first card } I'm not really sure what the problem is, but the output of random decks does the first two fine, but then after that each deck seems to be repeated in batches of 6 or 7. Do you think it's because it's iterating through this many before there's a change in the seed value?
-
Good day one and all, I have a randomness headache... I have a simulation that is trying to create upto 10,000 random decks of cards, one after the other, as quickly as possible. The problem I seem to have is that each random Deck repeats 4 or 5 times before a new one is created. I think this may be because the random function works off the current tick or seed (I've tried using DateTime.Now.Millisecond as seed). It seems that it's managing 4 or 5 iterations before the tick or seed value actually changes. Is there anyway I can use a seed that will be quick enough to take effect before the next iteration? I'm basically trying to build a poker odds calculator so it needs to be quick for the decision and extensive for the accuracy. Any advice would be much appreciated. Thanks!
-
splendid - thank you
- 2 replies
-
- accessibility
- c_sharp
-
(and 1 more)
Tagged with:
-
Good afternoon, I have a form that contains some user controls. Whilst any of the user controls are performing a certain function I would like to disable a button on their containing form. How can I do this when they are effectively separate classes? Form1.cs UserControl.cs Regards, Mike
- 2 replies
-
- accessibility
- c_sharp
-
(and 1 more)
Tagged with:
-
the code's there - thought I'd included it to start with!? Thank you.
-
Afternoon all, I have a little project that represents a petrol station. I have a user control that represents a petrol-pump. These can be added and removed dependant on how many are required. In my user control I have a combo-box that holds the fuel choices {Diesel, Premium, Unleaded} for example. The problem I have is that when I select a fuel in one instance of a user control, it also changes the selection in all other instances. I thought they would be completely independant of one another? How can I achieve this? I want to have one pump running Diesel, whilst the others can be running Unleaded or Premium. My code is below - I'm currently adding them dynamically with a click, I have however tried adding them prior to runtime in the designer, but I get the same result. private void btnAddPump_Click(object sender, EventArgs e) { //creates a petrolpump control instance and assigns a pump identifier //tlpPumpControlHolder.Controls.Add(new PetrolPump()); PetrolPump pumpInstance = new PetrolPump(_pumpIndex); tlpPumpControlHolder.Controls.Add(pumpInstance); //increment unique identifier _pumpIndex++; //needs calling to update fuel list for new pumps UpdatePumpsWithFuels(); } using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace PumpingStation_RunThrough { public partial class PetrolPump : UserControl { private int pumpIndex; //is this needed? private List<Fuel> _fuelList; private Fuel _selectedFuel; #region Constructors public PetrolPump() { InitializeComponent(); } public PetrolPump(int PumpIndex) { pumpIndex = PumpIndex; if (InvokeRequired) { MethodInvoker theFunction = new MethodInvoker(PetrolPump_ASync); Invoke(theFunction, null); } else { PetrolPump_ASync(); } pumpIndex = PumpIndex; //InitializeComponent(); //ThreadPool.QueueUserWorkItem(new WaitCallback(PetrolPump_ASync)); } private void PetrolPump_ASync() { //pumpIndex = PumpIndex; InitializeComponent(); } #endregion public List<Fuel> FuelList { get { return _fuelList; } set { _fuelList = value; UpdateFuelCombobox(); } //extra stuff to go here. When set is called a method will be required to update the PetrolPumps fuel combobox } private void UpdateFuelCombobox() { //make threadsafe if (InvokeRequired) { MethodInvoker theFunction = new MethodInvoker(UpdateFuelCombobox); } else { this.cmbFuelSelection.DataSource = null; this.cmbFuelSelection.DataSource = _fuelList; } } } } Please bear in mind that I had the same problem prior to attempting to make it asynchronous. Kind regards, Mike.
-
Haha, I appreciate your help. C# is almost completely foreign to me at the mo. I haven't done it in ages. I got lazy and decided to use manly VB. MISTAKE.
-
Hmmm, that's what you had to begin with?
-
Thank you very much, however with your method I noticed that the last number 51 is always in the last position at the end.
-
Hey all, I'm trying to generate a random array of 52 integers. My code below works, but doesn't seem to be very random. Now coming from VB I know there was a Randomize() function that helped with this, but I don't know how to achieve the same result in C#. Please help! private int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, max); } public int[] GenerateDeck() { int[] DECK = new int[52]; //creates an array to hold thegenerated deck int[] holdDECK = new int[52]; int iArrayLength = 52; int iNextLocation = 0; //initialise tempDECK [1,2,3...52] for (int counter = 1; counter < 53; counter++) { holdDECK[counter - 1] = counter; } do { int rndNum = RandomNumber(0, iArrayLength); //generate random number between 1 and tDECK.Length // Find the next empty spot while (DECK[iNextLocation] != 0) { // Go until we find a zero (empty) iNextLocation++; } DECK[iNextLocation] = holdDECK[rndNum]; //shuffle down at this point do { holdDECK[rndNum] = holdDECK[rndNum + 1]; rndNum++; } while ((rndNum + 1) < iArrayLength); holdDECK[iArrayLength-1] = 0; iArrayLength--; } while (iArrayLength > 0); return DECK;