コード例 #1
0
 public static void SomeMethod()
 {
     Threading.Thread t = new Threading.Thread(() =>
     {
         try {
             while (true)
             {
                 dynamic server = new NamedPipeServerStream("Closer", PipeDirection.InOut, -1);
                 server.WaitForConnection();
                 if (!server.IsConnected)
                 {
                     return;
                 }
                 dynamic reader  = new IO.StreamReader(server);
                 dynamic casetxt = reader.ReadToEnd();
                 server.Close();
                 RootForm.Invoke(() =>
                 {
                     if (casetxt == "End")
                     {
                         System.Environment.Exit(0);
                     }
                 });
             }
         } catch (Exception ex) {
             // try/catch required in all child threads as error silently ends app.
             // log it...
         }
     });
     t.IsBackground = true;
     t.Name         = "EnderListener";
     t.Start();
 }
コード例 #2
0
        /// <summary>
        /// Get the string of the specified Resource in the assembly
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="name"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        static public string GetManifestResourceString(this Assembly assembly, Encoding encoding, params string[] name)
        {
            IO.Stream stream = assembly.GetManifestResourceStream(name);
            if (stream != null)
            {
                using (IO.StreamReader reader = new IO.StreamReader(stream, encoding, true, 2048))
                    return(reader.ReadToEnd());
            }

            return(null);
        }
コード例 #3
0
        public static Newtonsoft.Json.Linq.JObject Parse(this HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            HttpRequest req = context.Request;

            if (req.ContentType == "application/x-www-form-urlencoded")
            {
                Newtonsoft.Json.Linq.JObject data = new Newtonsoft.Json.Linq.JObject();

                for (int i = 0; i < req.Form.Count; i++)
                {
                    data[req.Form.Keys[i]] = req.Form[i];
                }

                return(data);
            }
            else if (String.Compare("POST", req.HttpMethod, true) == 0)
            {
                IO.StreamReader reader = new IO.StreamReader(req.InputStream);
                try
                {
                    try
                    {
                        string data = reader.ReadToEnd();

                        if (!string.IsNullOrWhiteSpace(data))
                        {
                            return(Newtonsoft.Json.Linq.JObject.Parse(data));
                        }

                        return(new Newtonsoft.Json.Linq.JObject());
                    }
                    catch
                    {
                        return(null);
                    }
                }
                finally
                {
                    reader.Dispose();
                }
            }
            else
            {
                return(new Newtonsoft.Json.Linq.JObject());
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: sallly81/advance-c-
 private void Button2_Click(object sender, EventArgs e) {
     string kk;
     string ee;
     string mm;
     OpenFileDialog1.InitialDirectory = "e:\\";
     OpenFileDialog1.FileName = "open a file...";
     OpenFileDialog1.Filter = "only text files (*.txt)| *.txt";
     OpenFileDialog1.ShowDialog();
     IO.StreamReader rr = new IO.StreamReader(OpenFileDialog1.FileName);
     mm = rr.ReadToEnd;
     rr.Close();
     TextBox2.Text = this.bin_word(mm);
     kk = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" +
     "111111111111111111111111111";
     Stopwatch watch = Stopwatch.StartNew();
     watch.Start();
     ee = this.completedecryption(mm, kk);
     TextBox3.Text = ee.Substring(0, TextBox1.Text.Length);
     watch.Stop();
     TextBox5.Text = watch.Elapsed.TotalSeconds;
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: sallly81/advance-c-
 private void Button1_Click(object sender, EventArgs e) {
     string f;
     OpenFileDialog1.InitialDirectory = "e:\\";
     OpenFileDialog1.FileName = "open a file...";
     OpenFileDialog1.Filter = "only text files (*.txt)| *.txt";
     OpenFileDialog1.ShowDialog();
     IO.StreamReader r = new IO.StreamReader(OpenFileDialog1.FileName);
     TextBox1.Text = r.ReadToEnd;
     r.Close();
     //   MsgBox(Len(TextBox1.Text))
     string key = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" +
     "111111111111111111111111111";
     Stopwatch watch = Stopwatch.StartNew();
     watch.Start();
     f = this.completeencryption(TextBox1.Text, key);
     watch.Stop();
     TextBox4.Text = watch.Elapsed.TotalSeconds;
     System.IO.StreamWriter objWriter = new System.IO.StreamWriter("e:\\file1.txt", false);
     objWriter.WriteLine(f);
     objWriter.Close();
 }
コード例 #6
0
    private void Prog_In_Timer_Tick(object sender, EventArgs e)
    {
        //Inrement by +1 in progressbar #1 (get it started)
        ProgressBar1.Increment(+1);


        //Add percent towards the central label
        Label2.Text = "Loading... " + ProgressBar1.Value.ToString + "%";
        IO.StreamReader r = default(IO.StreamReader);


        //Self-setup and checkup

        if (ProgressBar1.Value == "1")
        {
            if (My.Computer.FileSystem.DirectoryExists("C:\\CoderRevolt\\WebBrowser\\V1"))
            {
                //Check if returning user
            }
            else
            {
                //If user is new, then create core directory folder
                My.Computer.FileSystem.CreateDirectory("C:\\CoderRevolt\\WebBrowser\\V1");
            }
        }

        //Make sure History and Bookmarks panels are loaded up for next ProgressCheck @ Value '10'
        if (ProgressBar1.Value == "5")
        {
            Hist.Show();
            Hist.Hide();

            Bookmarks.Show();
            Bookmarks.Hide();
        }

        //Bookmark Self-Check and Setup
        if (ProgressBar1.Value == "10")
        {
            if (My.Computer.FileSystem.FileExists("C:\\CoderRevolt\\WebBrowser\\V1\\Bookmarks.gwbb"))
            {
                r = new IO.StreamReader("C:\\CoderRevolt\\WebBrowser\\V1\\Bookmarks.gwbb");
                while ((r.Peek() > -1))
                {
                    Bookmarks.ListBox1.Items.Add(r.ReadLine);
                }
                r.Close();
            }
            else
            {
            }
            if (My.Computer.FileSystem.FileExists("C:\\CoderRevolt\\WebBrowser\\V1\\Bookmarks2.gwbb"))
            {
                r = new IO.StreamReader("C:\\CoderRevolt\\WebBrowser\\V1\\Bookmarks2.gwbb");
                while ((r.Peek() > -1))
                {
                    Bookmarks.ListBox2.Items.Add(r.ReadLine);
                }
                r.Close();
            }
            else
            {
            }
        }

        //History Self-Check and Setup
        if (ProgressBar1.Value == "20")
        {
            if (My.Computer.FileSystem.FileExists("C:\\CoderRevolt\\WebBrowser\\V1\\History1.gwbb"))
            {
                r = new IO.StreamReader("C:\\CoderRevolt\\WebBrowser\\V1\\History1.gwbb");
                while ((r.Peek() > -1))
                {
                    Hist.ListBox1.Items.Add(r.ReadLine);
                }
                r.Close();
            }
            else
            {
            }
            if (My.Computer.FileSystem.FileExists("C:\\CoderRevolt\\WebBrowser\\V1\\History2.gwbb"))
            {
                r = new IO.StreamReader("C:\\CoderRevolt\\WebBrowser\\V1\\History2.gwbb");
                while ((r.Peek() > -1))
                {
                    Hist.ListBox2.Items.Add(r.ReadLine);
                }
                r.Close();
            }
            else
            {
            }
        }
        if (ProgressBar1.Value == "100")
        {
            Prog_In_Timer.Stop();
            this.Hide();

            Main.Show();
        }
    }