Exemplo n.º 1
0
        public void PointsToLines()
        {
            var polygon = ShapeMaker.U(Vector3.Origin, new Vector3(40.0, 40.0), 10.0);
            var points  = polygon.Vertices;

            Assert.Equal(8.0, Shaper.PointsToLines(points.ToList(), true).Count);
        }
Exemplo n.º 2
0
        public void NonIntersecting()
        {
            var polygon =
                new Polygon
                (
                    new[]
            {
                Vector3.Origin,
                new Vector3(8.0, 0.0),
                new Vector3(8.0, 3.0),
                new Vector3(0.0, 3.0)
            }
                );
            var nearPolygon =
                new Polygon
                (
                    new[]
            {
                new Vector3(5.0, 0.0),
                new Vector3(8.0, 0.0),
                new Vector3(8.0, 20.0),
                new Vector3(5.0, 20.0)
            }
                );
            var polygons = Shaper.NearPolygons(polygon, nearPolygon, true);

            polygons = Shaper.NonIntersecting(polygon.ToList(), polygons);
            Assert.Equal(24, polygons.Count);
        }
        private void SetShaper(Shaper<RecordState> shaper, CoordinatorFactory<RecordState> coordinatorFactory, int depth)
        {
            _shaper = shaper;
            _coordinatorFactory = coordinatorFactory;
            _dataRecord = new BridgeDataRecord(shaper, depth);

            // To determine whether there are any rows for this coordinator at this place in 
            // the root enumerator, we pretty much just look at it's current record (we'll read 
            // one if there isn't one waiting) and if it matches our coordinator, we've got rows.
            _hasRows = false;

            if (!_shaper.DataWaiting)
            {
                _shaper.DataWaiting = _shaper.RootEnumerator.MoveNext();
            }

            if (_shaper.DataWaiting)
            {
                var currentRecord = _shaper.RootEnumerator.Current;

                if (null != currentRecord)
                {
                    _hasRows = (currentRecord.CoordinatorFactory == _coordinatorFactory);
                }
            }

            // Once we've created the root enumerator, we can get the default record state
            _defaultRecordState = coordinatorFactory.GetDefaultRecordState(_shaper);
            Debug.Assert(null != _defaultRecordState, "no default?");
        }
 internal BridgeDataRecord(Shaper<RecordState> shaper, int depth)
 {
     //Contract.Requires(null != shaper);
     Shaper = shaper;
     Depth = depth;
     // Rest of state is set through the SetRecordSource method.
 }
Exemplo n.º 5
0
        public void SortRadial()
        {
            var points =
                new List <Vector3>
            {
                new Vector3(13.0, 4.0),
                new Vector3(13.0, 4.0),
                new Vector3(13.0, 4.0),
                new Vector3(6.0, 11.0),
                new Vector3(6.0, 7.0),
                new Vector3(2.0, 7.0),
                new Vector3(2.0, 4.0),
                new Vector3(9.0, 0.0),
                new Vector3(9.0, 4.0),
                new Vector3(13.0, 7.0),
                new Vector3(9.0, 7.0),
                new Vector3(9.0, 11.0),
                new Vector3(6.0, 4.0),
                new Vector3(6.0, 0.0),
            };
            var sorted = Shaper.SortRadial(points, new Vector3(7.5, 5.5));

            Assert.Equal(12, sorted.Count());
            Assert.Equal(6.0, sorted.First().X);
            Assert.Equal(0.0, sorted.First().Y);
            Assert.Equal(9.0, sorted.Last().X);
            Assert.Equal(0.0, sorted.Last().Y);
        }
 internal BridgeDataRecord(Shaper <RecordState> shaper, int depth)
 {
     DebugCheck.NotNull(shaper);
     _shaper = shaper;
     Depth   = depth;
     // Rest of state is set through the SetRecordSource method.
 }
Exemplo n.º 7
0
        /// <summary>Releases the unmanaged resources used by the <see cref="T:System.Data.Entity.Core.Objects.ObjectResult`1" /> and optionally releases the managed resources.</summary>
        /// <param name="disposing">true to release managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            var reader = _reader;

            _reader = null;
            _nextResultGenerator = null;

            if (reader != null && _readerOwned)
            {
                reader.Dispose();
                if (_onReaderDispose != null)
                {
                    _onReaderDispose(this, new EventArgs());
                    _onReaderDispose = null;
                }
            }
            if (_shaper != null)
            {
                // This case includes when the ObjectResult is disposed before it
                // created an ObjectQueryEnumeration; at this time, the connection can be released
                if (_shaper.Context != null &&
                    _readerOwned &&
                    _shouldReleaseConnection)
                {
                    _shaper.Context.ReleaseConnection();
                }
                _shaper = null;
            }
        }
        private void SetShaper(Shaper <RecordState> shaper, CoordinatorFactory <RecordState> coordinatorFactory, int depth)
        {
            Shaper             = shaper;
            CoordinatorFactory = coordinatorFactory;
            DataRecord         = new BridgeDataRecord(shaper, depth);

            // To determine whether there are any rows for this coordinator at this place in
            // the root enumerator, we pretty much just look at it's current record (we'll read
            // one if there isn't one waiting) and if it matches our coordinator, we've got rows.
            _hasRows = false;

            if (!Shaper.DataWaiting)
            {
                Shaper.DataWaiting = Shaper.RootEnumerator.MoveNext();
            }
            if (Shaper.DataWaiting)
            {
                RecordState currentRecord = Shaper.RootEnumerator.Current;

                if (null != currentRecord)
                {
                    _hasRows = (currentRecord.CoordinatorFactory == CoordinatorFactory);
                }
            }

            // Once we've created the root enumerator, we can get the default record state
            DefaultRecordState = coordinatorFactory.GetDefaultRecordState(Shaper);
            Debug.Assert(null != DefaultRecordState, "no default?");
        }
Exemplo n.º 9
0
        private void Construct(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            Title       = "Freehand Pen";
            ToolTipText = "Draw the symbol of the object which should be created.";

            SmallIcon = global::Dataweb.NShape.Properties.Resources.FreehandIconSmall;
            SmallIcon.MakeTransparent(Color.Fuchsia);
            LargeIcon = global::Dataweb.NShape.Properties.Resources.FreehandIconLarge;
            LargeIcon.MakeTransparent(Color.Fuchsia);

            polygone      = new PathFigureShape();
            strokeSet     = new StrokeSequence();
            currentStroke = new Stroke();
            shaper        = new Shaper();

            timer          = new Timer();
            timer.Enabled  = false;
            timer.Interval = timeOut;
            timer.Elapsed += timer_Tick;

            this.project           = project;
            project.LibraryLoaded += project_LibraryLoaded;
            RegisterFigures();
        }
Exemplo n.º 10
0
        public override void Dispose()
        {
            // Technically, calling GC.SuppressFinalize is not required because the class does not
            // have a finalizer, but it does no harm, protects against the case where a finalizer is added
            // in the future, and prevents an FxCop warning.
            GC.SuppressFinalize(this);

            var reader = _reader;

            _reader = null;
            _nextResultGenerator = null;

            if (null != reader && _readerOwned)
            {
                reader.Dispose();
                if (_onReaderDispose != null)
                {
                    _onReaderDispose(this, new EventArgs());
                    _onReaderDispose = null;
                }
            }
            if (_shaper != null)
            {
                // This case includes when the ObjectResult is disposed before it
                // created an ObjectQueryEnumeration; at this time, the connection can be released
                if (_shaper.Context != null && _readerOwned)
                {
                    _shaper.Context.ReleaseConnection();
                }
                _shaper = null;
            }
        }
Exemplo n.º 11
0
        public void NearPolygons()
        {
            var polygon =
                new Polygon
                (
                    new[]
            {
                Vector3.Origin,
                new Vector3(8.0, 0.0),
                new Vector3(8.0, 3.0),
                new Vector3(0.0, 3.0)
            }
                );
            var nearPolygon =
                new Polygon
                (
                    new[]
            {
                new Vector3(5.0, 0.0),
                new Vector3(8.0, 0.0),
                new Vector3(8.0, 20.0),
                new Vector3(5.0, 20.0)
            }
                );
            var polygons = Shaper.NearPolygons(polygon, nearPolygon, true);

            Assert.Equal(32, polygons.Count);
        }
Exemplo n.º 12
0
        public void ExpandToArea()
        {
            var polygon = new Polygon
                          (
                new[]
            {
                new Vector3(),
                new Vector3(4, 0),
                new Vector3(4, 4),
                new Vector3(0, 4)
            }
                          );
            var within = new Polygon
                         (
                new[]
            {
                new Vector3(-5, -5),
                new Vector3(20, -5),
                new Vector3(20, 30),
                new Vector3(-5, 30)
            }
                         );
            var among = new List <Polygon>
            {
                new Polygon(
                    new []
                {
                    new Vector3(3, 1),
                    new Vector3(7, 1),
                    new Vector3(7, 5),
                    new Vector3(3, 5)
                }),
                new Polygon(
                    new[]
                {
                    new Vector3(1, 3),
                    new Vector3(2, 3),
                    new Vector3(2, 6),
                    new Vector3(1, 6),
                })
            };
            var coordGrid = new CoordGrid(within);

            polygon = Shaper.ExpandtoArea(polygon, 20, within, among);
            Debug.WriteLine(polygon.Area);
            var spaces = new List <Space>
            {
                new Space(polygon, 3.0, 2, new Material("blue", Palette.Blue)),
                new Space(within, 3.0, 0.1, new Material("aqua", Palette.Aqua)),
                new Space(among[0], 3.0, 2, new Material("yellow", Palette.Yellow)),
                new Space(among[1], 3.0, 2, new Material("green", Palette.Green))
            };
            var model = new Model();

            foreach (Space space in spaces)
            {
                model.AddElement(space);
            }
            model.SaveGlb("../../../../expandToArea.glb");
        }
Exemplo n.º 13
0
        internal ObjectResult <TResultType> Execute <TResultType>(ObjectContext context, ObjectParameterCollection parameterValues)
        {
            DbDataReader storeReader = null;

            try
            {
                // create entity command (just do this to snarf store command)
                EntityCommandDefinition commandDefinition = (EntityCommandDefinition)this.CommandDefinition;
                EntityCommand           entityCommand     = new EntityCommand((EntityConnection)context.Connection, commandDefinition);

                // pass through parameters and timeout values
                if (context.CommandTimeout.HasValue)
                {
                    entityCommand.CommandTimeout = context.CommandTimeout.Value;
                }

                if (parameterValues != null)
                {
                    foreach (ObjectParameter parameter in parameterValues)
                    {
                        int index = entityCommand.Parameters.IndexOf(parameter.Name);

                        if (index != -1)
                        {
                            entityCommand.Parameters[index].Value = parameter.Value ?? DBNull.Value;
                        }
                    }
                }

                // acquire store reader
                storeReader = commandDefinition.ExecuteStoreCommands(entityCommand, CommandBehavior.Default);

                ShaperFactory <TResultType> shaperFactory = (ShaperFactory <TResultType>) this.ResultShaperFactory;
                Shaper <TResultType>        shaper        = shaperFactory.Create(storeReader, context, context.MetadataWorkspace, this.MergeOption, true);

                // create materializer delegate
                TypeUsage resultItemEdmType;

                if (ResultType.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
                {
                    resultItemEdmType = ((CollectionType)ResultType.EdmType).TypeUsage;
                }
                else
                {
                    resultItemEdmType = ResultType;
                }

                return(new ObjectResult <TResultType>(shaper, this._singleEntitySet, resultItemEdmType));
            }
            catch (Exception)
            {
                if (null != storeReader)
                {
                    // Note: The caller is responsible for disposing reader if creating
                    // the enumerator fails.
                    storeReader.Dispose();
                }
                throw;
            }
        }
Exemplo n.º 14
0
 internal ObjectResult(
     Shaper <T> shaper, EntitySet singleEntitySet, TypeUsage resultItemType, bool readerOwned, bool shouldReleaseConnection)
     : this(
         shaper, singleEntitySet, resultItemType, readerOwned, shouldReleaseConnection, nextResultGenerator : null,
         onReaderDispose : null)
 {
 }
        internal virtual IDbEnumerator <T> GetDbEnumerator()
        {
            this.EnsureCanEnumerateResults();
            Shaper <T> shaper = this._shaper;

            this._shaper = (Shaper <T>)null;
            return(shaper.GetEnumerator());
        }
Exemplo n.º 16
0
        public void PolygonRegular()
        {
            var polygon = Shaper.PolygonRegular(new Vector3(10.0, 11.0), 10, 6);

            Assert.Equal(6.0, polygon.Vertices.Count());
            Assert.Equal(10.0, polygon.Centroid.X, 10);
            Assert.Equal(11.0, polygon.Centroid.Y, 10);
        }
Exemplo n.º 17
0
 internal BridgeDataRecord(Shaper <RecordState> shaper, int depth)
     : base()
 {
     Debug.Assert(null != shaper, "null shaper?");
     Shaper = shaper;
     Depth  = depth;
     // Rest of state is set through the SetRecordSource method.
 }
Exemplo n.º 18
0
        public void ExpandToArea()
        {
            var polygon = new Polygon
                          (
                new[]
            {
                Vector3.Origin,
                new Vector3(4.0, 0.0),
                new Vector3(4.0, 4.0),
                new Vector3(0.0, 4.0)
            }
                          );
            var within = new Polygon
                         (
                new[]
            {
                new Vector3(1.0, 1.0),
                new Vector3(8.0, 1.0),
                new Vector3(8.0, 8.0),
                new Vector3(1.0, 8.0)
            }
                         );
            var among = new List <Polygon>
            {
                new Polygon(
                    new []
                {
                    new Vector3(3.0, 1.0),
                    new Vector3(7.0, 1.0),
                    new Vector3(7.0, 5.0),
                    new Vector3(3.0, 5.0)
                }),
                new Polygon(
                    new[]
                {
                    new Vector3(1.0, 3.0),
                    new Vector3(2.0, 3.0),
                    new Vector3(2.0, 6.0),
                    new Vector3(1.0, 6.0),
                })
            };

            polygon = Shaper.ExpandtoArea(polygon, 20, within, among);
            var spaces = new List <Space>
            {
                new Space(polygon, 3.0, 0.0, new Material("blue", Palette.Blue)),
                new Space(within, 0.1, 0.0, new Material("aqua", Palette.Aqua)),
                new Space(among[0], 3.0, 0.0, new Material("yellow", Palette.Yellow)),
                new Space(among[1], 3.0, 0.0, new Material("green", Palette.Green))
            };
            var model = new Model();

            foreach (Space space in spaces)
            {
                model.AddElement(space);
            }
            model.SaveGlb("../../../../expandToArea.glb");
        }
Exemplo n.º 19
0
        public void PolygonBox()
        {
            var vertices = Shaper.PolygonBox(10.0, 10.0).Vertices;

            Assert.Contains(vertices, p => p.X == 0.0 && p.Y == 0.0);
            Assert.Contains(vertices, p => p.X == 10.0 && p.Y == 0.0);
            Assert.Contains(vertices, p => p.X == 10.0 && p.Y == 10.0);
            Assert.Contains(vertices, p => p.X == 0.0 && p.Y == 10.0);
        }
Exemplo n.º 20
0
        public Tower MakeTower()
        {
            var tower = new Tower()
            {
                Color       = Palette.Aqua,
                Elevation   = -8.0,
                Floors      = 20,
                HeightLimit = 80.0,
                Perimeter   = Shaper.Rectangle(60.0, 20.0),
                StoryHeight = 4.0,
                TargetArea  = 24000.0
            };

            tower.Stack();
            var entry = new Room()
            {
                Height = 6.0
            };

            tower.SetStoryHeight(0, 8.0);
            tower.Stories[0].Color = Palette.Granite;
            entry.SetPerimeter(new Vector3(30.0, -0.1), new Vector3(30.0, 6.0), 2.0);
            tower.Stories[1].AddCorridor(entry);
            var coreShaft = new Room()
            {
                Perimeter = Shaper.Rectangle(5.0, 8.0, new Vector3(27.5, 6.0))
            };

            for (int i = 1; i < 3; i++)
            {
                tower.Stories[i].Color = Palette.Green;
                tower.SetStoryHeight(i, 6.0);
                tower.Stories[i].RoomsByDivision(4, 1, 5.5, 0.5, "Retail", Palette.Lime);
                tower.Stories[i].AddExclusion(coreShaft);
            }
            var corridor = new Room()
            {
                Height = 3.5
            };

            corridor.SetPerimeter(new Vector3(0.5, 10.0), new Vector3(59.5, 10), 2.0);
            for (int i = 3; i < tower.Stories.Count; i++)
            {
                tower.Stories[i].RoomsByDivision(4, 2, 3.5, 0.5, "Office", Palette.Teal);
                tower.Stories[i].AddCorridor(corridor);
                tower.Stories[i].AddExclusion(coreShaft);
            }
            tower.AddCore(coreShaft.Perimeter, 0, 3.0, Palette.Granite);
            var model = new Model();

            foreach (Space space in tower.Spaces)
            {
                model.AddElement(space);
            }
            //model.ToGlTF("../../../../Tower.glb");
            return(tower);
        }
Exemplo n.º 21
0
        public void Initialize3D()
        {
            mover = new Mover();
            mover.AllowFreeMove = false;

            shaper = new Shaper();

            Renderer.ActiveEditor = shaper;
        }
Exemplo n.º 22
0
        /// <summary>
        /// The TestFunction2 function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A TestFunction2Outputs instance containing computed results and the model with any new elements.</returns>
        public static TestFunction2Outputs Execute(Dictionary <string, Model> inputModels, TestFunction2Inputs input)
        {
            /// Your code here.
            List <ModelCurve> modelCurves = new List <ModelCurve>();
            List <Curve>      Curves      = new List <Curve>();
            List <Polygon>    Polygons    = new List <Polygon>();

            var bndry     = input.Outline;
            var spine     = bndry.Spine();
            var jig       = bndry.Jigsaw();
            var skel      = bndry.Skeleton();
            var height    = 1.0;
            var volume    = input.Length * input.Width * height;
            var output    = new TestFunction2Outputs(1.0);
            var rectangle = Polygon.Rectangle(input.Length, input.Width);
            var mass      = new Mass(bndry, height);

            Polygons.AddRange(new[] { bndry });
            var bbox = new List <Polygon>();

            foreach (var item in jig)
            {
                bbox.Add(item.AlignedBox());
            }
            var clips = new List <Polygon>();

            for (int i = 0; i < bbox.Count - 1; i++)
            {
                clips.AddRange(Shaper.Differences(bbox[i].ToList(), bbox[i + 1].ToList()));
            }

            var masses = new List <Mass>();

            for (var i = 0; i < clips.Count; i++)
            {
                masses.Add(new Mass(clips[i], 1 + i, name: i.ToString()));
            }

            // Curves.AddRange(spine);
            // Curves.AddRange(jig);
            Curves.AddRange(clips);
            // Curves.AddRange(bbox);

            foreach (var crv in Curves)
            {
                modelCurves.Add(new ModelCurve(crv));
            }

            foreach (var crv in Polygons)
            {
                modelCurves.Add(new ModelCurve(crv));
            }
            // modelCurves[0].
            output.Model.AddElements(modelCurves);
            output.Model.AddElements(masses);
            return(output);
        }
Exemplo n.º 23
0
        private KeyValuePair <Shaper <RecordState>, CoordinatorFactory <RecordState> > CreateShaperInfo(
            DbDataReader storeDataReader,
            ColumnMap columnMap,
            MetadataWorkspace workspace)
        {
            Shaper <RecordState> key = this._translator.TranslateColumnMap <RecordState>(columnMap, workspace, (SpanIndex)null, MergeOption.NoTracking, true, true).Create(storeDataReader, (ObjectContext)null, workspace, MergeOption.NoTracking, true, true);

            return(new KeyValuePair <Shaper <RecordState>, CoordinatorFactory <RecordState> >(key, key.RootCoordinator.TypedCoordinatorFactory));
        }
        /// <summary>
        /// Constructor used by the ResultColumn when doing GetValue, and by the Create factory
        /// method.
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="isRoot"></param>
        /// <param name="nextResultShaperInfos">enumrator of the shapers for NextResult() calls</param>
        internal BridgeDataReader(Shaper<RecordState> shaper, CoordinatorFactory<RecordState> coordinatorFactory, int depth, IEnumerator<KeyValuePair<Shaper<RecordState>, CoordinatorFactory<RecordState>>> nextResultShaperInfos)
            : base() {
            Debug.Assert(null != shaper, "null shaper?");
            Debug.Assert(null != coordinatorFactory, "null coordinatorFactory?");
            Debug.Assert(depth == 0 || nextResultShaperInfos == null, "Nested data readers should not have multiple result sets.");

            NextResultShaperInfoEnumerator = nextResultShaperInfos != null ? nextResultShaperInfos : null;
            SetShaper(shaper, coordinatorFactory, depth);
        }
Exemplo n.º 25
0
        public void RectangleByRatio()
        {
            var polygon = Shaper.RectangleByRatio(2.0);

            Assert.Equal(2.0, polygon.Area());
            Assert.Contains(polygon.Vertices, p => p.X == 0.0 && p.Y == 0.0);
            Assert.Contains(polygon.Vertices, p => p.X == 1.0 && p.Y == 0.0);
            Assert.Contains(polygon.Vertices, p => p.X == 1.0 && p.Y == 2.0);
            Assert.Contains(polygon.Vertices, p => p.X == 0.0 && p.Y == 2.0);
        }
Exemplo n.º 26
0
        public void RoomsByDivision()
        {
            var roomGroup = new RoomGroup()
            {
                Perimeter = Shaper.PolygonBox(60.0, 20.0)
            };

            roomGroup.RoomsByDivision(4, 2);
            Assert.Equal(8.0, roomGroup.Rooms.Count, 10);
        }
Exemplo n.º 27
0
        public void AreaPlaced()
        {
            var roomGroup = new RoomGroup()
            {
                Perimeter = Shaper.PolygonBox(60.0, 20.0)
            };

            roomGroup.RoomsByDivision(4, 2);
            Assert.Equal(1200.0, roomGroup.AreaPlaced, 10);
        }
Exemplo n.º 28
0
 internal ObjectResult(Shaper <T> shaper, EntitySet singleEntitySet, TypeUsage resultItemType, bool readerOwned, NextResultGenerator nextResultGenerator, Action <object, EventArgs> onReaderDispose)
 {
     _shaper              = shaper;
     _reader              = _shaper.Reader;
     _singleEntitySet     = singleEntitySet;
     _resultItemType      = resultItemType;
     _readerOwned         = readerOwned;
     _nextResultGenerator = nextResultGenerator;
     _onReaderDispose     = onReaderDispose;
 }
Exemplo n.º 29
0
        public void PolygonByArea()
        {
            var polygon = Shaper.PolygonByArea(9.0, 1.0, new Vector3(10.0, 10.0));

            Assert.Equal(9.0, polygon.Area);
            Assert.Contains(polygon.Vertices, p => p.X == 10.0 && p.Y == 10.0);
            Assert.Contains(polygon.Vertices, p => p.X == 13.0 && p.Y == 13.0);
            Assert.Contains(polygon.Vertices, p => p.X == 10.0 && p.Y == 13.0);
            Assert.Contains(polygon.Vertices, p => p.X == 13.0 && p.Y == 13.0);
        }
 internal ObjectResult(
     Shaper <T> shaper,
     EntitySet singleEntitySet,
     TypeUsage resultItemType,
     bool readerOwned,
     bool shouldReleaseConnection,
     DbCommand command = null)
     : this(shaper, singleEntitySet, resultItemType, readerOwned, shouldReleaseConnection, (NextResultGenerator)null, (Action <object, EventArgs>)null, command)
 {
 }
        /// <summary>
        /// Constructor used by the ResultColumn when doing GetValue, and by the Create factory
        /// method.
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="isRoot"></param>
        /// <param name="nextResultShaperInfos">enumrator of the shapers for NextResult() calls</param>
        internal BridgeDataReader(Shaper <RecordState> shaper, CoordinatorFactory <RecordState> coordinatorFactory, int depth, IEnumerator <KeyValuePair <Shaper <RecordState>, CoordinatorFactory <RecordState> > > nextResultShaperInfos)
            : base()
        {
            Debug.Assert(null != shaper, "null shaper?");
            Debug.Assert(null != coordinatorFactory, "null coordinatorFactory?");
            Debug.Assert(depth == 0 || nextResultShaperInfos == null, "Nested data readers should not have multiple result sets.");

            NextResultShaperInfoEnumerator = nextResultShaperInfos != null ? nextResultShaperInfos : null;
            SetShaper(shaper, coordinatorFactory, depth);
        }
Exemplo n.º 32
0
        public void SizeXY()
        {
            var roomGroup = new RoomGroup()
            {
                Perimeter = Shaper.PolygonBox(60.0, 20.0)
            };

            Assert.Equal(60.0, roomGroup.SizeX, 10);
            Assert.Equal(20.0, roomGroup.SizeY, 10);
        }
Exemplo n.º 33
0
        internal BridgeDataReader(
            Shaper<RecordState> shaper, CoordinatorFactory<RecordState> coordinatorFactory, int depth,
            IEnumerator<KeyValuePair<Shaper<RecordState>, CoordinatorFactory<RecordState>>> nextResultShaperInfos)
        {
            //Contract.Requires(null != shaper);
            //Contract.Requires(null != coordinatorFactory);
            //Contract.Requires(depth == 0 || nextResultShaperInfos == null, "Nested data readers should not have multiple result sets.");

            _nextResultShaperInfoEnumerator = nextResultShaperInfos;
            SetShaper(shaper, coordinatorFactory, depth);
        }
Exemplo n.º 34
0
        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        public IEnumerator <T> GetEnumerator()
        {
            EnsureCanEnumerateResults();

            Shaper <T> shaper = _shaper;

            _shaper = null;
            IEnumerator <T> result = shaper.GetEnumerator();

            return(result);
        }
Exemplo n.º 35
0
        public TextPipeline(FontDevice fontDevice)
        {
            Contract.Requires(fontDevice != null);

            _FontDevice = fontDevice;

            _TextAnalyzer = new Analyzer(_FontDevice.Factory);
            _AggregatorSink = new AggregatorSink();
            _Aggregator = new Aggregator(_AggregatorSink);
            _ShaperSink = new ShaperSink();
            _Shaper = new Shaper(_FontDevice, _ShaperSink);
            _FormatterSink = new FormatterSink();
            _Formatter = new Formatter(_FormatterSink);
            _TypesetterSink = new TypesetterSink();
            _Typesetter = new Typesetter(_TypesetterSink);
            _GeometryCache = new TextGeometryCache();
        }
Exemplo n.º 36
0
        // <summary>
        // Registers this hierarchy of coordinators in the given shaper.
        // </summary>
        internal void Initialize(Shaper shaper)
        {
            ResetCollection(shaper);

            // Add this coordinator to the appropriate state slot in the 
            // shaper so that it is available to materialization delegates.
            shaper.State[CoordinatorFactory.StateSlot] = this;

            if (null != Child)
            {
                Child.Initialize(shaper);
            }
            if (null != Next)
            {
                Next.Initialize(shaper);
            }
        }
Exemplo n.º 37
0
            private void Returns_SimpleEnumerator_for_simple_CoordinatorFactory(
                Func<IDbEnumerator<object>, List<object>> toList)
            {
                var sourceEnumerable = new[] { new object[] { 1 }, new object[] { 2 } };

                var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0));

                var shaper = new Shaper<object>(
                    MockHelper.CreateDbDataReader(sourceEnumerable),
                    /*context*/ null,
                    /*workspace*/ null,
                    MergeOption.AppendOnly,
                    /*stateCount*/ 1,
                    coordinatorFactory,
                    /*readerOwned*/ false,
                    /*useSpatialReader*/ false);

                var actualEnumerator = shaper.GetEnumerator();

                Assert.Equal(sourceEnumerable.SelectMany(e => e).ToList(), toList(actualEnumerator));
            }
Exemplo n.º 38
0
        private void Construct(Project project)
        {
            if (project == null) throw new ArgumentNullException("project");

            Title = "Freehand Pen";
            ToolTipText = "Draw the symbol of the object which should be created.";

            SmallIcon = global::Dataweb.NShape.Properties.Resources.FreehandIconSmall;
            SmallIcon.MakeTransparent(Color.Fuchsia);
            LargeIcon = global::Dataweb.NShape.Properties.Resources.FreehandIconLarge;
            LargeIcon.MakeTransparent(Color.Fuchsia);

            polygone = new PathFigureShape();
            strokeSet = new StrokeSequence();
            currentStroke = new Stroke();
            shaper = new Shaper();

            timer = new Timer();
            timer.Enabled = false;
            timer.Interval = timeOut;
            timer.Elapsed += timer_Tick;

            this.project = project;
            project.LibraryLoaded += project_LibraryLoaded;
            RegisterFigures();
        }
Exemplo n.º 39
0
 // <summary>
 // Precondition: the current row has data and contains a new element for the coordinator.
 // Reads the next element in this collection.
 // </summary>
 internal abstract void ReadNextElement(Shaper shaper);
Exemplo n.º 40
0
        // <summary>
        // Precondition: the current row has data for the coordinator.
        // Side-effects: updates keys currently stored in state and updates IsEntered if a new value is encountered.
        // Determines whether the row contains the next element in this collection.
        // </summary>
        internal bool HasNextElement(Shaper shaper)
        {
            // check if this row contains a new element for this coordinator
            var result = false;

            if (!IsEntered
                || !CoordinatorFactory.CheckKeys(shaper))
            {
                // remember initial keys values
                CoordinatorFactory.SetKeys(shaper);
                IsEntered = true;
                result = true;
            }

            return result;
        }
Exemplo n.º 41
0
 // <summary>
 // This method is called when the current collection is finished and it's time to move to the next collection.
 // Recursively initializes children and siblings as well.
 // </summary>
 internal abstract void ResetCollection(Shaper shaper);
Exemplo n.º 42
0
 /// <summary>
 /// Called from the Element expression on the Coordinator to gather all 
 /// the data for the record; we just turn around and call the expression
 /// we build on the RecordStateFactory.
 /// </summary>
 internal RecordState GatherData(Shaper shaper)
 {
     RecordStateFactory.GatherData(shaper);
     _pendingIsNull = false;
     return this;
 }
Exemplo n.º 43
0
            private void Returns_RecordStateEnumerator_for_nested_coordinatorFactories_of_RecordState(
                Func<IDbEnumerator<RecordState>, List<object>> toList)
            {
                var sourceEnumerable = new[]
                                           {
                                               new object[] { 1, "A", null },
                                               new object[] { 2, null, "X" },
                                               new object[] { 3, "B", "Z" },
                                               // Should stop reading at "B", since the coordinators are at the same depth
                                               new object[] { 4, "C", null },
                                               new object[] { 4, "D", null } // 4 shouldn't be added as it's repeated
                                           };

                var nestedCoordinatorFactoryOne = Objects.MockHelper.CreateCoordinatorFactory<string, RecordState>(
                    depth: 1,
                    stateSlot: 2,
                    ordinal: 1,
                    nestedCoordinators: new CoordinatorFactory[0],
                    producedValues: null);

                var nestedCoordinatorFactoryTwo = Objects.MockHelper.CreateCoordinatorFactory<string, RecordState>(
                    depth: 1,
                    stateSlot: 4,
                    ordinal: 2,
                    nestedCoordinators: new CoordinatorFactory[0],
                    producedValues: null);

                var rootCoordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory<int, RecordState>(
                    depth: 0,
                    stateSlot: 0,
                    ordinal: 0,
                    nestedCoordinators: new[] { nestedCoordinatorFactoryOne, nestedCoordinatorFactoryTwo },
                    producedValues: null);

                var shaper = new Shaper<RecordState>(
                    MockHelper.CreateDbDataReader(sourceEnumerable),
                    /*context*/ null,
                    /*workspace*/ null,
                    MergeOption.AppendOnly,
                    /*stateCount*/ 6,
                    rootCoordinatorFactory,
                    /*readerOwned*/ false,
                    /*useSpatialReader*/ false);

                Assert.Equal(new object[] { 1, "A", 2, "X", 3, "B", 4, "C", "D" }.ToList(), toList(shaper.RootEnumerator));
            }
Exemplo n.º 44
0
        public void SimpleEnumerator_MoveNextAsync_does_not_throw_if_shaper_is_not_active_even_if_task_is_being_cancelled()
        {
            var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0));

            var shaper = new Shaper<object>(
                new Mock<DbDataReader>().Object,
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 1,
                coordinatorFactory,
                /*readerOwned*/ false,
                /*streaming*/ false);

            using (var enumerator = shaper.GetEnumerator())
            {
                Assert.Contains("SimpleEnumerator", enumerator.GetType().FullName);

                enumerator.MoveNext();

                Assert.False(enumerator.MoveNextAsync(new CancellationToken(canceled: true))
                        .GetAwaiter().GetResult());
            }
        }
Exemplo n.º 45
0
        public void ObjectQueryNestedEnumerator_MoveNextAsync_throws_OperationCanceledException_if_task_is_cancelled()
        {
            var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0), s => true);

            var shaper = new Shaper<object>(
                new Mock<DbDataReader>().Object,
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 1,
                coordinatorFactory,
                /*readerOwned*/ false,
                /*streaming*/ false);

            using (var enumerator = shaper.GetEnumerator())
            {
                Assert.Contains("ObjectQueryNestedEnumerator", enumerator.GetType().FullName);

                Assert.Throws<OperationCanceledException>(
                    () => enumerator.MoveNextAsync(new CancellationToken(canceled: true))
                        .GetAwaiter().GetResult());
            }
        }
Exemplo n.º 46
0
        public void RecordStateEnumerator_MoveNextAsync_returns_reader_consumed_even_if_task_is_being_cancelled()
        {
            var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => (RecordState)null, s => true);

            var shaper = new Shaper<RecordState>(
                new Mock<DbDataReader>().Object,
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 1,
                coordinatorFactory,
                /*readerOwned*/ false,
                /*streaming*/ false);


            using (var enumerator = shaper.GetEnumerator())
            {
                Assert.Contains("RecordStateEnumerator", enumerator.GetType().FullName);
                enumerator.MoveNext();
                Assert.False(enumerator.MoveNextAsync(new CancellationToken(canceled: true)).GetAwaiter().GetResult());
            }
        }
Exemplo n.º 47
0
        /// <summary>
        /// Called from the Element expression on the Coordinator to indicate that
        /// the record should be NULL.
        /// </summary>
        internal RecordState SetNullRecord(Shaper shaper)
        {
            // 


            for (int i = 0; i < PendingColumnValues.Length; i++)
            {
                PendingColumnValues[i] = DBNull.Value;
            }
            _pendingEntityRecordInfo = null; // the default is already setup correctly on the record state factory
            _pendingIsNull = true;
            return this;
        }
Exemplo n.º 48
0
 internal BridgeDataRecord(Shaper<RecordState> shaper, int depth)
     : base() {
     Debug.Assert(null != shaper, "null shaper?");
     Shaper = shaper;
     Depth = depth;
     // Rest of state is set through the SetRecordSource method.
 }
Exemplo n.º 49
0
            private void Returns_ObjectQueryNestedEnumerator_for_nested_coordinatorFactories(
                Func<IDbEnumerator<object>, List<object>> toList)
            {
                var sourceEnumerable = new[]
                                           {
                                               new object[] { 1, "A", null },
                                               new object[] { 2, null, "X" },
                                               new object[] { 3, "B", "Z" },
                                               // Should stop reading at "B", since the coordinators are at the same depth
                                               new object[] { 4, "C", null },
                                               new object[] { 4, "D", null } // 4 shouldn't be added as it's repeated
                                           };

                var actualValuesFromNestedCoordinatorOne = new List<string>();
                var nestedCoordinatorFactoryOne = Objects.MockHelper.CreateCoordinatorFactory<string, string>(
                    depth: 1,
                    stateSlot: 1,
                    ordinal: 1,
                    nestedCoordinators: new CoordinatorFactory[0],
                    producedValues: actualValuesFromNestedCoordinatorOne);

                var actualValuesFromNestedCoordinatorTwo = new List<string>();
                var nestedCoordinatorFactoryTwo = Objects.MockHelper.CreateCoordinatorFactory<string, string>(
                    depth: 1,
                    stateSlot: 2,
                    ordinal: 2,
                    nestedCoordinators: new CoordinatorFactory[0],
                    producedValues: actualValuesFromNestedCoordinatorTwo);

                var actualValuesFromRootCoordinator = new List<object>();
                var rootCoordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory<int, object>(
                    depth: 0,
                    stateSlot: 0,
                    ordinal: 0,
                    nestedCoordinators: new[] { nestedCoordinatorFactoryOne, nestedCoordinatorFactoryTwo },
                    producedValues: actualValuesFromRootCoordinator);

                var shaper = new Shaper<object>(
                    MockHelper.CreateDbDataReader(sourceEnumerable),
                    /*context*/ null,
                    /*workspace*/ null,
                    MergeOption.AppendOnly,
                    /*stateCount*/ 3,
                    rootCoordinatorFactory,
                    /*readerOwned*/ false,
                    /*useSpatialReader*/ false,
                    shouldReleaseConnection: true);

                var actualEnumerator = shaper.GetEnumerator();

                Assert.Equal(new object[] { 1, 2, 3, 4 }.ToList(), toList(actualEnumerator));
                Assert.Equal(new object[] { 1, 2, 3, 4 }.ToList(), actualValuesFromRootCoordinator);
                Assert.Equal(new[] { "A", "B", "C", "D" }.ToList(), actualValuesFromNestedCoordinatorOne);
                Assert.Equal(new[] { "X" }.ToList(), actualValuesFromNestedCoordinatorTwo);
            }