Exemple #1
0
        public ActionResult Validate()
        {
            try
            {
                APIUtil.Authenticate(this.Request);

                if (this.metaData == null || lastDownload + TimeSpan.FromMinutes(1) < DateTime.Now)
                {
                    var url = APIUtil.GetSettingsUrl();
                    this.metaData = ApplicationMetadataUtil.DownloadMetadata <ApplicationClientMetadata>(url);
                    lastDownload  = DateTime.Now;
                }

                var context = APIUtil.ReadBody(this.Request);
                using (var vw = new VowpalWabbit(new VowpalWabbitSettings(metaData.TrainArguments)
                {
                    EnableStringExampleGeneration = true,
                    EnableStringFloatCompact = true
                }))
                    using (var serializer = new VowpalWabbitJsonSerializer(vw))
                        using (var example = serializer.ParseAndCreate(context))
                        {
                            return(Json(new { VWExample = example.VowpalWabbitString }));
                        }
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                new TelemetryClient().TrackException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
        public static DecisionServiceClient <string> AddOrGetExisting(Action <byte[]> modelSuccessNotifier)
        {
            return(DecisionServiceStaticClient.AddOrGetExisting("single", _ =>
            {
                var telemetry = new TelemetryClient();
                string azureStorageConnectionString = ConfigurationManager.AppSettings[ApplicationMetadataStore.AKConnectionString];

                var storageAccount = CloudStorageAccount.Parse(azureStorageConnectionString);
                var blobClient = storageAccount.CreateCloudBlobClient();
                var settingsBlobContainer = blobClient.GetContainerReference(ApplicationBlobConstants.SettingsContainerName);
                var clientSettingsBlob = settingsBlobContainer.GetBlockBlobReference(ApplicationBlobConstants.LatestClientSettingsBlobName);

                //var settingsUrl = clientSettingsBlob.StorageUri.PrimaryUri.ToString();
                var settingsUrl = APIUtil.GetSettingsUrl();

                telemetry.TrackEvent($"DecisionServiceClient created: '{settingsUrl}'");

                var config = new DecisionServiceConfiguration(settingsUrl)
                {
                    InteractionUploadConfiguration = new BatchingConfiguration
                    {
                        MaxDuration = TimeSpan.FromSeconds(2),
                        UploadRetryPolicy = BatchUploadRetryPolicy.ExponentialRetry
                    },
                    ModelPollSuccessCallback = modelSuccessNotifier,
                    ModelPollFailureCallback = e => telemetry.TrackException(e, new Dictionary <string, string> {
                        { "Pool failure", "model" }
                    }),
                    SettingsPollFailureCallback = e => telemetry.TrackException(e, new Dictionary <string, string> {
                        { "Pool failure", "settings" }
                    }),
                    AzureStorageConnectionString = ConfigurationManager.AppSettings[ApplicationMetadataStore.AKConnectionString]
                };

                return DecisionService.CreateJson(config);
            }));
        }