/// <summary> /// Synchronizes the controller changes to native. /// </summary> /// <param name="controllerChanges">The controller changes.</param> /// <exception cref="ControllerNotFoundException"></exception> internal void SyncControllerChangesToNative(IEnumerable <ControllerChange> controllerChanges) { Application.Current.EnsureMainThread(); Logger.Debug(string.Format("Sync controller changes to native: {0}", JsonConvert.SerializeObject(controllerChanges))); foreach (var controllerChange in controllerChanges) { if (!ObservableControllers.ContainsKey(controllerChange.Id)) { throw new ControllerNotFoundException(); } var observableController = ObservableControllers[controllerChange.Id]; foreach (var changeProperty in controllerChange.Properties) { observableController.SetPropertyValue(changeProperty.Key, changeProperty.Value); } foreach (var observableCollectionChanges in controllerChange.ObservableCollections) { observableController.SetObservableCollectionChanges(observableCollectionChanges.Key, observableCollectionChanges.Value); } } }
/// <summary> /// Creates the observable controller. /// </summary> internal ObservableController CreateObservableController(string name) { var controllerProvider = Application.Current.ControllerProvider; var id = FindNextFreeControllerId(); var observableController = controllerProvider.CreateObservableController(name, id); ObservableControllers.Add(id, observableController); return(observableController); }
/// <summary> /// Destroys the controllers. /// </summary> internal void DestroyControllers() { foreach (var controller in Controllers.Values) { controller.Dispose(); } Controllers.Clear(); foreach (var observableController in ObservableControllers.Values) { observableController.Dispose(); } ObservableControllers.Clear(); }
/// <summary> /// Calls the method. /// </summary> /// <param name="controllerId">The controller identifier.</param> /// <param name="methodName">Name of the method.</param> /// <param name="arguments">The arguments.</param> /// <param name="internalMethod">if set to <c>true</c> [internal method].</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">methodName</exception> /// <exception cref="ControllerNotFoundException"></exception> internal object CallMethod(int controllerId, string methodName, JArray arguments, bool internalMethod) { if (string.IsNullOrWhiteSpace(methodName)) { throw new ArgumentNullException("methodName"); } if (Controllers.ContainsKey(controllerId)) { return(Controllers[controllerId].CallMethod(methodName, arguments, internalMethod)); } if (ObservableControllers.ContainsKey(controllerId)) { return(ObservableControllers[controllerId].CallMethod(methodName, arguments, internalMethod)); } throw new ControllerNotFoundException(); }
/// <summary> /// Destroys the controller. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> internal bool DestroyController(int id) { if (Controllers.ContainsKey(id)) { var controller = Controllers[id]; controller.Dispose(); Controllers.Remove(id); return(true); } if (ObservableControllers.ContainsKey(id)) { var observableController = ObservableControllers[id]; observableController.Dispose(); ObservableControllers.Remove(id); return(true); } return(false); }