示例#1
0
        private async Task LogNumberOfRuns()
        {
            try
            {
                int numRuns = 0;
                _skillStorage = SkillStorage.GetDatabase(Skill);

                //Keep track of the number of times this is run in the file
                IDictionary <string, object> storedData = await _skillStorage.LoadDataAsync();

                if (storedData != null && storedData.ContainsKey("NumberOfRuns"))
                {
                    numRuns = Convert.ToInt32(storedData["NumberOfRuns"]);
                }

                await _skillStorage.SaveDataAsync(new Dictionary <string, object> {
                    { "NumberOfRuns", ++numRuns }
                });
            }
            catch (Exception ex)
            {
                _misty.SkillLogger.Log("Failed to update run number in data store.", ex);
            }
        }
示例#2
0
        /// <summary>
        /// Method to load the startup parameters into the skill fields
        /// </summary>
        /// <param name="parameters"></param>
        private async Task ProcessStartupParameters(IDictionary <string, object> parameters)
        {
            try
            {
                IDictionary <string, object> storedData = await _skillStorage.LoadDataAsync() ?? new Dictionary <string, object>();

                int numRuns = 0;
                if (storedData.ContainsKey("NumberOfRuns"))
                {
                    numRuns = Convert.ToInt32(storedData["NumberOfRuns"]);
                    storedData.Remove("NumberOfRuns");
                }
                storedData.Add("NumberOfRuns", ++numRuns);

                //Handle Passed in auth settings.
                //TODO Should encypt this info for production
                IDictionary <AzureServiceType, AzureServiceAuthorization> servicesAuth = new Dictionary <AzureServiceType, AzureServiceAuthorization>();

                string region   = "westus";
                string endpoint = "https://westus.api.cognitive.microsoft.com/";

                string key = GetStringField(parameters, storedData, "visionkey");
                if (key != null)
                {
                    region   = GetStringField(parameters, storedData, "visionregion") ?? "westus";
                    endpoint = GetStringField(parameters, storedData, "visionendpoint") ?? "https://westus.api.cognitive.microsoft.com/";

                    servicesAuth.Remove(AzureServiceType.ComputerVision);
                    servicesAuth.Add
                    (
                        AzureServiceType.ComputerVision,
                        new AzureServiceAuthorization
                    {
                        Region          = region,
                        Endpoint        = endpoint,
                        ServiceType     = AzureServiceType.ComputerVision,
                        SubscriptionKey = key
                    }
                    );
                }

                key = GetStringField(parameters, storedData, "speechkey");
                if (key != null)
                {
                    region   = GetStringField(parameters, storedData, "speechregion") ?? "westus";
                    endpoint = GetStringField(parameters, storedData, "speechendpoint") ?? "https://westus.api.cognitive.microsoft.com/";

                    servicesAuth.Remove(AzureServiceType.Speech);
                    servicesAuth.Add
                    (
                        AzureServiceType.Speech,
                        new AzureServiceAuthorization
                    {
                        Region          = region,
                        Endpoint        = endpoint,
                        ServiceType     = AzureServiceType.Speech,
                        SubscriptionKey = key
                    }
                    );
                }
                _azureCognitive = new AzureCognitiveService(servicesAuth, _misty.SkillLogger);

                await _skillStorage.SaveDataAsync(storedData);
            }
            catch (Exception ex)
            {
                _misty.SkillLogger.Log("Failed handling startup parameters", ex);
            }
        }