Esempio n. 1
0
        /// <summary>
        /// Deletes the object from storage.
        /// </summary>
        /// <remarks>
        /// Only valid when the current <see cref="DataState"/> is <see cref="DataObjectState.Current"/> or <see cref="DataObjectState.Changed"/>.
        /// Sets the <see cref="DataState"/> to <see cref="DataObjectState.Deleted"/> once successful.
        /// </remarks>
        public virtual void Delete()
        {
            lock (SyncRoot)
            {
                // Suspend events
                SuspendEvents();
                try
                {
                    // Validate state
                    if (DataState != DataObjectState.Current &&
                        DataState != DataObjectState.Changed)
                    {
                        throw new InvalidOperationException(Resources.DataObjectDeleteStateInvalid);
                    }

                    // Call implementor method to delete object
                    OnDelete(_originalProperties);
                    _originalProperties = new Dictionary <Guid, object>();
                    _changedProperties  = new Dictionary <Guid, object>();

                    // Update state
                    DataState = DataObjectState.Deleted;

                    // Fire event
                    DoDataChanged(DataObjectChangeAction.Delete, null);
                }
                finally
                {
                    // Resume events
                    ResumeEvents();
                }
            }
        }
Esempio n. 2
0
        protected void SetField <T>(string fieldName, ref T valueHolder, T value)
        {
            var changingArgs = new Events.FieldValueChangingEventArgs(
                fieldName, valueHolder, value);

            if (OnFieldValueChanging != null)
            {
                OnFieldValueChanging.Invoke(this, changingArgs);
            }

            //populating original values should come first than setting values
            if (!m_isSaveRequired)
            {
                PopulateOriginalValues();
            }

            valueHolder = (T)changingArgs.NewValue;

            m_isSaveRequired = true;
            if (m_objectState == DataObjectState.Unchanged)
            {
                m_objectState = DataObjectState.Modified;
            }

            if (OnFieldValueChanged != null)
            {
                OnFieldValueChanged.Invoke(this, new Events.FieldValueChangedEventArgs(fieldName,
                                                                                       valueHolder, changingArgs.NewValue));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the object in storage.
        /// </summary>
        /// <remarks>
        /// Only valid when the <see cref="DataState"/> is <see cref="DataObjectState.None"/>.
        /// Sets the <see cref="DataState"/> to <see cref="DataObjectState.Current"/> once successful
        /// </remarks>
        public void Create()
        {
            lock (SyncRoot)
            {
                // Assert state
                if (DataState != DataObjectState.None)
                {
                    throw new InvalidOperationException(Resources.DataObjectCreateStateInvalid);
                }

                // Suspend events
                SuspendEvents();
                try
                {
                    // Call implementor method to create object with current properties
                    _originalProperties = OnCreate(_changedProperties);
                    _changedProperties  = new Dictionary <Guid, object>();

                    // Update state
                    DataState = DataObjectState.Current;

                    // Fire event
                    DoDataChanged(DataObjectChangeAction.Create, null);
                }
                finally
                {
                    // Resume events
                    ResumeEvents();
                }
            }
        }
Esempio n. 4
0
        public override IEnumerable <IPersistenceObject> FromStream(ZetboxStreamReader sr)
        {
            var baseResult = base.FromStream(sr);

            sr.ReadConverter(i => _objectState = (DataObjectState)i);
            return(baseResult);
        }
Esempio n. 5
0
        public override void SetUnmodified()
        {
            var oldValue = this._ObjectState;

            NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.Unmodified);
            this._ObjectState = DataObjectState.Unmodified;
            NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.Unmodified);
        }
Esempio n. 6
0
 protected override void SetModified()
 {
     _objectState = DataObjectState.Modified;
     if (this.Context != null)
     {
         this.Context.Internals().SetModified(this);
     }
 }
Esempio n. 7
0
        internal void MarkAsRemoved()
        {
            if (State == DataObjectState.Removed)
            {
                return;
            }

            _dataObject.PropertyChanged -= DataObjectChanged;
            State = DataObjectState.Removed;
        }
Esempio n. 8
0
        internal void MarkAsClean()
        {
            if (State == DataObjectState.Clean)
            {
                return;
            }

            _dataObject.PropertyChanged += DataObjectChanged;
            State = DataObjectState.Clean;
        }
Esempio n. 9
0
        private void SetObjectState(DataObjectState newState)
        {
            var oldValue = this._ObjectState;

            NotifyPropertyChanging("ObjectState", oldValue, newState);
            this._ObjectState = newState;
            if (this.Context != null && newState.In(DataObjectState.Modified, DataObjectState.Deleted))
            {
                this.Context.Internals().SetModified(this);
            }
            NotifyPropertyChanged("ObjectState", oldValue, newState);
        }
Esempio n. 10
0
        public override void SetDeleted()
        {
            var oldValue = this._ObjectState;

            NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.Deleted);
            this._ObjectState = DataObjectState.Deleted;
            if (this.Context != null)
            {
                this.Context.Internals().SetModified(this);
            }
            NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.Deleted);
        }
Esempio n. 11
0
 protected override void SetModified()
 {
     if (this.ObjectState == DataObjectState.Unmodified)
     {
         var oldValue = this._ObjectState;
         NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.Modified);
         this._ObjectState = DataObjectState.Modified;
         NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.Modified);
     }
     // Sadly, this is requiered on _every_ change because some ViewModels
     // rely on the Context.IsModified change event
     // TODO: Improve that!
     if (this.Context != null)
     {
         this.Context.Internals().SetModified(this);
     }
 }
Esempio n. 12
0
        public virtual void Delete()
        {
            if (Session == null)
            {
                throw new SessionNotInstantiatedException();
            }

            if (OnDelete != null)
            {
                OnDelete.Invoke(this, new Events.DataObjectOnDeleteEventArgs());
            }
            m_objectState = DataObjectState.Deleted;
            Session.Delete(this);

            if (AfterDelete != null)
            {
                AfterDelete.Invoke(this, new Events.DataObjectAfterDeleteEventArgs());
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StateEntry"/> class.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="state">Type of the state.</param>
        internal StateEntry(object dataObject, DataObjectState state)
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }

            _dataObject = dataObject as INotifyPropertyChanged;

            if (_dataObject == null)
            {
                throw new InvalidOperationException(Resources.ChangeTrackingIsOnlySupportedForINotifyPropertyChanged);
            }

            State = state;
            if (state == DataObjectState.Clean)
            {
                _dataObject.PropertyChanged += DataObjectChanged;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Fires or caches the DataChanged event.
        /// </summary>
        /// <remarks>
        /// Sets <see cref="DataState"/> property to <see cref="DataObjectState.Changed"/> when properties change.
        /// </remarks>
        protected void DoDataChanged(DataObjectChangeAction action, Guid?propertyId)
        {
            lock (SyncRoot)
            {
                // Validate and update state when properties change
                if (action == DataObjectChangeAction.Property)
                {
                    if (DataState == DataObjectState.Deleted)
                    {
                        throw new InvalidOperationException();
                    }
                    DataState = DataObjectState.Changed;
                }

                // Fire or cache event
                if (EventsAreEnabled)
                {
                    // Fire event immediately
                    OnDataChanged(new DataObjectChangeEventArgs(action, propertyId.HasValue ? new[] { propertyId.Value } : null));
                }
                else
                {
                    // Cache event...

                    // Add any chaned property to instance cache
                    if (propertyId.HasValue && !_instancePropertiesChanged.Contains(propertyId.Value))
                    {
                        _instancePropertiesChanged.Add(propertyId.Value);
                    }

                    // Process commit or clear instance property change cache depending on action
                    switch (action)
                    {
                    case DataObjectChangeAction.Create:
                    case DataObjectChangeAction.Update:

                        // Commit all instance property changes
                        foreach (var instancePropertyId in _instancePropertiesChanged)
                        {
                            if (!_committedPropertiesChanged.Contains(instancePropertyId))
                            {
                                _committedPropertiesChanged.Add(instancePropertyId);
                            }
                        }
                        _instancePropertiesChanged.Clear();

                        // Update is ignored if Create is cached
                        if ((action == DataObjectChangeAction.Update && !_lastChangeAction.HasValue && _lastChangeAction != DataObjectChangeAction.Create) ||
                            (action == DataObjectChangeAction.Create))
                        {
                            _lastChangeAction = action;
                        }
                        break;

                    case DataObjectChangeAction.Read:

                        // Clear all non-committed instance property changes on read
                        _instancePropertiesChanged.Clear();
                        if (_lastChangeAction.HasValue && _lastChangeAction.Value == DataObjectChangeAction.Property)
                        {
                            _lastChangeAction = null;
                        }

                        // Read is weakest action
                        if (!_lastChangeAction.HasValue)
                        {
                            _lastChangeAction = action;
                        }
                        break;

                    case DataObjectChangeAction.Delete:

                        // Clear all instance and committed property changes on delete
                        _committedPropertiesChanged.Clear();
                        _instancePropertiesChanged.Clear();

                        // Delete is strongest action, unless preceded by Create
                        if (!_lastChangeAction.HasValue || _lastChangeAction.Value != DataObjectChangeAction.Create)
                        {
                            // Delete overrides any other value
                            _lastChangeAction = action;
                        }
                        else
                        {
                            // Delete after Create cancels out all changes
                            _committedPropertiesChanged.Clear();
                            _instancePropertiesChanged.Clear();
                            _lastChangeAction = null;
                        }
                        break;

                    case DataObjectChangeAction.Property:

                        // Add property to instance cache
                        if (!propertyId.HasValue)
                        {
                            throw new ArgumentNullException("propertyId");
                        }
                        if (!_instancePropertiesChanged.Contains(propertyId.Value))
                        {
                            _instancePropertiesChanged.Add(propertyId.Value);
                        }

                        // Instance changes only override read
                        if (!_lastChangeAction.HasValue || _lastChangeAction.Value == DataObjectChangeAction.Read)
                        {
                            _lastChangeAction = action;
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 15
0
 public override void SetDeleted()
 {
     _objectState = DataObjectState.Deleted;
 }
Esempio n. 16
0
 public override void SetNew()
 {
     base.SetNew();
     _objectState = DataObjectState.New;
 }
Esempio n. 17
0
 public void AcceptChanges()
 {
     m_objectState    = DataObjectState.Unchanged;
     m_isSaveRequired = false;
 }
Esempio n. 18
0
 protected BaseMemoryPersistenceObject(Func<IFrozenContext> lazyCtx)
     : base(lazyCtx)
 {
     _objectState = DataObjectState.New;
 }
Esempio n. 19
0
 public OrderDetailEx(Orderdetail oBase, DataObjectState objectState)
     : base(oBase.Createddate, oBase.Createdby, oBase.Lastediteddate, oBase.Lasteditedby, oBase.Orderqty, oBase.Unitprice, oBase.Unitpricediscount, oBase.Orderpriority, oBase.Item, oBase.Orderheader, oBase.Specialoffer)
 {
     Id = oBase.Id;
     ObjectState = objectState;
 }
        /// <summary>
        /// Moves data to a folder and/or state.
        /// <remarks>The collection_id/collection_key parameter means that one can use either one of them - collection_id or collection_key.</remarks>
        /// <remarks>User API key usage permitted. Updates only data that are in a container with an update_data permission (or update_own_data for Data Objects associated with current user).</remarks>
        /// </summary>
        /// <param name="request">Request for querying DataObjects.</param>
        /// <param name="newFolder">Destination folder where data will be moved. If not specified, leaves folder as is.</param>
        /// <param name="newState">State to be set data for specified data. Accepted values: Pending, Moderated. If not specified, leaves state as is.</param>
        /// <returns>Boolen value indicating success of method.</returns>
        public Task<bool> Move(DataObjectSimpleQueryRequest request, string newFolder = null,
            DataObjectState? newState = null)
        {
            if (request.ProjectId == null)
                throw new ArgumentNullException();

            if (request.CollectionId == null && request.CollectionKey == null)
                throw new ArgumentNullException();

            if (request.Limit > MaxVauluesPerRequest || request.Limit < 0)
                throw new ArgumentException();

            var dataIds = request.DataIds == null ? new List<string>() : new List<string>(request.DataIds);
            if (dataIds.Count + (request.DataId != null ? 1 : 0) > MaxVauluesPerRequest)
                throw new ArgumentException();
            if (request.DataId != null)
                dataIds.Add(request.DataId);

            var folders = request.Folders == null ? new List<string>() : new List<string>(request.Folders);
            if (folders.Count + (request.Folder != null ? 1 : 0) >
                MaxVauluesPerRequest)
                throw new ArgumentException();
            if (request.Folder != null)
                folders.Add(request.Folder);

            return _syncanoClient.GetAsync("data.move",
                new
                {
                    project_id = request.ProjectId,
                    collection_id = request.CollectionId,
                    collection_key = request.CollectionKey,
                    data_ids = dataIds.ToArray(),
                    folders = folders.ToArray(),
                    state = request.State.ToString(),
                    filter = request.Filter == null ? null : request.Filter.ToString(),
                    by_user = request.ByUser,
                    limit = request.Limit,
                    new_folder = newFolder,
                    new_state = newState.ToString()
                });
        }
Esempio n. 21
0
 public override void SetUnDeleted()
 {
     _objectState = DataObjectState.Modified;
 }
Esempio n. 22
0
 public override void SetDeleted()
 {
     _objectState = DataObjectState.Deleted;
 }
Esempio n. 23
0
 public override void SetNew()
 {
     base.SetNew();
     _objectState = DataObjectState.New;
 }
Esempio n. 24
0
 public override IEnumerable<IPersistenceObject> FromStream(ZetboxStreamReader sr)
 {
     var baseResult = base.FromStream(sr);
     sr.ReadConverter(i => _objectState = (DataObjectState)i);
     return baseResult;
 }
Esempio n. 25
0
 public override void SetUnmodified()
 {
     _objectState = DataObjectState.Unmodified;
 }
Esempio n. 26
0
 private void SetObjectState(DataObjectState newState)
 {
     var oldValue = this._ObjectState;
     NotifyPropertyChanging("ObjectState", oldValue, newState);
     this._ObjectState = newState;
     if (this.Context != null && newState.In(DataObjectState.Modified, DataObjectState.Deleted))
         this.Context.Internals().SetModified(this);
     NotifyPropertyChanged("ObjectState", oldValue, newState);
 }
Esempio n. 27
0
 public override void SetUnmodified()
 {
     _objectState = DataObjectState.Unmodified;
 }
Esempio n. 28
0
 private void DataObjectChanged(object sender, PropertyChangedEventArgs e)
 {
     State = DataObjectState.Modified;
     _dataObject.PropertyChanged -= DataObjectChanged;
 }
Esempio n. 29
0
 public override void SetNew()
 {
     base.SetNew();
     var oldValue = this._ObjectState;
     NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.New);
     this._ObjectState = DataObjectState.New;
     if (this.Context != null)
         this.Context.Internals().SetModified(this);
     NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.New);
 }
Esempio n. 30
0
 public override void SetUnmodified()
 {
     var oldValue = this._ObjectState;
     NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.Unmodified);
     this._ObjectState = DataObjectState.Unmodified;
     NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.Unmodified);
 }
Esempio n. 31
0
 public override void SetUnDeleted()
 {
     _objectState = DataObjectState.Modified;
 }
Esempio n. 32
0
 /// <summary>
 /// 
 /// </summary>
 protected DataObject()
 {
     m_objectState = DataObjectState.New;
 }
Esempio n. 33
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="session"></param>
 protected DataObject(ISession session)
 {
     m_objectState = DataObjectState.New;
     m_session = session;
 }
Esempio n. 34
0
 public override IEnumerable<IPersistenceObject> FromStream(ZetboxStreamReader sr)
 {
     var baseResult = base.FromStream(sr);
     sr.ReadConverter(i => _ObjectState = (DataObjectState)i);
     sr.ReadConverter(i => ApplyRightsFromStream((API.AccessRights)i));
     return baseResult;
 }
Esempio n. 35
0
 /// <summary>
 ///
 /// </summary>
 protected DataObject()
 {
     m_objectState = DataObjectState.New;
 }
Esempio n. 36
0
 public override void SetUnDeleted()
 {
     var oldValue = this._ObjectState;
     NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.Modified);
     this._ObjectState = DataObjectState.Modified;
     if (this.Context != null)
         this.Context.Internals().SetModified(this);
     NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.Modified);
 }
Esempio n. 37
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="session"></param>
 protected DataObject(ISession session)
 {
     m_objectState = DataObjectState.New;
     m_session     = session;
 }
Esempio n. 38
0
 protected override void SetModified()
 {
     if (this.ObjectState == DataObjectState.Unmodified)
     {
         var oldValue = this._ObjectState;
         NotifyPropertyChanging("ObjectState", oldValue, DataObjectState.Modified);
         this._ObjectState = DataObjectState.Modified;
         NotifyPropertyChanged("ObjectState", oldValue, DataObjectState.Modified);
     }
     // Sadly, this is requiered on _every_ change because some ViewModels
     // rely on the Context.IsModified change event
     // TODO: Improve that!
     if (this.Context != null)
         this.Context.Internals().SetModified(this);
 }
Esempio n. 39
0
 protected override void SetModified()
 {
     _objectState = DataObjectState.Modified;
     if (this.Context != null) this.Context.Internals().SetModified(this);
 }