/// <summary> /// Intercept any changes from the view or model. /// </summary> /// <param name="observable">The observable that was changed</param> /// <param name="command">The actual data that got changed + some metadata.</param> public override void ObservableChanged(Observable observable, ObservableArgs args) { //We received an update from the model. if (args is ObservableModelArgs) { //Convert ModelArgs to an actual command, using the command factory, // The CommandFactory determines which command we want to send.s ObservableModelArgs modelArgs = args as ObservableModelArgs; Command networkCommand = CommandFactory.GetNetCommandFromModel(modelArgs); //To let the view know we have a new command, we need to notify the view. // The command we just made, we convert it to a string we want to send of the network. // And the string we get we pass as arguments. ObservableArgs commandArgs = new ObservableArgs { Content = networkCommand.ToNet() }; //Let the view know we have changed! Notify(commandArgs); } //We received an update from the view. //if(args is ObservableViewArgs) }
/// <summary> /// A listener for when any of the observed observables are changed. /// This method will proxy the request through to the controller (who is observing the model). /// </summary> /// <param name="payload"></param> public void ObservableChanged(Observable observable, ObservableArgs args) { bool success = observables.TryGetValue(observable, out string name); if (success) { ObservableModelArgs modelArgs = new ObservableModelArgs { Model = modelName, Field = name, Action = args.Action, Content = args.Content }; Notify(modelArgs); } else { //Something really bad went on here, should logically not be possible. throw new Exception("The model is observing a observable but is not registered to the model, huh!?"); } }
/// <summary> /// Intercept any incoming changes from the controller/model. /// </summary> /// <param name="observable">The observable that got changed (presumably a controller)</param> /// <param name="arguments">The arguments for the changing piece of data.</param> public override void ObservableChanged(Observable observable, ObservableArgs arguments) { //Get the content from the arguments. dynamic content = arguments.Content; //If we have a string... if (content is string) { //Don't bother sending empty shit. if (!string.IsNullOrEmpty(content)) { //Send it! //NOTE: This is wrapped in Task.Run, so we don't // have to make literally _everything_ async... Task.Run(async() => { await Send(content); }); } } else { Console.WriteLine("Trying to send a non-string over net, that's bad!"); } }
/// <summary> /// Implemented by the inheriting controller. /// This abstract method receives all the changes from the model and view. /// </summary> /// <param name="observable">The observable that has changed.</param> /// <param name="command">The data accompanied by the observable.</param> public abstract void ObservableChanged(Observable observable, ObservableArgs args);
public virtual void ObservableChanged(Observable observable, ObservableArgs arguments) { //Console.WriteLine("Oh a controller changed: " + arguments.Content); }