public ProjectDocumentImporter(string folder, string templateFolder)
 {
     this._rootFolder     = folder;
     this._templateFolder = templateFolder;
     ProcessFolder(folder, null, string.Empty);
     CLLogger.LogVerbose(string.Format("The total size of the folder '{0}' is '{1}' mb", folder, totalSize));
 }
Example #2
0
        private static FolderTemplate ImportFolder(Guid folderTemplateHeaderId, Guid folderTemplateParentId, string division, string folder)
        {
            var date            = folder.Trim().Substring(folder.Trim().Length - 10);
            var cleanFolderName = folder.Trim().Substring(0, folder.Trim().Length - 10).Trim();

            CLLogger.LogInformation(string.Format(@"Found folder '{0}\{1}' Date : '{2}'", division, cleanFolderName, date));
            return(CreateNewFolderTemplate(folderTemplateHeaderId, folderTemplateParentId, cleanFolderName));
        }
Example #3
0
        private static void SetDefaultDocumentManager()
        {
            App.Cache.Companies();            // load companies before in order to avoid an error of transaction scope
            var temp = App.Cache.EntityLists; // To load entities in cache

            DocumentManagerProvider.DocumentManagerChooser = new Func <IDocumentManager>(() =>
            {
                try
                {
                    var company = App.Cache.Companies().FirstOrDefault(x => x.Id == new Guid("2F018D31-A8E4-47AC-8A29-C78190768147"));

                    if (company != null && company.UseSharepoint)
                    {
                        return(new SharepointDocumentManager()
                        {
                            SharepointDomain = company.SharepointDomain,
                            SharepointLibraryName = company.SharepointLibraryName,
                            SharepointUrl = company.SharepointUrl,
                            SharepointUserName = company.SharepointUserName,
                            SharepointPassword = company.SharepointPassword,
                            SharepointInCloud = company.SharepointInCloud,
                            SharepointUseInternalTagFolder = true //company.SharepointUseInternalTagFolder
                        });
                    }
                }
                catch (Exception ex)
                {
                    CLLogger.LogError(ex);
                }

                return(new JMSLDocumentManager());
            });

            DocumentManagerProvider.DocumentBaseFolderName = new Func <JMSL.Framework.DAL.Entities.BaseEntitiesDbContext, JMSL.Framework.Business.Entities.EntityInfo, Guid, string>((db, entityInfo, referenceId) =>
            {
                if (entityInfo != null)
                {
                    if (entityInfo.Name.Compare("Project"))
                    {
                        return(entityInfo.Name + "\\" + ProjectServices.GetProjectNumberById(db as ComboxDbContext, referenceId).Replace("\"", ""));
                    }
                    else if (entityInfo.Name.Compare("Client"))
                    {
                        return(entityInfo.Name + "\\" + ClientServices.GetClientInfo(db as ComboxDbContext, referenceId).Name.Replace("\"", ""));
                    }
                    else if (entityInfo.Name.Compare("Documentation"))
                    {
                        return(entityInfo.Name);
                    }
                    else
                    {
                        return(entityInfo.Name + "\\");
                    }
                }

                return(string.Empty);
            });
        }
        internal void GetConvertedAmount(string originalCurrency, string targetCurrency)
        {
            var    value             = ConvertedAmountField.GetAttribute("value");
            string valueChanged      = ReplaceCommasWithStars(value);
            string valueChangedTwo   = ReplaceDotsWithCommas(valueChanged);
            string valueChangedTHree = ReplaceStarsWithDots(valueChangedTwo);

            //CLLogger.Info($"{originalCurrency} to {targetCurrency} = {value}");
            CLLogger.Info($"{valueChangedTHree}");
            //return value;
        }
Example #5
0
        protected static void Synchronize(object stateInfo)
        {
            try
            {
                var startingTime = DateTime.Now;
                SetDefaultDocumentManager();
                //new ProjectDocumentImporter(@"P:\Ingenierie\PART DOCUMENTS\PRODUCTION PART\", @"Amélioration continue\À classer");

                RenameEntityFolderSharepointProcess.Execute();

                CLLogger.LogVerbose("The upload takes " + DateTime.Now.Subtract(startingTime).TotalMinutes.ToString() + " minutes.");
            }
            catch (Exception ex)
            {
                CLLogger.LogCritical(ex);
            }
        }
Example #6
0
        private static void ChangeFileCustomProperties()
        {
            var doc = new OleDocumentPropertiesClass();

            try
            {
                doc.Open(@"C:\test danny.txt");
                //doc.SummaryProperties.Company = "ComboxTest";
                doc.CustomProperties.Add("ComboxManager", Guid.NewGuid().ToString());
            }
            catch (Exception ex)
            {
                CLLogger.LogError(ex);
                Console.WriteLine(ex.Message);
                ex = null;
            }

            //after making changes, you need to use this line to save them
            doc.Save();
        }
        private void UpdateProjectProgram(Guid projectId, string programName)
        {
            var projectNeedsToBeUpdated = false;
            var programId = Cache.GetProjectProgramId(programName);

            using (var context = FactoryDbContext.Create())
            {
                projectNeedsToBeUpdated = context.Projects.Any(x => x.Id == projectId && x.ProgramId != programId);
            }

            if (projectNeedsToBeUpdated)
            {
                var project = Project.Get(projectId);

                project.ProgramId          = programId;
                project.CurrentUserId      = Constants.User.Admin;
                project.IsModifiedByImport = true;
                project.Save();
                CLLogger.LogVerbose(string.Format("The project '{0}' program as been updated to '{1}'", project.Name, programName));
                project = null;
            }
        }
Example #8
0
 private static FolderTemplate ImportDivision(Guid folderTemplateHeaderId, string division)
 {
     CLLogger.LogInformation(string.Format(@"Found division '{0}'", division));
     return(CreateNewFolderTemplate(folderTemplateHeaderId, null, division));
 }
        private void ProcessFile(FileInfo file, Guid projectId, string comboxPath)
        {
            CLLogger.LogVerbose(string.Format("The file '{0}' --> '{2}' will be associated to project '{1}'", file.FullName.Substring(_rootFolder.Length), Cache.GetProjectName(projectId), comboxPath));
            totalSize += (file.Length * 1d) / 1024 / 1024;

            var  cleanPath = comboxPath.TrimEnd('\\').Split('\\');
            Guid?folderId  = null;

            using (var context = FactoryDbContext.Create())
            {
                for (var i = 0; i < cleanPath.Length; i++)
                {
                    var currentFolder    = CleanStringForWeb(cleanPath[i]);
                    var existingFolderId = context.EntityFolders.Where(x => x.ReferenceId == projectId && x.ParentId == folderId && x.Name == currentFolder).Select(x => x.Id).FirstOrDefault();

                    if (existingFolderId == Guid.Empty)
                    {
                        var folder = EntityFolder.New();
                        folder.CurrentUserId = Constants.User.Admin;
                        folder.Id            = Guid.NewGuid();
                        folder.EntityId      = Constants.EntityType.Project;
                        folder.ReferenceId   = projectId;
                        folder.ParentId      = folderId;
                        folder.Name          = currentFolder;
                        folder.Save();

                        folderId = folder.Id;
                    }
                    else
                    {
                        folderId = existingFolderId;
                    }
                }
            }

            var document = Document.New();

            document.ReferenceId     = projectId;
            document.EntityId        = Constants.EntityType.Project;
            document.CurrentUserId   = Constants.User.Admin;
            document.CreatedOn       = DateTime.Now;
            document.LastUpdatedOn   = DateTime.Now;
            document.CreatedById     = Constants.User.Admin;
            document.LastUpdatedById = Constants.User.Admin;
            document.Id              = Guid.NewGuid();
            document.FolderId        = folderId;
            document.DocumentTypeId  = LookupServices.GetLookupItemIdFromTag("LST_DOCUMENT_TYPE_NOT_CLASSIFIED");
            document.Filename        = CleanStringForWeb(file.Name).Replace("..", ".");
            document.FileExtension   = file.Extension;
            document.FileContentType = ContentTypes.GetContentTypeFromFileExtension(document.FileExtension);

            try
            {
                using (var stream = file.OpenRead())
                {
                    document.Insert <JMSL.Framework.DAL.Entities.Document, Document>(DocumentManagerProvider.Get(),
                                                                                     new TransferDocument()
                    {
                        FileName       = document.Filename,
                        FileLength     = file.Length,
                        FileByteStream = stream
                    });
                }
            }
            catch (Exception ex)
            {
                CLLogger.LogError(ex);
            }
        }
        private void ProcessFolder(string folder, Guid?parentProjectId, string comboxPath)
        {
            if (Directory.Exists(folder))
            {
                foreach (var folderInfo in new DirectoryInfo(folder).GetDirectories())
                {
                    var projectId          = Cache.GetProjectId(folderInfo.Name, folderInfo.FullName);
                    var originalComboxPath = comboxPath;
                    if (projectId == null)
                    {
                        projectId = parentProjectId;
                    }

                    if (parentProjectId == null || projectId != parentProjectId)
                    {
                        comboxPath = this._templateFolder + @"\";
                    }
                    if (projectId == Guid.Empty)
                    {
                        //CLLogger.LogVerbose(string.Format("The folder is excluded: '{0}'", folderInfo.FullName));
                    }
                    else if (projectId != null)
                    {/*
                      * var acceptedProject = new List<string>() {
                      *     "1006M3205C001",
                      *     "1006M3300C001"
                      *      };
                      * if (acceptedProject.Contains(Cache.GetProjectName(projectId.Value)))
                      * {
                      *     if (_projectProgram.ContainsKey(folderInfo.Name))
                      *     {
                      *         UpdateProjectProgram(projectId.Value, _projectProgram[folderInfo.Name]);
                      *     }
                      *     else if (_projectProgram.ContainsKey(Cache.GetProjectName(projectId.Value)))
                      *     {
                      *         UpdateProjectProgram(projectId.Value, _projectProgram[Cache.GetProjectName(projectId.Value)]);
                      *
                      *         if (!folderInfo.Name.ToUpper().Contains("COMMERCIAL") && !folderInfo.Name.ToUpper().Contains("MILITAIRE"))
                      *         {
                      *             comboxPath += folderInfo.Name + @"\";
                      *         }
                      *     }
                      *     else if (folderInfo.Name.ToUpper().Contains("COMMERCIAL"))
                      *     {
                      *         UpdateProjectProgram(projectId.Value, "Commercial");
                      *     }
                      *     else if (folderInfo.Name.ToUpper().Contains("MILITAIRE"))
                      *     {
                      *         UpdateProjectProgram(projectId.Value, "Militaire");
                      *     }
                      *     else if (projectId == parentProjectId)
                      *     {
                      *         comboxPath += folderInfo.Name + @"\";
                      *     }
                      *
                      *     if (_folderMapping.ContainsKey(folderInfo.Name.ToUpper()))
                      *     {
                      *         comboxPath = _folderMapping[folderInfo.Name.ToUpper()] + @"\";
                      *     }
                      *
                      *     ProcessFolder(folderInfo.FullName, projectId, comboxPath);
                      *
                      *     foreach (var fileInfo in folderInfo.GetFiles())
                      *     {
                      *         if (!fileInfo.Name.StartsWith("~") && !_excludedEndFiles.Any(x => fileInfo.Name.Trim().EndsWith(x, StringComparison.InvariantCultureIgnoreCase)))
                      *         {
                      *             if (!_excludedFileExtensions.Any(x => x.Equals(fileInfo.Extension.Trim(), StringComparison.InvariantCultureIgnoreCase) ||
                      *                                                   ("." + x).Equals(fileInfo.Extension.Trim(), StringComparison.InvariantCultureIgnoreCase)))
                      *             {
                      *                 ProcessFile(fileInfo, projectId.Value, comboxPath);
                      *             }
                      *             else
                      *             {
                      *                 CLLogger.LogVerbose(string.Format("The file '{0}' with extension '{1}' will be excluded for project '{2}'", fileInfo.FullName, fileInfo.Extension, Cache.GetProjectName(projectId.Value)));
                      *             }
                      *         }
                      *         else
                      *         {
                      *             CLLogger.LogVerbose(string.Format("The file '{0}' will be excluded for project '{1}'", fileInfo.FullName, Cache.GetProjectName(projectId.Value)));
                      *         }
                      *     }
                      * }
                      */
                    }
                    else
                    {
                        CLLogger.LogVerbose(string.Format("The folder was not imported: '{0}'", folderInfo.FullName));
                        //ProcessFolder(folderInfo.FullName, null, string.Empty);
                    }
                    comboxPath = originalComboxPath;
                }
            }
            else
            {
                CLLogger.LogVerbose(string.Format("The following path was not found : '{0}'", folder));
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                args[0] = args[0].ToLower();
            }

            AppDomain.CurrentDomain.UnhandledException += CLLogger.AppDomainUnhandledExceptionHandler;
            Application.ThreadException += CLLogger.ThreadExceptionHandler;

            MailUtilities.DefaultSmtpServer = ConfigurationManager.AppSettings["DefaultSmtpServer"];
            MailUtilities.DefaultFromAdress = ConfigurationManager.AppSettings["DefaultSmtpFromAdress"];
            MailUtilities.DefaultUserName   = ConfigurationManager.AppSettings["DefaultSmtpUserName"];
            MailUtilities.DefaultPassword   = ConfigurationManager.AppSettings["DefaultSmtpPassword"];

            if (ConfigurationManager.AppSettings["DefaultErrorEmailRecipient"].HasValue())
            {
                CLLogger.DefaultErrorEmailRecipient.Add(ConfigurationManager.AppSettings["DefaultErrorEmailRecipient"]);
            }
            else if (ConfigurationManager.AppSettings["AlertRecipient"].HasValue())
            {
                CLLogger.DefaultErrorEmailRecipient.Add(ConfigurationManager.AppSettings["AlertRecipient"]);
            }

            CLLogger.LogInformation(String.Format("Started with args.count = {0} Args: {1}", args.Count(), String.Join(" ", args)));

            if (args.Count() == 0)
            {
                Init();
                ServiceBase[] servicesToRun = new ServiceBase[] { new DocumentImportService() };
                ServiceBase.Run(servicesToRun);
            }
            else
            {
                #region Monitor

                if (args[0] == "monitor")
                {
                    Init();
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Monitor());
                }

                #endregion

                #region Started with args... as a service controler/manager

                else
                {
                    using (var sc = new ServiceController(Program.ServiceName))
                    {
                        switch (args[0])
                        {
                        case "start":
                            sc.Start();
                            break;

                        case "stop":
                            sc.Stop();
                            break;

                        case "pause":
                            sc.Pause();
                            break;

                        case "continue":
                            sc.Continue();
                            break;

                        case "status":
                            CLLogger.LogInformation("Service status:" + sc.Status);
                            break;

                        case "install":
                            var installProcess = new System.Diagnostics.Process();
                            installProcess.StartInfo.FileName = JMSL.Framework.Divers.My.AppName() + "_Install.bat";
                            var installPath = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /ShowCallStack " + JMSL.Framework.Divers.My.AppName(false);
                            CLLogger.LogInformation(string.Format("If you need to reinstall the service, you should run the following command or run {0}_Install.bat", JMSL.Framework.Divers.My.AppName()));
                            CLLogger.LogInformation(installPath);
                            JMSL.Framework.Divers.FileIO.WriteToFile(installProcess.StartInfo.FileName, installPath + "\r\n@pause");
                            installProcess.Start();
                            break;

                        case "uninstall":
                            var uninstallProcess = new System.Diagnostics.Process();
                            uninstallProcess.StartInfo.FileName = JMSL.Framework.Divers.My.AppName() + "_UnInstall.bat";
                            var uninstallPath = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\installUtil.exe /u /ShowCallStack " + JMSL.Framework.Divers.My.AppName(false);
                            CLLogger.LogInformation(string.Format("If you need to uninstall the service, you should run the following command or run {0}_uninstall.bat", JMSL.Framework.Divers.My.AppName()));
                            CLLogger.LogInformation(uninstallPath);
                            JMSL.Framework.Divers.FileIO.WriteToFile(uninstallProcess.StartInfo.FileName, uninstallPath + "\r\n@pause");
                            uninstallProcess.Start();
                            break;

                        default:
                            CLLogger.LogInformation("Unknown arguments:" + args[0]);
                            break;
                        }
                    }
                    return;
                }

                #endregion
            }
        }