示例#1
0
        public async Task<HttpResponseMessage> RecordDomain(MigrationDomain record)
        {
            var setting = _storeSettingService.GetByKey(Constants.StoreSettingKeys.HasDomainRecordKey);

            if (setting != null && setting.Value == "False")
            {
                try
                {
                    var migrationManager = new WebMigrationManager();
                    var response = await migrationManager.PostDomainRecord(record);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        var ex = new Exception(response.ReasonPhrase);
                        MultiLogHelper.Error<SettingsApiController>("Failed to record domain analytic", ex);
                    }

                    setting.Value = true.ToString();
                    _storeSettingService.Save(setting);

                    return response;
                }
                catch (Exception ex)
                {
                    // this is for analytics only and we don't want to throw
                    MultiLogHelper.Error<SettingsApiController>("Failed to record analytics (Domain)", ex);
                }

            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
示例#2
0
        /// <summary>
        /// Posts a record of the domain.
        /// </summary>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task<HttpResponseMessage> PostDomainRecord(MigrationDomain record)
        {
            if (!MerchelloConfiguration.Current.Section.EnableInstallTracking)
                return new HttpResponseMessage(HttpStatusCode.OK);

            var data = JsonConvert.SerializeObject(record);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage responseMessage = null;
                try
                {
                    responseMessage = await client.PostAsync(RecordDomainUrl, new StringContent(data, Encoding.UTF8, "application/json"));
                }
                catch (Exception ex)
                {
                    if (responseMessage == null)
                    {
                        responseMessage = new HttpResponseMessage();
                    }

                    responseMessage.StatusCode = HttpStatusCode.InternalServerError;
                    responseMessage.ReasonPhrase = string.Format("PostDomainRecord failed: {0}", ex);
                }

                return responseMessage;
            }
        }