Ejemplo n.º 1
0
 public static bool migration(string connectionstringname, string connectionstring)
 {
     using (WBSSLStoreDb context = new WBSSLStoreDb(connectionstring))
     {
         try
         {
             if (context.Database.Exists() && context.Database.CompatibleWithModel(true))
             {
                 Site obj = context.Sites.Where(x => x.isActive).ToList().FirstOrDefault();
                 if (obj == null)
                 {
                     //context.Database.Delete();
                     //context.Database.Create();
                     DefaultDataSeed seed = new DefaultDataSeed();
                     seed.MySeed(context);
                     seed = null;
                 }
                 return(true);
             }
             else
             {
                 context.Database.Delete();
                 context.Database.Create();
                 DefaultDataSeed seed = new DefaultDataSeed();
                 seed.MySeed(context);
                 seed = null;
                 return(true);
             }
         }
         catch
         {
             context.Database.Delete();
             context.Database.Create();
             DefaultDataSeed seed = new DefaultDataSeed();
             seed.MySeed(context);
             seed = null;
             return(true);
         }
     }
 }
Ejemplo n.º 2
0
 public WBSSLStoreDb Get()
 {
     return(_db ?? (_db = new WBSSLStoreDb()));
 }
Ejemplo n.º 3
0
        public void MySeed(WBSSLStoreDb db)
        {
            // using (WBSSLStoreDb db = new WBSSLStoreDb())
            {
                System.Xml.Linq.XDocument xdoc = System.Xml.Linq.XDocument.Load(AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\Configuration\\coutrywb.xml");
                if (!db.Countries.Any(x => x.ID > 0))
                {
                    var lv1s = (from lv1 in xdoc.Descendants("Row")
                                select new Country
                    {
                        CountryName = lv1.Descendants("Data").FirstOrDefault().Value.Replace(" ", ""),
                        ISOName = lv1.Descendants("IsoCode").FirstOrDefault().Value.Replace(" ", ""),
                        RecordStatus = RecordStatus.ACTIVE,
                        RecordStatusID = (int)RecordStatus.ACTIVE
                    }).ToArray();

                    db.Countries.AddOrUpdate(lv1s);

                    db.SaveChanges();
                }

                if (!db.Brands.Any(x => x.ID > 0 && x.isActive == true))
                {
                    var lv1s = (from lv1 in xdoc.Descendants("Brand")
                                select new Brand
                    {
                        BrandName = lv1.Descendants("BrandName").FirstOrDefault().Value.Replace(" ", ""),
                        ID = Convert.ToInt32(lv1.Descendants("ID").FirstOrDefault().Value),
                        isActive = true
                    }).ToArray();

                    db.Brands.AddOrUpdate(lv1s);
                    db.SaveChanges();
                }

                if (!db.Languages.Any(x => x.ID > 0))
                {
                    var lv1s = (from lv1 in xdoc.Descendants("Languages")
                                select new Language
                    {
                        LangName = lv1.Descendants("LangName").FirstOrDefault().Value.Replace(" ", "").Replace("\n", ""),
                        LangCode = lv1.Descendants("LangCode").FirstOrDefault().Value.Replace(" ", "").Replace("\n", ""),
                        RecordStatusID = (int)RecordStatus.ACTIVE
                    }).ToArray();

                    db.Languages.AddOrUpdate(lv1s);
                    db.SaveChanges();
                }



                using (db)
                {
                    Site obj = db.Sites.Where(x => x.isActive).ToList().FirstOrDefault();
                    if (obj == null)
                    {
                        obj                = new Site();
                        obj.Alias          = "";
                        obj.CName          = System.Web.HttpContext.Current.Request.Url.Host;
                        obj.DateCreated    = DateTime.Now;
                        obj.DateModified   = DateTime.Now;
                        obj.isActive       = true;
                        obj.APIisInTest    = true;
                        obj.APIPartnerCode = "xxx";
                        obj.APIPassword    = "******";
                        obj.APIUsername    = "******";
                        obj.APIAuthToken   = "xxx";
                        db.Sites.Add(obj);
                        db.SaveChanges();
                    }

                    Audit objAudit = new Audit();
                    objAudit.ByUserID       = 0;
                    objAudit.DateCreated    = DateTime.Now;
                    objAudit.DateModified   = DateTime.Now;
                    objAudit.HttpHeaderDump = "SYSTEM";
                    objAudit.IP             = System.Web.HttpContext.Current.Request.UserHostAddress;
                    db.Audits.Add(objAudit);
                    db.SaveChanges();

                    User objUser = db.Users.Where(x => x.RecordStatusID.Equals((int)RecordStatus.ACTIVE) && x.UserTypeID.Equals((int)UserType.ADMIN)).FirstOrDefault();
                    if (objUser == null)
                    {
                        Address add = new Address();
                        add.City        = "St pete";
                        add.CompanyName = objUser != null ? objUser.CompanyName : "system";
                        add.Email       = objUser != null ? objUser.Email : "*****@*****.**";
                        add.CountryID   = 5;
                        add.Fax         = "";
                        add.Mobile      = "";
                        add.Phone       = "134654632";
                        add.State       = "Florida";
                        add.Street      = "Stpet";
                        add.Zip         = "13245";
                        db.Addresses.Add(add);
                        db.SaveChanges();

                        User u = new User();

                        u.SiteID                      = obj.ID;
                        u.AddressID                   = add.ID;
                        u.FirstName                   = "System";
                        u.LastName                    = "Admin";
                        u.Email                       = "*****@*****.**";
                        u.CompanyName                 = "System";
                        u.AlternativeEmail            = "*****@*****.**";
                        u.PasswordSalt                = WBSSLStore.Web.Helpers.WBHelper.CreateSalt();
                        u.PasswordHash                = WBSSLStore.Web.Helpers.WBHelper.CreatePasswordHash("system20167", u.PasswordSalt);
                        u.ConfirmPassword             = WBSSLStore.Web.Helpers.WBHelper.CreatePasswordHash("system20167", u.PasswordSalt);
                        u.RecordStatus                = RecordStatus.ACTIVE;
                        u.RecordStatusID              = (int)RecordStatus.ACTIVE;
                        u.UserTypeID                  = (int)UserType.ADMIN;
                        u.UserType                    = UserType.ADMIN;
                        u.AuditDetails                = new Audit();
                        u.AuditID                     = u.AuditDetails.ID;
                        u.AuditDetails.ByUserID       = 0;
                        u.AuditDetails.DateCreated    = DateTime.Now;
                        u.AuditDetails.DateModified   = DateTime.Now;
                        u.AuditDetails.HttpHeaderDump = "SYSTEM";
                        u.AuditDetails.IP             = System.Web.HttpContext.Current.Request.UserHostAddress;
                        db.Users.Add(u);
                        db.SaveChanges();
                    }



                    if (!db.EmailTemplateses.Any(x => x.ID > 0))
                    {
                        System.Xml.Linq.XDocument xdocEmail = System.Xml.Linq.XDocument.Load(AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\Configuration\\Emailconfiguration.xml");
                        var lstEmailTemp = (from lv1 in xdocEmail.Descendants("EmailTemplate")
                                            select new EmailTemplates
                        {
                            BCC = "",
                            CC = "",
                            EmailContent = (lv1.Descendants("EmailContent").FirstOrDefault() != null ? lv1.Descendants("EmailContent").FirstOrDefault().Value.Trim() : ""),
                            EmailSubject = (lv1.Descendants("EmailSubject").FirstOrDefault() != null ? lv1.Descendants("EmailSubject").FirstOrDefault().Value.Trim() : ""),
                            EmailTypeId = Convert.ToInt32((lv1.Descendants("EmailContent").Select(x => x.Attribute("EmailTypeId").Value.Replace("\n", "").Replace("\r", "").Trim()).FirstOrDefault())),
                            From = "*****@*****.**",
                            isActive = true,
                            LangID = Convert.ToInt32((lv1.Descendants("EmailContent").Select(x => x.Attribute("LangID").Value.Replace("\n", "").Replace("\r", "").Trim()).FirstOrDefault())),
                            MailMerge = (lv1.Descendants("EmailContent").Select(x => x.Attribute("MailMerge").Value.Replace("\n", "").Replace("\r", "").Trim()).FirstOrDefault()),
                            ReplyTo = "",
                            SiteID = obj.ID
                        }).ToArray();

                        db.EmailTemplateses.AddOrUpdate(lstEmailTemp);
                        db.SaveChanges();
                    }
                    WebServerType objWbServer = new WebServerType();
                    objWbServer.BrandID       = 1;
                    objWbServer.isActive      = true;
                    objWbServer.WebServerName = "MicroSoft IIS";
                    db.WebServerTypes.Add(objWbServer);
                    db.SaveChanges();
                }
            }
        }
        public void SendMessage()
        {
            try
            {
                if (logger == null)
                {
                    logger = new Logger.Logger();
                }

                //logger.Log("-------Start Sending Mails:" + DateTime.Now + "-------", Logger.LogType.EMAILQUEUE);

                int iCount = 0, iMaxCount = Convert.ToInt16(ConfigurationManager.AppSettings["MaxNoOfTries"]);
                var emailqueues = objDbContext.EmailQueues.Where(e => e.Site.isActive == true && e.NumberOfTries <= iMaxCount).EagerLoad(x => x.SiteSMTP).OrderBy(e => e.NumberOfTries).ToList();
                if (objDbContext != null)
                {
                    if (_db != null)
                    {
                        _db.Dispose();
                        _db = null;
                    }
                    objDbContext.Dispose();
                    objDbContext = null;
                }
                foreach (EmailQueue email in emailqueues)
                {
                    try
                    {
                        context = prepareMessage(email);
                        SendMail(context, iCount);
                    }
                    catch (SmtpException smtpex)
                    {
                        email.LastAttempt      = DateTime.Now;
                        email.NumberOfTries    = context.domain.NumberOfTries + 1;
                        email.LastErrorMessage = (smtpex.Message.Length > 126 ? smtpex.Message.Substring(0, 125) : smtpex.Message);

                        //objDbContext.EmailQueues.Attach(email);
                        //objDbContext.Entry<EmailQueue>(email).State = System.Data.Entity.EntityState.Modified;

                        SaveinDB(iCount, email, false);
                    }
                    catch (Exception ex)
                    {
                        email.LastAttempt      = DateTime.Now;
                        email.NumberOfTries    = context.domain.NumberOfTries + 1;
                        email.LastErrorMessage = (ex.Message.Length > 126 ? ex.Message.Substring(0, 125) : ex.Message);

                        //objDbContext.EmailQueues.Attach(context.domain);
                        //objDbContext.Entry<EmailQueue>(context.domain).State = System.Data.Entity.EntityState.Modified;


                        logger.LogException(ex);

                        SaveinDB(iCount, email, false);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(ex);
            }
            finally
            {
                if (objDbContext != null)
                {
                    if (_db != null)
                    {
                        _db.Dispose();
                        _db = null;
                    }
                    objDbContext.Dispose();
                    objDbContext = null;
                }
                // logger.Log("-------End  Sending Mails:" + DateTime.Now + "-------", Logger.LogType.EMAILQUEUE);
            }
        }