private void exec(string File) { try { String extension = Path.GetExtension(File).ToLower(); if (Core.Img.imageExtensions.Contains(extension)) { String ValuesImg = Path.GetFileNameWithoutExtension(File); String AR_Ref = ValuesImg; int position, AttributeArticle; int Article = Core.Global.SearchReference(ValuesImg, out AR_Ref, out position, out AttributeArticle); if (Article != 0) { Core.ImportSage.ImportArticleImage import = new Core.ImportSage.ImportArticleImage(); import.Exec(File, Article, position, AttributeArticle); if (import.logs != null && import.logs.Count > 0) { lock (this.Logs) { Logs.AddRange(import.logs); } } } if (Core.Global.GetConfig().ImportImageSearchReferenceClient) { List <int> listID = Core.Global.SearchListReference(ValuesImg); if (listID != null && listID.Count > 0) { foreach (int id_article_local in listID) { Core.ImportSage.ImportArticleImage import = new Core.ImportSage.ImportArticleImage(); import.Exec(File, id_article_local); if (import.logs != null && import.logs.Count > 0) { lock (this.Logs) { Logs.AddRange(import.logs); } } } } } } } catch (Exception ex) { Core.Error.SendMailError("[IMPORT IMAGE SAGE]<br />" + ex.ToString()); } }
public void Sync(string File) { this.Semaphore.WaitOne(); try { int Article = 0; string extension = Path.GetExtension(File).ToLower(); string filename = Path.GetFileNameWithoutExtension(File); Model.Local.MediaAssignmentRuleRepository MediaAssignmentRuleRepository = new Model.Local.MediaAssignmentRuleRepository(); List <Model.Local.MediaAssignmentRule> list = MediaAssignmentRuleRepository.List(); if (list.Count(r => filename.EndsWith(r.SuffixText)) > 0) { foreach (Model.Local.MediaAssignmentRule mediarule in list.Where(r => filename.EndsWith(r.SuffixText))) { if (filename.EndsWith(mediarule.SuffixText)) { string ref_art = filename.Substring(0, filename.Length - mediarule.SuffixText.Length); Article = Core.Global.SearchReference(ref_art); if (Article != 0) { switch (mediarule.Rule) { case (short)Core.Parametres.MediaRule.AsAttachment: Core.ImportSage.ImportArticleDocument Sync = new Core.ImportSage.ImportArticleDocument(); Sync.Exec(File, Article, (!string.IsNullOrEmpty(mediarule.AssignName) ? mediarule.AssignName : filename), null, null); break; case (short)Core.Parametres.MediaRule.AsPicture: if (Core.Img.imageExtensions.Contains(extension)) { int position, AttributeArticle; Core.Global.SearchReference(filename, out position, out AttributeArticle); Core.ImportSage.ImportArticleImage ImportImage = new Core.ImportSage.ImportArticleImage(); ImportImage.Exec(File, Article, position, AttributeArticle); } break; } } } } } else { Article = Core.Global.SearchReference(filename); if (Article != 0) { if (Core.Img.imageExtensions.Contains(extension)) { // Unactive import //Core.ImportSage.ImportArticleImage ImportImage = new Core.ImportSage.ImportArticleImage(); //ImportImage.Exec(File, Article); } else { Core.ImportSage.ImportArticleDocument Sync = new Core.ImportSage.ImportArticleDocument(); Sync.Exec(File, Article); } } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } lock (this) { this.CurrentCount += 1; } this.ReportProgress(this.CurrentCount * 100 / this.ListCount); this.Semaphore.Release(); }
public void Sync(int IdArticle) { this.Semaphore.WaitOne(); try { Model.Sage.F_ARTICLEMEDIARepository F_ARTICLEMEDIARepository = new Model.Sage.F_ARTICLEMEDIARepository(); Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); Model.Local.Article Article = new Model.Local.Article(); if (ArticleRepository.ExistArticle(IdArticle)) { Article = ArticleRepository.ReadArticle(IdArticle); // <JG> 24/03/2015 ajout option suppression auto if (Core.Global.GetConfig().ImportMediaAutoDeleteAttachment) { Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository(); if (AttachmentRepository.ExistArticle(IdArticle)) { List <Model.Local.Attachment> ListArticle = AttachmentRepository.ListArticle(IdArticle); ListArticle = ListArticle.Where(at => at.Sag_Id != null).ToList(); foreach (Model.Local.Attachment Attachment in ListArticle) { if (!F_ARTICLEMEDIARepository.Exist(Attachment.Sag_Id.Value)) { if (System.IO.File.Exists(System.IO.Path.Combine(Core.Global.GetConfig().Folders.RootAttachment, Attachment.Att_File))) { File.Delete(System.IO.Path.Combine(Core.Global.GetConfig().Folders.RootAttachment, Attachment.Att_File)); } if (Attachment.Pre_Id != null && Attachment.Pre_Id > 0) { // Suppression de l'occurence du document sur prestashop Model.Prestashop.PsAttachmentRepository psAttachmentRepository = new Model.Prestashop.PsAttachmentRepository(); Model.Prestashop.PsAttachmentLangRepository psAttachmentLangRepository = new Model.Prestashop.PsAttachmentLangRepository(); Model.Prestashop.PsProductAttachmentRepository psProductAttachmentRepository = new Model.Prestashop.PsProductAttachmentRepository(); Model.Prestashop.PsAttachment psAttachment = psAttachmentRepository.ReadAttachment(Convert.ToUInt32(Attachment.Pre_Id.Value)); string distant_file = string.Empty; if (psAttachment != null) { distant_file = psAttachment.File; psProductAttachmentRepository.Delete(psProductAttachmentRepository.ListAttachment(psAttachment.IDAttachment)); psAttachmentLangRepository.Delete(psAttachmentLangRepository.ListAttachment(psAttachment.IDAttachment)); psAttachmentRepository.Delete(psAttachment); } if (Core.Global.GetConfig().ConfigFTPActive) { String FTP = Core.Global.GetConfig().ConfigFTPIP; String User = Core.Global.GetConfig().ConfigFTPUser; String Password = Core.Global.GetConfig().ConfigFTPPassword; string ftpfullpath = FTP + "/download/" + distant_file; if (Core.Ftp.ExistFile(ftpfullpath, User, Password)) { try { System.Net.FtpWebRequest request = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath); request.Credentials = new System.Net.NetworkCredential(User, Password); request.Method = System.Net.WebRequestMethods.Ftp.DeleteFile; request.UseBinary = true; request.UsePassive = true; request.KeepAlive = false; System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)request.GetResponse(); response.Close(); } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } } } } AttachmentRepository.Delete(Attachment); } } } } if (F_ARTICLEMEDIARepository.ExistReference(Article.Art_Ref)) { foreach (Model.Sage.F_ARTICLEMEDIA F_ARTICLEMEDIA in F_ARTICLEMEDIARepository.ListReference(Article.Art_Ref)) { String File = (System.IO.File.Exists(F_ARTICLEMEDIA.ME_Fichier)) ? F_ARTICLEMEDIA.ME_Fichier : Path.Combine(DirDoc, F_ARTICLEMEDIA.ME_Fichier.Substring(2)); if (System.IO.File.Exists(File)) { string extension = Path.GetExtension(File).ToLower(); string filename = Path.GetFileNameWithoutExtension(File); Model.Local.MediaAssignmentRuleRepository MediaAssignmentRuleRepository = new Model.Local.MediaAssignmentRuleRepository(); List <Model.Local.MediaAssignmentRule> list = MediaAssignmentRuleRepository.List(); if (list.Count(r => filename.EndsWith(r.SuffixText)) > 0) { foreach (Model.Local.MediaAssignmentRule mediarule in list.Where(r => filename.EndsWith(r.SuffixText))) { if (filename.EndsWith(mediarule.SuffixText)) { switch (mediarule.Rule) { case (short)Core.Parametres.MediaRule.AsAttachment: Core.ImportSage.ImportArticleDocument Sync = new Core.ImportSage.ImportArticleDocument(); Sync.Exec(File, Article.Art_Id, (!string.IsNullOrEmpty(mediarule.AssignName) ? mediarule.AssignName : F_ARTICLEMEDIA.ME_Commentaire), null, F_ARTICLEMEDIA.cbMarq); break; case (short)Core.Parametres.MediaRule.AsPicture: if (Core.Img.imageExtensions.Contains(extension)) { int position, AttributeArticle; Core.Global.SearchReference(filename, out position, out AttributeArticle); Core.ImportSage.ImportArticleImage ImportImage = new Core.ImportSage.ImportArticleImage(); ImportImage.Exec(File, Article.Art_Id, position, AttributeArticle); } break; } } } } else { if (Core.Img.imageExtensions.Contains(extension)) { if (Core.Global.GetConfig().ImportMediaIncludePictures) { int position, AttributeArticle; Core.Global.SearchReference(filename, out position, out AttributeArticle); Core.ImportSage.ImportArticleImage ImportImage = new Core.ImportSage.ImportArticleImage(); ImportImage.Exec(File, Article.Art_Id, position, AttributeArticle); } } else { Core.ImportSage.ImportArticleDocument Sync = new Core.ImportSage.ImportArticleDocument(); Sync.Exec(File, Article.Art_Id, F_ARTICLEMEDIA.ME_Commentaire, null, F_ARTICLEMEDIA.cbMarq); } } } } } } } catch (Exception ex) { Core.Error.SendMailError("[IM] " + ex.ToString()); } lock (this) { this.CurrentCount += 1; } this.ReportProgress(this.CurrentCount * 100 / this.ListCount); this.Semaphore.Release(); }
private void LoadWorker_DoWork(object sender, DoWorkEventArgs e) { // parcours des données Sage if (Core.Global.GetConfig().ImportImageUseSageDatas) { Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository(); List <Model.Sage.F_ARTICLE_Photo> ListPhoto = F_ARTICLERepository.ListPhoto(); Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); List <int> ListSageLocal = ArticleRepository.ListSageId(); ListPhoto = ListPhoto.Where(ap => ListSageLocal.Contains(ap.cbMarq)).ToList(); ListCount = ListPhoto.Count; CurrentCount = 0; foreach (Model.Sage.F_ARTICLE_Photo F_ARTICLE_Photo in ListPhoto) { string file = null; if (!string.IsNullOrWhiteSpace(F_ARTICLE_Photo.AC_Photo)) { file = System.IO.Path.Combine(Core.Global.GetConfig().AutomaticImportFolderPicture, F_ARTICLE_Photo.AC_Photo); } else if (!string.IsNullOrWhiteSpace(F_ARTICLE_Photo.AR_Photo)) { file = System.IO.Path.Combine(Core.Global.GetConfig().AutomaticImportFolderPicture, F_ARTICLE_Photo.AR_Photo); } if (file != null && System.IO.File.Exists(file)) { Model.Local.Article Article = ArticleRepository.ReadSag_Id(F_ARTICLE_Photo.cbMarq); String extension = Path.GetExtension(file).ToLower(); if (Core.Img.imageExtensions.Contains(extension)) { Core.ImportSage.ImportArticleImage import = new Core.ImportSage.ImportArticleImage(); import.Exec(file, Article.Art_Id); if (import.logs != null && import.logs.Count > 0) { lock (this.Logs) { Logs.AddRange(import.logs); } } lock (this) { this.CurrentCount += 1; LoadWorker.ReportProgress(this.CurrentCount * 100 / this.ListCount); } } } } } // fonction par défaut = parcours dossier local ou réseau else { String[] Files = System.IO.Directory.GetFiles(this.DirImg); this.ListCount = Files.Length; foreach (string file in Files) { exec(file); lock (this) { this.CurrentCount += 1; LoadWorker.ReportProgress(this.CurrentCount * 100 / this.ListCount); } } } }