private async Task SaveItemAsync()
        {
            Notification     result      = Notification.Success();
            ModelUpdateEvent updateEvent = _isNewModel ? ModelUpdateEvent.Created : ModelUpdateEvent.Updated;

            result = _validator.ValidateModel(Model);

            if (result.IsValid())
            {
                var saveResult = await _repository.SaveSampleItemAsync(Model, updateEvent);

                result.AddRange(saveResult);
            }

            if (result.IsValid())
            {
                var eventMessenger = CC.IoC.Resolve <IEventAggregator>();
                ModelUpdatedMessageResult <SampleItem> eventResult = new ModelUpdatedMessageResult <SampleItem>()
                {
                    UpdatedModel = Model, UpdateEvent = updateEvent
                };
                eventMessenger.GetEvent <ModelUpdatedMessageEvent <SampleItem> >().Publish(eventResult);
                await Close();
            }
            else
            {
                await UserNotifier.ShowMessageAsync(result.ToString(), "Save Failed");
            }
        }
        private async void SaveItem()
        {
            Notification     result      = Notification.Success();
            ModelUpdateEvent updateEvent = _isNewModel ? ModelUpdateEvent.Created : ModelUpdateEvent.Updated;

            //TODO: model validation

            var saveResult = await _repository.SaveItemAsync(Model, updateEvent);

            result.AddRange(saveResult);

            if (result.IsValid())
            {
                ModelUpdatedMessageResult <TodoItem> eventResult = new ModelUpdatedMessageResult <TodoItem> {
                    UpdatedModel = Model, UpdateEvent = updateEvent
                };
                App.EventManager.GetEvent <ModelUpdatedMessageEvent <TodoItem> >().Publish(eventResult);
                await Navigation.GoBackAsync();                 //NOTE: fails :( will work if INavigationService injected in constructor
            }
            else
            {
                //TODO: show user failure message
                //await UserNotifier.ShowMessageAsync(result.ToString(), "Save Failed");
            }
        }
        private static void RegisterTransformers(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
        {
            foreach (var powerTransformer in command.PowerTransformers)
            {
                equipmentByGid[powerTransformer.GID] = new EquipmentNodeItem(powerTransformer.GetType(),
                                                                             powerTransformer,
                                                                             connectedTo: powerTransformer.TransformerWindings,
                                                                             hidden: true);
            }

            foreach (var ratioTapChanger in command.RatioTapChangers)
            {
                equipmentByGid[ratioTapChanger.GID] = new EquipmentNodeItem(ratioTapChanger.GetType(),
                                                                            ratioTapChanger,
                                                                            connectedTo: new[] { ratioTapChanger.TransformerWinding },
                                                                            hidden: true);
            }

            foreach (var winding in command.TransformerWindings)
            {
                var tapChanger       = equipmentByGid[winding.RatioTapChanger].Item as RatioTapChangerDto;
                var powerTransformer = equipmentByGid[winding.PowerTransformer].Item as PowerTransformerDto;
                var transformer      = new TransformerModel(winding, tapChanger, powerTransformer);

                equipmentByGid[winding.GID] = new EquipmentNodeItem(transformer.GetType(),
                                                                    transformer,
                                                                    connectedTo: winding.Terminals);
            }
        }
Exemplo n.º 4
0
        private async Task <Notification> SaveItem <T>(T item, ModelUpdateEvent updateEvent) where T : ModelBase
        {
            Notification retNotification = Notification.Success();

            try
            {
                if (updateEvent == ModelUpdateEvent.Created)
                {
                    if (string.IsNullOrWhiteSpace(item.Id))
                    {
                        item.Id = Guid.NewGuid().ToString();
                    }
                    await _database.InsertAsync(item);
                }
                else
                {
                    await _database.UpdateAsync(item);
                }
            }
            catch (SQLiteException)
            {
                //LOG:
                retNotification.Add(new NotificationItem("Save Failed"));
            }

            return(retNotification);
        }
Exemplo n.º 5
0
 public async Task <Notification> SaveAppointmentAsync(Appointment item, ModelUpdateEvent updateEvent)
 {
     if (updateEvent == ModelUpdateEvent.Created)
     {
         item.UserId = _currentUserId;
     }
     return(await SaveItem(item, updateEvent));
 }
Exemplo n.º 6
0
	public void Bind(string name, ModelUpdateEvent action)
	{
		if (!_events.ContainsKey (name)) {
			_events.Add(name, null);
		}

		_events [name] = _events [name] + action;
	}
 private static void RegisterDisconnectors(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
 {
     foreach (var disconnector in command.Disconnectors)
     {
         equipmentByGid[disconnector.GID] = new EquipmentNodeItem(disconnector.GetType(),
                                                                  disconnector,
                                                                  connectedTo: disconnector.Terminals);
     }
 }
 private static void RegisterBreakers(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
 {
     foreach (var breaker in command.Breakers)
     {
         equipmentByGid[breaker.GID] = new EquipmentNodeItem(breaker.GetType(),
                                                             breaker,
                                                             connectedTo: breaker.Terminals);
     }
 }
 private static void RegisterAsynchronousMachines(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
 {
     foreach (var item in command.AsynchronousMachines)
     {
         equipmentByGid[item.GID] = new EquipmentNodeItem(item.GetType(),
                                                          item,
                                                          connectedTo: item.Terminals);
     }
 }
 private static void RegisterTerminals(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
 {
     foreach (var terminal in command.Terminals)
     {
         equipmentByGid[terminal.GID] = new EquipmentNodeItem(terminal.GetType(),
                                                              terminal,
                                                              connectedTo: new[] { terminal.ConnectivityNode, terminal.ConductingEquipment },
                                                              hidden: true);
     }
 }
 private static void RegisterConnectivityNodes(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
 {
     foreach (var connectivityNode in command.ConnectivityNodes)
     {
         equipmentByGid[connectivityNode.GID] = new EquipmentNodeItem(connectivityNode.GetType(),
                                                                      connectivityNode,
                                                                      connectedTo: connectivityNode.Terminals,
                                                                      hidden: true);
     }
 }
Exemplo n.º 12
0
        public static void Publish(T updatedModel, ModelUpdateEvent updateEvent)
        {
            var messenger    = App.EventManager;
            var updateResult = new ModelUpdatedMessageResult <T>
            {
                UpdatedModel = updatedModel,
                UpdateEvent  = updateEvent
            };

            messenger.GetEvent <ModelUpdatedMessageEvent <T> >().Publish(updateResult);
        }
        public static void Publish(T updatedModel, ModelUpdateEvent updateEvent)
        {
            var updateResult = new ModelUpdatedMessageResult <T>
            {
                UpdatedModel = updatedModel,
                UpdateEvent  = updateEvent
            };
            var eventMessenger = DependencyService.Get <IEventAggregator>(DependencyFetchTarget.GlobalInstance);

            eventMessenger.GetEvent <ModelUpdatedMessageEvent <T> >().Publish(updateResult);
        }
Exemplo n.º 14
0
        public void Update(object sender, ModelUpdateEvent e)
        {
            EquipmentTreeNode root   = EquipmentTreeFactory.CreateFrom(e);
            var fastNodeLookupByMrid = new FastLookupByMrid(root);

            App.Current.Dispatcher.Invoke((System.Action) delegate
            {
                measurementUpdater = new MeasurementUpdater(fastNodeLookupByMrid);
                DisplayTree(root);
                UpdateTransfomerList(root);
            });
        }
        public static Dictionary <long, EquipmentNodeItem> Convert(ModelUpdateEvent command)
        {
            var equipmentByGid = new Dictionary <long, EquipmentNodeItem>();

            RegisterConnectivityNodes(command, equipmentByGid);
            RegisterTerminals(command, equipmentByGid);
            RegisterAsynchronousMachines(command, equipmentByGid);
            RegisterBreakers(command, equipmentByGid);
            RegisterDisconnectors(command, equipmentByGid);
            RegisterTransformers(command, equipmentByGid);
            RegisterMeasurements(command, equipmentByGid);

            return(equipmentByGid);
        }
Exemplo n.º 16
0
        public static EquipmentTreeNode CreateFrom(ModelUpdateEvent command)
        {
            Debug.WriteLine("Creating tree from command...");

            Dictionary <long, EquipmentNodeItem> equipmentNodeByGid = EquipmentByGidConverter.Convert(command);

            var nodes = GetTreeNodes(equipmentNodeByGid, command.SourceGid);

            foreach (var item in nodes)
            {
                item.TurnedOn = false;
            }
            return(nodes.FirstOrDefault());
        }
 private static void RegisterMeasurements(ModelUpdateEvent command, Dictionary <long, EquipmentNodeItem> equipmentByGid)
 {
     foreach (var analogMeasurement in command.Analogs)
     {
         equipmentByGid[analogMeasurement.GID] = new EquipmentNodeItem(analogMeasurement.GetType(),
                                                                       analogMeasurement,
                                                                       connectedTo: new[] { analogMeasurement.Terminals },
                                                                       hidden: true);
     }
     foreach (var discreteMeasurement in command.Discretes)
     {
         equipmentByGid[discreteMeasurement.GID] = new EquipmentNodeItem(discreteMeasurement.GetType(),
                                                                         discreteMeasurement,
                                                                         connectedTo: new[] { discreteMeasurement.Terminals },
                                                                         hidden: true);
     }
 }
Exemplo n.º 18
0
        public async Task <Notification> SaveContactAsync(Contact item, ModelUpdateEvent updateEvent)
        {
            Notification retNotification = Notification.Success();

            try
            {
                if (updateEvent == ModelUpdateEvent.Created)
                {
                    await _database.InsertAsync(item);
                }
                else
                {
                    await _database.UpdateAsync(item);
                }
            }
            catch (SQLiteException)
            {
                //LOG:
                retNotification.Add(new NotificationItem("Save Failed"));
            }

            return(retNotification);
        }
Exemplo n.º 19
0
        public static void UpdateCollection <T>(this ObservableCollection <T> collection, T model, ModelUpdateEvent updateEvent) where T : ModelBase
        {
            T existing = collection.FirstOrDefault(x => x.Id == model.Id);

            switch (updateEvent)
            {
            case ModelUpdateEvent.Created:
            case ModelUpdateEvent.Updated:
                if (existing != null)
                {
                    collection.Remove(existing);
                }
                collection.Add(model);                         //NOTE: don't worry about inserting record in original position - caller must filter and order
                break;

            case ModelUpdateEvent.Deleted:
                if (existing != null)
                {
                    collection.Remove(existing);
                }
                break;
            }
        }
Exemplo n.º 20
0
 public Task Handle(ModelUpdateEvent message, IMessageHandlerContext context)
 {
     modelUpdate.Invoke(this, message);
     return(Task.CompletedTask);
 }
Exemplo n.º 21
0
 public async Task <Notification> SaveProviderAsync(HealthCareProvider item, ModelUpdateEvent updateEvent)
 {
     return(await SaveItem(item, updateEvent));
 }
Exemplo n.º 22
0
 internal void ModelUpdate()
 {
     ModelUpdateEvent?.Invoke(this, new ModelUpdateEventArgs());
 }
Exemplo n.º 23
0
	public void Unbind(string name, ModelUpdateEvent action)
	{
		if (_events.ContainsKey (name)) {
			_events[name] = _events[name] - action;
		}
	}