Exemplo n.º 1
0
        /// <summary>
        /// Saves the Model, first committing changes if ManagedObjectLifetime is true.
        /// </summary>
        protected virtual void BeginSave()
        {
            try
            {
                if (Model is IEnumerable)
                {
                    ListApply();
                }
                else
                {
                    ObjectApply();
                }

                var savable = Model as ISavable;
                if (ManageObjectLifetime)
                {
                    // clone the object if possible
                    ICloneable clonable = Model as ICloneable;
                    if (clonable != null)
                    {
                        savable = (ISavable)clonable.Clone();
                    }

                    //apply changes
                    var undoable = savable as ISupportUndo;
                    if (undoable != null)
                    {
                        undoable.ApplyEdit();
                    }
                }

                savable.Saved += (o, e) =>
                {
                    IsBusy = false;
                    if (e.Error == null)
                    {
                        var result = e.NewObject;
                        var model  = (T)result;
                        OnSaving(model);
                        Model = model;
                    }
                    else
                    {
                        Error = e.Error;
                    }

                    OnSaved();
                };
                Error  = null;
                IsBusy = true;
                savable.BeginSave();
            }
            catch (Exception ex)
            {
                IsBusy = false;
                Error  = ex;
                OnSaved();
            }
        }
        private void RecreateControlPoints()
        {
            System.ICloneable prototype = (System.ICloneable)_controlPointPrototype;

            ControlPoint[] controlPoints = new ControlPoint[4];
            for (int i = 0; i < controlPoints.Length; i++)
            {
                controlPoints[i] = (ControlPoint)prototype.Clone();
            }

            _transformedPoints   = new ControlPointCollection(controlPoints);
            _updateControlPoints = true;

            UpdateControlPointsState();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the Model, first committing changes if ManagedObjectLifetime is true.
        /// </summary>
        protected virtual async System.Threading.Tasks.Task <T> SaveAsync()
        {
            try
            {
                if (Model is IEnumerable)
                {
                    ListApply();
                }
                else
                {
                    ObjectApply();
                }

                var savable = Model as ISavable;
                if (ManageObjectLifetime)
                {
                    // clone the object if possible
                    ICloneable clonable = Model as ICloneable;
                    if (clonable != null)
                    {
                        savable = (ISavable)clonable.Clone();
                    }

                    //apply changes
                    var undoable = savable as ISupportUndo;
                    if (undoable != null)
                    {
                        undoable.ApplyEdit();
                    }
                }

                Error  = null;
                IsBusy = true;
                OnSaving(Model);
                Model = (T)await savable.SaveAsync();

                IsBusy = false;
                OnSaved();
            }
            catch (Exception ex)
            {
                IsBusy = false;
                Error  = ex;
                OnSaved();
            }

            return(Model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Saves the Model, first committing changes if ManagedObjectLifetime is true.
        /// </summary>
        protected virtual T DoSave()
        {
            T result = Model;

            Error = null;
            try
            {
                if (Model is IEnumerable)
                {
                    ListApply();
                }
                else
                {
                    ObjectApply();
                }

                var savable = Model as ISavable;
                if (ManageObjectLifetime)
                {
                    // clone the object if possible
                    ICloneable clonable = Model as ICloneable;
                    if (clonable != null)
                    {
                        savable = (ISavable)clonable.Clone();
                    }

                    //apply changes
                    var undoable = savable as ISupportUndo;
                    if (undoable != null)
                    {
                        undoable.ApplyEdit();
                    }
                }

                result = (T)savable.Save();

                Model = result;
                OnSaved();
            }
            catch (Exception ex)
            {
                Error = ex;
                OnSaved();
            }

            return(result);
        }
Exemplo n.º 5
0
            public override void execute3(RunTimeValueBase thisObj, FunctionDefine functionDefine, SLOT returnSlot,SourceToken token,StackFrame stackframe,out bool success)
            {
                System.ICloneable _this =
                    (System.ICloneable)((LinkSystemObject)((ASBinCode.rtData.rtObjectBase)thisObj).value).GetLinkData();

                try
                {
                    object _result_ = _this.Clone()
                    ;
                    stackframe.player.linktypemapper.storeLinkObject_ToSlot(_result_,functionDefine.signature.returnType,returnSlot,bin,stackframe.player);
                    success = true;
                }
                catch (ASRunTimeException tlc)
                {
                    success = false;
                    stackframe.throwAneException(token,tlc.Message);
                }
                catch (InvalidCastException ic)
                {
                    success = false;
                    stackframe.throwAneException(token,ic.Message);
                }
                catch (ArgumentException a)
                {
                    success = false;
                    stackframe.throwAneException(token,a.Message);
                }
                catch (IndexOutOfRangeException i)
                {
                    success = false;
                    stackframe.throwAneException(token,i.Message);
                }
                catch (NotSupportedException n)
                {
                    success = false;
                    stackframe.throwAneException(token,n.Message);
                }
            }