예제 #1
0
        protected virtual void OnPropertyChanged(string propertyName, object originalValue, object nowvalue)
        {
            if (m_notSendPropertyChanged)
            {
                return;
            }

            var changeditem = this.ChangedProperties[propertyName];

            if (changeditem != null)
            {
                if (changeditem.OriginalValue == null && nowvalue == null)
                {
                    ChangedProperties.Remove(propertyName);
                }
                else if (changeditem.OriginalValue != null && changeditem.OriginalValue.Equals(nowvalue))
                {
                    ChangedProperties.Remove(propertyName);
                }
            }
            else
            {
                this.ChangedProperties[propertyName] = new DataModelChangedItem()
                {
                    OriginalValue = originalValue,
                };
            }
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
예제 #2
0
        /// <summary>
        /// Salva o log de alteração do Grupo
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        public override Colosoft.Business.SaveResult Save(Colosoft.Data.IPersistenceSession session)
        {
            if (ExistsInStorage)
            {
                #region Log

                if (ChangedProperties.Contains("IdGrupo"))
                {
                    var planoContasAnterior = Microsoft.Practices.ServiceLocation.ServiceLocator
                                              .Current.GetInstance <IProvedorPlanoContas>()
                                              .ObtemPlanoContas(IdConta);

                    var logAlteracao = ObterLogAlteracao();

                    logAlteracao.ValorAnterior = planoContasAnterior.Grupo.Descricao;
                    logAlteracao.ValorAtual    = Grupo.Descricao;
                    logAlteracao.Campo         = "Grupo";

                    logAlteracao.Save(session);
                }

                #endregion
            }

            return(base.Save(session));
        }
예제 #3
0
 /// <summary>
 /// Push property changed updates to the client.
 /// </summary>
 public void PushUpdates()
 {
     if (ChangedProperties.Any())
     {
         RequestPushUpdates?.Invoke(this, null);
     }
 }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void SendPropertyChanging(String propertyName, object originalValue, object nowvalue)
        {
            if (m_notSendPropertyChanged)
            {
                return;
            }

            DataValueChangedItem changeditem = this.ChangedProperties[propertyName];

            if (changeditem != null)
            {
                if (changeditem.OriginalValue == null && nowvalue == null)
                {
                    ChangedProperties.Remove(propertyName);
                }
                else if (changeditem.OriginalValue != null && changeditem.OriginalValue.Equals(nowvalue))
                {
                    ChangedProperties.Remove(propertyName);
                }
            }
            else
            {
                this.ChangedProperties[propertyName] = new DataValueChangedItem()
                {
                    OriginalValue = originalValue,
                };
            }
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }
예제 #5
0
 /// <summary>
 /// Push property changed updates to the client.  It accepts a boolean to force the request be sent to the VMController
 /// even when there is no changed properties in this view model.  The intent is to allow a way for this view model to
 /// push changes in other view models that share the same VMController.
 /// This method also returns a boolean just so it can support fluent chaining.
 /// </summary>
 /// <param name="force">Always send push update request.</param>
 /// <returns>True, just so it returns a value.</returns>
 public virtual bool PushUpdates(bool force)
 {
     if (ChangedProperties.Any() || force)
     {
         RequestPushUpdates?.Invoke(this, null);
     }
     return(true);
 }
예제 #6
0
        /// <summary>
        /// Raises a Property Changed event
        /// </summary>
        protected virtual void OnPropertyChanged(string propertyName, object before, object after)
        {
            // Register Property Changed
            if (!ChangedProperties.Contains(propertyName) && propertyName != "" && before != after)
            {
                ChangedProperties.Add(propertyName);
            }

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
예제 #7
0
 public void AddChangedProperties(IEnumerable <string> props)
 {
     if (ChangedProperties == null)
     {
         ChangedProperties = props.ToArray();
     }
     else
     {
         ChangedProperties = ChangedProperties.Concat(props.Where(p => !ChangedProperties.Contains(p))).ToArray();
     }
 }
예제 #8
0
 public void PropertyChange(string name, object value)
 {
     if (ChangedProperties.ContainsKey(name) == true)
     {
         ChangedProperties[name] = value;
     }
     else
     {
         ChangedProperties.Add(name, value);
     }
 }
예제 #9
0
 protected virtual void OnPropertyChanged(string propertyName)
 {
     if (ChangedProperties.ContainsKey(propertyName))
     {
         ChangedProperties[propertyName] = true;
     }
     else
     {
         ChangedProperties[propertyName] = false;
     }
 }
예제 #10
0
        private void NotifyPropertyChanged()
        {
            if (PropertyChanged != null)
            {
                foreach (string propName in ChangedProperties)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propName));
                }
            }

            ChangedProperties.Clear();
        }
예제 #11
0
        /// <summary>
        /// Raises a Property Changed event
        /// </summary>
        public void OnPropertyChanged(string propertyName, object before, object after)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

            if (propertyName == null || ChangeTrackingDisabled)
            {
                return;
            }

            // Register Property Changed
            if (!ChangedProperties.Contains(propertyName) && before != after)
            {
                ChangedProperties.Add(propertyName);
            }
        }
      /// <summary>
      /// Paginates the query results.
      /// It sets the Pagination and Page properties.
      /// </summary>
      private List<MovieRecord> Paginate(IEnumerable<MovieRecord> iQueryResults)
      {
         IEnumerable<MovieRecord> results;

         // ChangedProperties is a base class property that contains a list of changed properties.
         // Here it's used to check whether user has changed the Page property value through clicking a pagination link.
         if (ChangedProperties.ContainsKey("Page"))
            results = iQueryResults.Skip(_recordsPerPage * (Page - 1)).Take(_recordsPerPage);
         else
         {
            var pageCount = (int)Math.Ceiling(iQueryResults.Count() / (double)_recordsPerPage);
            Pagination = Enumerable.Range(1, pageCount).ToArray();
            results = iQueryResults.Take(_recordsPerPage);
         }
         return results.ToList();
      }
예제 #13
0
        /// <summary>
        /// Sets a specified property value.
        /// </summary>
        /// <param name="name">The property name. May not be null.</param>
        /// <param name="value">The value.</param>
        /// <param name="setChanged">if set to <c>true</c> set the HasChanged property to true.</param>
        /// <param name="forceRaise">if set to <c>true</c> force the raise, even if RaisePropertyChanged is set to false.</param>
        /// <param name="trackChanged">if set to <c>true</c> the property is tracked in the changed properties.</param>
        /// <returns>
        /// true if the value has changed; otherwise false.
        /// </returns>
        protected virtual bool SetProperty(string name, object value, bool setChanged, bool forceRaise, bool trackChanged)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            object oldValue;
            bool   hasOldValue = Properties.TryGetValue(name, out oldValue);

            if (hasOldValue && ArePropertiesEqual(value, oldValue))
            {
                return(false);
            }

            if (!hasOldValue)
            {
                oldValue = GetDefaultValue(name);
                if (ArePropertiesEqual(value, oldValue))
                {
                    return(false);
                }
            }

            if (!OnPropertyChanging(name))
            {
                return(false);
            }

            if (trackChanged && TrackChangedProperties)
            {
                if (!ChangedProperties.ContainsKey(name))
                {
                    ChangedProperties[name] = oldValue;
                }
            }

            bool oldValid = IsValid;

            Properties[name] = value;
            OnPropertyChanged(name, setChanged, forceRaise);
            if (oldValid != IsValid)
            {
                OnPropertyChanged("IsValid");
            }
            return(true);
        }
예제 #14
0
        /// <summary>
        /// Changes property of the object
        /// </summary>
        /// <typeparam name="TTarget"></typeparam>
        /// <param name="propertyExpr"></param>
        /// <param name="value"></param>
        public void Set <TTarget>(Expression <Func <TObj, TTarget> > propertyExpr, TTarget value)
        {
            if (!(propertyExpr.Body is MemberExpression memberSelectorExpression))
            {
                return;
            }

            var property = memberSelectorExpression.Member as PropertyInfo;

            if (property == null)
            {
                return;
            }

            var getter   = CreateGetter(propertyExpr);
            var oldValue = getter(_object);

            var handledValue = value;

            if (typeof(TTarget) == typeof(DateTime))
            {
                if (((DateTime)(object)oldValue).Difference((DateTime)(object)handledValue) > TimeSpan.FromSeconds(1))
                {
                    ActionIfDiff();
                }

                return;
            }
            if (typeof(TTarget) == typeof(TimeSpan))
            {
                if (((TimeSpan)(object)oldValue).Subtract((TimeSpan)(object)handledValue).Duration() > TimeSpan.FromSeconds(1))
                {
                    ActionIfDiff();
                }

                return;
            }

            if (!typeof(TTarget).IsSimple())
            {
                var jsonSerializerSettings = new JsonSerializerSettings();
                jsonSerializerSettings.Converters.Add(new DecimalConverter()
                {
                    Precision = 4
                });
                var jsonSerializer = JsonSerializer.Create(jsonSerializerSettings);
                if (typeof(IEnumerable).IsAssignableFrom(typeof(TTarget)))
                {
                    if (!JToken.DeepEquals(JArray.FromObject(oldValue, jsonSerializer), JArray.FromObject(handledValue, jsonSerializer)))
                    {
                        ActionIfDiff();
                    }
                }
                else
                {
                    if (!JToken.DeepEquals(JObject.FromObject(oldValue, jsonSerializer), JObject.FromObject(handledValue, jsonSerializer)))
                    {
                        ActionIfDiff();
                    }
                }

                return;
            }

            if (!Equals(oldValue, handledValue))
            {
                ActionIfDiff();
            }

            void ActionIfDiff()
            {
                var setter = CreateSetter(propertyExpr);

                setter(_object, handledValue);
                _actionIfChanged?.Invoke();
                IsChanged = true;

                if (IsLogChangedPropertiesEnabled)
                {
                    ChangedProperties.Add(new ChangedPropertyItem()
                    {
                        PropertyName = property.Name,
                        PropertyType = property.PropertyType,
                        OldValue     = oldValue,
                        NewValue     = handledValue
                    });
                }
            }
        }
예제 #15
0
 public bool IsPropertyChanged(Columns column)
 {
     return(ChangedProperties.ContainsKey(column.ToString()));
 }
 public void                                         raisePropertiesChanged()
 {
     ChangedProperties?.Invoke(this, EventArgs.Empty);
 }
예제 #17
0
 private void Invariants()
 {
     Contract.Invariant(ChangedProperties != null, "A change tracker must expose its changed properties with a non-null reference to a collection");
     Contract.Invariant(UnchangedProperties != null, "A change tracker must expose its unchanged properties with a non-null reference to a collection");
     Contract.Invariant(ChangedProperties.Intersect(UnchangedProperties).Count == 0, "Changed and unchanged property collection cannot match, because it would mean that one or many properties would be changed and unchanged");
 }
예제 #18
0
 public void NetworkConnectionPropertyChanged(Guid id, ChangedProperties properties) =>
 NetworkListManager.OnNetworkConnectionPropertyChanged(id, properties);
예제 #19
0
        /// <summary>
        /// Persiste a entidade no banco de dados.
        /// </summary>
        /// <param name="session"></param>
        public virtual SaveResult Persist(Data.IPersistenceSession session)
        {
            if (!IsChanged && ExistsInStorage)
            {
                return(new SaveResult(true, null));
            }
            var result = OnSaving();

            if (!result.Success)
            {
                return(result);
            }
            var          actionId     = 0;
            DeleteResult deleteResult = null;

            Data.IPersistenceSession beforeSession = null;
            Data.IPersistenceSession afterSession  = null;
            if (!ExistsInStorage)
            {
                actionId = session.Insert(DataModel, SaveActionCallback);
            }
            else
            {
                var changeProperties = ChangedProperties.ToArray();
                if (changeProperties.Length > 0)
                {
                    actionId = session.Update(DataModel, SaveActionCallback, changeProperties);
                }
            }
            _lastActionId = actionId;
            if (actionId > 0)
            {
                beforeSession = session.CreateBeforeSessionForAction(actionId);
                afterSession  = session.CreateAfterSessionForAction(actionId);
            }
            else
            {
                beforeSession = session;
                afterSession  = session;
            }
            Colosoft.Domain.DomainEvents.Instance.GetEvent <EntityPersistingEvent>().Publish(new EntityPersistingEventArgs(this, session, beforeSession, afterSession));
            var references              = Loader.GetReferences().Where(f => this.IsReferenceInitialized(f.Name));
            var beforeLinksAccessors    = Loader.GetLinksAccessors(EntityChildSavePriority.BeforeEntity);
            var beforeChildrenAccessors = Loader.GetChildrenAccessors(EntityChildSavePriority.BeforeEntity);
            var linksAccessors          = Loader.GetLinksAccessors(EntityChildSavePriority.AfterEntity);
            var childrenAccessors       = Loader.GetChildrenAccessors(EntityChildSavePriority.AfterEntity);
            var deleteProcessing        = false;

            if (!session.Root.Parameters.Contains("DeleteOperationsProcessing"))
            {
                session.Root.Parameters["DeleteOperationsProcessing"] = true;
                deleteProcessing = true;
                deleteResult     = ProcessDeleteOperations(beforeSession);
                if (!deleteResult.Success)
                {
                    return(new SaveResult(deleteResult.Success, deleteResult.Message));
                }
            }
            foreach (var i in beforeLinksAccessors)
            {
                var entity = i.Get(this);
                if (entity != null)
                {
                    if (entity is ISaveOperationsContainer)
                    {
                        var container = (ISaveOperationsContainer)entity;
                        result = container.ProcessUpdateOperations(beforeSession);
                        if (result.Success)
                        {
                            result = container.ProcessInsertOperations(beforeSession);
                        }
                    }
                    else
                    {
                        result = entity.Save(beforeSession);
                    }
                    if (!result.Success)
                    {
                        return(result);
                    }
                    if (entity is IEntitySavePersistenceSessionObserver)
                    {
                        ((IEntitySavePersistenceSessionObserver)entity).Register(beforeSession);
                    }
                }
            }
            foreach (var i in beforeChildrenAccessors)
            {
                var entity        = i.Get(this);
                var entityRemoved = GetSingleChildRemoved(i.Name);
                if (entityRemoved != null)
                {
                    deleteResult = entityRemoved.Delete(beforeSession);
                    if (!deleteResult.Success)
                    {
                        return(new SaveResult(deleteResult.Success, deleteResult.Message));
                    }
                }
                if (entity != null)
                {
                    if (entity is ISaveOperationsContainer)
                    {
                        var container = (ISaveOperationsContainer)entity;
                        result = container.ProcessUpdateOperations(beforeSession);
                        if (result.Success)
                        {
                            result = container.ProcessInsertOperations(beforeSession);
                        }
                    }
                    else
                    {
                        result = entity.Save(beforeSession);
                    }
                    if (!result.Success)
                    {
                        return(result);
                    }
                    if (entity is IEntitySavePersistenceSessionObserver)
                    {
                        ((IEntitySavePersistenceSessionObserver)entity).Register(beforeSession);
                    }
                }
            }
            foreach (var i in references.Where(f => f.SavePriority == EntityChildSavePriority.BeforeEntity))
            {
                var entity = i.ParentValueGetter(this);
                if (entity != null && entity.IsChanged)
                {
                    if (entity is ISaveOperationsContainer)
                    {
                        var container = (ISaveOperationsContainer)entity;
                        result = container.ProcessUpdateOperations(beforeSession);
                        if (result.Success)
                        {
                            result = container.ProcessInsertOperations(beforeSession);
                        }
                    }
                    else
                    {
                        result = entity.Save(beforeSession);
                    }
                    if (!result.Success)
                    {
                        return(result);
                    }
                    if (entity is IEntitySavePersistenceSessionObserver)
                    {
                        ((IEntitySavePersistenceSessionObserver)entity).Register(beforeSession);
                    }
                }
            }
            foreach (var i in linksAccessors)
            {
                var entity = i.Get(this);
                if (entity != null)
                {
                    if (entity is ISaveOperationsContainer)
                    {
                        var container = (ISaveOperationsContainer)entity;
                        result = container.ProcessUpdateOperations(afterSession);
                        if (result.Success)
                        {
                            result = container.ProcessInsertOperations(afterSession);
                        }
                    }
                    else
                    {
                        result = entity.Save(afterSession);
                    }
                    if (!result.Success)
                    {
                        return(result);
                    }
                    if (entity is IEntitySavePersistenceSessionObserver)
                    {
                        ((IEntitySavePersistenceSessionObserver)entity).Register(afterSession);
                    }
                }
            }
            foreach (var i in childrenAccessors)
            {
                var entity        = i.Get(this);
                var entityRemoved = GetSingleChildRemoved(i.Name);
                if (entityRemoved != null)
                {
                    deleteResult = entityRemoved.Delete(afterSession);
                    if (!deleteResult.Success)
                    {
                        return(new SaveResult(deleteResult.Success, deleteResult.Message));
                    }
                }
                if (entity != null)
                {
                    if (entity is ISaveOperationsContainer)
                    {
                        var container = (ISaveOperationsContainer)entity;
                        result = container.ProcessUpdateOperations(afterSession);
                        if (result.Success)
                        {
                            result = container.ProcessInsertOperations(afterSession);
                        }
                    }
                    else
                    {
                        result = entity.Save(afterSession);
                    }
                    if (!result.Success)
                    {
                        return(result);
                    }
                    if (entity is IEntitySavePersistenceSessionObserver)
                    {
                        ((IEntitySavePersistenceSessionObserver)entity).Register(afterSession);
                    }
                }
            }
            foreach (var i in references.Where(f => f.SavePriority == EntityChildSavePriority.AfterEntity))
            {
                var entity = i.ParentValueGetter(this);
                if (entity != null && entity.IsChanged)
                {
                    if (entity is ISaveOperationsContainer)
                    {
                        var container = (ISaveOperationsContainer)entity;
                        result = container.ProcessUpdateOperations(afterSession);
                        if (result.Success)
                        {
                            result = container.ProcessInsertOperations(afterSession);
                        }
                    }
                    else
                    {
                        result = entity.Save(afterSession);
                    }
                    if (!result.Success)
                    {
                        return(result);
                    }
                    if (entity is IEntitySavePersistenceSessionObserver)
                    {
                        ((IEntitySavePersistenceSessionObserver)entity).Register(afterSession);
                    }
                }
            }
            if (deleteProcessing)
            {
                session.Root.Parameters.Remove("DeleteOperationsProcessing");
            }
            return(result);
        }
예제 #20
0
 public bool ShouldSerializeChangedProperties()
 {
     return(ChangedProperties.Any());
 }
예제 #21
0
 internal static void OnNetworkConnectionPropertyChanged(Guid id, ChangedProperties properties) =>
 NetworkConnectionPropertyChanged?.Invoke(id, properties);
예제 #22
0
        public void ChangeCellIndex(int totalDeltaCellIndexX, int totalDeltaCellIndexY)
        {
            int newCellIndexX = CellIndexX;
            int newCellImgX   = CellImgX;

            int newCellIndexY = CellIndexY;
            int newCellImgY   = CellImgY;

            if (totalDeltaCellIndexX != 0)
            {
                int deltaCellIndexX = totalDeltaCellIndexX > 0 ? 1 : -1;

                newCellIndexX = (CellIndexX + deltaCellIndexX + NumCellX) % NumCellX;

                if (deltaCellIndexX < 0 && CellIndexX == 0 && CellIndexX < newCellIndexX)
                {
                    if (newCellImgX + NumCellX >= TotalNumCellX)
                    {
                        CurrMapPage = CurrMapPage.Right;
                        //if (Neighbors[CurrMapPage].ContainsKey("R"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["R"];
                        //}
                        //else if (Neighbors[CurrMapPage].ContainsKey("L"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["L"];
                        //}
                    }
                    newCellImgX = (newCellImgX + NumCellX + TotalNumCellX) % TotalNumCellX;
                }

                if (deltaCellIndexX > 0 && CellIndexX + 1 == NumCellX && CellIndexX > newCellIndexX)
                {
                    if (newCellImgX - NumCellX < 0)
                    {
                        CurrMapPage = CurrMapPage.Left;
                        //if (Neighbors[CurrMapPage].ContainsKey("L"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["L"];
                        //}
                        //else if (Neighbors[CurrMapPage].ContainsKey("R"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["R"];
                        //}
                    }
                    newCellImgX = (newCellImgX - NumCellX + TotalNumCellX) % TotalNumCellX;
                }
            }

            if (totalDeltaCellIndexY != 0)
            {
                int deltaCellIndexY = totalDeltaCellIndexY > 0 ? 1 : -1;

                newCellIndexY = (CellIndexY + deltaCellIndexY + NumCellY) % NumCellY;

                if (deltaCellIndexY < 0 && CellIndexY == 0 && CellIndexY < newCellIndexY)
                {
                    if (newCellImgY + NumCellY >= TotalNumCellY)
                    {
                        CurrMapPage = CurrMapPage.Bottom;
                        //if (Neighbors[CurrMapPage].ContainsKey("B"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["B"];
                        //}
                        //else if (Neighbors[CurrMapPage].ContainsKey("T"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["T"];
                        //}
                    }
                    newCellImgY = (newCellImgY + NumCellY + TotalNumCellY) % TotalNumCellY;
                }

                if (deltaCellIndexY > 0 && CellIndexY + 1 == NumCellY && CellIndexY > newCellIndexY)
                {
                    if (newCellImgY - NumCellY < 0)
                    {
                        CurrMapPage = CurrMapPage.Top;
                        //if (Neighbors[CurrMapPage].ContainsKey("T"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["T"];
                        //}
                        //else if (Neighbors[CurrMapPage].ContainsKey("B"))
                        //{
                        //    CurrMapPage = Neighbors[CurrMapPage]["B"];
                        //}
                    }
                    newCellImgY = (newCellImgY - NumCellY + TotalNumCellY) % TotalNumCellY;
                }
            }

            if (CellIndexX != newCellIndexX)
            {
                CellIndexX = newCellIndexX;
                ChangedProperties.Add("CellX");
            }

            if (CellIndexY != newCellIndexY)
            {
                CellIndexY = newCellIndexY;
                ChangedProperties.Add("CellY");
            }

            if (CellImgX != newCellImgX || CellImgY != newCellImgY)
            {
                CellImgX = newCellImgX;
                CellImgY = newCellImgY;
                ChangedProperties.Add("CellImgPath");
            }

            NotifyPropertyChanged();
        }
예제 #23
0
 protected void clearAbstract()
 {
     ChangedProperties.Clear();
     Status_IsAlreadySaved = false;
     Status_IsDirty        = false;
 }