コード例 #1
0
        public virtual SqlHierarchyId CreateDirectory(string table, string dir, SqlHierarchyId pathId, SqlConnection conn, bool pipeToOutput = false)
        {
            SqlConnManager.IsConnected(conn);
            if (!FileTableExists(table, conn))
            {
                throw new Exception("Table does not exists or is not a FileTable.");
            }
            var CreateDirectoryQry = "INSERT INTO {0} (name, is_directory)"
                                     + " OUTPUT Inserted.path_locator"
                                     + " VALUES (@dir, 1)";
            var qry = string.Format(CreateDirectoryQry, table);
            var cmd = new SqlCommand(qry, conn);

            cmd.Parameters.Add(new SqlParameter("@dir", dir));
            if (!pathId.IsNull)
            {
                pathId             = HierarchyBuilder.NewChildHierarchyId(pathId);
                CreateDirectoryQry = "INSERT INTO {0} (name, is_directory, path_locator)"
                                     + " OUTPUT Inserted.path_locator"
                                     + " VALUES (@dir, 1, @pathId)";
                cmd.CommandText = string.Format(CreateDirectoryQry, table);
                var param1 = new SqlParameter("@pathId", pathId)
                {
                    UdtTypeName = Constants.HierarchyId
                };
                cmd.Parameters.Add(param1);
            }
            pathId = (SqlHierarchyId)(cmd.ExecuteScalar() ?? SqlHierarchyId.Null);
            if (pipeToOutput)
            {
                PipeFile(table, pathId, conn);
            }
            return(pathId);
        }
コード例 #2
0
        /// <summary>
        /// The main entry point for the application
        /// </summary>
        private static void Main(string[] args)
        {
            try
            {
                Settings settings;
                if (!TryInitialize(out settings))
                {
                    Usage();
                    return;
                }

                using (var builder = new HierarchyBuilder(settings))
                {
                    builder.Run();

                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                Usage();
            }
        }
コード例 #3
0
        public virtual string CreateDirectory(string table, string dir, string pathId, SqlConnection conn)
        {
            SqlConnManager.IsConnected(conn);
            if (!FileTableExists(table, conn))
            {
                throw new Exception("Table does not exists or is not a FileTable.");
            }
            var CreateDirectoryQry = "INSERT INTO {0} (name, is_directory)"
                                     + " OUTPUT Inserted.path_locator.ToString()"
                                     + " VALUES (@dir, 1)";
            var qry = string.Format(CreateDirectoryQry, table);
            var cmd = new SqlCommand(qry, conn);

            cmd.Parameters.Add(new SqlParameter("@dir", dir));
            if (!string.IsNullOrWhiteSpace(pathId))
            {
                pathId             = HierarchyBuilder.NewChildHierarchyId(pathId);
                CreateDirectoryQry = "INSERT INTO {0} (name, is_directory, path_locator)"
                                     + " OUTPUT Inserted.path_locator.ToString()"
                                     + " VALUES (@dir, 1, @pathId)";
                cmd.CommandText = string.Format(CreateDirectoryQry, table);
                cmd.Parameters.Add(new SqlParameter("@pathId", pathId as object));
            }
            pathId = cmd.ExecuteScalar() as string;
            return(pathId);
        }
コード例 #4
0
        public void Test2VerticesAgumented()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaAugmentedSize);

            graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.Compress();

            // contract graph.
            var hierarchyBuilder = new HierarchyBuilder <Weight>(graph,
                                                                 new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)),
                                                                 new DykstraWitnessCalculator(int.MaxValue), new WeightHandler(null));

            hierarchyBuilder.Run();

            // check edges.
            var edges01 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges01);
            var edge10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edge10);
        }
コード例 #5
0
        public Guid CreateFile(string table, string fileName, SqlHierarchyId pathId, byte[] data, SqlConnection conn)
        {
            SqlConnManager.IsConnected(conn);
            if (!FileTableExists(table, conn)) // This is used to prevent SQL injection
            {
                throw new Exception("Table does not exists or is not a FileTable.");
            }
            if (pathId.IsNull)
            {
                pathId = HierarchyBuilder.NewChildHierarchyId(SqlHierarchyId.Null);
            }
            var insertQry = "INSERT INTO {0} (name, file_stream, path_locator) "
                            + " OUTPUT Inserted.stream_id"
                            + " VALUES (@fileName, @data, @pathId)";
            var qry = string.Format(insertQry, table);
            var cmd = new SqlCommand(qry, conn);

            cmd.Parameters.Add(new SqlParameter("@fileName", fileName));
            cmd.Parameters.Add(new SqlParameter("@data", data));
            cmd.Parameters.Add(new SqlParameter("@pathId", pathId)
            {
                UdtTypeName = Constants.HierarchyId
            });
            var streamId = (Guid)cmd.ExecuteScalar();

            PipeScalar(SqlDbType.UniqueIdentifier, streamId);
            return(streamId);
        }
コード例 #6
0
        public void TestUncontractedWitnessed()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 3, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 1, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 2, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 3, 10, null, Constants.NO_VERTEX);
            graph.Compress();

            // contract graph.
            var priorities = new Dictionary <uint, float>();

            priorities.Add(1, 0);
            priorities.Add(0, 1);
            priorities.Add(2, 2);
            priorities.Add(3, 3);
            var hierarchyBuilder = new HierarchyBuilder(graph,
                                                        new MockPriorityCalculator(priorities),
                                                        new DykstraWitnessCalculator(int.MaxValue));

            hierarchyBuilder.Run();

            // edges 1->2 and 2->1 should have been removed.
            var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNotNull(edge);
            var edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);

            Assert.AreEqual(110, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(1, edgeData.ContractedId);

            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);

            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);
            Assert.AreEqual(10, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);

            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);
            Assert.AreEqual(10, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);
        }
コード例 #7
0
        /// <summary>
        /// The main entry point for the application
        /// </summary>
        private static void Main(string[] args)
        {
            try
            {
                Settings settings;
                if (!TryInitialize(out settings))
                {
                    Usage();
                    return;
                }

                using (var builder = new HierarchyBuilder(settings))
                {
                    builder.Run();

                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                Usage();
            }
        }
コード例 #8
0
        public void GetHierarchy_GetsHierarchyForSandbox()
        {
            //Arrange
            var context = new MockAppContextProvider();

            context.IsProxyInstalledRetValue = false;
            context.SetSandbox();
            SharePointEnvironment.ApplicationContextProvider = context;
            BSPSite site = new BSPSite();
            var     web  = site.SetRootWeb();

            web.ServerRelativeUrl = "foo/bar";
            BSPList list = web.Lists.SetOne();

            list.Title = ConfigurationList.ConfigListName;
            web.ID     = TestsConstants.TestGuid;
            site.ID    = new Guid("{7C039254-10B7-49F0-AA8D-F592206C7130}");
            var moleWeb = new Microsoft.SharePoint.Moles.MSPWeb(web);

            moleWeb.GetListString = (listUrl) =>
            {
                if (listUrl == "foo/bar/Lists/" + ConfigurationList.ConfigListName)
                {
                    return(list);
                }
                return(null);
            };

            //Act
            IPropertyBagHierarchy target = HierarchyBuilder.GetHierarchy(web);

            //Assert
            Assert.IsInstanceOfType(target, typeof(SandboxPropertyBagHierarchy));
        }
コード例 #9
0
        public void Test3Vertices()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, null);
            graph.AddEdge(1, 0, 100, null);
            graph.AddEdge(1, 2, 100, null);
            graph.AddEdge(2, 1, 100, null);
            graph.Compress();

            // contract graph.
            var hierarchyBuilder = new HierarchyBuilder(graph, new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)),
                                                        new DykstraWitnessCalculator(int.MaxValue), (i) => Enumerable.Empty <uint[]>());

            hierarchyBuilder.Run();

            // check edges.
            var edges01 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges01);
            var edge10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edge10);
            var edge12 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edge12);
            var edges21 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges21);
        }
コード例 #10
0
        public void GetLongTest1Part2()
        {
            var guid      = new Guid("588FE337-604A-4A90-B20D-60138E43318D");
            var byteArray = guid.ToByteArray();
            var actual    = HierarchyBuilder.GetLong(6, 6, byteArray);

            Assert.AreEqual(158650489200659, actual);
        }
コード例 #11
0
        public void GetLongTest1Part3()
        {
            var guid      = new Guid("588FE337-604A-4A90-B20D-60138E43318D");
            var byteArray = guid.ToByteArray();
            var actual    = HierarchyBuilder.GetLong(12, 4, byteArray);

            Assert.AreEqual(2386768269, actual);
        }
コード例 #12
0
        public void NewChildHierarchyIdNullParentPathIdTest()
        {
            var childPathId = SqlHierarchyId.Parse("/61450502031968.158650489200659.2386768269/");
            var guid        = new Guid("588FE337-604A-4A90-B20D-60138E43318D");
            var actual      = new HierarchyBuilder().NewChildHierarchyId(SqlHierarchyId.Null, guid);

            Assert.AreEqual(childPathId, actual);
        }
コード例 #13
0
        public void GetLongTest1Part1()
        {
            var guid      = new Guid("588FE337-604A-4A90-B20D-60138E43318D");
            var byteArray = guid.ToByteArray();
            var actual    = HierarchyBuilder.GetLong(0, 6, byteArray);

            Assert.AreEqual(61450502031968, actual);
        }
コード例 #14
0
        public HierarchyBuilderTest()
        {
            this.superState = A.Fake<IState<string, int>>();
            A.CallTo(() => this.superState.Id).Returns(SuperState);
            this.states = A.Fake<IStateDictionary<string, int>>();
            A.CallTo(() => this.states[SuperState]).Returns(this.superState);

            this.testee = new HierarchyBuilder<string, int>(this.states, SuperState);
        }
コード例 #15
0
        public void NewChildHierarchyIdTest()
        {
            var parentPathId           = SqlHierarchyId.Parse("/9958588825279.274102742982672.185216777/");
            var expectedCombinedPathId = SqlHierarchyId.Parse(parentPathId.ToString() + "61450502031968.158650489200659.2386768269/");
            var guid   = new Guid("588FE337-604A-4A90-B20D-60138E43318D");
            var actual = new HierarchyBuilder().NewChildHierarchyId(parentPathId, guid);

            Assert.AreEqual(expectedCombinedPathId, actual);
        }
コード例 #16
0
        public HierarchyBuilderTest()
        {
            this.superState = new StateDefinition <string, int>(SuperState);
            this.states     = A.Fake <IImplicitAddIfNotAvailableStateDefinitionDictionary <string, int> >();
            A.CallTo(() => this.states[SuperState]).Returns(this.superState);
            this.initiallyLastActiveStates = A.Fake <IDictionary <string, string> >();

            this.testee = new HierarchyBuilder <string, int>(SuperState, this.states, this.initiallyLastActiveStates);
        }
コード例 #17
0
        public void GetHierarchy_GetsHierarchyForFarm()
        {
            //Arrange
            var f = new BSPConfiguredFarm();

            //Act
            IPropertyBagHierarchy target = HierarchyBuilder.GetHierarchy(null);

            //Assert
            Assert.IsInstanceOfType(target, typeof(FarmPropertyBagHierarchy));
        }
コード例 #18
0
        /// <summary>
        /// Creates a new contracted graph and adds it to the router db for the given profile.
        /// </summary>
        public static void AddContracted <T>(this RouterDb db, Profiles.Profile profile, WeightHandler <T> weightHandler, bool forceEdgeBased = false)
            where T : struct
        {
            // create the raw directed graph.
            ContractedDb contractedDb = null;

            lock (db)
            {
                if (forceEdgeBased)
                { // edge-based is needed when complex restrictions found.
                    var contracted           = new DirectedDynamicGraph(weightHandler.DynamicSize);
                    var directedGraphBuilder = new Itinero.Algorithms.Contracted.EdgeBased.DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted,
                                                                                                                    weightHandler);
                    directedGraphBuilder.Run();

                    // contract the graph.
                    var priorityCalculator = new Itinero.Algorithms.Contracted.EdgeBased.EdgeDifferencePriorityCalculator <T>(contracted, weightHandler,
                                                                                                                              new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue));
                    priorityCalculator.DifferenceFactor = 5;
                    priorityCalculator.DepthFactor      = 5;
                    priorityCalculator.ContractedFactor = 8;
                    var hierarchyBuilder = new Itinero.Algorithms.Contracted.EdgeBased.HierarchyBuilder <T>(contracted, priorityCalculator,
                                                                                                            new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue), weightHandler, db.GetGetRestrictions(profile, null));
                    hierarchyBuilder.Run();

                    contractedDb = new ContractedDb(contracted);
                }
                else
                { // vertex-based is ok when no complex restrictions found.
                    var contracted           = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, weightHandler.MetaSize);
                    var directedGraphBuilder = new DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler);
                    directedGraphBuilder.Run();

                    // contract the graph.
                    var priorityCalculator = new EdgeDifferencePriorityCalculator(contracted,
                                                                                  new DykstraWitnessCalculator(int.MaxValue));
                    priorityCalculator.DifferenceFactor = 5;
                    priorityCalculator.DepthFactor      = 5;
                    priorityCalculator.ContractedFactor = 8;
                    var hierarchyBuilder = new HierarchyBuilder <T>(contracted, priorityCalculator,
                                                                    new DykstraWitnessCalculator(int.MaxValue), weightHandler);
                    hierarchyBuilder.Run();

                    contractedDb = new ContractedDb(contracted);
                }
            }

            // add the graph.
            lock (db)
            {
                db.AddContracted(profile, contractedDb);
            }
        }
コード例 #19
0
        public string CreateFile(string table, string path, byte[] data, SqlConnection conn)
        {
            var file   = Path.GetFileName(path);
            var dir    = Path.GetDirectoryName(path);
            var pathId = DirectoryExists(table, dir, conn);

            if (string.IsNullOrWhiteSpace(pathId))
            {
                pathId = CreateDirectory(table, dir, conn);
            }
            var hierarchyId = FileTableRepo.CreateFile(table, file, HierarchyBuilder.NewChildHierarchyId(pathId), data, conn);

            return(hierarchyId);
        }
コード例 #20
0
        public void TestDoubleContraction()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 2, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 0, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(0, 3, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 0, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 200, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 200, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 3, 200, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 1, 200, null, Constants.NO_VERTEX);
            graph.Compress();

            // contract graph.
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue));

            priorityCalculator.DepthFactor      = 0;
            priorityCalculator.ContractedFactor = 0;
            var hierarchyBuilder = new HierarchyBuilder(graph, priorityCalculator,
                                                        new DykstraWitnessCalculator(int.MaxValue));

            hierarchyBuilder.Run();

            // check edges.
            var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNull(edge);
            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 0);
            Assert.IsNotNull(edge);

            edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNull(edge);
            edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 0);
            Assert.IsNotNull(edge);

            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);
            Assert.IsNull(edge);
            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2);
            Assert.IsNotNull(edge);

            edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1);
            Assert.IsNull(edge);
            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
        }
コード例 #21
0
        public void GetHierarchy_GetsHierarchyForSandboxFarm()
        {
            //Arrange
            var context = new MockAppContextProvider();

            context.AddProxyType(ProxyArgs.ReadConfigArgs.OperationTypeName);
            context.AddProxyType(ProxyArgs.ProxyInstalledArgs.OperationTypeName);
            context.SetSandbox();
            SharePointEnvironment.ApplicationContextProvider = context;

            //Act
            IPropertyBagHierarchy target = HierarchyBuilder.GetHierarchy(null);

            //Assert
            Assert.IsInstanceOfType(target, typeof(SandboxFarmPropertyBagHierarchy));
        }
コード例 #22
0
        public void GetHierarchy_GetsHierarchyForFullTrust()
        {
            //Arrange
            var site   = new BSPSite();
            var web    = site.SetRootWeb();
            var webApp = new BSPWebApplication();

            site.WebApplication = webApp;
            var f = new BSPConfiguredFarm();

            webApp.Farm = SPFarm.Local;

            //Act
            IPropertyBagHierarchy target = HierarchyBuilder.GetHierarchy(web);

            //Assert
            Assert.IsInstanceOfType(target, typeof(FullTrustPropertyBagHierarchy));
        }
コード例 #23
0
        /// <summary>
        /// Adds the consul configuration.
        /// </summary>
        /// <param name="hostBuilder">The host builder.</param>
        /// <param name="convensionSetting">
        /// Convention builder for setting the Consul hierarchic structure.
        /// Default convention is: Application, Environment, Component</param>
        /// <param name="address">Optional address of the console service.
        /// If missing will check:
        /// * Environment variable: consul-url
        /// * default (if don't find anything): http://127.0.0.1:8500
        /// .</param>
        /// <param name="configOverride">Enable to override configuration.</param>
        /// <param name="httpClientOverride">Enable to override HTTP client.</param>
        /// <param name="httpClientHandlerOverride">Enable to override HTTP client handler.</param>
        /// <returns></returns>
        public static IHostBuilder AddConsulConfiguration(
            this IHostBuilder hostBuilder,
            Func <IConsulHierarchyBuilder, IConsulHierarchy>?hierarchyConventionSetting = null,
            string?address = null,
            Action <ConsulClientConfiguration>?configOverride    = null,
            Action <HttpClient>?httpClientOverride               = null,
            Action <HttpClientHandler>?httpClientHandlerOverride = null)
        {
            var            options = new ConsulClientOptions(address, configOverride, httpClientOverride, httpClientHandlerOverride);
            IConsulFactory factory = new ConsulClientFactory(options);

            hostBuilder.ConfigureServices((hostContext, services) =>
            {
                services.AddSingleton(factory);
            });

            hostBuilder.ConfigureAppConfiguration(
                (host, builder) =>
            {
                // string consoleUrl = host.Configuration["Consul:Host"];
                IHostEnvironment env = host.HostingEnvironment;

                #region IConsulHierarchy hierarchyConvention = ...


                IConsulHierarchyBuilder hierarchyBuilder = new HierarchyBuilder(env);
                IConsulHierarchy hierarchyConvention     =
                    hierarchyConventionSetting?.Invoke(hierarchyBuilder) ??
                    hierarchyBuilder.ByAppName()
                    .ByEnvironment()
                    //.ByComponent()
                    .Build();

                #endregion          // IConsulHierarchy hierarchyConvention = ...

                builder.SetBasePath(env.ContentRootPath);

                var configSource = new ConsulConfigurationSource(hierarchyConvention, factory);
                builder.Add(configSource);

                // builder.AddEnvironmentVariables();
            });
            return(hostBuilder);
        }
コード例 #24
0
        public void Test3VerticesComplete()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(0, 2, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 0, 100, null, Constants.NO_VERTEX);
            graph.Compress();

            // contract graph.
            var hierarchyBuilder = new HierarchyBuilder(graph, new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)),
                                                        new DykstraWitnessCalculator(int.MaxValue));

            hierarchyBuilder.Run();

            // check edges.
            var edges01 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges01);
            var edges02 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNotNull(edges02);
            var edge10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edge10);
            var edge12 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNull(edge12);
            var edges20 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edges20);
            var edges21 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges21);
        }
コード例 #25
0
ファイル: Menu.cs プロジェクト: tenniskit/n2cms
        private void BuildControlHierarchy(ContentItem currentItem, ContentItem startPage)
        {
            if (currentItem == null)
            {
                currentItem = startPage;
            }

            var children = currentItem.Children.WhereNavigatable();

            if (children.Count > 0)
            {
                currentItem = children[0];
            }
            IEnumerable <ContentItem> ancestors = GetAncestors(currentItem, startPage);
            ContentItem startingPoint           = GetStartingPoint();

            if (startingPoint != null)
            {
                HierarchyBuilder builder = null;

                if (BranchMode)
                {
                    builder = new BranchHierarchyBuilder(currentItem, startingPoint);
                }
                else
                {
                    builder = new TreeHierarchyBuilder(startingPoint, MaxLevels);
                }

                HierarchyNode <ContentItem> node = builder.Children(Filters).Build();
                if (node.Current != null)
                {
                    AddControlsRecursive(this, node, CurrentItem, ancestors);
                }
            }
        }
コード例 #26
0
        public string CreateFile(string table, string fileName, string pathId, byte[] data, SqlConnection conn)
        {
            SqlConnManager.IsConnected(conn);
            if (!FileTableExists(table, conn))
            {
                throw new Exception("Table does not exists or is not a FileTable.");
            }
            if (string.IsNullOrWhiteSpace(pathId))
            {
                pathId = HierarchyBuilder.NewChildHierarchyId(null);
            }
            var insertQry = "INSERT INTO {0} (name, file_stream, path_locator) "
                            + " OUTPUT Inserted.path_locator.ToString()"
                            + " VALUES (@fileName, @data, HierarchyId::Parse(@pathId))";
            var qry = string.Format(insertQry, table);
            var cmd = new SqlCommand(qry, conn);

            cmd.Parameters.Add(new SqlParameter("@fileName", fileName));
            cmd.Parameters.Add(new SqlParameter("@data", data));
            cmd.Parameters.Add(new SqlParameter("@pathId", pathId));
            var hierarchyid = cmd.ExecuteScalar() as string;

            return(hierarchyid);
        }
コード例 #27
0
ファイル: Tree.cs プロジェクト: wrohrbach/n2cms
        Func <ContentItem, string> liClassProvider;        // obsolete

        #region Constructor

        public Tree(HierarchyBuilder builder)
        {
            hierarchy  = builder ?? new FixedHierarchyBuilder(new HierarchyNode <ContentItem>(null));
            linkWriter = (n, w) => Link.To(n.Current).WriteTo(w);
        }
コード例 #28
0
ファイル: Tree.cs プロジェクト: wrohrbach/n2cms
 public static Tree Using(HierarchyBuilder hierarchy)
 {
     return(TreeFactory(hierarchy));
 }
コード例 #29
0
 public TreeBuilder(HierarchyBuilder builder)
     : base(builder)
 {
 }
コード例 #30
0
        public void TestRestrictedNetwork2()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, null);
            graph.AddEdge(1, 0, 100, null);
            graph.AddEdge(1, 2, 100, null);
            graph.AddEdge(2, 1, 100, null);
            graph.AddEdge(1, 3, 100, null);
            graph.AddEdge(3, 1, 100, null);
            graph.AddEdge(1, 4, 100, null);
            graph.AddEdge(4, 1, 100, null);
            graph.AddEdge(2, 3, 100, null);
            graph.AddEdge(3, 2, 100, null);
            graph.Compress();

            // contract graph.
            var priorities = new Dictionary <uint, float>();

            priorities.Add(1, 0);
            priorities.Add(0, 1);
            priorities.Add(2, 2);
            priorities.Add(3, 3);
            priorities.Add(4, 4);
            var hierarchyBuilder = new HierarchyBuilder(graph,
                                                        new MockPriorityCalculator(priorities),
                                                        new DykstraWitnessCalculator(int.MaxValue), (i) =>
            {
                if (i == 0 || i == 1 || i == 4)
                {
                    return(new uint[][]
                    {
                        new uint[] { 0, 1, 4 }
                    });
                }
                return(null);
            });

            hierarchyBuilder.Run();

            // check all edges.
            ContractedEdgeData edgeData;
            var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x =>
            {
                if (x.Neighbour == 4)
                {
                    edgeData = ContractedEdgeDataSerializer.Deserialize(x.Data[0], Constants.NO_VERTEX);
                    return(edgeData.Direction == true);
                }
                return(false);
            });

            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(500, edgeData.Weight);
            Assert.AreEqual(true, edgeData.Direction);
            Assert.AreEqual(1, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x =>
            {
                if (x.Neighbour == 4)
                {
                    edgeData = ContractedEdgeDataSerializer.Deserialize(x.Data[0], Constants.NO_VERTEX);
                    return(edgeData.Direction == false);
                }
                return(false);
            });
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(200, edgeData.Weight);
            Assert.AreEqual(false, edgeData.Direction);
            Assert.AreEqual(1, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(200, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(1, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(200, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(1, edge.GetContracted());

            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(null, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(null, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(null, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 4);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(null, edge.GetContracted());

            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(null, edge.GetContracted());
            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 4);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(200, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(1, edge.GetContracted());

            edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 4);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX);
            Assert.AreEqual(200, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(1, edge.GetContracted());
        }
コード例 #31
0
        public void TestPentagonDirected()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, true);
            graph.AddEdge(1, 0, 100, false);
            graph.AddEdge(1, 2, 100, true);
            graph.AddEdge(2, 1, 100, false);
            graph.AddEdge(2, 3, 100, true);
            graph.AddEdge(3, 2, 100, false);
            graph.AddEdge(3, 4, 100, true);
            graph.AddEdge(4, 3, 100, false);
            graph.AddEdge(4, 0, 100, true);
            graph.AddEdge(0, 4, 100, false);
            graph.Compress();

            // contract graph.
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue));

            priorityCalculator.ContractedFactor = 0;
            priorityCalculator.DepthFactor      = 0;
            var hierarchyBuilder = new HierarchyBuilder(graph, priorityCalculator,
                                                        new DykstraWitnessCalculator(int.MaxValue), (i) => Enumerable.Empty <uint[]>());

            hierarchyBuilder.Run();

            // check edges.
            var edges01 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges01);
            var edges10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edges10);

            var edges12 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNull(edges12);
            var edges21 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges21);

            var edges23 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNotNull(edges23);
            var edges32 = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNull(edges32);

            var edges34 = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 4);

            Assert.IsNull(edges34);
            var edges43 = graph.GetEdgeEnumerator(4).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNotNull(edges43);

            var edges40 = graph.GetEdgeEnumerator(4).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edges40);
            var edges04 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 4);

            Assert.IsNotNull(edges04);

            var edges41 = graph.GetEdgeEnumerator(4).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges41);
            var s1 = edges41.GetSequence1();
            var s2 = edges41.GetSequence2();

            Assert.AreEqual(1, s1.Length);
            Assert.AreEqual(0, s1[0]);
            Assert.AreEqual(1, s2.Length);
            Assert.AreEqual(0, s2[0]);
            var edges14 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 4);

            Assert.IsNull(edges14);

            var edges31 = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges31);
            s1 = edges31.GetSequence1();
            s2 = edges31.GetSequence2();
            Assert.AreEqual(1, s1.Length);
            Assert.AreEqual(4, s1[0]);
            Assert.AreEqual(1, s2.Length);
            Assert.AreEqual(0, s2[0]);
            var edges13 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNull(edges13);
        }
コード例 #32
0
 public Tree(HierarchyBuilder builder)
 {
     root         = builder.Build();
     linkProvider = Link.To;
 }