Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is IList <Dimension>))
            {
                return(false);
            }

            ReadOnlyDimensionList dl2 = (ReadOnlyDimensionList)this;
            IList <Dimension>     dl1 = (IList <Dimension>)obj;

            if (dl1.Count != dl2.Count)
            {
                return(false);
            }

            for (int i = 0; i < dl1.Count; i++)
            {
                Dimension d1 = dl1[i];

                int j = dl2.FindIndex(d1.Name);
                if (j < 0)
                {
                    return(false);
                }

                Dimension d2 = dl2[d1.Name];
                if (d1.Length != d2.Length)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            base.Initialize();

            // Getting initial shape from our neighboors.
            int[] proposedShape      = new int[Rank];
            var   sch                = DataSet.GetSchema(SchemaVersion.Recent);
            ReadOnlyDimensionList dl = this.Dimensions;
            int j = 0;

            foreach (var v in sch.Variables)
            {
                if (v.ID == DataSet.GlobalMetadataVariableID || v.ID == ID)
                {
                    continue;
                }
                for (int k = 0; k < v.Dimensions.Count; k++)
                {
                    var d = v.Dimensions[k];
                    if (dl.Contains(d.Name))
                    {
                        j = dl.FindIndex(d.Name);
                        if (proposedShape[j] < d.Length)
                        {
                            proposedShape[j] = d.Length;
                        }
                    }
                }
            }
            changes.Shape             = proposedShape;
            changes.AffectedRectangle = new Rectangle(new int[Rank], proposedShape);
        }
Ejemplo n.º 3
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;
            }
        }