Пример #1
0
        public void Update_Sla_Applies_IsInactive_Statuses()
        {
            Sla.UpdateSLA(Guid.NewGuid(), false, isActive: false);

            Assert.AreEqual((int)SlaService.State.Draft, Entity.GetAttributeValue <OptionSetValue>("statecode").Value);
            Assert.AreEqual((int)SlaService.Status.Draft, Entity.GetAttributeValue <OptionSetValue>("statuscode").Value);
        }
Пример #2
0
        public List <Sla> summarySlaEDM()
        {
            TeraManager tmm = new TeraManager();
            DataTable   dt  = new DataTable();
            List <Sla>  lst = new List <Sla>();
            Sla         sla;

            try {
                string strQuery = string.Empty;
                strQuery  = " select meet ,miss ,meet_p , miss_p ,completed ";
                strQuery += " from DATALAB_OPER.pss_report_sumary_prj_stm_01 ";
                strQuery += " where project='' and tier ='TIER1' ";

                dt = tmm.GetDataTableTera(strQuery);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sla           = new Sla();
                    sla.Meet      = Int16.Parse(dt.Rows[i]["meet"].ToString());
                    sla.Miss      = Int16.Parse(dt.Rows[i]["miss"].ToString());
                    sla.Meet_p    = Int16.Parse(dt.Rows[i]["meet_p"].ToString());
                    sla.Miss_p    = Int16.Parse(dt.Rows[i]["miss_p"].ToString());
                    sla.Completed = Int16.Parse(dt.Rows[i]["completed"].ToString());
                    lst.Add(sla);
                }
            }
            catch (Exception e) {
                Console.Out.WriteLine(e.Message.ToString());
            }

            return(lst);
        }
Пример #3
0
        public void Update_Sla_Calls_Service()
        {
            var entityId = Guid.NewGuid();

            Sla.UpdateSLA(entityId, false, false);

            Service.Verify(s => s.Update(It.Is <Entity>(e => e.Id == entityId)));
        }
Пример #4
0
        public void Updates_Sla_With_Id()
        {
            var id = Guid.NewGuid();

            Sla.UpdateSLA(id, true, true);

            Assert.AreEqual(id, Entity.Id);
            Assert.AreEqual("sla", Entity.LogicalName);
        }
Пример #5
0
        public void Adds_Business_Hours_If_Not_Null()
        {
            var businessHours = new EntityReference {
                LogicalName = "calendar", Id = Guid.NewGuid()
            };

            Sla.UpdateSLA(Guid.NewGuid(), true, true, businessHours);

            Assert.AreEqual(businessHours, Entity.GetAttributeValue <object>("businesshoursid"));
        }
Пример #6
0
 public void Guardar(Sla sla)
 {
     try
     {
         using (BusinessSla negocio = new BusinessSla())
         {
             negocio.Guardar(sla);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #7
0
        public void Gets_Calendar_Given_Valid_Id()
        {
            var id = Guid.NewGuid();

            Service.Setup(s => s.Retrieve(
                              It.Is <string>(c => c == "calendar"),
                              It.Is <Guid>(g => g == id),
                              It.IsAny <ColumnSet>()))
            .Returns(new Entity("calendar", id));

            var businessHours = Sla.TryGetBusinessHours(id.ToString());

            Assert.AreEqual(id, businessHours.Id);
            Assert.AreEqual("calendar", businessHours.LogicalName);
        }
Пример #8
0
        public List <Sla> ListadoSLA(Contrato entidad)
        {
            List <Sla> Lista = null;

            try
            {
                using (SqlConnection conection = new SqlConnection(ConfigurationManager.ConnectionStrings["cnx"].ConnectionString))
                {
                    conection.Open();
                    //Fin totalizado

                    using (SqlCommand command = new SqlCommand("select * from SLA where SLA_ID not in(select CSL_SLA_ID from ContratoSLA where CSL_CON_ID=" + entidad.CON_ID + ")", conection))
                    {
                        using (SqlDataReader dr = command.ExecuteReader())
                        {
                            if (dr.HasRows)
                            {
                                Lista = new List <Sla>();
                                while (dr.Read())
                                {
                                    Sla item = new Sla();
                                    item.SLA_ID          = dr.GetInt32(dr.GetOrdinal("SLA_ID"));
                                    item.SLA_Descripcion = dr.GetString(dr.GetOrdinal("SLA_Descripcion"));
                                    Lista.Add(item);
                                }
                            }
                        }
                    }

                    conection.Close();
                }
                return(Lista);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Пример #9
0
        public void Guardar(Sla sla)
        {
            DataBaseModelContext db = new DataBaseModelContext();

            try
            {
                db.ContextOptions.ProxyCreationEnabled = _proxy;
                //TODO: Cambiar habilitado por el embebido
                sla.Habilitado = true;
                if (sla.Id == 0)
                {
                    db.Sla.AddObject(sla);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception((ex.InnerException).Message);
            }
            finally
            {
                db.Dispose();
            }
        }
Пример #10
0
 public ServiceSla()
 {
     _Sla = new Sla();
 }
        public async Task <bool> SendEmail(StorePickUpConstants.MailTemplateType templateType, VtexOrder order)
        {
            bool             success          = false;
            MerchantSettings merchantSettings = await _storePickupRepository.GetMerchantSettings();

            if (string.IsNullOrEmpty(merchantSettings.AppKey) || string.IsNullOrEmpty(merchantSettings.AppToken))
            {
                Console.WriteLine("App Settings missing.");
            }

            string responseText = string.Empty;
            string templateName = string.Empty;
            string subjectText  = string.Empty;
            string toEmail      = string.Empty;
            string nextAction   = string.Empty;
            string shopperEmail = order.ClientProfileData.Email;
            List <LogisticsInfo> pickUpItems = order.ShippingData.LogisticsInfo.Where(i => i.Slas.Any(s => s.PickupStoreInfo.IsPickupStore)).ToList();
            string storeEmail = string.Empty;

            // TODO: Divide notifications by store location.  Send separate email to each.
            foreach (LogisticsInfo logisticsInfo in pickUpItems)
            {
                string selectedSla = logisticsInfo.SelectedSla;
                Sla    sla         = logisticsInfo.Slas.Where(s => s.Id.Equals(selectedSla)).FirstOrDefault();
                storeEmail = sla.PickupStoreInfo.Address.Complement;
                if (!string.IsNullOrEmpty(storeEmail))
                {
                    break;
                }
            }

            Console.WriteLine($"Store Email = {storeEmail}");
            switch (templateType)
            {
            case StorePickUpConstants.MailTemplateType.AtLocation:
                templateName = StorePickUpConstants.MailTemplates.AtLocation;
                subjectText  = StorePickUpConstants.TemplateSubject.AtLocation;
                toEmail      = storeEmail;
                nextAction   = StorePickUpConstants.MailTemplates.PickedUp;
                break;

            case StorePickUpConstants.MailTemplateType.PackageReady:
                templateName = StorePickUpConstants.MailTemplates.PackageReady;
                subjectText  = StorePickUpConstants.TemplateSubject.PackageReady;
                toEmail      = shopperEmail;
                nextAction   = StorePickUpConstants.MailTemplates.AtLocation;
                break;

            case StorePickUpConstants.MailTemplateType.ReadyForPacking:
                templateName = StorePickUpConstants.MailTemplates.ReadyForPacking;
                subjectText  = StorePickUpConstants.TemplateSubject.ReadyForPacking;
                toEmail      = storeEmail;
                nextAction   = StorePickUpConstants.MailTemplates.PackageReady;
                break;

            case StorePickUpConstants.MailTemplateType.PickedUp:
                templateName = StorePickUpConstants.MailTemplates.PickedUp;
                subjectText  = StorePickUpConstants.TemplateSubject.PickedUp;
                toEmail      = shopperEmail;
                break;
            }

            //templateName = "test1";

            string encryptedOrderId     = _cryptoService.EncryptString(order.ClientProfileData.Email, order.OrderId, _context.Vtex.Account);
            string queryText            = $"{order.ClientProfileData.Email}|{encryptedOrderId}";
            string queryArgs            = Uri.EscapeDataString(_cryptoService.EncryptString(nextAction, queryText, _context.Vtex.Account));
            string cancelOrderQueryArgs = Uri.EscapeDataString(_cryptoService.EncryptString(StorePickUpConstants.MailTemplates.CancelOrder, queryText, _context.Vtex.Account));
            // https://sandboxusdev.myvtex.com/_v/pickup/notification/package-ready/{{queryArgs}}
            string actionLink = $"https://{_context.Vtex.Host}/_v/curbside-pickup/notification/{nextAction}/{queryArgs}";
            string cancelLink = $"https://{_context.Vtex.Host}/_v/curbside-pickup/notification/{StorePickUpConstants.MailTemplates.CancelOrder}/{cancelOrderQueryArgs}";

            EmailMessage emailMessage = new EmailMessage
            {
                templateName = templateName,
                providerName = StorePickUpConstants.Acquirer,
                jsonData     = new JsonData
                {
                    order          = order,
                    curbsidePickup = new CurbsidePickup
                    {
                        actionLink       = actionLink,
                        cancelLink       = cancelLink,
                        encryptedOrderId = encryptedOrderId,
                        toEmail          = toEmail,
                        queryArgs        = queryArgs
                    }
                }
            };

            string accountName = _httpContextAccessor.HttpContext.Request.Headers[StorePickUpConstants.VTEX_ACCOUNT_HEADER_NAME].ToString();
            string message     = JsonConvert.SerializeObject(emailMessage);

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"{StorePickUpConstants.MailService}?an={accountName}"),
                Content    = new StringContent(message, Encoding.UTF8, StorePickUpConstants.APPLICATION_JSON)
            };

            request.Headers.Add(StorePickUpConstants.USE_HTTPS_HEADER_NAME, "true");
            string authToken = this._httpContextAccessor.HttpContext.Request.Headers[StorePickUpConstants.HEADER_VTEX_CREDENTIAL];

            if (authToken != null)
            {
                request.Headers.Add(StorePickUpConstants.AUTHORIZATION_HEADER_NAME, authToken);
                request.Headers.Add(StorePickUpConstants.PROXY_AUTHORIZATION_HEADER_NAME, authToken);
            }

            request.Headers.Add(StorePickUpConstants.AppKey, merchantSettings.AppKey);
            request.Headers.Add(StorePickUpConstants.AppToken, merchantSettings.AppToken);

            HttpClient client = _clientFactory.CreateClient();

            try
            {
                HttpResponseMessage responseMessage = await client.SendAsync(request);

                string responseContent = await responseMessage.Content.ReadAsStringAsync();

                responseText = $"[-] SendEmail [{responseMessage.StatusCode}] {responseContent}";
                _context.Vtex.Logger.Info("SendEmail", null, $"{toEmail} [{responseMessage.StatusCode}] {responseContent}");
                success = responseMessage.IsSuccessStatusCode;
                if (responseMessage.StatusCode.Equals(HttpStatusCode.NotFound))
                {
                    _context.Vtex.Logger.Error("SendEmail", null, $"Template {templateName} not found.");
                }
            }
            catch (Exception ex)
            {
                responseText = $"[-] SendEmail Failure [{ex.Message}]";
                _context.Vtex.Logger.Error("SendEmail", null, "Failure", ex);
                success = false;  //jic
            }

            Console.WriteLine(responseText);
            return(success);
        }
        public async Task <bool> SendEmail(StorePickUpConstants.MailTemplateType templateType, VtexOrder order)
        {
            bool             success          = false;
            MerchantSettings merchantSettings = await _storePickupRepository.GetMerchantSettings();

            if (string.IsNullOrEmpty(merchantSettings.AppKey) || string.IsNullOrEmpty(merchantSettings.AppToken))
            {
                _context.Vtex.Logger.Error("SendEmail", null, "App Settings Missing.");
                return(success);
            }

            string templateName = string.Empty;
            string subjectText  = string.Empty;
            string toEmail      = string.Empty;
            string nextAction   = string.Empty;
            string shopperEmail = order.ClientProfileData.Email;
            List <LogisticsInfo> pickUpItems = order.ShippingData.LogisticsInfo.Where(i => i.Slas.Any(s => s.PickupStoreInfo.IsPickupStore)).ToList();
            string storeEmail = string.Empty;

            if (pickUpItems != null && pickUpItems.Count > 0)
            {
                try
                {
                    // TODO: Divide notifications by store location.  Send separate email to each.
                    foreach (LogisticsInfo logisticsInfo in pickUpItems)
                    {
                        string selectedSla = logisticsInfo.SelectedSla;
                        Sla    sla         = logisticsInfo.Slas.FirstOrDefault(s => s.Id.Equals(selectedSla));
                        if (sla.PickupStoreInfo.Address != null && !string.IsNullOrEmpty(sla.PickupStoreInfo.Address.Complement))
                        {
                            storeEmail = sla.PickupStoreInfo.Address.Complement;
                        }
                    }
                }
                catch (Exception ex)
                {
                    _context.Vtex.Logger.Error("SendEmail", null, $"Pickup Store Info Missing.  Order Id {order.OrderId}", ex);
                    return(success);
                }
            }
            else
            {
                _context.Vtex.Logger.Error("SendEmail", null, $"Pickup Store Info Missing.  Order Id {order.OrderId}");
                return(success);
            }

            // Store email fallback
            if (string.IsNullOrWhiteSpace(storeEmail))
            {
                try
                {
                    foreach (LogisticsInfo logisticsInfo in pickUpItems)
                    {
                        string selectedSla = logisticsInfo.SelectedSla;
                        Sla    sla         = logisticsInfo.Slas.FirstOrDefault(s => s.Id.Equals(selectedSla));
                        if (sla.PickupStoreInfo.Address != null && !string.IsNullOrEmpty(sla.PickupStoreInfo.AdditionalInfo))
                        {
                            string emailToVerify = sla.PickupStoreInfo.AdditionalInfo.Trim();
                            if (this.IsValidEmail(emailToVerify))
                            {
                                storeEmail = emailToVerify;
                                _context.Vtex.Logger.Info("SendEmail", null, "Using email from AdditionalInfo.");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _context.Vtex.Logger.Warn("SendEmail", null, $"Pickup Store Info Missing.  Order Id {order.OrderId}");
                    return(success);
                }
            }

            switch (templateType)
            {
            case StorePickUpConstants.MailTemplateType.AtLocation:
                templateName = StorePickUpConstants.MailTemplates.AtLocation;
                subjectText  = StorePickUpConstants.TemplateSubject.AtLocation;
                toEmail      = storeEmail;
                nextAction   = StorePickUpConstants.MailTemplates.PickedUp;
                break;

            case StorePickUpConstants.MailTemplateType.PackageReady:
                templateName = StorePickUpConstants.MailTemplates.PackageReady;
                subjectText  = StorePickUpConstants.TemplateSubject.PackageReady;
                toEmail      = shopperEmail;
                nextAction   = StorePickUpConstants.MailTemplates.AtLocation;
                break;

            case StorePickUpConstants.MailTemplateType.ReadyForPacking:
                templateName = StorePickUpConstants.MailTemplates.ReadyForPacking;
                subjectText  = StorePickUpConstants.TemplateSubject.ReadyForPacking;
                toEmail      = storeEmail;
                nextAction   = StorePickUpConstants.MailTemplates.PackageReady;
                break;

            case StorePickUpConstants.MailTemplateType.PickedUp:
                templateName = StorePickUpConstants.MailTemplates.PickedUp;
                subjectText  = StorePickUpConstants.TemplateSubject.PickedUp;
                toEmail      = shopperEmail;
                break;
            }

            if (string.IsNullOrWhiteSpace(toEmail))
            {
                // log the missing email address, but allow the mail to send in the event that the to address is in the template
                _context.Vtex.Logger.Error("SendEmail", null, "'To' email address missing.", null, new[] { ("templateType", templateType.ToString()), ("order", JsonConvert.SerializeObject(order)) });
Пример #13
0
        public void Update_Sla_Applies_IsDefault_For_False()
        {
            Sla.UpdateSLA(Guid.NewGuid(), isDefault: false, isActive: true);

            Assert.IsFalse(Entity.GetAttributeValue <bool>("isdefault"));
        }
Пример #14
0
        public void Returns_No_Business_Hours_Given_Invalid_Id()
        {
            var businessHours = Sla.TryGetBusinessHours("abc");

            Assert.AreEqual(Guid.Empty, businessHours.Id);
        }
Пример #15
0
        public void Doesnt_Add_Business_Hours_If_Null()
        {
            Sla.UpdateSLA(Guid.NewGuid(), true, true);

            Assert.IsNull(Entity.GetAttributeValue <object>("businesshoursid"));
        }
Пример #16
0
 public AbstractValue Evaluate(Sla expr)
 {
     throw new NotImplementedException();
 }