private void SaveNewToDB(string name, UploadNewResult modelResult, string groupID, string title, System.Windows.Forms.RichTextBox lbError) { try { if (modelResult != null) { lbError.Invoke(new Action(() => lbError.Text += "\n" + modelResult.description)); if (modelResult.products != null && modelResult.products.Count > 0) { string[] temp = name.Split(new string[] { Settings.Default.SplitString }, StringSplitOptions.None); string realName = name; if (temp != null) { realName = temp[0]; } ArtModel model = new ArtModel(); model.AccountUpload = SunfrogController.Instance.SFAcc; model.LogoName = SunfrogConfig.Logo; model.Name = name; model.Title = title; string primaryMockup = LogoConfig.PrimaryMockupName; string sunfrogPage = "https://www.sunfrog.com/"; for (int i = 0; i < modelResult.products.Count; i++) { var product = modelResult.products[i]; if (product.id == "19" && primaryMockup.ToLower().EndsWith(product.color.ToLower())) { model.HoodieLink = sunfrogPage + product.pageName; model.HoodieImage = "http:" + product.imageFront; //SunfrogToolKit.UploadLink = model.SunfrogLink; } else if (product.id == "8" && primaryMockup.ToLower().EndsWith(product.color.ToLower())) { model.GuysLink = sunfrogPage + product.pageName; model.GuysImage = "http:" + product.imageFront; } else if (product.id == "34" && primaryMockup.ToLower().EndsWith(product.color.ToLower())) { model.LadiesLink = sunfrogPage + product.pageName; model.LadiesImage = "http:" + product.imageFront; } } MongoController.Instance.InsertArtModel(model); lbError.Invoke(new Action(() => { lbError.Text += "\r\n" + model.HoodieLink; })); } } } catch (Exception ex) { lbError.Invoke(new Action(() => lbError.Text += "\r\n" + name + " error: " + ex.Message)); logger.Error(ex.Message); } }
public bool InsertArtModel(ArtModel artModel) { try { _instance.artModelRep.Add(artModel); } catch (Exception ex) { logger.Error(ex.Message); return(false); } return(true); }
public IActionResult AddArt([Bind("title", "medium", "description", "yearCompleted")] ArtModel newArt, int artistID) { // return Content("Add Art"); // find artist with id matching artist id parameter ArtistModel matchingArtist = _context.artists.Include(artist => artist.associatedWorks).FirstOrDefault(artist => artist.id == artistID); // check if matching artist is found if (matchingArtist != null) { // check if data passed in body of request is valid if (ModelState.IsValid) { // if data is valid add art to matching artists and database matchingArtist.associatedWorks.Add(newArt); _context.worksOfArt.Add(newArt); _context.SaveChanges(); return(View("ViewArt", matchingArtist)); } else { // send errors as view data item if data is invalid List <string> errors = GetErrorListFromModelState(ModelState); string displayErrors = ""; // build errors into string to pass to view errors.ForEach(error => displayErrors += $"Error : {error}\n"); ViewData["errorMessage"] = displayErrors; return(View("Error")); } } else { // if matching artist is found ViewData["errorMessage"] = "No Artist Found"; return(View("Error")); } }
public Art(ArtModel model) : base(model, new AnimationManager(model.animations)) { }
public BackgroundModel(Vector2 cameraPosition, ArtModel background, List <ArtModel> arts) { this.cameraPosition = cameraPosition; this.background = background; this.arts = arts; }
public bool Step2(System.Windows.Forms.RichTextBox lbError, System.Windows.Forms.ProgressBar progCurrentName, System.Windows.Forms.Label lblCurName, System.Windows.Forms.Label lblNameIndex, bool isScaleAll, bool isAutoLogo = true, bool isSaveDb = true, bool isFast = true) { try { string folderPath = Directory.GetCurrentDirectory(); string exportLogoPath = folderPath + Settings.Default.LogoExportPath; string logoName = SunfrogConfig.Logo; ////string logoName = "Logo 83"; string logoRootPath = folderPath + Settings.Default.LogoPath + logoName + "\\"; for (int i = 0; i < nameList.Count; i++) { if (string.IsNullOrEmpty(nameList[i])) { nameList.RemoveAt(i); i--; } } if (isAutoLogo) { if (SunfrogConfig.StartRange + SunfrogConfig.EndRange > nameList.Count) { nameList = nameList.Skip(SunfrogConfig.StartRange).Take(nameList.Count).DefaultIfEmpty().ToList(); } else { nameList = nameList.Skip(SunfrogConfig.StartRange).Take(SunfrogConfig.EndRange).DefaultIfEmpty().ToList(); } } if (!isSaveDb) { if (File.Exists(folderPath + Settings.Default.ListNameSuccess)) { var existedList = File.ReadLines(folderPath + Settings.Default.ListNameSuccess).ToList(); for (int i = 0; i < existedList.Count; i++) { nameList.Remove(existedList[i]); } } } if (nameList.Count > 0) { progCurrentName.Invoke(new Action(() => progCurrentName.Value = progCurrentName.Minimum)); for (int i = 0; i < nameList.Count; i++) //int i = 0; // Parallel.ForEach(nameList, (name) => { string logoPath = string.Empty; string name = nameList[i]; if (!isAutoLogo) { logoPath = nameList[i]; name = Path.GetFileNameWithoutExtension(logoPath); } try { string[] temp = name.Split(new string[] { Settings.Default.SplitString }, StringSplitOptions.None); string realName = name; if (temp != null) { realName = temp[0]; } //string realName = name.Replace(Settings.Default.SplitString, Settings.Default.ExportSplitString); lblCurName.Invoke(new Action(() => lblCurName.Text = realName)); ArtModel model = null; if (isSaveDb) { model = MongoController.Instance.FindModel(name, logoName); } if (model == null) { if (isAutoLogo) { logoPath = LoadNewSunfrogData(name, exportLogoPath, folderPath + Settings.Default.LogoPath, logoName, Settings.Default.SplitString, Settings.Default.ExportSplitString, isScaleAll); } string title = string.Empty; string jsonData = CreateNewSunfrogData(name, logoPath, ref title, isFast); SunfrogController.Instance.web.SendRequest("https://manager.sunfrogshirts.com/Designer/", "GET", null); string result = SunfrogController.Instance.UplodNewMockup(jsonData); if (result.Contains("Temporarily Unavailable") || result.Contains("Sorry, this service is currently unavailable")) { lbError.Invoke(new Action(() => lbError.Text += "\nSunfrog bảo trì rồi")); // System.Windows.Forms.MessageBox.Show("Sunfrog bao tri!"); BackendController.IsMaintain = true; i--; SchedulerController.Instance.Start(); while (!BackendController.IsMaintain) { Thread.Sleep(1000 * 60 * 5); } } logger.Debug("result: " + result); UploadNewResult modelResult = Newtonsoft.Json.JsonConvert.DeserializeObject <UploadNewResult>(result); if (modelResult != null) { string description = modelResult.description.ToLower(); if (description.Contains("error creating mockup image.")) { logger.Error("upload error: " + description); break; } else if (description.Contains("Please refresh this page to login")) { SunfrogController.Instance.Login(SunfrogConfig.SFAcc, SunfrogConfig.SFPass); Thread.Sleep(1000 * 60 * 3); i--; continue; } } string rawLink = modelResult.products[0].pageName; string groupID = ExtractGroupID(rawLink); string jsonUpdateData = CreateUpdatingMockupJson(groupID, SunfrogController.Instance.AM, isFast); Task task = SunfrogController.Instance.UpdateMockup(jsonUpdateData); Task.WhenAll(task); Console.WriteLine("test"); if (isSaveDb) { SaveNewToDB(name, modelResult, groupID, title, lbError); } lbError.Invoke(new Action(() => { if (lbError.TextLength >= 500) { lbError.Text = ""; } })); //SaveNewToDB(name, modelResult, Settings.Default.SplitString, Settings.Default.ExportSplitString); File.AppendAllLines(folderPath + Settings.Default.ListNameSuccess, new String[] { name }); // File.AppendAllLines(folderPath + Settings.Default.UploadedLinks, new String[] { SunfrogLink }); } //else { lbError.Invoke(new Action(() => { lbError.Text += "\r\n" + name + " da upload!"; })); } } catch (Exception ex) { logger.WarnFormat("Error Message: {0}\nStacktrace: {1}", ex.Message, ex.StackTrace); File.AppendAllLines(folderPath + Settings.Default.ErrorNameList, new String[] { name }); } progCurrentName.Invoke(new Action(() => progCurrentName.Value = (i + 1) * 100 / nameList.Count)); lblNameIndex.Invoke(new Action(() => lblNameIndex.Text = string.Format("{0}/{1}", i + 1, nameList.Count))); } ; } } catch (Exception ex) { logger.ErrorFormat("Error Message: {0}\nStacktrace: {1}", ex.Message, ex.StackTrace); } return(false); }
private void SaveNewToDB(string name, UploadNewResult modelResult, string splitString, string exportSplitString) { try { if (modelResult != null) { if (modelResult.products != null && modelResult.products.Count > 0) { string exportName = name.Replace(splitString, exportSplitString); string[] temp = name.Split(new string[] { splitString }, StringSplitOptions.None); //string realName = name; //if (temp != null) // realName = temp[0]; ArtModel model = new ArtModel(); model.AccountUpload = SunfrogConfig.SFAcc; model.LogoName = SunfrogConfig.Logo; model.Name = exportName; if (temp != null && temp.Length > 0) { model.Title = ContentConfig.Title; for (int i = 0; i < temp.Length; i++) { model.Title = model.Title.Replace("{" + i + "}", temp[i]); } } else { model.Title = string.Format(ContentConfig.Title, name); } string primaryMockup = LogoConfig.PrimaryMockupName; string sunfrogPage = "https://www.sunfrog.com/"; for (int i = 0; i < modelResult.products.Count; i++) { var product = modelResult.products[i]; if (product.id == "19" && primaryMockup.ToLower().EndsWith(product.color.ToLower())) { model.HoodieLink = sunfrogPage + product.pageName; model.HoodieImage = "http:" + product.imageFront; SunfrogLink = model.HoodieLink; } else if (product.id == "8" && primaryMockup.ToLower().EndsWith(product.color.ToLower())) { model.GuysLink = sunfrogPage + product.pageName; model.GuysImage = "http:" + product.imageFront; } else if (product.id == "34" && primaryMockup.ToLower().EndsWith(product.color.ToLower())) { model.LadiesLink = sunfrogPage + product.pageName; model.LadiesImage = "http:" + product.imageFront; } } MongoController.Instance.InsertArtModel(model); } } } catch (Exception ex) { logger.Error(ex.Message); } }