Example #1
0
        private void FillOutDatabaseObjectNames(string cmdName, CheckedListBox clb, DatabaseObjectType objectType)
        {
            string   objectName;
            string   strCmd      = ConfigurationManager.AppSettings[cmdName];
            Database db          = DatabaseFactory.CreateDatabase();
            Action   beginUpdate = () => clb.BeginUpdate();

            clb.Invoke(beginUpdate);
            using (IDataReader reader = db.ExecuteReader(CommandType.Text, strCmd))
            {
                Action addItem;
                while (reader.Read())
                {
                    objectName = reader.GetString(0);
                    addItem    = () => clb.Items.Add(new ListItem()
                    {
                        Value = objectName, Type = objectType
                    });
                    clb.Invoke(addItem);
                }
            }
            Action endUpdate = () => clb.EndUpdate();

            clb.Invoke(endUpdate);
        }
Example #2
0
 private void initializeCheckBoxAnswers(QuestionsInitializer i_QuestionToConvert, CheckedListBox i_CheckListToFill)
 {
     i_CheckListToFill.Invoke(new Action(() => i_CheckListToFill.Items.Clear()));
     foreach (string answer in i_QuestionToConvert.m_Amswers)
     {
         i_CheckListToFill.Invoke(new Action(() => i_CheckListToFill.Items.Add(answer)));
     }
 }
Example #3
0
        protected void UpdateUsersList(User user)
        {
            if (string.IsNullOrEmpty(user.Name))
            {
                return;
            }

            checkedListBoxUsers.Invoke((MethodInvoker)(() => {
                var createNewUser = true;

                for (var i = 0; i < checkedListBoxUsers.Items.Count; i++)
                {
                    var userFromList = GetUserFromListBoxName(checkedListBoxUsers.Items[i].ToString());
                    if (user.Equals(userFromList))
                    {
                        userFromList.IsOnline = !user.IsOnline;
                        checkedListBoxUsers.Items[i] = userFromList.ListViewName;
                        createNewUser = false;
                        break;
                    }
                }

                if (createNewUser)
                {
                    Users.Add(user);
                    checkedListBoxUsers.Items.Add(user.ListViewName);
                }
            }));
        }
Example #4
0
        private void hendler(string message)
        {
            string[] msg = message.Split('[');
            if (msg[0] == "PublicKey")
            {
                Console.Out.Write("\nEps:" + msg[1] + "\n");
                Console.Out.Write("\nN: " + msg[2] + "\n");

                if (rtb != null)
                {
                    rtb.Invoke((MethodInvoker) delegate()
                    {
                        string[] pers = msg[3].Split(']');
                        Console.Out.WriteLine(pers);
                        for (int i = 0; i < pers.Length - 1; i++)
                        {
                            clb.Invoke((MethodInvoker) delegate()
                            {
                                clb.Items.Add(pers[i].Split('|')[0], false);
                            });
                            Console.Out.WriteLine(pers[i].Split('|')[0] + "\n" + pers[i].Split('|')[1] + "\n");
                            rtb.Text += pers[i].Split('|')[0] + "\n" + pers[i].Split('|')[1] + "\n";
                        }
                    });
                }

                rsa = new RSA(BigInteger.Parse(msg[1]), BigInteger.Parse(msg[2]));
            }
            if (msg[0] == "Error")
            {
                MessageBox.Show(msg[1]);
                ClientClose();
            }
            if (msg[0] == "Answer")
            {
                Form1.index = Convert.ToInt32(msg[2]);
                MessageBox.Show(msg[1] + "\nПозиция: " + msg[2]);
                //ClientClose();
            }
            if (msg[0] == "vAnswer")
            {
                if (rtb != null)
                {
                    rtb.Invoke((MethodInvoker) delegate()
                    {
                        rtb.Text += "\n" + msg[1] + "\n";
                    });
                }
                Form1.canVoite = true;
                //ClientClose();
            }
            if (msg[0] == "Result")
            {
                result = msg[1];
                //ClientClose();
            }
        }
Example #5
0
        /// <summary>
        /// Task to refresh PAK items.
        /// </summary>
        /// <returns></returns>
        public static async Task RefreshList()
        {
            await Task.Delay(2000);

            CheckedListBox listBox = (Application.OpenForms[0] as Encdec).listBox;

            CheckedListBox.ObjectCollection collection = listBox.Items;

            Directory.CreateDirectory(Program.Arguments.Input);
            while (true)
            {
                if (ExplorerCollection.Count != Directory.GetFiles(Program.Arguments.Input, "*.pak").Length)
                {
                    ExplorerCollection.Clear();
                    listBox.Invoke(new Action(() => collection.Clear()));

                    List <string> paks = Directory.GetFiles(Program.Arguments.Input, "*.pak")
                                         .Select(item => item.Replace(Program.Arguments.Input + "\\", "")).ToList();
                    ExplorerCollection.AddRange(paks);
                    listBox.Invoke(new Action(() => collection.AddRange(paks.ToArray())));
                }
                await Task.Delay(1000);
            }
        }
Example #6
0
        //This is run as a thread for each client connected to the server.
        public void Conversation(CheckedListBox orders, CheckedListBox requests)
        {
            incoming_orders   = orders;
            incoming_requests = requests;
            NetworkStream stream;

            try
            {
                byte[] bytes = new byte[5000];
                string data;
                Console.WriteLine("Connection accepted.");
                stream = client.GetStream();

                int i = stream.Read(bytes, 0, bytes.Length);
                while (i != 0)
                {
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                    Console.WriteLine(String.Format("Received: {0}, press 1 to confirm", data));

                    //Update UI
                    raw_message = data;
                    String[] splitdata = data.Split(':');
                    message_from_client = splitdata;
                    if (splitdata[0].Equals("REQUEST"))
                    {
                        orders.Invoke(new EventHandler(UpdateRequestList));
                    }
                    else if (splitdata[0].Equals("ORDER"))
                    {
                        orders.Invoke(new EventHandler(UpdateOrderList));
                    }



                    //hostresponse = Console.ReadLine();

                    while (listening == true)
                    {
                    }

                    if (splitdata[0].Equals("ORDER"))//create the order object
                    {
                        ConfirmOrder();
                    }

                    byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine);
                    stream.Write(newline, 0, newline.Length);

                    stream.Flush();


                    Console.WriteLine(String.Format("Sent: {0} \n", data));



                    i = 0;
                }
                stream.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e + " " + e.StackTrace);
            }

            //If things go bad, close all connections to client.
            finally
            {
                //if (stream != null) stream.Close();
                if (client != null)
                {
                    client.Close();
                }
            }
        }
Example #7
0
 public void addUser(string name)
 {
     lbUsers.Invoke((MethodInvoker)(() => lbUsers.Items.Add(name)));
 }