private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); del(status); }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); this.BeginInvoke(del, status); }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); this.BeginInvoke(del, status); // the following code collects the offset cache to help me improve the code if (status == InjectionHelper.Status.Ready) { string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); dir = Regex.Replace(dir, @"^(file\:\\)", string.Empty); dir = Path.Combine(dir, "cache"); if (Directory.Exists(dir)) { string [] files = Directory.GetFiles(dir, "*.cache", SearchOption.TopDirectoryOnly); foreach (string file in files) { try { // collect the cache and upload to my server to improve the initialization speed string url = string.Format("http://jerrywang.zoka.cc/cache/upload.php?hash={0}", Path.GetFileNameWithoutExtension(file)); HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; byte[] buffer = null; using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); } request.ContentLength = buffer.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); using (Stream responseStream = request.GetResponse().GetResponseStream()) { using (StreamReader sr = new StreamReader(responseStream)) { string text = sr.ReadToEnd(); Trace.WriteLine(text); } } } catch (System.Exception ex) { } } // foreach } // if } }
private void InitializationCompleted(InjectionHelper.Status status) { if (status == InjectionHelper.Status.Ready) { Console.WriteLine(@"Initialization is completed successfully, enjoy!"); } else { Console.WriteLine(string.Format(@"Initialization is failed with error [{0}]!", status.ToString())); } }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); this.BeginInvoke(del, status); // the following code collects the offset cache to help me improve the code /*if (status == InjectionHelper.Status.Ready) * { * string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "") + "\\cache"; * if (Directory.Exists(dir)) * { * string[] files = Directory.GetFiles(dir, "*.cache", SearchOption.TopDirectoryOnly); * foreach (string file in files) * { * try * { * // collect the cache and upload to my server to improve the initialization speed * string url = string.Format("http://jerrywang.zoka.cc/cache/upload.php?hash={0}", Path.GetFileNameWithoutExtension(file)); * HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; * request.Method = "POST"; * * byte[] buffer = null; * using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) * { * buffer = new byte[fs.Length]; * fs.Read(buffer, 0, buffer.Length); * fs.Close(); * } * * request.ContentLength = buffer.Length; * Stream requestStream = request.GetRequestStream(); * requestStream.Write(buffer, 0, buffer.Length); * requestStream.Close(); * * using (Stream responseStream = request.GetResponse().GetResponseStream()) * { * using (StreamReader sr = new StreamReader(responseStream)) * { * string text = sr.ReadToEnd(); * Trace.WriteLine(text); * } * } * } * catch * { * } * }// foreach * }// if * }*/ }
private void InitializationCompleted(InjectionHelper.Status status) { if (status == InjectionHelper.Status.Ready) { txtOutput.Text = @"Initialization is completed successfully, enjoy!"; foreach (Control ctrl in this.Controls) { if (ctrl is Button) { ctrl.Enabled = true; } } txtOutput.Enabled = true; } else { txtOutput.Text = string.Format(@"Initialization is failed with error [{0}]!", status.ToString()); } }
private Injector(bool showOutputInWindow) { // I don't like the UI as dependency to the dll, but then again this is a unit test dll so it should be OK // Should introduce UI separately (perhaps the UI itself is the parameter on the constructor, that's it!!) // like this // public Injector(UIObject debugWindow) -- next version :) InjectionHelper.Initialize(showOutputInWindow); CurrentStatus = InjectionHelper.Status.Uninitialized; var errorCountAllowed = 100; // TODO: need to fix threading to actaully wait on a callback InjectionHelper.Log("Initializing Injector."); try { Thread.Sleep(1500); // TODO: need to fix threading to actaully wait on a callback do { CurrentStatus = InjectionHelper.GetStatus(); InjectionHelper.Log("Checking status."); if (CurrentStatus.ToString().ToUpper().Contains("ERROR")) { Log(string.Format("Injector Initialization Error or Delay: {0} {1} Retries remaining ", new object[] { CurrentStatus.ToString(), errorCountAllowed })); if (errorCountAllowed-- <= 0) { break; } } } while (CurrentStatus != InjectionHelper.Status.Ready); if (CurrentStatus == InjectionHelper.Status.Ready) { IniALL.Ini(); } } catch (Exception e) { InjectionHelper.Log("Error during Injector Intialization :" + e.Message); } }