コード例 #1
0
ファイル: ModelSetting.cs プロジェクト: omerz10/ImageService
        public void Removehandler(string handler)
        {
            try
            {
                // remove from handlers
                //if (this.handlers.Count > 0 && this.handlers.Contains(handler) && handler != null)
                //{
                //    this.handlers.Remove(handler);
                //}

                // update server handler was removed
                CommandRecievedEventArgs command = new CommandRecievedEventArgs(
                    (int)CommandEnum.CloseCommand, new string[] { handler }, string.Empty);
                var serializedData = JsonConvert.SerializeObject(command);
                this.client.sendMessage(serializedData);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ", cannot remove this handler");
            }
        }
コード例 #2
0
        public void ReadMesagge()
        {
            new Task(() =>
            {
                try
                {
                    string arg;
                    stream = this.client.GetStream();
                    BinaryReader reader = new BinaryReader(stream);

                    while (client.Connected)
                    {
                        lock (o)
                        {
                            arg = reader.ReadString();
                            Console.WriteLine("recieved " + arg);
                            CommandRecievedEventArgs e = JsonConvert.DeserializeObject <CommandRecievedEventArgs>(arg);
                            //if (e.CommandID == (int)CommandEnum.ExitCommand)
                            //{
                            //    // Client want to exit.
                            //    break;
                            //}
                            //Thread.Sleep(1000);
                            OnCommandRecieved?.Invoke(this, e);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //finally
                //{
                //    client.Close();

                //}
            }).Start();
        }
コード例 #3
0
 public void OnCommandRecieved(object sender, CommandRecievedEventArgs e)
 {
     Console.WriteLine(e.CommandID + e.Args[0]);
     if (e.CommandID == (int)CommandEnum.GetListLogCommand)
     {
         App.Current.Dispatcher.Invoke(new Action(() =>
         {
             List <LogObject> temp = JsonConvert.DeserializeObject <List <LogObject> >(e.Args[0]);
             foreach (LogObject lo in temp)
             {
                 this.LogsList.Add(lo);
             }
         }));
     }
     else if (e.CommandID == (int)CommandEnum.LogCommand)
     {
         App.Current.Dispatcher.Invoke(new Action(() =>
         {
             LogObject newLog = JsonConvert.DeserializeObject <LogObject>(e.Args[0]);
             this.LogsList.Add(newLog);
         }));
     }
 }