/// <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);
            }
        }
Esempio n. 2
0
        public async Task <HttpResponseMessage> RecordDomain(MigrationDomain record)
        {
            var setting = _storeSettingService.GetByKey(Constants.StoreSetting.HasDomainRecordKey);

            if (setting != null && setting.Value == "False")
            {
                try
                {
                    var migrationManager = new WebMigrationManager(UmbracoContext.Application);
                    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));
        }
Esempio n. 3
0
        public void ConsultarProdutosCargaInicial()
        {
            // Act
            List <Produto> produtos = new MigrationDomain().PesquisarCargaInicialProduto();
            var            produto  = produtos.First(p => p.Nome == "Caneta Azul" && p.Valor == 1.39M);

            // Assert
            Assert.True(produto.Nome == "Caneta Azul" && produto.Valor == 1.39M);
        }
Esempio n. 4
0
        public void ConsultarProdutos()
        {
            try
            {
                // Act
                bool sucesso = new MigrationDomain().PesquisarTabelaProduto();

                // Assert
                Assert.True(sucesso);
            }
            catch (System.Exception)
            {
                // Assert
                Assert.True(false);
            }
        }