/// <summary> /// Messages from server. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="CommandEventArgs" /> instance containing the event data.</param> public void MessageFromServer(object sender, CommandEventArgs args) { CommandEnum commandID = args.CommandID; if (commandID == CommandEnum.GetAllLogsCommand) { GUIClient client = (GUIClient)sender; string message = args.CommandArgs[0]; var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <List <MessageRecievedEventArgs> >(message); List <MessageRecievedEventArgs> logs = (List <MessageRecievedEventArgs>)obj; logs.Reverse(); foreach (MessageRecievedEventArgs log in (List <MessageRecievedEventArgs>)obj) { ReceivedLog?.Invoke(this, log); } //for (int i = logs.Count - 1; i >= 0; i++) { ReceivedLog?.Invoke(this, logs[i]); } } else if (commandID == CommandEnum.LogCommand) { GUIClient client = (GUIClient)sender; string message = args.CommandArgs[0]; var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageRecievedEventArgs>(args.CommandArgs[0]); //string log = message.Substring(1); // string log = message; // MessageRecievedEventArgs logInfo = ParseLogFromString(log); MessageRecievedEventArgs logInfo = (MessageRecievedEventArgs)obj; ReceivedLog?.Invoke(this, logInfo); } }
/// <summary> /// Initializes a new instance of the <see cref="SettingsModel"/> class. /// </summary> public SettingsModel() { GUIClient client = GUIClient.GetInstance(); client.MessageReceived += MessageFromServer; Task.Run(() => client.SendMessageToServer(CommandEnum.GetConfigCommand, new string[] { "" })); }
public SettingsModel() { client = GUIClient.Instance; config = new ConfigData(new List <string>(), "", "", "", 0); client.CommandReceived += HandleCommand; client.Register(); client.SendCommand(new CommandRecievedEventArgs((int)CommandEnum.ConfigCommand, null, "")); }
public LogsModel() { client = GUIClient.Instance; logsLock = new object(); logs = new ObservableCollection <MessageRecievedEventArgs>(); client.CommandReceived += HandleCommand; client.Register(); client.SendCommand(new CommandRecievedEventArgs((int)CommandEnum.LogHistoryCommand, null, null)); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class. /// </summary> public MainWindowViewModel() { GUIClient client = GUIClient.GetInstance(); ServerConnected = GUIClient.isConnected; client.CheckConnection += CheckConnection; WindowColor = Brushes.Gray; if (ServerConnected) { WindowColor = Brushes.MediumVioletRed; } }
public LogModel() { client = GUIClient.Instance(); model_entries = new ObservableCollection <EventLogEntry>(); //to enable non UI thread to update the collection BindingOperations.EnableCollectionSynchronization(model_entries, _lock); //enlisting for new log message event case client.NewMessage += UpdateLog; //sending request for log base JObject response = new JObject(); response["commandID"] = (int)CommandEnum.LogCommand; client.SendMessage(response.ToString()); }
/// <summary> /// ctor init as blank and than updating using event (different func) /// </summary> public ConfigModel() { client = GUIClient.Instance(); //update setting on new message event client.NewMessage += UpdateSettings; //blank properties model_OPD = ""; model_handlers = new ObservableCollection<string>(); BindingOperations.EnableCollectionSynchronization(model_handlers, _lock); model_logName = ""; model_source = ""; model_thumbSize = ""; //requesting config data JObject response = new JObject(); response["commandID"] = (int)CommandEnum.GetConfigCommand; client.SendMessage(response.ToString()); //waiting for update with delay Task.Delay(500).Wait(); }
public MainWindow() { InitializeComponent(); //this context is to check if connected to color accordingly this.DataContext = GUIClient.Instance(); }
/// <summary> /// Sends the message to server. /// </summary> /// <param name="commandID">The command identifier.</param> /// <param name="args">The arguments.</param> public override void SendMessageToServer(CommandEnum commandID, string args) { GUIClient client = GUIClient.GetInstance(); client.SendMessageToServer(commandID, new string[] { args }); }
public MainModel() { client = GUIClient.Instance; }
public HomeModel() { client = GUIClient.Instance(); }
//Constructor - establishing client connection public WebModel() { client = GUIClient.Instance; client.Connect(); }