コード例 #1
0
 public void setClient(MyClient client)
 {
     this.client = client;
 }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            StreamReader confF = null;

            try
            {
                if (client == null)
                {
                    client = new MyClient();// è la prima volta che un client si connette
                }

                if (!Directory.Exists(@"C:\local\"))
                {
                    Directory.CreateDirectory(@"C:\local\");
                }

                if (File.Exists(Application.StartupPath + "\\data.txt"))
                {
                    string line = string.Empty;
                    confF = new StreamReader(Application.StartupPath + "\\data.txt");
                    ListViewItem item2 = null;
                    while ((line = confF.ReadLine()) != null)
                    {
                        /* salto se è un commento */
                        if (isComment(line))
                        {
                            continue;
                        }

                        /* controllo se la parola nel file corrisponde
                         *  a qualcuna della mia lista */
                        int val = 0;
                        foreach (AccettableStrings item in Enum.GetValues(typeof(AccettableStrings)))
                        {
                            if (line.StartsWith(item.ToString()))
                            {
                                switch (item.ToString())
                                {
                                case "ADDRESS":
                                    item2 = new ListViewItem(getContent(line), clientConnected);
                                    break;

                                case "HOTKEYS":
                                    Keys k = (Keys)Enum.Parse(typeof(Keys), getContent(line));
                                    item2.SubItems.Add(getContent(line));
                                    // Keys k = (Keys)val;

                                    bool success = RegisterHotKey(this.Handle, idHotkey, HotKeyWindows.Win32ModifiersFromKeys(k), HotKeyWindows.CharCodeFromKeys(k));
                                    if (success)
                                    {
                                        idHotkey++;
                                        hotKeyValues = val.ToString();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Could not register Hotkey - there is probably a conflict.  ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                    break;

                                case "ENDSERVER":
                                    item2.Checked = true;
                                    item2.SubItems.Add(" ");
                                    item2.SubItems.Add(GetTimestamp(DateTime.Now));
                                    //Add the items to the ListView.
                                    listView1.Items.AddRange(new ListViewItem[] { item2 });
                                    clientConnected++;
                                    indexListView++;
                                    client.alignListSocketWithConfigurationFIle();
                                    break;

                                default: item2.SubItems.Add(getContent(line));
                                    break;
                                }
                            }
                        }
                    }
                    confF.Close();
                }
            }catch (Exception ex) {
                if (confF != null)
                {
                    confF.Close();
                }
                MessageBox.Show("Errore nell' apertura del file");
                return;
            }
        }