Exemplo n.º 1
0
        public void MakeXMLTest()
        {
            ConfigLoader _testloader = new ConfigLoader();

            _testloader.Load();

            OSMXMLMaker _testMaker = new OSMXMLMaker();

            #region Make Mock Data

            CommonAttributes _tAttr = new CommonAttributes();

            List<Tag> _tTags = new List<Tag>();

            for(int i = 0; i < 2; ++i)
            {
                Tag _t = new Tag("key" + i.ToString(), "value" + i.ToString());

                _tTags.Add(_t);
            }

            Node _tNode = new Node(_tAttr,"0.1","0.2",_tTags);

            List<Node> _tNodes = new List<Node>();
            _tNodes.Add(_tNode);

            Way _tWay = new Way(_tAttr, _tNodes, _tTags);

            #endregion

            _testMaker.MakeXMLFile(_tWay , _testloader.classConfigResult);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            if (5 != args.Length)
            {
                Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpbasicauthstring> <servicetype> <realm> <advancedsearchdescriptionfilename>");
            }
            else
            {
                string apiDomain           = args[0];
                string httpBasicAuthString = args[1];
                string serviceType         = args[2];
                string realm = args[3];
                string advancedSearchDescriptionFileName = args[4];

                if (File.Exists(advancedSearchDescriptionFileName))
                {
                    Uri upstreamServerUrl = new Uri($"https://{apiDomain}");

                    using (CtmsRegistryClient registryClient = new CtmsRegistryClient(new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString)))
                    {
                        const string registeredLinkRelSearches = "search:searches";
                        Searches     searchesResource          = PlatformTools.PlatformToolsSDK.FindInRegistry <Searches>(registryClient, serviceType, realm, registeredLinkRelSearches);

                        if (null != searchesResource)
                        {
                            const string registeredLinkRelAdvancedSearch = "search:advanced-search";
                            Link         advancedSearchLink = searchesResource.DiscoverLink(registeredLinkRelAdvancedSearch);
                            /// Check, whether simple search is supported:
                            if (null != advancedSearchLink)
                            {
                                UriTemplate advancedSearchUriTemplate = new UriTemplate(advancedSearchLink.Href);
                                advancedSearchUriTemplate.SetParameter("offset", 0);
                                advancedSearchUriTemplate.SetParameter("limit", 50);

                                string advancedSearchUri = advancedSearchUriTemplate.Resolve();

                                string advancedSearchDescription = File.ReadAllText(advancedSearchDescriptionFileName);

                                /// Doing the search and write the results to stdout:
                                // The search description must be passed as content type "application/json":
                                using (HttpContent content = new StringContent(advancedSearchDescription, Encoding.UTF8, "application/json"))
                                {
                                    using (HttpResponseMessage response = registryClient.HttpClient.PostAsync(advancedSearchUri, content).Result)
                                    {
                                        AdvancedSearch searchResult = response.Content.ReadAsAsyncHal <AdvancedSearch>().Result;

                                        int assetNo = 0;
                                        int pageNo  = 0;
                                        // Page through the result:
                                        StringBuilder sb = new StringBuilder();
                                        sb.AppendLine(DateTime.Now.ToString());
                                        do
                                        {
                                            if (searchResult.AssetList.Any())
                                            {
                                                sb.AppendLine($"Page#: {++pageNo}, search description from file '{advancedSearchDescriptionFileName}'");
                                                foreach (Asset asset in searchResult.AssetList)
                                                {
                                                    BaseInfo         baseInfo         = asset.Base;
                                                    CommonAttributes commonAttributes = asset.Common;

                                                    sb.AppendLine($"Asset#: {++assetNo}, id: {asset.Base.Id}, name: '{asset.Common.Name}'");
                                                }
                                            }

                                            // If we have more results, follow the next link and get the next page:
                                            searchResult = registryClient.GetHalResource <SimpleSearch>(searchResult.GetUri("next", Enumerable.Empty <EmbedResource>()));
                                        }while (searchResult != null);
                                        Console.WriteLine(sb);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Advanced search not supported.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Advanced search not supported.");
                        }

                        Console.WriteLine("End");
                    }
                }
            }
        }
Exemplo n.º 3
0
 public DocumentAttribute GetCommonAttribute(string name) => CommonAttributes.TryGetValue(name, out DocumentAttribute val) ? val : null;
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            if (5 != args.Length || "'".Equals(args[4]) || !args[4].StartsWith("'") || !args[4].EndsWith("'"))
            {
                Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpBasicAuthString> <servicetype> <realm> '<simplesearchexpression>'");
            }
            else
            {
                string apiDomain           = args[0];
                string httpBasicAuthString = args[1];
                string serviceType         = args[2];
                string realm = args[3];
                string rawSearchExpression = args[4].Trim('\'');

                Uri upstreamServerUrl = new Uri($"https://{apiDomain}");

                using (CtmsRegistryClient registryClient = new CtmsRegistryClient(new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString)))
                {
                    const string registeredLinkRelSearches = "search:searches";
                    Searches     searchesResource          = PlatformTools.PlatformToolsSDK.FindInRegistry <Searches>(registryClient, serviceType, realm, registeredLinkRelSearches);

                    if (null != searchesResource)
                    {
                        const string registeredLinkRelSimpleSearch = "search:simple-search";
                        Link         simpleSearchLink = searchesResource.DiscoverLink(registeredLinkRelSimpleSearch);
                        /// Check, whether simple search is supported:
                        if (null != simpleSearchLink)
                        {
                            UriTemplate simpleSearchUrlTemplate = new UriTemplate(simpleSearchLink.Href);
                            simpleSearchUrlTemplate.SetParameter("search", rawSearchExpression);
                            Uri simpleSearchResultPageUrl = new Uri(simpleSearchUrlTemplate.Resolve());

                            /// Doing the search and write the results to stdout:
                            SimpleSearch searchResult = registryClient.GetHalResource <SimpleSearch>(simpleSearchResultPageUrl);

                            int assetNo = 0;
                            int pageNo  = 0;
                            // Page through the result:
                            StringBuilder sb = new StringBuilder();
                            do
                            {
                                if (searchResult.AssetList.Any())
                                {
                                    sb.AppendLine($"Page#: {++pageNo}, search expression: '{rawSearchExpression}'");
                                    foreach (Asset asset in searchResult.AssetList)
                                    {
                                        BaseInfo         baseInfo         = asset.Base;
                                        CommonAttributes commonAttributes = asset.Common;

                                        sb.AppendLine($"Asset#: {++assetNo}, id: {asset.Base.Id}, name: '{asset.Common.Name}'");
                                    }
                                }

                                // If we have more results, follow the next link and get the next page:
                                searchResult = registryClient.GetHalResource <SimpleSearch>(searchResult.GetUri("next", Enumerable.Empty <EmbedResource>()));
                            }while (searchResult != null);
                            Console.WriteLine(sb);
                        }
                    }
                }

                Console.WriteLine("End");
            }
        }