/// <summary> /// The method will execute the given command with its arguments. /// </summary> /// <param name="args">The arguments.</param> /// <param name="result">if set to <c>true</c> [result].</param> /// <returns>System.String.</returns> /// The command's arguments. /// The result of the command success/failure. public string Execute(string[] args, out bool result) { if (GetCongigCommand.handlers.Contains(args[0])) { GetCongigCommand.handlers.Remove(args[0]); } RemoveHandler?.Invoke(this, args[0]); result = true; return(args[0]); }
private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null) { var index = e.NewStartingIndex; foreach (var item in e.NewItems.Cast <TFrom>()) { Target.Insert(index++, Mapper(item)); } } else if (e.Action == NotifyCollectionChangedAction.Move) { throw new NotImplementedException(); } else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null) { for (int i = 0; i < e.OldItems.Count; i++) { var index = e.OldStartingIndex + i; var item = Target[index]; Target.RemoveAt(index); RemoveHandler?.Invoke(item); } } else if (e.Action == NotifyCollectionChangedAction.Replace) { throw new NotImplementedException(); } else if (e.Action == NotifyCollectionChangedAction.Reset) { foreach (var item in Target) { RemoveHandler?.Invoke(item); } Target.Clear(); foreach (var item in Source) { Target.Add(Mapper(item)); } } }
public string Execute(string[] args, out bool result) { RemoveHandler?.Invoke(this, args[0]); result = true; return(args[0]); }
private void removeExecute() { RemoveHandler?.Invoke(this); }
/// <summary> /// the constructor. /// </summary> private ModelCommunication() { ///getting a tcpClient instance. client = TcpClientChannel.GetInstance(); //if not already connected then connect. if (!TcpClientChannel.connected) { try { //connecting to the server and setting the connected boolean to true. TcpClientChannel.Connect(8000); connected = true; } catch (Exception) { //connection failed. connected = false; } } //If we connected we will continue if (TcpClientChannel.connected) { try { Task t = new Task(() => { //Receiving messages. while (true) { MessageToClient message; //getting all things that relate to the message. try { message = client.recieveMessage(); } catch (Exception) { connected = false; return; } int id = message.TypeMessage; string content = message.Content; bool allClients = message.AllClients; //Check to who transfer the message if (id == (int)SendClientEnum.AddLog) { AddLog?.Invoke(this, content); } if (id == (int)SendClientEnum.RemoveHandler) { RemoveHandler?.Invoke(allClients, content); } if (id == (int)SendClientEnum.GetConfig) { GetConfig?.Invoke(this, content); } if (id == (int)SendClientEnum.GetLogs) { GetLogs?.Invoke(this, content); } } }); t.Start(); } catch (Exception) { connected = false; } } }
/// <summary> /// raise the RemoveHandler event if it has already asigned /// it is useful when reading this data is requested before the end of writing, /// but because of an exception, the data is removed /// if a thread waits for completion of writing, cancel the thread /// </summary> public void Remove() { RemoveHandler?.Invoke(this, new EventArgs()); }