コード例 #1
0
ファイル: UFLLoader.cs プロジェクト: wallenius71/Wind-Dev
        private void checkFilesLoaded(Dictionary <string, clsFileList> processFiles)
        {
            string findFile     = string.Empty;
            string destFilename = string.Empty;

            DocLibHelper dlh = new DocLibHelper();

            // Check if we have anything to do
            if (processFiles.Count == 0)
            {
                return;
            }

            Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Checking files have loaded");

            foreach (clsFileList f in processFiles.Values)
            {
                // PI UFL renames the files to use the following format:
                // <original filename><datetime>._OK
                findFile = String.Format("{0}*._OK", f.Filename.Substring(0, f.Filename.Length - 4));

                DirectoryInfo di      = new DirectoryInfo(f.Directory);
                FileInfo[]    rgFiles = di.GetFiles(findFile);

                foreach (FileInfo fi in rgFiles)
                {
                    Utils.WriteToLog(Utils.LogSeverity.Info, processName, "File loaded: " + fi.FullName);

                    destFilename = string.Format("{0}\\{1}", ConfigurationSettings.AppSettings["FolderLoaded"], f.Filename);

                    Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("Moving file to {0}", destFilename));

                    Utils.CopyLocalFileFromTo(fi.FullName, destFilename, true);

                    // log status in db
                    var ProcessedFilesQuery = from processedFiles in windARTDataContext.ProcessFiles
                                              where processedFiles.Name == f.FullFilePath && processedFiles.FileStatus == (int)Utils.FileStatus.Verified
                                              select processedFiles;

                    foreach (ProcessFile pf in ProcessedFilesQuery)
                    {
                        pf.FileStatus = (int)Utils.FileStatus.Loaded;
                        pf.Name       = destFilename;

                        windARTDataContext.SubmitChanges();

                        // set Sharepoint status
                        dlh.UpdateFileStatus(pf.ProcessFileId, Utils.FileStatus.Loaded, f.FileFormatId, f.SiteId);
                    }
                }
            }
        }
コード例 #2
0
        private void parkFile(clsFileList vf, ProcessFile pf)
        {
            DocLibHelper dlh = new DocLibHelper();

            // move file into Parked folder
            string destFilename = ConfigurationSettings.AppSettings["FolderParked"] + @"\" + vf.Filename;

            Utils.CopyLocalFileFromTo(vf.FullFilePath, destFilename, true);

            // set db status
            pf.FileStatus = (int)Utils.FileStatus.Parked;
            pf.Name       = destFilename;

            windARTDataContext.SubmitChanges();

            // set Sharepoint status
            dlh.UpdateFileStatus(pf.ProcessFileId, Utils.FileStatus.Parked, 0, 0);

            Utils.WriteToLog(Utils.LogSeverity.Warning, processName, vf.FullFilePath + " parked - unknown formart");
        }
コード例 #3
0
        public void IdentifyFileFormat(Dictionary <string, clsFileList> verifyFiles)
        {
            List <String> importedFileContent;
            bool          headersMatch          = false;
            bool          multiLineHeadersMatch = false;

            DocLibHelper dlh          = new DocLibHelper();
            string       destFilename = string.Empty;

            foreach (clsFileList vf in verifyFiles.Values)
            {
                importedFileContent = loadFileFromList(vf);
                if (importedFileContent == null)
                {
                    Utils.DeleteMissingFileinDB(vf);
                    continue;
                }

                // Did we load a file with content?
                // Only check data matches if we did
                if (importedFileContent != null && importedFileContent.Count > 0)
                {
                    multiLineHeadersMatch = false;
                    headersMatch          = true;

                    // repeat whilst we are finding a header
                    // but mismatching the multiline header rows
                    while (headersMatch && !multiLineHeadersMatch)
                    {
                        headersMatch = checkHeaderMatchs(importedFileContent, vf);

                        // Now we have the fileFormatId, check the multi line details match
                        if (headersMatch)
                        {
                            multiLineHeadersMatch = checkMultiLineHeaderMatchs(importedFileContent, vf);
                        }
                    }
                }

                var ProcessedFilesQuery = from processedFiles in windARTDataContext.ProcessFiles
                                          where processedFiles.Name == vf.FullFilePath &&
                                          processedFiles.FileStatus == (int)Utils.FileStatus.ReadyForImport
                                          select processedFiles;

                foreach (ProcessFile pf in ProcessedFilesQuery)
                {
                    if (headersMatch && multiLineHeadersMatch)
                    {
                        // insert date from Julian date
                        insertDateFromJulianDate(importedFileContent);

                        // save file contents to file
                        destFilename = string.Format("{0}\\f{1}_{2}", ConfigurationSettings.AppSettings["FolderVerified"], vf.FileFormatId.ToString().PadLeft(4, '0'), vf.Filename);
                        saveToFile(importedFileContent, destFilename);

                        // remove original file
                        File.Delete(vf.FullFilePath);

                        // set db status
                        pf.FileStatus   = (int)Utils.FileStatus.Verified;
                        pf.FileFormatId = vf.FileFormatId;
                        pf.Name         = destFilename;
                        pf.SiteId       = vf.SiteId;

                        windARTDataContext.SubmitChanges();

                        // set Sharepoint status
                        dlh.UpdateFileStatus(pf.ProcessFileId, Utils.FileStatus.Verified, (int)pf.FileFormatId, (int)pf.SiteId);

                        Utils.WriteToLog(Utils.LogSeverity.Info, processName, vf.FullFilePath + " verified as formart " + vf.FileFormatId);
                        unParkFile(vf);
                    }
                    else
                    {
                        parkFile(vf, pf);
                    }
                }
            }
        }
コード例 #4
0
        public void processEncryptedFiles(Dictionary<string, clsFileList> encryptedFiles)
        {
            DocLibHelper dlh = new DocLibHelper();
            string newFilename = string.Empty;

            foreach (clsFileList cfl in encryptedFiles.Values)
            {
                //if (cfl.Encrypted)
                //{
                    Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("Attempting to decrypt: {0}", cfl.FullFilePath));

                    // Ensure the destination file doesn't exist
                    // otherwise the NRG app will create a new filename!
                    newFilename = Utils.GetKeyFromConfig("FolderReadyForImport") + @"\" + Utils.DropExtension(cfl.Filename) + ".txt";
                    File.Delete(newFilename);


                    bool result = Utils.Exec(Utils.GetKeyFromConfig("NRGExecutable"), String.Format("/s \"{0}\" ", cfl.FullFilePath), true);

                    // Check new file exists
                    bool newFileExists = File.Exists(newFilename);

                    if (result && newFileExists)
                    {
                        // Update status in MOSS to decrypted
                        dlh.UpdateFileStatus(cfl.ProcessFileId, Utils.FileStatus.Decrypted, cfl.FileFormatId, cfl.SiteId);

                        // Update status in DB
                        Utils.UpdateStatusInDB(cfl, Utils.FileStatus.Decrypted);

                        // Remove original encrypted file
                        File.Delete(cfl.FullFilePath);

                        // add to db
                        // add to sharepoint

                        cfl.OriginalFullFilepath = cfl.FullFilePath;
                        cfl.ProcessFileId = 0;
                        cfl.FullFilePath = newFilename;
                        cfl.Encrypted = false;
                        // addNewFileToDB
                        Utils.RecordFileDetailsInDB(cfl, processName);

                        // addNewFileToSharePoint
                        Utils.CopyFilesToDocumentLibrary(cfl, Utils.FileStatus.ReadyForImport, processName);
                    }
                    else
                    {
                        try
                        {
                            Utils.WriteToLog(Utils.LogSeverity.Critical, processName, String.Format("Error decrypting: {0}", cfl.FullFilePath));

                            // Move problematic file
                            File.Delete(Utils.GetKeyFromConfig("FolderParked") + @"\" + cfl.Filename);
                            
                            if (File.Exists(cfl.FullFilePath))
                            {
                                File.Move(cfl.FullFilePath, Utils.GetKeyFromConfig("FolderParked") + @"\" + cfl.Filename);
                                // Update status in DB
                                Utils.UpdateStatusInDB(cfl, Utils.FileStatus.Parked);
                                // Update status in MOSS to decrypted
                                dlh.UpdateFileStatus(cfl.ProcessFileId, Utils.FileStatus.Parked, cfl.FileFormatId, cfl.SiteId);
                            }
                            else
                            {
                                //the file does not exist. Remove the entry from processfile and report the action
                                Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("File does not exist, removing from listing: {0}", cfl.FullFilePath));
                                Utils.DeleteMissingFileinDB(cfl);
                            }
                        }
                        catch (Exception e)
                        {
                            Utils.WriteToLog(Utils.LogSeverity.Critical, processName, String.Format("Error moving file to parked folder: {0}", e.Message));
                        }
                    }
                //}
            }
        }