예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("1 - Change name of microsites.");
            Console.WriteLine("2 - Change name of profiles.");
            Console.WriteLine("3 - Check emails in users");
            Console.WriteLine("4 - Fix duplicates");
            Console.WriteLine("5 - Fix Not exitst one with Regular");
            Console.WriteLine("6 - Add fanid for each microsite");
            Console.WriteLine("7 - Add dealers ranking");
            Console.WriteLine("8 - Remove duplicate players");
            Console.WriteLine("9 - Switch back to previous description");
            Console.WriteLine("9 - Switch back to previous description");
            Console.WriteLine("10 - Change the name of the microsites in taa_microsite");
            Console.WriteLine("11 - Copy images to fanid");
            Console.WriteLine("12 - Download microsites has been created using xml files to have logos");
            Console.WriteLine("13 - Change http://dev. to http://thefanorama.com");
            Console.WriteLine("14 - Change description button");

            Console.Write("Option:");
            string option = Console.ReadLine();
            if (option.Equals("1"))
            {
                string path = @"C:\backup\archives1\microsite";
                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
                var filesInFolder = dir.GetFiles();

                foreach (System.IO.FileInfo f in filesInFolder)
                {
                    string[] newname = Regex.Split(f.Name, "microsite");
                    f.CopyTo(string.Format("c:/archives/microsite/microsite{0}", newname[1]), true);
                    Console.WriteLine(newname[1]);

                }
            }
            else if (option.Equals("2"))
            {
                string path = @"C:\backup\archives1\profile";
                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
                var filesInFolder = dir.GetFiles();

                foreach (System.IO.FileInfo f in filesInFolder)
                {
                    string[] newname = Regex.Split(f.Name, "fan");
                    f.CopyTo(string.Format("c:/archives/profile/fan{0}", newname[1]), true);
                    Console.WriteLine(newname[1]);

                }
            }

            else if (option.Equals("3"))
            {
                //fanlive4Entities entity = new fanlive4Entities();
                //foreach (User user in entity.Users)
                //{
                //    if (!IsValid(user.Email) )
                //    {
                //        BadUser baduser = new BadUser();

                //        entity.BadUsers.AddObject(baduser);
                //    }
                //}
            }
            else if (option.Equals("4"))
            {
                fanlive4Entities entity = new fanlive4Entities();
                string pricelist = ConfigurationManager.AppSettings["duplicatedPricelist"].ToString();
                var duplicates = (from d in entity.UserProfiles where d.PropertyDefinitionID == 69 && d.PropertyValue.Equals(pricelist) select d).DefaultIfEmpty();
                var duplicateTable = (from dc in duplicates
                                      group dc by dc.UserID into g
                                      let c = g.Count()
                                      where c > 1
                                      select new { g.Key, c }).DefaultIfEmpty();
                foreach (var dup in duplicateTable)
                {
                    if (dup != null)
                    {
                        //find the userid inside duplicates
                        var repeated = from d in duplicates where dup.Key == d.UserID select d;
                        int counter = 0;
                        // loop through all of them
                        if (repeated != null)
                        {
                            foreach (var rep in repeated)
                            {
                                if (rep != null && counter > 0)
                                {
                                    entity.UserProfiles.DeleteObject(rep);
                                    Console.WriteLine(rep.UserID);
                                }
                                counter++;

                            }
                        }
                    }
                }
                entity.SaveChanges();
            }
            else if (option.Equals("5"))
            {
                fanlive4Entities entity = new fanlive4Entities();
                string path = string.Format(@"c:\kianoush\profile\");
                string fullpath;
                List<string> result = new List<string>();
                List<string> profileFiles = listAllFiles(path);
                foreach (string profileFile in profileFiles)
                {

                    fullpath = string.Format("{0}{1}", path, profileFile);
                    try
                    {
                        if (System.IO.File.Exists(fullpath))
                        {
                            using (XmlTextReader xmlreader = new XmlTextReader(fullpath))
                            {

                                InsertIntoDB(xmlreader, entity);
                            }
                        }
                        else
                        {
                            Console.WriteLine(string.Format("{0} hasn't been uploaded", profileFile));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            else if (option.Equals("6"))
            {
                fanlive4Entities entity = new fanlive4Entities();
                var createdmicrosites = from m in entity.TAA_Microsite where m.IntegratorRetrievalCode != null select m;
                foreach (var microsite in createdmicrosites)
                {
                    TAA_FanID newfan = new TAA_FanID();
                    newfan.Accent = microsite.Accent;
                    newfan.PrimaryColor = microsite.PrimaryColour;
                    newfan.SecondaryColor = microsite.SecondaryColour;
                    newfan.City = microsite.City;
                    newfan.TeamName = microsite.TeamName;
                    newfan.CreatedByUserID = -1;
                    newfan.CreatedOnDate = DateTime.Now;
                    newfan.Deleted = false;
                    newfan.School = microsite.School;
                    newfan.City = microsite.City;
                    newfan.DesignName = microsite.TeamName;
                    newfan.MicrositeID = microsite.MicrositeID;
                    newfan.PrimaryColorID = microsite.PrimaryColorID;
                    newfan.SecondaryColorID = microsite.SecondaryColorID;
                    newfan.AccentColorID = microsite.AccentColorID;
                    int sportid = -1;

                    if (microsite.SportID == null)
                        sportid = -1;
                    else
                        sportid = (int)microsite.SportID;
                    newfan.TAASportID = sportid;
                    string sport;
                    sport = newfan.Sport;
                    if (newfan.Sport == null)
                        sport = "-1";
                    newfan.Sport = sport;
                    entity.TAA_FanID.AddObject(newfan);

                }
                entity.SaveChanges();
            }
            else if (option.Equals("7"))
            {
                string path = string.Format(@"d:\kianoush\dealers\dealer.xml");
                XmlSerializer serializer = new XmlSerializer(typeof(Table));
                StreamReader reader = new StreamReader(path);
                Table dealers = (Table)serializer.Deserialize(reader);
                reader.Close();
                string customerid;
                fanlive4Entities entity = new fanlive4Entities();
                StreamWriter writer = new StreamWriter(@"d:\kianoush\dealers\notimported.csv");
                foreach (var dealer in dealers.Items)
                {
                    customerid = dealer.Cell[0].Data.Trim();
                    var userprofile = (from f in entity.UserProfiles where f.PropertyValue.Trim().Equals(customerid) select f).FirstOrDefault();
                    if (userprofile != null)
                    {
                        UserProfile newuserprofile = new UserProfile();
                        newuserprofile.UserID = userprofile.UserID;
                        newuserprofile.Visibility = 2;
                        newuserprofile.PropertyDefinitionID = 68;
                        newuserprofile.PropertyValue = "True";
                        newuserprofile.LastUpdatedDate = DateTime.Now;
                        entity.UserProfiles.AddObject(newuserprofile);

                        newuserprofile = new UserProfile();

                        newuserprofile.UserID = userprofile.UserID;
                        newuserprofile.Visibility = 2;
                        newuserprofile.PropertyDefinitionID = 67;
                        newuserprofile.PropertyValue = dealer.Cell[4].Data;
                        newuserprofile.LastUpdatedDate = DateTime.Now;
                        entity.UserProfiles.AddObject(newuserprofile);
                        Console.WriteLine(customerid);

                    }
                    else
                    {

                        writer.WriteLine(customerid);
                    }

                }
                writer.Close();
                entity.SaveChanges();
            }
            else if (option.Equals("8"))
            {
                fanlive4Entities entity = new fanlive4Entities();
                string path = string.Format(@"c:\kianoush\microsite\");
                var players = from p in entity.TAA_RoleCards select p;
                string fullpath;
                List<string> result = new List<string>();
                List<string> profileFiles = listAllFiles(path);
                foreach (string profileFile in profileFiles)
                {

                    fullpath = string.Format("{0}{1}", path, profileFile);
                    try
                    {
                        if (System.IO.File.Exists(fullpath))
                        {
                            using (XmlTextReader xmlreader = new XmlTextReader(fullpath))
                            {

                            }
                        }
                        else
                        {
                            Console.WriteLine(string.Format("{0} hasn't been uploaded", profileFile));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            else if (option.Equals("9"))
            {
                fanlive4Entities entity = new fanlive4Entities();
                DateTime yesterday = DateTime.Now.AddDays(-2);
                InsertNewProduct(entity, yesterday, "D0008", 13);
                InsertNewProduct(entity, yesterday, "D0010", 8);
                InsertNewProduct(entity, yesterday, "D0012", 2);

            }
            else if (option.Equals("10"))
            {
                fanlive4Entities entity = new fanlive4Entities();

                foreach (var microsite in entity.TAA_Microsite)
                {
                    if (microsite.URL != null)
                        if (microsite.URL.Contains("thefanorama.com"))
                        {
                            //string temp = microsite.URL.Replace("slp.", string.Empty);
                            //if (microsite.URL.Contains("blondgorilla"))
                            //    temp = temp.Replace("blondgorilla.", string.Empty);4
                            string temp = microsite.URL.Replace("thefanorama.com", "dev.thefanorama.blondgorilla.com");
                            microsite.URL = temp;
                            Console.WriteLine(temp);
                        }
                }
                entity.SaveChanges();

            }
            else if (option.Equals("11"))
            {
                fanlive4Entities entity = new fanlive4Entities();
                var microsites = entity.TAA_Microsite.Where(p => p.CreatedFromSLP == false).DefaultIfEmpty();
                string path = string.Empty;
                string target = string.Empty;
                string fileName = string.Empty;
                string fileExtention = string.Empty;

                foreach (var microsite in microsites)
                {
                    string mainpath = @"D:\inetpub\wwwroot\FanoramaLive\";
                    path = string.Format(@"{0}MicrositeImages/{1}/",mainpath, microsite.MicrositeID);
                    List<string> files = listAllFiles(path);
                    if (files.Count > 0 )
                    {
                        int indexMax = findLargestFile(files, path);
                        var fanid = entity.TAA_FanID.Where(p => p.MicrositeID == microsite.MicrositeID).FirstOrDefault();

                        fileName = Guid.NewGuid().ToString();
                        string oldpath = string.Format("{0}{1}", path, files[indexMax]);
                        fileExtention = Path.GetExtension(oldpath);
                        string targetBasePath = string.Format(@"{0}/FanIdImages/{1}/",mainpath, fanid.FanID);
                        if (!Directory.Exists(targetBasePath))
                            Directory.CreateDirectory(targetBasePath);
                        target = string.Format(@"{0}/FanIdImages/{1}/{2}{3}",mainpath, fanid.FanID, fileName, fileExtention);
                        File.Copy(oldpath, target,true);
                        fanid.UserUploadedGraphic = target.Replace(mainpath,"http://thefanorama.com");
                        target = string.Format(@"{0}/FanIdImages/{1}/{2}.tif",mainpath, fanid.FanID, fileName);
                        if(!File.Exists(target))
                            File.Copy(oldpath, target);
                        fanid.GAUploadedGraphic = target.Replace(mainpath, "http://thefanorama.com");
                        Console.WriteLine(target);

                    }

                }
                entity.SaveChanges();

            }
            else if (option.Equals("12"))
            {
                var webClient = new WebClient();

                var fanImagesPath = @"D:\inetpub\wwwroot\FanoramaLive\MicrositeImages\";
                var filepath = "";
                var sceneSevenUrl = "http://216.23.175.26/is/image/TeamworkAthletic/customerUploads/";
                string sceneFilePath;
                var microsites = entity.TAA_Microsite.Where(p => p.CreatedFromSLP == false).DefaultIfEmpty();

                foreach (var microsite in microsites)
                {
                    if (!string.IsNullOrEmpty(microsite.TeamLogo))
                    {
                        filepath = string.Format("{0}{1}", fanImagesPath, microsite.MicrositeID);
                        if (!Directory.Exists(filepath))
                        {
                            Directory.CreateDirectory(filepath);
                        }
                        sceneFilePath = string.Format("{0}{1}", sceneSevenUrl, microsite.TeamLogo);
                        SaveLogo(sceneFilePath, microsite, fanImagesPath);
                    }
                }
                entity.SaveChanges();
            }

            else if (option.Equals("13"))
            {
                var fans = entity.TAA_FanID.Where(e => e.UserUploadedGraphic.Contains("dev."));
                foreach (var fan in fans)
                {
                    fan.UserUploadedGraphic = fan.UserUploadedGraphic.Replace(
                        "http://dev.thefanorama.blondgorilla.com", "http://thefanorama.com");
                    if(fan.GAUploadedGraphic!=null)
                    fan.GAUploadedGraphic = fan.GAUploadedGraphic.Replace("http://dev.thefanorama.blondgorilla.com", "http://thefanorama.com");
                }

                entity.SaveChanges();
            }
            else if (option.Equals("14"))
            {
                var fans = entity.CAT_Products.Where(e => e.Free1.Contains("<img src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\">"));
                foreach (var fan in fans)
                {
                    fan.Free1 = fan.Free1.Replace("<img src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\">", "<a href=\"#\"><img onclick=\"ShowDesignZoneDialog();\" src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\"></a>");
                  fan.Free2 = fan.Free2.Replace("<img src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\">", "<a href=\"#\"><img onclick=\"ShowDesignZoneDialog();\" src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\"></a>");
                  fan.Free3 = fan.Free3.Replace("<img src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\">", "<a href=\"#\"><img onclick=\"ShowDesignZoneDialog();\" src=\"http://thefanorama.com/Portals/0/images/click_to_design.png\"></a>");
                }

                entity.SaveChanges();
            }

            //else if (option.Equals("9"))
            //{
            //    NewTweaker.dnnolddescriptionEntities oldentities = new NewTweaker.dnnolddescriptionEntities();
            //    fanlive4Entities newentity = new fanlive4Entities();
            //    string temp;
            //    foreach (NewTweaker.CAT_Products oldproduct in oldentities.CAT_Products)
            //    {
            //        var newproduct = newentity.CAT_Products.Where(o => o.ProductID.Equals(oldproduct.ProductID)).FirstOrDefault();
            //       temp = newproduct.Free1;
            //        if(newproduct!=null)
            //        {
            //            newproduct.Free1 = oldproduct.Free1;
            //            newproduct.Free2 = oldproduct.Free2;
            //            newproduct.Free3 = oldproduct.Free3;
            //        }
            //        Console.WriteLine(string.Format("Product number {0} has been changed description1 {1} to {2}",newproduct.ProductID,temp, newproduct.Free1));
            //    }
            //    newentity.AcceptAllChanges();
            //    newentity.SaveChanges();
            //}
            //else if (option.Equals("9"))
            //{
            //    fanlive4Entities entity = new fanlive4Entities();
            //    var products = from c in entity.CAT_Products where c.CMSProductID>193 && c.ProductName.Contains("Youth") select c;
            //    foreach (var product in products)
            //    {
            //        CAT_AdvCatProducts adv = new CAT_AdvCatProducts();
            //        adv.ProductID = product.ProductID;
            //        adv.AdvCatID = 12;
            //        entity.CAT_AdvCatProducts.AddObject(adv);
            //    }
            //    entity.SaveChanges();
            //}
            //else if (option.Equals("10"))
            //{
            //    fanlive4Entities entity = new fanlive4Entities();
            //    var products = from c in entity.CAT_Products where c.CMSProductID > 193 && c.ProductName.Contains("Adult") select c;
            //    foreach (var product in products)
            //    {
            //        CAT_AdvCatProducts adv = new CAT_AdvCatProducts();
            //        adv.ProductID = product.ProductID;
            //        adv.AdvCatID = 0;
            //        entity.CAT_AdvCatProducts.AddObject(adv);
            //    }
            //    entity.SaveChanges();
            //}
            Console.WriteLine("Done!");
            Console.ReadLine();
        }
예제 #2
0
        private static void InsertNewProduct(fanlive4Entities entity, DateTime yesterday, string stylenumber, int category)
        {
            var styleProducts = from f in entity.CAT_Products where f.EAN.Contains(stylenumber) && f.PublicationStart > yesterday select f;
            foreach (var styleProduct in styleProducts)
            {
                if (entity.CAT_AdvCatProducts.Any(d => d.CAT_Products.ProductID != styleProduct.ProductID))
                {
                    CAT_AdvCatProducts catproduct = new CAT_AdvCatProducts();
                    catproduct.AdvCatID = category;
                    catproduct.CAT_Products = styleProduct;
                    entity.CAT_AdvCatProducts.AddObject(catproduct);
                    Console.WriteLine(styleProduct.ProductID);
                }
            }

            entity.SaveChanges();
        }