public DefaultDiscoveryServiceExtension(int duplicateMessageHistoryLength)
 {
     this.discoveryService = new DefaultDiscoveryService(
         this,
         new DiscoveryMessageSequenceGenerator(),
         duplicateMessageHistoryLength);
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Discovery API -- 'Fields'-Parameter");

            // Create the service.
            var service = new DiscoveryService();
            RunSample(service);
            CommandLine.PressAnyKeyToExit();
        }
        public async Task<ActionResult> DiscoveryService()
        {
            // Create the service.
            var service = new DiscoveryService(new BaseClientService.Initializer
            {
                ApplicationName = this.ApplicationName,                
                ApiKey = this.ApiKey,
            });

            // Run the request.            
            var result = await service.Apis.List().ExecuteAsync();            
            return View(result);
        }
Beispiel #4
0
        private static void RunSample(DiscoveryService service)
        {
            // Run the request.
            CommandLine.WriteAction("Executing Partial GET ...");
            var request = service.Apis.GetRest("discovery", "v1");
            request.FieldsMask = "description,title";
            var result = request.Fetch();

            // Display the results.
            CommandLine.WriteResult("Description", result.Description);
            CommandLine.WriteResult("Title", result.Title);
            CommandLine.WriteResult("Name (not requested)", result.Name);
        }
Beispiel #5
0
        private static void RunSample(DiscoveryService service)
        {
            // Run the request.
            CommandLine.WriteAction("Executing List-request ...");
            var result = service.Apis.List().Fetch();

            // Display the results.
            if (result.Items != null)
            {
                foreach (DirectoryList.ItemsData api in result.Items)
                {
                    CommandLine.WriteResult(api.Id, api.Title);
                }
            }
        }
        public IDiscoveryService GetDiscoveryService()
        {
            CrmConnection connection = null;
            try
            {

                connection = _CrmConnectionProvider.GetDiscoveryServiceConnection();
                connection.UserTokenExpiryWindow = new TimeSpan(0, 3, 0);
                var service = new DiscoveryService(connection);
                return service;
            }
            catch (Exception ex)
            {
                throw new FailedToConnectToCrmException(connection, ex);
            }
        }
        private async Task Run()
        {
            var service = new DiscoveryService();

            // Run the request.
            Console.WriteLine("Executing Partial GET ...");
            var request = service.Apis.GetRest("discovery", "v1");
            request.Fields = "description,title";
            var result = await request.ExecuteAsync();

            // Display the results.
            Console.WriteLine("\tDescription: " + result.Description);
            Console.WriteLine();
            Console.WriteLine("\tTitle:" + result.Title);
            Console.WriteLine();
            Console.WriteLine("\tName (not requested): " + result.Name);
        }
        public void GetCredentials()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.GetCredentials(
                environmentId: environmentId,
                credentialId: credentialId
                );

            Console.WriteLine(result.Response);
        }
Beispiel #9
0
        /// <summary>
        /// Get the detailed information of collections for a domain
        /// </summary>
        /// <param name="domainID">ID of the domain whose collection info needed</param>
        /// <param name="catalogInfoArray">Details of the catalog</param>
        /// <param name="dService">object of Discovery service</param>
        /// <returns></returns>
        public static ArrayList GetDetailedCollectionInformation(string domainID, CatalogInfo[] catalogInfoArray, DiscoveryService dService)
        {
            ArrayList        colInfo    = new ArrayList();
            DiscoveryService locService = dService;

            NameValueCollection collectionsOnHost = new NameValueCollection();

            Member member = Store.GetStore().GetDomain(domainID).GetCurrentMember();

            foreach (CatalogInfo ci in catalogInfoArray)
            {
                //Collect all the CollectionIDs for HostID.
                collectionsOnHost.Add(ci.HostID, ci.CollectionID);
            }

            foreach (string hostID in collectionsOnHost.AllKeys)
            {
                try
                {
                    if (member.HomeServer != null && hostID == member.HomeServer.UserID)
                    {
                        //We already have a connection. Reuse it.
                        colInfo.AddRange(locService.GetAllCollectionInfo(collectionsOnHost.GetValues(hostID), member.UserID));
                    }
                    else
                    {
                        //Get all collection info in one call.
                        HostNode         hNode  = HostNode.GetHostByID(domainID, hostID);
                        SimiasConnection smConn = new SimiasConnection(domainID,
                                                                       member.UserID,
                                                                       SimiasConnection.AuthType.BASIC,
                                                                       hNode);
                        DiscoveryService discService = new DiscoveryService();
                        smConn.InitializeWebClient(discService, "DiscoveryService.asmx");
                        colInfo.AddRange(discService.GetAllCollectionInfo(collectionsOnHost.GetValues(hostID), member.UserID));
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }

            locService = null;
            return(colInfo);
        }
Beispiel #10
0
        public async Task <StatusCollection> GetAll()
        {
            var statusHttpServices = DiscoveryService.GetLocalRegisteredServices("STATUS.HTTP").DistinctBy(srv => srv.ApplicationName);
            var collection         = new StatusCollection();
            var getTasks           = new List <(Task <string> Data, string IpAddress, string Port, WebClient Client)>();

            foreach (var srv in statusHttpServices)
            {
                if (!(srv.Data.GetValue() is Dictionary <string, object> data))
                {
                    continue;
                }
                if (!data.TryGetValue("Port", out var port))
                {
                    continue;
                }
                var client     = WebClients.New();
                var clientTask = client.DownloadStringTaskAsync($"http://{srv.Addresses[0]}:{port}/xml");
                getTasks.Add((clientTask, srv.Addresses[0].ToString(), port.ToString(), client));
            }
            await Task.WhenAll(getTasks.Select(i => i.Data)).ConfigureAwait(false);

            foreach (var item in getTasks)
            {
                var statusCollection = item.Data.Result.DeserializeFromXml <StatusItemCollection>();
                collection.Statuses.Add(new StatusCollectionItem {
                    Data = statusCollection, IpAddress = item.IpAddress, Port = item.Port
                });
                WebClients.Store(item.Client);
            }
            collection.Statuses.Sort((x, y) =>
            {
                var cmp = string.Compare(x.Data.EnvironmentName, y.Data.EnvironmentName, StringComparison.Ordinal);
                if (cmp == 0)
                {
                    cmp = string.Compare(x.Data.MachineName, y.Data.MachineName, StringComparison.Ordinal);
                }
                if (cmp == 0)
                {
                    cmp = string.Compare(x.Data.ApplicationName, y.Data.ApplicationName, StringComparison.Ordinal);
                }
                return(cmp);
            });
            return(collection);
        }
        public void FederatedQuery()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.FederatedQuery(
                environmentId: environmentId,
                naturalLanguageQuery: naturalLanguageQuery,
                returnFields: "extracted_metadata.sha1"
                );

            Console.WriteLine(result.Response);
        }
        public void DeleteDocument()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.DeleteDocument(
                environmentId: environmentId,
                collectionId: collectionId,
                documentId: documentId
                );

            Console.WriteLine(result.Response);
        }
        public void UpdateCollection()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.UpdateCollection(
                environmentId: environmentId,
                collectionId: collectionId,
                name: updatedCollectionName
                );

            Console.WriteLine(result.Response);
        }
        private async Task Run()
        {
            var service = new DiscoveryService();

            // Run the request.
            Console.WriteLine("Executing Partial GET ...");
            var request = service.Apis.GetRest("discovery", "v1");

            request.Fields = "description,title";
            var result = await request.ExecuteAsync();

            // Display the results.
            Console.WriteLine("\tDescription: " + result.Description);
            Console.WriteLine();
            Console.WriteLine("\tTitle:" + result.Title);
            Console.WriteLine();
            Console.WriteLine("\tName (not requested): " + result.Name);
        }
Beispiel #15
0
        public void ListTrainingExamples()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.ListTrainingExamples(
                environmentId: environmentId,
                collectionId: collectionId,
                queryId: queryId
                );

            Console.WriteLine(result.Response);
        }
Beispiel #16
0
        public void Setup()
        {
            BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
                bearerToken: bearerToken
                );

            service = new DiscoveryService("2019-10-03", authenticator);
            service.SetServiceUrl(serviceUrl);
            service.DisableSslVerification(true);

            var listEnvironmentsResult = service.ListEnvironments();

            environmentId = listEnvironmentsResult.Result.Environments[0].EnvironmentId;

            var listCollectionsResult = service.ListCollections(environmentId: environmentId);

            collectionId = listCollectionsResult.Result.Collections[0].CollectionId;
        }
        public void CreateConfiguration()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            DiscoveryService service = new DiscoveryService("2019-04-30", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.CreateConfiguration(
                environmentId: "{environmentId}",
                name: "doc-config"
                );

            Console.WriteLine(result.Response);

            configurationId = result.Result.ConfigurationId;
        }
Beispiel #18
0
        public void ListCollections()
        {
            CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
                url: "https://{cpd_cluster_host}{:port}",
                username: "******",
                password: "******"
                );

            DiscoveryService service = new DiscoveryService("2019-11-22", authenticator);

            service.SetServiceUrl("{https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api}");

            var result = service.ListCollections(
                projectId: "{project_id}"
                );

            Console.WriteLine(result.Response);
        }
Beispiel #19
0
        public void UpdateCollection()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.UpdateCollection(
                environmentId: environmentId,
                collectionId: collectionId,
                name: updatedCollectionName
                );

            Console.WriteLine(result.Response);
        }
Beispiel #20
0
        public void DeleteDocument()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.DeleteDocument(
                environmentId: environmentId,
                collectionId: collectionId,
                documentId: documentId
                );

            Console.WriteLine(result.Response);
        }
        public void DeleteTrainingExample()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            DiscoveryService service = new DiscoveryService("2019-04-30", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.DeleteTrainingExample(
                environmentId: "{environmentId}",
                collectionId: "{collectionId}",
                queryId: "{queryId}",
                exampleId: "{exampleId}"
                );

            Console.WriteLine(result.Response);
        }
        public void FederatedQuery()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            DiscoveryService service = new DiscoveryService("2019-04-30", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.FederatedQuery(
                environmentId: "{environmentId}",
                collectionIds: "{collectionIds}",
                naturalLanguageQuery: "{naturalLanguageQuery}",
                _return: "{returnFields}"
                );

            Console.WriteLine(result.Response);
        }
        public void ListTrainingExamples()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.ListTrainingExamples(
                environmentId: environmentId,
                collectionId: collectionId,
                queryId: queryId
                );

            Console.WriteLine(result.Response);
        }
    IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }
        TokenOptions tokenOptions = new TokenOptions {
            IamApiKey = iamApikey
        };
        Credentials credentials = new Credentials(tokenOptions, serviceUrl);

        ServiceState = "Waiting for token data";
        while (!credentials.HasIamTokenData())
        {
            yield return(null);
        }
        service = new DiscoveryService(versionDate, credentials);
    }
        public void CreateGateway()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            DiscoveryService service = new DiscoveryService("2019-04-30", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.CreateGateway(
                environmentId: "{environmentId}",
                name: "gateway"
                );

            Console.WriteLine(result.Response);

            gatewayId = result.Result.GatewayId;
        }
Beispiel #26
0
        public void FederatedQuery()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.FederatedQuery(
                environmentId: environmentId,
                naturalLanguageQuery: naturalLanguageQuery,
                returnFields: "extracted_metadata.sha1"
                );

            Console.WriteLine(result.Response);
        }
Beispiel #27
0
        private async Task StartListening(int port)
        {
            var connected = false;

            while (true)
            {
                try
                {
                    _numberOfTries++;
                    await _httpServer.StartAsync(port).ConfigureAwait(false);

                    connected = true;
                    break;
                }
                catch (Exception ex)
                {
                    Core.Log.Write(ex);
                    if (_numberOfTries > MaxNumberOfTries)
                    {
                        break;
                    }
                    await Task.Delay(1000).ConfigureAwait(false);
                }
            }
            if (!connected)
            {
                Core.Log.Error("There was a problem trying to bind the Http Server on port {0}, please check the exception messages", port);
            }
            else
            {
                Core.Status.Attach(col =>
                {
                    col.Add("Port", port);
                }, this);
                var settings = Core.GetSettings <HttpStatusSettings>();
                if (settings.Discovery)
                {
                    _discoveryServiceId = DiscoveryService.RegisterService(DiscoveryService.FrameworkCategory, "STATUS.HTTP", "Status engine http transport service", new Dictionary <string, object>
                    {
                        ["Port"] = port
                    });
                }
            }
        }
        public DiscoveryServiceExample(string username, string password)
        {
            _discovery = new DiscoveryService(username, password, DiscoveryService.DISCOVERY_VERSION_DATE_2016_12_01);
            //_discovery.Endpoint = "http://localhost:1234";

            GetEnvironments();
            CreateEnvironment();
            Task.Factory.StartNew(() =>
            {
                Console.WriteLine("\nChecking environment status in 30 seconds.");
                System.Threading.Thread.Sleep(30000);
                IsEnvironmentReady(_createdEnvironmentId);
            });
            autoEvent.WaitOne();
            GetEnvironment();
            UpdateEnvironment();

            GetConfigurations();
            CreateConfiguration();
            GetConfiguration();
            UpdateConfiguration();

            PreviewEnvironment();

            GetCollections();
            CreateCollection();
            GetCollection();
            GetCollectionFields();
            UpdateCollection();

            AddDocument();
            GetDocument();
            UpdateDocument();

            Query();
            GetNotices();

            DeleteDocument();
            DeleteCollection();
            DeleteConfiguration();
            DeleteEnvironment();

            Console.WriteLine("\n~ Discovery examples complete.");
        }
        private Task SearchAsync()
        {
            Device.BeginInvokeOnMainThread(() => { ViewModel.Device = "Searching"; });

            var tcs = new TaskCompletionSource <bool>();

            Task.Run(async() =>
            {
                using (var discoveryService = new DiscoveryService())
                    using (var observer = new AnonymousObserver <DeviceAvailableEventArgs>(async e =>
                    {
                        State.PreviousDevice = await TargetDevice.FromDiscoveredDeviceAsync(e.DiscoveredDevice);
                        tcs.SetResult(true);
                    }))
                    {
                        var pipeline = Observable
                                       .FromEventPattern <DeviceAvailableEventArgs>(
                            handler => discoveryService.OnDevice += handler,
                            handler => discoveryService.OnDevice -= handler
                            )
                                       .Select(x => x.EventArgs);

                        if (State.PreviousDevice == null)
                        {
                            pipeline = pipeline
                                       .Take(1);
                        }

                        if (State?.PreviousDevice?.Usn != null)
                        {
                            pipeline = pipeline
                                       .Where(x => x.DiscoveredDevice.Usn == State.PreviousDevice.Usn)
                                       .Take(1);
                        }

                        pipeline.Subscribe(observer);

                        await discoveryService.SearchAsync();
                        tcs.SetResult(true);
                    }
            });

            return(tcs.Task);
        }
        public void CreateConfiguration()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.CreateConfiguration(
                environmentId: environmentId,
                name: configurationName
                );

            Console.WriteLine(result.Response);

            configurationId = result.Result.ConfigurationId;
        }
        public void QueryNotices()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            var result = service.QueryNotices(
                environmentId: environmentId,
                collectionId: collectionId,
                naturalLanguageQuery: naturalLanguageQuery,
                passages: true
                );

            Console.WriteLine(result.Response);
        }
        public MainViewModel()
        {
            _logLock = new object();

            _discoveryService        = new DiscoveryService();
            _discoveryService.Error += OnServiceError;

            _downloadService        = new DownloadService();
            _downloadService.Error += OnServiceError;

            _installService        = new InstallService();
            _installService.Error += OnServiceError;

            IsBusy = true;
            InitLog();
            InitPorts();
            InitVersions();
            IsBusy = false;
        }
Beispiel #33
0
        public void CreateGateway()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.CreateGateway(
                environmentId: environmentId,
                name: "dotnet-sdk-example-gateway"
                );

            Console.WriteLine(result.Response);

            gatewayId = result.Result.GatewayId;
        }
Beispiel #34
0
        public void CreateConfiguration()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.CreateConfiguration(
                environmentId: environmentId,
                name: configurationName
                );

            Console.WriteLine(result.Response);

            configurationId = result.Result.ConfigurationId;
        }
Beispiel #35
0
        public void QueryNotices()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.QueryNotices(
                environmentId: environmentId,
                collectionId: collectionId,
                naturalLanguageQuery: naturalLanguageQuery,
                passages: true
                );

            Console.WriteLine(result.Response);
        }
        public void ListFields()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            DiscoveryService service = new DiscoveryService("2019-04-30", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.ListFields(
                environmentId: "{environmentId}",
                collectionIds: new List <string>()
            {
                "{collection_id1}", "{collection_id2}"
            }
                );

            Console.WriteLine(result.Response);
        }
        public async Task <bool> SignOut(string accessToken)
        {
            var result        = false;
            var introspection = await IdentityIntrospectionService.IntrospectToken(accessToken);

            var discovery = await DiscoveryService.GetDiscovery();

            var requestUrl = new RequestUrl(discovery.AuthorizeEndpoint);
            var url        = requestUrl.CreateAuthorizeUrl(Config.ClientId, "id_token", "openid email TSAPI");

            using (var client = new HttpClient())
            {
                var response = await client.GetAsync(url);

                result = response.StatusCode == System.Net.HttpStatusCode.OK;
            }

            return(result);
        }
        private async Task Run()
        {
            // Create the service.
            var service = new DiscoveryService(new BaseClientService.Initializer
                {
                    ApplicationName = "Discovery Sample",
                });

            // Run the request.
            Console.WriteLine("Executing a list request...");
            var result = await service.Apis.List().ExecuteAsync();

            // Display the results.
            if (result.Items != null)
            {
                foreach (DirectoryList.ItemsData api in result.Items)
                {
                    Console.WriteLine(api.Id + " - " + api.Title);
                }
            }
        }