Esempio n. 1
0
        protected virtual void UpdateChanges(DataSet.Changes changes)
        {
            if (changes == null)
            {
                return;
            }

            if (sourceVariable != null && sourceVariable is IDependantVariable)
            {
                ((IDependantVariable)sourceVariable).UpdateChanges(changes);
            }

            Variable.Changes myChanges = changes.GetVariableChanges(ID);

            /*if (myChanges == null)
             *  return; // doesn't depend*/
            Variable.Changes srcChanges = changes.GetVariableChanges(sourceVariable.ID);
            if (srcChanges == null)
            {
                return;
            }

            bool srcMetadataChanged = srcChanges.MetadataChanges.Count != 0 || srcChanges.MetadataChanges.HasChanges;

            var affectedRectangle = TransformIndexRectangle(srcChanges.AffectedRectangle);

            int[] shape = null;

            if (myChanges == null && affectedRectangle.IsEmpty && !srcMetadataChanged)
            {
                return;                                                                        // no changes
            }
            if (!affectedRectangle.IsEmpty)
            {
                shape = TransformIndexRectangle(new Rectangle(new int[sourceVariable.Rank], srcChanges.Shape)).Shape;
            }

            if (myChanges == null)
            {
                var metadataChanges = metadata.FilterChanges(srcChanges.MetadataChanges);
                if (shape == null)
                {
                    shape = GetShape(); // and affectedRect is not empty
                }
                myChanges = new Changes(Version + 1, GetSchema(SchemaVersion.Committed), metadataChanges, null,
                                        shape, affectedRectangle);
                changes.UpdateChanges(myChanges);
            }
            else
            {
                if (shape != null) // there are changes in source var
                {
                    myChanges.AffectedRectangle = affectedRectangle;
                    myChanges.Shape             = shape;
                }
            }
        }
Esempio n. 2
0
		internal DataSetChangeset(DataSet sds, DataSet.Changes changes, bool initializeAtOnce)
		{
			if (changes == null)
				throw new ArgumentNullException("changes");
			lock (sds)
			{
				this.changes = changes;
				this.dataSet = sds;
				this.changeSetId = sds.Version;// +1;
				this.source = changes.ChangesetSource;

				if (initializeAtOnce)
					Initialize();
			}
		}
Esempio n. 3
0
        /// <summary>
        /// Checks the constraints and throws an exception if the check failed.
        /// </summary>
        /// <exception cref="Exception">Constraints are not satisfied.</exception>
        /// <remarks>
        /// <para>The method checks the constraints and throws an exception if the check failed.</para>
        /// <para>
        /// The constraint of a coordinate system means reversibility of its every axes' data.
        /// Common variable provides an access to its values by an integer index or a vector of indices,
        /// but an axis should allow finding an index (or a vector of indices) by a coordinate value
        /// from that axis. This is a reversed index selection operation which enables retrieving a value
        /// from a variable by its coordinate values in a given coordinate system
        /// (see <see cref="Variable{DataType}.GetValue(object[])"/>).
        /// The constraint in the one-dimensional case is just a claim for data to be strictly monotonic
        /// for numeric and date/time data types, or contain no duplicate values for others
        /// (for instance, strings).
        /// </para>
        /// </remarks>
        /// <exception cref="ConstraintsFailedException"/>
        internal void CheckConstraints(DataSet.Changes changeset)
        {
            ICollection <Variable> myAxes = committed ?
                                            (ICollection <Variable>)roAxes : (ICollection <Variable>)axes;

            if (myAxes == null || myAxes.Count == 0)
            {
                throw new ConstraintsFailedException("Coordinate system must contain at least one axis");
            }

            /*foreach (Variable var in myAxes)
             * {
             *      if (!var.CheckReversibility(changeset.GetVariableChanges(var.ID)))
             *              throw new ConstraintsFailedException("Variable " + var + " is an axis but is not reversible");
             * }*/
        }
Esempio n. 4
0
        /// <summary>
        /// Returns the dimensions list for the coordinate system base on given changeset.
        /// </summary>
        /// <returns></returns>
        public ReadOnlyDimensionList GetDimensions(DataSet.Changes changeset)
        {
            DimensionList          dlist  = new DimensionList();
            IEnumerable <Variable> myAxes = committed ?
                                            (IEnumerable <Variable>)roAxes : (IEnumerable <Variable>)axes;

            foreach (Variable a in myAxes)
            {
                var vc = changeset.GetVariableChanges(a.ID);
                ReadOnlyDimensionList list = vc == null?a.GetDimensions(SchemaVersion.Committed) :
                                                 vc.GetDimensionList();

                dlist.AddRange(list);
            }
            return(new ReadOnlyDimensionList(dlist));
        }
Esempio n. 5
0
        internal DataSetChangeset(DataSet sds, DataSet.Changes changes, bool initializeAtOnce)
        {
            if (changes == null)
            {
                throw new ArgumentNullException("changes");
            }
            lock (sds)
            {
                this.changes     = changes;
                this.dataSet     = sds;
                this.changeSetId = sds.Version;                // +1;
                this.source      = changes.ChangesetSource;

                if (initializeAtOnce)
                {
                    Initialize();
                }
            }
        }
Esempio n. 6
0
        protected override void UpdateChanges(DataSet.Changes changes)
        {
            base.UpdateChanges(changes);

            Variable.Changes varChanges = changes.GetVariableChanges(ID);
            if (varChanges != null && varChanges.MetadataChanges.ContainsKey(StriddenVariableKeys.KeyForOrigin))
            {
                int[]  prOrigin;
                object mvalue = varChanges.MetadataChanges[StriddenVariableKeys.KeyForOrigin];
                if (mvalue == null)
                {
                    prOrigin = null;
                }
                else
                {
                    int[] t = mvalue as int[];
                    if (t == null)
                    {
                        throw new ConstraintsFailedException("Value for attribute \"" + StriddenVariableKeys.KeyForOrigin + "\" must be int[" + SourceVariable.Rank + "]");
                    }
                    if (t.Length != SourceVariable.Rank)
                    {
                        throw new ConstraintsFailedException("Value for attribute \"" + StriddenVariableKeys.KeyForOrigin + "\" must be int[" + SourceVariable.Rank + "]");
                    }
                    prOrigin = t;
                }
                try
                {
                    InnerUpdateChanges(changes, prOrigin);
                }
                catch (Exception ex)
                {
                    throw new ConstraintsFailedException(StriddenVariableKeys.KeyForOrigin + " attribute value is incorrect", ex);
                }
            }
        }
Esempio n. 7
0
 public DataSetCommittingEventArgs(DataSet sds, DataSet.Changes changes)
 {
     this.sds = sds;
     this.cancel = false;
     this.changes = changes;
 }
Esempio n. 8
0
        protected override void OnPrecommit(DataSet.Changes changes)
        {
            if (!_IsInitialized)
            {
                return;
            }

            DataSetChangeset changeSet = changes.GetChangeset();

            if (changeSet.AddedVariables != null && changeSet.AddedVariables.Length != 0)
            {
                throw new DataSetException(@"Addition of new variables isn't supported.");
            }
            foreach (var i in changeSet.UpdatedVariables)
            {
                if (i.ChangeType == Variable.ChangeTypes.MetadataUpdated)
                {
                    throw new DataSetException(@"Metadata modification isn't supported.");
                }
                var _shape = this.variables[i.InitialSchema.Name].GetShape();
                if (_shape.Length != i.Shape.Length)
                {
                    throw new DataSetException(@"Shape modification isn't supported.");
                }
                for (int j = 0; j < _shape.Length; ++j)
                {
                    if (_shape[j] != i.Shape[j])
                    {
                        throw new DataSetException(@"Shape modification isn't supported.");
                    }
                }
                var origin = i.AffectedRectangle.Origin;
                var shape  = i.AffectedRectangle.Shape;
                if (origin.Length != _shape.Length || shape.Length != _shape.Length)
                {
                    throw new DataSetException("Wrong number of dimensions.");
                }
                for (int j = 1; j < shape.Length; ++j)
                {
                    if (_shape[j] != shape[j] || origin[j] != 0)
                    {
                        throw new DataSetException("Can only part data by its 1st dimension.");
                    }
                }
                if (origin[0] + shape[0] > _shape[0])
                {
                    throw new DataSetException(@"Can't write more data than there is space reserved for.");
                }
                if (this.variables[i.InitialSchema.Name].Dimensions.Count == 1)
                {
                    //(origin[0] != 0 || shape[0] != _shape[0])) throw new DataSetException(@"Can't part single-dimensional data");
                    int  datalen    = shape[0];
                    int  datumSize  = datumSizeDictionary[i.InitialSchema.Name];
                    int  byteLen    = datalen * datumSize;
                    long byteOrigin = origin[0] * datumSize;
                    if (byteOrigin % 512 != 0 || (origin[0] + datalen != _shape[0] && byteLen % 512 != 0))
                    {
                        throw new ArgumentException(@"Can write only full 512 byte pages of single-dimensional data starting at a 512 bytes aligned position.");
                    }
                }
            }

            base.OnPrecommit(changes);
        }
Esempio n. 9
0
 internal DataSetChangeset(DataSet sds, DataSet.Changes changes)
     : this(sds, changes, false)
 {
 }
Esempio n. 10
0
        /// <summary>
        /// Completely updates shape and affected rect when "origin" changes and
        /// possibly source variable changed.
        /// </summary>
        /// <param name="changes"></param>
        /// <param name="origin"></param>
        private void InnerUpdateChanges(DataSet.Changes changes, int[] origin)
        {
            int srank = SourceVariable.Rank;

            if (origin == null)
            {
                origin = new int[srank];
            }
            if (origin.Length != srank)
            {
                throw new ArgumentException("Wrong origin indices");
            }

            int[]            sourceShape;
            Variable.Changes srcChanges = changes.GetVariableChanges(SourceVariable.ID);
            if (srcChanges == null)
            {
                sourceShape = SourceVariable.GetShape();
            }
            else
            {
                sourceShape = srcChanges.Shape;
            }

            for (int i = 0; i < srank; i++)
            {
                if (origin[i] < 0)
                {
                    throw new ArgumentOutOfRangeException("origin is negative");
                }
                if ((count[i] == 0) && (origin[i] != this.origin[i]))
                {
                    throw new ArgumentException("Can't set origin[" + i + "]new value because count[" + i + "]=0");
                }
                if ((count[i] > 0) &&
                    ((origin[i] + stride[i] * (count[i] - 1)) >= sourceShape[i]))
                {
                    //	|| (origin[i] > sourceShape[i])))
                    //if ((((count[i] > 0) && (origin[i] + stride[i] * (count[i] - 1)) >= sourceShape[i]))
                    //    || ((count[i] > 0) && origin[i] > sourceShape[i]))
                    throw new ArgumentException("Source variable does not contain this range of data");
                }
            }

            //**********************************
            int rank = Rank;

            int[] aorigin = new int[rank];
            int[] ashape  = new int[rank];
            for (int i = 0, k = 0; i < stride.Length; i++)
            {
                if (stride[i] > 0)
                {
                    if (count[i] > 0)
                    {
                        ashape[k] = count[i];
                    }
                    else
                    {
                        int t = (sourceShape[i] - origin[i] - 1) / stride[i];
                        if (t < 0)
                        {
                            t = 0;
                        }
                        if (sourceShape[i] > origin[i])
                        {
                            ashape[k] = 1 + t;
                        }
                        else
                        {
                            ashape[k] = 0;
                        }
                    }
                    k++;
                }
            }

            Rectangle AffectedRect = new Rectangle(aorigin, ashape);
            /***********************************************************************/
            // Making changes
            var myChanges = changes.GetVariableChanges(ID);

            myChanges.Shape             = ashape;
            myChanges.AffectedRectangle = AffectedRect;
            changes.UpdateChanges(myChanges);
        }
Esempio n. 11
0
 public DataSetCommittingEventArgs(DataSet sds, DataSet.Changes changes)
 {
     this.sds     = sds;
     this.cancel  = false;
     this.changes = changes;
 }
Esempio n. 12
0
 void IDependantVariable.UpdateChanges(DataSet.Changes changes)
 {
     UpdateChanges(changes);
 }
Esempio n. 13
0
        protected virtual void UpdateChanges(DataSet.Changes changes)
        {
            if (changes == null)
            {
                return;
            }

            // Building proposed changes for this variable depending
            // on shape of other variables of the same data set
            // sharing the same dimensions.

            bool shapeUpdated = false;
            int  rank         = Rank;

            int[] proposedShape = null;

            ReadOnlyDimensionList dl = this.Dimensions;
            int j = 0;

            foreach (var v in changes.Variables)
            {
                if (v.ID == DataSet.GlobalMetadataVariableID || v.ID == ID)
                {
                    continue;
                }
                var vch = changes.GetVariableChanges(v.ID);
                if (vch == null)
                {
                    continue;
                }

                if (proposedShape == null)
                {
                    proposedShape = this.GetShape(); // committed shape to update
                }
                var dims = vch.InitialSchema.Dimensions.AsNamesArray();
                for (int k = 0; k < vch.Shape.Length; k++)
                {
                    string name = dims[k];
                    int    d    = vch.Shape[k];
                    if (dl.Contains(name))
                    {
                        j = dl.FindIndex(name);
                        if (proposedShape[j] < d)
                        {
                            proposedShape[j] = d;
                            shapeUpdated     = true;
                        }
                    }
                }
            }
            if (!shapeUpdated)
            {
                return;
            }

            Variable.Changes myChanges = changes.GetVariableChanges(ID);
            if (myChanges != null)
            {
                shapeUpdated = false;
                int[] prevPropShape = myChanges.Shape;
                for (int i = 0; i < rank; i++)
                {
                    if (proposedShape[i] != prevPropShape[i])
                    {
                        shapeUpdated = true;
                        break;
                    }
                }
                if (!shapeUpdated)
                {
                    return;
                }
            }

            int[] ar_origin  = new int[rank];
            int[] ar_shape   = new int[rank];
            bool  hadChanges = false;

            for (int i = 0; i < rank; i++)
            {
                if (proposedShape[i] == shape[i] || // no changes for dim #i
                    hadChanges)
                {
                    ar_origin[i] = 0;
                    ar_shape[i]  = proposedShape[i];
                }
                else // changes for dim #i
                {
                    hadChanges   = true;
                    ar_origin[i] = shape[i];
                    ar_shape[i]  = proposedShape[i] - shape[i];
                }
            }

            if (myChanges == null)
            {
                var ar    = new Rectangle(ar_origin, ar_shape);
                var shape = proposedShape;

                myChanges = new Changes(Version + 1, GetSchema(SchemaVersion.Committed), new MetadataDictionary(),
                                        null, shape, ar);

                changes.UpdateChanges(myChanges);
            }
            else
            {
                myChanges.AffectedRectangle = new Rectangle(ar_origin, ar_shape);
                myChanges.Shape             = proposedShape;
            }
        }