示例#1
0
        /// <summary>
        /// Imports a Module/Standard.
        /// </summary>
        /// <param name="externalStandard"></param>
        public static void ProcessStandard(IExternalStandard externalStandard)
        {
            log.Info("ModuleImporter.ProcessStandard - basic");


            LogManager.Instance.LogDebugMessage("ModuleImporter.ProcessStandard");

            SETS_CATEGORY category;
            int?          categoryOrder = 0;
            var           setname       = Regex.Replace(externalStandard.ShortName, @"\W", "_");

            var documentImporter = new DocumentImporter();
            var set = new SETS();

            var db = new CSET_Context();

            var existingSet = db.SETS.FirstOrDefault(s => s.Set_Name == setname);

            if (existingSet != null)
            {
                // result.LogError("Module already exists.  If this is a new version, please change the ShortName field to reflect this.");
            }
            category = db.SETS_CATEGORY.FirstOrDefault(s => s.Set_Category_Name.Trim().ToLower() == externalStandard.Category.Trim().ToLower());

            if (category == null)
            {
                // result.LogError("Module Category is invalid.  Please check the spelling and try again.");
            }
            else
            {
                categoryOrder = category.SETS.Max(s => s.Order_In_Category);
            }

            set.Set_Category_Id       = category?.Set_Category_Id;
            set.Order_In_Category     = categoryOrder;
            set.Short_Name            = externalStandard.ShortName;
            set.Set_Name              = setname;
            set.Full_Name             = externalStandard.Name;
            set.Is_Custom             = true;
            set.Is_Question           = true;
            set.Is_Requirement        = true;
            set.Is_Displayed          = true;
            set.IsEncryptedModuleOpen = true;
            set.IsEncryptedModule     = false;
            set.Is_Deprecated         = false;

            set.Standard_ToolTip = externalStandard.Summary;

            db.SETS.Add(set);
            db.SaveChanges();


            ProcessRequirements(externalStandard, set);
        }
示例#2
0
        public void Import(Stream file, DocumentoRepositorio DocumentoRepositorio)
        {
            FolderInfo folderInfo         = Folder.GetFolderInfo(DocumentoRepositorio.Ruta, LFSesion);
            int        documentoResultado = Document.Create(folderInfo, DocumentoRepositorio.Nombre, EntryNameOption.None, LFSesion);

            DocumentInfo     docInfo = Document.GetDocumentInfo(documentoResultado, LFSesion);
            DocumentImporter di      = new DocumentImporter();

            di.Document = docInfo;

            string mimeType = ObtenerTipoMime(file);

            di.ImportEdoc(mimeType, file);
        }
示例#3
0
        static void Main(string[] args)
        {
            InitLogging();
            var settings = GetSettings(args);

            if (!Verify(settings))
            {
                PrintUsage();
                log.Error("Settings are not valid, Import aborted.");
            }
            else
            {
                var importer = new DocumentImporter(settings);
                importer.Execute();
            }
            log.Info("Import completed.");
        }
示例#4
0
        public void Import(string fileLocation, bool overwrite, DocumentoRepositorio DocumentoRepositorio)
        {
            EntryNameOption TipoOpcionDeEntradaSeleccionada = overwrite ? EntryNameOption.Overwrite : EntryNameOption.None;

            FileStream   file         = File.OpenRead(fileLocation);
            FolderInfo   folderInfo   = Folder.GetFolderInfo(DocumentoRepositorio.Ruta, LFSesion);
            DocumentInfo documentInfo = null;

            //Si el archivo existe borrar y crear nuevamente
            try
            {
                documentInfo = Document.GetDocumentInfo(folderInfo, DocumentoRepositorio.Nombre, LFSesion);
            }
            catch (Exception e)
            {
                documentInfo = null;
            }

            int documentoResultado;

            if (documentInfo == null)
            {
                documentoResultado = Document.Create(folderInfo, DocumentoRepositorio.Nombre, TipoOpcionDeEntradaSeleccionada, LFSesion);
            }
            else if (overwrite)
            {
                documentoResultado = documentInfo.Id;
            }
            else
            {
                throw new Exception("Cannot overwrite");
            }


            DocumentInfo     docInfo = Document.GetDocumentInfo(documentoResultado, LFSesion);
            DocumentImporter di      = new DocumentImporter();

            di.OverwritePages = overwrite;
            di.Document       = docInfo;

            string mimeType = ObtenerTipoMime(file);

            di.ImportEdoc(mimeType, file);
        }
示例#5
0
        public void ImportDocument(string laserfichePath, string volume, string filePath)
        {
            using (EntryInfo entry = Entry.TryGetEntryInfo(laserfichePath, _session) ?? new DocumentInfo(_session))
            {
                if (!(entry is DocumentInfo document))
                {
                    throw new Exception($"Error creating laserfiche document {laserfichePath}");
                }

                if (document.IsNew)
                {
                    document.Create(laserfichePath, volume, EntryNameOption.AutoRename);
                }

                DocumentImporter importer = new DocumentImporter
                {
                    Document  = document,
                    OcrImages = true
                };
                importer.ImportImages(filePath);
            }
        }
        static int Main(string[] args)

        {
            if (args.Length == 0)
            {
                Logger.MessageToFile("Laserfiche PDF to TIFF did not receive an entry id.");
                return(-1);
            }
            else
            {
                Logger.MessageToFile("Started looking at conversion....");
                /* CONSTANTS */
                string Laserfiche_server     = ConfigurationManager.AppSettings["LaserficheServer"];
                string Laserfiche_repository = ConfigurationManager.AppSettings["LaserficheRepository"];
                string Laserfiche_user       = ConfigurationManager.AppSettings["LaserficheUser"];
                string Laserfiche_password   = ConfigurationManager.AppSettings["LaserfichePassword"];
                string temp_save_folder      = ConfigurationManager.AppSettings["TemporarySaveFolder"];
                /* Ghostscript specific parameters */
                string tiff_image_resolution = "-r" + ConfigurationManager.AppSettings["TiffImageResolution"];
                string tiff_image_type       = "-sDEVICE=" + ConfigurationManager.AppSettings["TiffImageType"];
                string inputMime;
                /* VARIABLES */
                int    entry_id       = Int32.Parse(args[0]);
                string message_id     = "Laserfiche Entry#" + entry_id + "(" + Laserfiche_repository + ")";
                string message_id_eol = message_id + ".";

                /* LASERFICHE SESSION */
                RepositoryRegistration repositoryRegistration = new RepositoryRegistration(Laserfiche_server, Laserfiche_repository);
                Session LaserficheSession = new Session
                {
                    IsSecure = false
                };
                LaserficheSession.LogIn(Laserfiche_user, Laserfiche_password, repositoryRegistration);

                /* LASERFICHE OBJECTS */
                LaserficheReadStream electronicDocument = Document.ReadEdoc(entry_id, out inputMime, LaserficheSession);
                DocumentInfo         document           = Document.GetDocumentInfo(entry_id, LaserficheSession);
                EntryInfo            entry = Entry.GetEntryInfo(entry_id, LaserficheSession);

                /* UNLOCK ENTRIES JUST IN CASE */
                document.Unlock();
                entry.Unlock();

                /* LENGTH OF PDF FILE / Byte Array */
                MemoryStream memoryStream = new MemoryStream();
                electronicDocument.CopyTo(memoryStream);
                byte[] byteArray = memoryStream.ToArray();

                /* LASERFICHE VARS - EXTRA INFORMATION */
                string fileExt = document.Extension.ToString();

                /* EXPORT PDF and convert to TIFFs */
                if (document.PageCount == 0 && inputMime == "application/pdf")
                {
                    Logger.MessageToFile("Started downloading PDF for " + message_id_eol);
                    /* Save PDF */
                    string     pdf_file_path = temp_save_folder + document.Id.ToString() + '.' + fileExt;
                    FileStream fileStream    = new FileStream(pdf_file_path, FileMode.Create, FileAccess.ReadWrite);
                    fileStream.Write(byteArray, 0, byteArray.Length);

                    fileStream.Close();

                    /* Ghostscript Variables */
                    var    pdf_file_info  = new FileInfo(pdf_file_path);
                    string tiff_file_path = Path.Combine(temp_save_folder, pdf_file_info.Name.Replace(pdf_file_info.Extension, ".tiff"));

                    /* delete the TIFF if it is already there....*/
                    if (File.Exists(tiff_file_path))
                    {
                        File.Delete(tiff_file_path);
                    }

                    /* Extract TIFF from PDF using Ghostscript DLL ... */
                    /* MORE INFORMATION ABOUT GHOSTSCRIPT : https://www.ghostscript.com/doc/current/Use.htm */
                    /* -dNOPAUSE -dBATCH keeps ghostscript from prompting user input */
                    /* -dSAFER enables access controls on files. https://www.ghostscript.com/doc/current/Use.htm#Safer */

                    try
                    {
                        Logger.MessageToFile("Started ghostscript conversion for " + message_id_eol);
                        string[] argv = new string[] { "PDF2TIFF", "-q", "-sOutputFile=" + tiff_file_path, "-dNOPAUSE", "-dBATCH", "-P-", "-dSAFER", tiff_image_type, tiff_image_resolution, pdf_file_path };
                        Ghostscript.Run(argv);
                    }
                    catch (Exception e)
                    {
                        Logger.MessageToFile("FAIL : Ghostscript conversion for " + message_id_eol);
                        Logger.MessageToFile(e.ToString());
                        Environment.Exit(0);
                    }
                    finally
                    {
                        Logger.MessageToFile("SUCCESS : Downloading / converting PDF to TIFF for " + message_id_eol);
                        try
                        {
                            DocumentImporter documentImporter = new DocumentImporter
                            {
                                Document = document
                            };
                            documentImporter.ImportImages(tiff_file_path);
                        }
                        catch (Exception e)
                        {
                            Logger.MessageToFile("FAIL : importing pages to " + message_id_eol);
                            Logger.MessageToFile(e.ToString());
                            Environment.Exit(0);
                        }
                        finally
                        {
                            Logger.MessageToFile("SUCCESS : imported pages to " + message_id_eol);
                            File.Delete(pdf_file_path);
                            File.Delete(tiff_file_path);
                            memoryStream.Close();
                            electronicDocument.Close();
                            document.Dispose();
                            entry.Dispose();
                            LaserficheSession.Close();
                            LaserficheSession.Discard();
                        }
                    }
                    Logger.MessageToFile("SUCCESS : " + message_id + " uploaded with a total of " + document.PageCount + " pages.");
                    return(document.PageCount);
                }
                else
                {
                    Logger.MessageToFile("BYPASS : "******" already had pages generated / " + document.PageCount + " pages.");
                    return(document.PageCount);
                }
            }
        }
示例#7
0
        public static int MainLoop(string[] args)
        {
            ILog   log     = null;
            string baseDir = Directory.GetCurrentDirectory();
            // Initialize log4j
            Configuration options = new Configuration(baseDir, args);

            if (options.help)
            {
                Console.Error.WriteLine(options.GetUsage());
                return(1);
            }
            List <string> errors = options.ValidateConfiguration();

            if (errors.Count > 0)
            {
                Console.Error.WriteLine(string.Format("{0} Configuration Errors detected:", errors.Count));
                foreach (string e in errors)
                {
                    Console.Error.WriteLine(string.Format("\t* {0}", e));
                }
                return(2);
            }

            System.IO.Directory.CreateDirectory(options.caches);

            string logDir = string.Format("{0}\\logs", baseDir);

            System.IO.Directory.CreateDirectory(logDir);

            Environment.SetEnvironmentVariable("CMF_LOGDATE", string.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now));
            Environment.SetEnvironmentVariable("CMF_LOGDIR", logDir);

            XmlConfigurator.Configure(new FileInfo(string.Format("{0}\\log4net.xml", baseDir)));
            LOG = log = LogManager.GetLogger(typeof(Launcher));
            log.Info("Initializing Application");

            if (options.indexOnly)
            {
                ImportContext  importContext  = new ImportContext(null, options.content, options.metadata, options.caches);
                FormatResolver formatResolver = new FormatResolver(importContext);
                new DocumentImporter(new FolderImporter(importContext), formatResolver, options.locationMode, options.fixExtensions).StoreLocationIndex();
                return(0);
            }

            ServicePointManager.MaxServicePointIdleTime = (int)SharePointSession.TIME_OUT.TotalMilliseconds;
            ServicePointManager.SetTcpKeepAlive(true, (int)SharePointSession.TIME_OUT.TotalMilliseconds, 60000);
            ServicePointManager.DefaultConnectionLimit = options.threads * 10;

            using (DirectoryEntry ldapDirectory = BindToLDAP(options))
            {
                log.Info(string.Format("Using SharePoint at [{0}]", options.siteUrl));

                string userString = options.user;
                if (!string.IsNullOrWhiteSpace(options.domain))
                {
                    userString = string.Format("{0}@{1}", userString, options.domain);
                }

                SecureString userPassword = null;
                if (!string.IsNullOrWhiteSpace(options.user))
                {
                    if (options.password == null)
                    {
                        Console.Write(string.Format("Enter The Sharepoint Password for [{0}]: ", userString));
                        userPassword = Tools.ReadPassword();
                    }
                    else
                    {
                        String pass = CRYPT.Decrypt(options.password);
                        pass = CRYPT.Encrypt(pass);
                        log.Info(string.Format("Using stored credentials for [{0}] = [{1}]", userString, pass));
                        userPassword = new SecureString();
                        foreach (char c in CRYPT.Decrypt(pass))
                        {
                            userPassword.AppendChar(c);
                        }
                    }
                }

                using (SharePointSessionFactory sessionFactory = new SharePointSessionFactory(new SharePointSessionInfo(options.siteUrl, options.user, userPassword, options.domain, options.applicationId, options.certificateKey, options.certificatePass, options.library, options.reuseCount)))
                {
                    ImportContext importContext = new ImportContext(sessionFactory, options.content, options.metadata, options.caches);
                    using (ObjectPool <SharePointSession> .Ref sessionRef = sessionFactory.GetSession())
                    {
                        SharePointSession session       = sessionRef.Target;
                        ClientContext     clientContext = session.ClientContext;
                        List documentLibrary            = sessionRef.Target.DocumentLibrary;
                        // We configure the document library as required
                        documentLibrary.EnableVersioning    = true;
                        documentLibrary.EnableMinorVersions = true;
                        documentLibrary.ForceCheckout       = false;
                        documentLibrary.ContentTypesEnabled = true;
                        // documentLibrary.MajorVersionLimit = 50000;
                        // documentLibrary.MajorWithMinorVersionsLimit = 50000;
                        documentLibrary.Update();
                        session.ExecuteQuery();
                    }

                    FormatResolver formatResolver = new FormatResolver(importContext);

                    ContentTypeImporter contentTypeImporter = null;
                    for (int i = 0; i <= options.retries; i++)
                    {
                        try
                        {
                            contentTypeImporter = new ContentTypeImporter(importContext, options.library, options.cleanTypes);
                            break;
                        }
                        catch (Exception e)
                        {
                            contentTypeImporter = null;
                            log.Warn("WARNING: ContentTypeImporter failed to initialize due to an exception", e);
                        }
                    }
                    if (contentTypeImporter == null)
                    {
                        log.Error(string.Format("ContentTypeImporter failed to initialize after {0} attempts", options.retries + 1));
                        return(3);
                    }

                    UserGroupImporter userGroupImporter = null;
                    for (int i = 0; i <= options.retries; i++)
                    {
                        try
                        {
                            userGroupImporter = new UserGroupImporter(importContext, ldapDirectory, options.ldapSyncDomain, options.fallbackUser, options.internalUser, options.fallbackGroup, options.internalGroup);
                            break;
                        }
                        catch (Exception e)
                        {
                            userGroupImporter = null;
                            log.Warn("WARNING: UserGroupImporter failed to initialize due to an exception", e);
                        }
                    }
                    if (userGroupImporter == null)
                    {
                        log.Error(string.Format("UserGroupImporter failed to initialize after {0} attempts", options.retries + 1));
                        return(4);
                    }

                    PermissionsImporter permissionsImporter = new PermissionsImporter(userGroupImporter);
                    FolderImporter      folderImporter      = new FolderImporter(contentTypeImporter, permissionsImporter);
                    DocumentImporter    documentImporter    = new DocumentImporter(folderImporter, formatResolver, options.locationMode, options.fixExtensions);
                    bool aborted = false;

                    Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
                    {
                        if (aborted)
                        {
                            return;
                        }
                        aborted  = true;
                        e.Cancel = true;
                        documentImporter.Abort = true;
                        folderImporter.Abort   = true;
                        string msg = "Program Interrupted (hit Ctrl-C again to terminate immediately)";
                        if (log == null)
                        {
                            Console.WriteLine(msg);
                        }
                        else
                        {
                            log.Warn(msg);
                        }
                    };

                    try
                    {
                        documentImporter.StoreDocuments(options.threads, options.simulationMode, options.locationMode, options.autoPublish, options.retries);
                        folderImporter.FinalizeFolders(options.threads, options.retries);
                        documentImporter.StoreLocationIndex();
                    }
                    finally
                    {
                        log.Info(documentImporter.ProcessingReport);
                        log.Info(folderImporter.ProcessingReport);
                    }
                    return(aborted ? 1 : 0);
                }
            }
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="externalRequirement"></param>
        /// <param name="setName"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        public static NEW_REQUIREMENT SaveRequirement(this IExternalRequirement externalRequirement, string setName,
                                                      int sequence, ILogger logger)
        {
            var result         = new ConverterResult <NEW_REQUIREMENT>(logger);
            var newRequirement = result.Result;

            //basic mappings
            newRequirement.Supplemental_Info      = externalRequirement.Supplemental;
            newRequirement.Requirement_Text       = externalRequirement.Text;
            newRequirement.Requirement_Title      = externalRequirement.Identifier;
            newRequirement.Original_Set_Name      = setName;
            newRequirement.Weight                 = externalRequirement.Weight;
            newRequirement.REQUIREMENT_LEVELS     = new List <REQUIREMENT_LEVELS>();
            newRequirement.REQUIREMENT_REFERENCES = new List <REQUIREMENT_REFERENCES>();
            newRequirement.REQUIREMENT_SETS       = new List <REQUIREMENT_SETS>()
            {
                new REQUIREMENT_SETS()
                {
                    Set_Name             = setName,
                    Requirement_Sequence = sequence
                }
            };

            QUESTION_GROUP_HEADING          questionGroupHeading = null;
            UNIVERSAL_SUB_CATEGORY_HEADINGS uschPairing          = null;

            var db = new CSET_Context();

            try
            {
                questionGroupHeading = db.QUESTION_GROUP_HEADING.FirstOrDefault(s => s.Question_Group_Heading1.Trim().ToLower() == externalRequirement.Heading.Trim().ToLower());
                try
                {
                    var subcatId = db.UNIVERSAL_SUB_CATEGORIES.FirstOrDefault(s => s.Universal_Sub_Category.Trim().ToLower() == externalRequirement.Subheading.Trim().ToLower())?.Universal_Sub_Category_Id ?? 0;
                    if (subcatId == 0)
                    {
                        var subcat = new UNIVERSAL_SUB_CATEGORIES()
                        {
                            Universal_Sub_Category = externalRequirement.Subheading
                        };
                        db.UNIVERSAL_SUB_CATEGORIES.Add(subcat);
                        db.SaveChanges();
                        subcatId = subcat.Universal_Sub_Category_Id;
                    }

                    try
                    {
                        uschPairing = db.UNIVERSAL_SUB_CATEGORY_HEADINGS.FirstOrDefault(s => (s.Universal_Sub_Category_Id == subcatId) && (s.Question_Group_Heading_Id == questionGroupHeading.Question_Group_Heading_Id));
                        if (uschPairing == null)
                        {
                            uschPairing = new UNIVERSAL_SUB_CATEGORY_HEADINGS()
                            {
                                Set_Name = "Standards",
                                Universal_Sub_Category_Id = subcatId,
                                Question_Group_Heading_Id = questionGroupHeading.Question_Group_Heading_Id
                            };
                            db.UNIVERSAL_SUB_CATEGORY_HEADINGS.Add(uschPairing);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception exc)
                    {
                        var myExc = exc;
                    }
                }
                catch
                {
                }
            }
            catch
            {
            }


            if (questionGroupHeading == null)
            {
                result.LogError(String.Format("Heading invalid for requirement {0} {1}.  Please double check that the heading is spelled correctly.", externalRequirement.Identifier, externalRequirement.Text));
            }
            else
            {
                newRequirement.Question_Group_Heading_Id = questionGroupHeading.Question_Group_Heading_Id;
            }


            if (uschPairing == null)
            {
                result.LogError(String.Format("Subheading invalid for requirement {0} {1}.  Please double check that the heading is spelled correctly.", externalRequirement.Identifier, externalRequirement.Text));
            }

            externalRequirement.Category = string.IsNullOrWhiteSpace(externalRequirement.Category) ? externalRequirement.Heading : externalRequirement.Category;
            var category = db.STANDARD_CATEGORY.FirstOrDefault(s => s.Standard_Category1 == externalRequirement.Category);

            if (category == null)
            {
                newRequirement.Standard_CategoryNavigation = new STANDARD_CATEGORY()
                {
                    Standard_Category1 = externalRequirement.Category
                };
            }
            else
            {
                newRequirement.Standard_Category = category.Standard_Category1;
            }

            newRequirement.Standard_Sub_Category = externalRequirement.Subheading;


            // SAL
            foreach (string sal in externalRequirement.SecurityAssuranceLevels)
            {
                var rl = new REQUIREMENT_LEVELS()
                {
                    Standard_Level = sal,
                    Level_Type     = "NST"
                };

                if (newRequirement.REQUIREMENT_LEVELS.Count(x => x.Standard_Level == rl.Standard_Level) == 0)
                {
                    newRequirement.REQUIREMENT_LEVELS.Add(rl);
                }
            }


            var importer = new DocumentImporter();

            if (externalRequirement.References != null)
            {
                foreach (var reference in externalRequirement.References)
                {
                    var reqReference = new REQUIREMENT_REFERENCES();
                    try
                    {
                        reqReference.Destination_String = reference.Destination;
                        reqReference.Page_Number        = reference.PageNumber;
                        reqReference.Section_Ref        = String.IsNullOrEmpty(reference.SectionReference) ? "" : reference.SectionReference;
                        reqReference.Gen_File_Id        = importer.LookupGenFileId(reference.FileName);
                    }
                    catch
                    {
                        result.LogError(String.Format("Reference {0} could not be added for requirement {1} {2}.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                    if (reqReference.Gen_File_Id == 0)
                    {
                        result.LogError(String.Format("Reference {0} has not been loaded into CSET.  Please add the file and try again.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                    else
                    {
                        newRequirement.REQUIREMENT_REFERENCES.Add(reqReference);
                    }
                }
            }

            var reqSource = new REQUIREMENT_SOURCE_FILES();

            try
            {
                if (externalRequirement.Source != null)
                {
                    reqSource.Gen_File_Id        = importer.LookupGenFileId(externalRequirement.Source.FileName);
                    reqSource.Page_Number        = externalRequirement.Source.PageNumber;
                    reqSource.Destination_String = externalRequirement.Source.Destination;
                    reqSource.Section_Ref        = String.IsNullOrEmpty(externalRequirement.Source.SectionReference) ? "" : externalRequirement.Source.SectionReference;
                    if (reqSource.Gen_File_Id == 0)
                    {
                        result.LogError(String.Format("Source {0} has not been loaded into CSET.  Please add the file and try again.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                    else
                    {
                        newRequirement.REQUIREMENT_SOURCE_FILES.Add(reqSource);
                    }
                }
            }
            catch
            {
                result.LogError(String.Format("Source {0} could not be added for requirement {1} {2}.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
            }

            try
            {
                db.NEW_REQUIREMENT.Add(newRequirement);
                db.SaveChanges();
            }
            catch (Exception exc)
            {
                // throw exc;
            }


            // Save any Questions associated with the Requirement
            SaveQuestions(setName, externalRequirement, newRequirement,
                          questionGroupHeading, uschPairing,
                          db);


            return(newRequirement);
        }