示例#1
0
 public FileBasedSimpleDataSource(string folderPath, IOutputMessage messages, string authorNameFile)
 {
     _folderPath = folderPath;
     _messages   = messages;
     _filter     = new AuthorNameCorrectionFilter(authorNameFile);
     _reader     = new FileReader();
 }
示例#2
0
 public BookFileList(FileFinder fileList, IOutputMessage messages)
 {
     _readers  = new List <IBookFileReader>();
     _lookup   = new Dictionary <string, IBookFileReader>(StringComparer.CurrentCultureIgnoreCase);
     _fileList = fileList;
     _messages = messages;
 }
示例#3
0
文件: Matcher.cs 项目: adarmus/ebook
 public Matcher(IBookFinder bookFinder, IOutputMessage messages)
 {
     _messages   = messages;
     _bookFinder = bookFinder;
 }
示例#4
0
        /// <summary>
        /// Load folder into FCM Database and into FCM folder
        /// </summary>
        /// <param name="sourceFolder"></param>
        /// <param name="uioutput"></param>
        /// <param name="parentUID"></param>
        /// <param name="sequenceNumber"></param>
        /// <param name="headerInfo"></param>
        /// <returns></returns>
        static public ResponseStatus LoadFolder(string sourceFolder,
                                                IOutputMessage uioutput,
                                                int parentUID, int sequenceNumber, HeaderInfo headerInfo)
        {
            ResponseStatus response = new ResponseStatus();

            response.Message = "Folder loaded successfully.";

            if (!Directory.Exists(sourceFolder))
            {
                response.ReturnCode = -0010;
                response.ReasonCode = -0001;
                response.Message    = "Source folder does not exist.";
                response.UniqueCode = "E00.00.0001";
                response.Icon       = MessageBoxIcon.Error;
                return(response);
            }

            string[] folderNameSplit = sourceFolder.Split('\\');
            string   folderName      = folderNameSplit[folderNameSplit.Length - 1];

            uioutput.Activate();

            string[] files = Directory.GetFiles(sourceFolder);

            // Create folder that contains files and keep the parent
            //
            // ...
            Model.ModelDocument.Document folder = new Model.ModelDocument.Document();

            if (folderName.Length >= 7)
            {
                folder.CUID = folderName.Substring(0, 7);
            }
            else
            {
                folder.CUID = folderName;
            }

            folder.FileName    = folderName;
            folder.Comments    = "Loaded by batch";
            folder.Name        = folderName;
            folder.DisplayName = folderName;
            folder.FKClientUID = 0;
            folder.IssueNumber = 0;
            string refPath =
                MakHelperUtils.getReferenceFilePathName(sourceFolder);

            if (string.IsNullOrEmpty(refPath))
            {
                response.ReturnCode = -0010;
                response.ReasonCode = -0002;
                response.Message    = "Folder selected is not under managed template folder.";
                response.UniqueCode = "E00.00.0001";
                return(response);
            }

            folder.Location = refPath;
            // Store the folder being loaded at the root level
            //
            folder.Location       = MakConstant.SYSFOLDER.TEMPLATEFOLDER;
            folder.ParentUID      = parentUID;
            folder.SequenceNumber = 0;
            folder.SourceCode     = "FCM";
            folder.UID            = 0;
            folder.RecordType     = MakHelperUtils.RecordType.FOLDER;
            folder.DocumentType   = MakHelperUtils.DocumentType.FOLDER;
            folder.SimpleFileName = folder.Name;
            folder.FileExtension  = "FOLDER";
            folder.IsProjectPlan  = "N";

            // parentUID = folder.Save(headerInfo, MakHelperUtils.SaveType.NEWONLY);

            parentUID = RepDocument.Save(headerInfo, folder, MakHelperUtils.SaveType.NEWONLY);

            // Store each file
            //
            foreach (string file in files)
            {
                #region File Processing
                string name = Path.GetFileName(file);

                string fileName      = Path.GetFileNameWithoutExtension(file);
                string fileExtension = Path.GetExtension(file);

                string validExtensions = ".doc .docx .xls .xlsx .pdf .dotx";

                // Not every extension will be loaded
                //
                if (!validExtensions.Contains(fileExtension))
                {
                    continue;
                }


                string fileNameExt = Path.GetFileName(file);

                string simpleFileName = fileNameExt;
                if (fileNameExt.Length > 10)
                {
                    simpleFileName = fileNameExt.Substring(10).Trim();
                }

                Model.ModelDocument.Document document = new Model.ModelDocument.Document();
                document.CUID     = fileName.Substring(0, 6);
                document.FileName = fileNameExt;

                //string refPath =
                //        Utils.getReferenceFilePathName(sourceFolder);

                document.Location = refPath;
                string issue = "1";
                document.IssueNumber = Convert.ToInt32(issue);

                try
                {
                    issue = fileName.Substring(7, 2);
                    document.IssueNumber = Convert.ToInt32(issue);
                }
                catch (Exception ex)
                {
                    LogFile.WriteToTodaysLogFile(ex.ToString());
                }
                document.Name           = fileName;
                document.SimpleFileName = simpleFileName;
                document.DisplayName    = simpleFileName;
                document.SequenceNumber = sequenceNumber;
                document.ParentUID      = parentUID;

                document.Comments      = "Loaded via batch";
                document.SourceCode    = "FCM";
                document.FKClientUID   = 0;
                document.RecordType    = MakHelperUtils.RecordType.DOCUMENT;
                document.FileExtension = fileExtension;
                document.Status        = FCMUtils.FCMConstant.DocumentStatus.ACTIVE;
                document.IsProjectPlan = "N";

                switch (fileExtension)
                {
                case ".doc":
                    document.DocumentType = MakHelperUtils.DocumentType.WORD;
                    break;

                case ".docx":
                    document.DocumentType = MakHelperUtils.DocumentType.WORD;
                    break;

                case ".dotx":
                    document.DocumentType = MakHelperUtils.DocumentType.WORD;
                    break;

                case ".xls":
                    document.DocumentType = MakHelperUtils.DocumentType.EXCEL;
                    break;

                case ".xlsx":
                    document.DocumentType = MakHelperUtils.DocumentType.EXCEL;
                    break;

                case ".pdf":
                    document.DocumentType = MakHelperUtils.DocumentType.PDF;
                    break;

                default:
                    document.DocumentType = MakHelperUtils.DocumentType.UNDEFINED;
                    break;
                }

                // document.Save(headerInfo, MakHelperUtils.SaveType.NEWONLY);

                RepDocument.Save(headerInfo, document, MakHelperUtils.SaveType.NEWONLY);

                uioutput.AddOutputMessage(document.Name, "", userID);

                sequenceNumber++;
                #endregion File Processing
            }

            // Recursion removed
            //
            string[] folders = Directory.GetDirectories(sourceFolder);
            foreach (string directory in folders)
            {
                string name = Path.GetFileName(directory);
                LoadFolder(directory, uioutput, parentUID, 0, headerInfo);
            }

            return(response);
        }
示例#5
0
        // ---------------------------------------------
        //             Copy Documents
        // ---------------------------------------------
        public static object CopyDocument(
            string fromFileName,
            string destinationFileName,
            List <WordDocumentTasks.TagStructure> tag,
            IOutputMessage uioutput,
            string processName,
            string userID
            )
        {
            var vkExcelApp = new Microsoft.Office.Interop.Excel.Application();

            vkExcelApp.Visible = false;

            // Excel.ApplicationClass vkExcelApp = new Excel.ApplicationClass();

            string saveFile = destinationFileName;

            object vkReadOnly = false;
            object vkVisible  = true;
            object vkFalse    = false;
            object vkTrue     = true;
            object vkDynamic  = 2;

            object vkMissing = System.Reflection.Missing.Value;

            // Let's make the excel application not visible
            // vkExcelApp.Visible = false;
            // vkExcelApp.Activate();

            // Let's copy the document
            File.Copy(fromFileName, destinationFileName, true);

            // Let's open the DESTINATION document
            //Word.Document vkMyDoc = vkExcelApp.Documents.Open(
            //    ref destinationFileName, ref vkMissing, ref vkReadOnly,
            //    ref vkMissing, ref vkMissing, ref vkMissing,
            //    ref vkMissing, ref vkMissing, ref vkMissing,
            //    ref vkMissing, ref vkMissing, ref vkVisible );

            Excel.Workbook vkMyDoc = vkExcelApp.Workbooks.Open(
                destinationFileName,
                vkMissing, false, vkMissing, vkMissing,
                vkMissing, true, vkMissing, "\t", vkMissing,
                vkMissing, vkMissing, vkMissing, vkMissing, vkMissing);

            foreach (var t in tag)
            {
                // 17/02/2013
                // Ignore **MD** and other with ** because it is too risky
                //
                if (t.Tag == "**MD**" || t.Tag == "**PM**" || t.Tag == "**SM**" || t.Tag == "**ADDRESS**")
                {
                    continue;
                }

                if (t.TagType == "IMAGE")
                {
                    continue;
                }

                FindAndReplace(t.Tag, t.TagValue, 1, vkExcelApp, vkMyDoc);
            }

            try
            {
                vkMyDoc.Save();
            }
            catch (Exception ex)
            {
                uioutput.AddOutputMessage("(Excel) ERROR in file:  " + fromFileName + " --- Message: " + ex.ToString(), processName, userID);
                uioutput.AddErrorMessage("(Excel) ERROR in file:  " + fromFileName + " --- Message: " + ex.ToString(), processName, userID);
            }

            // close the new document
            vkMyDoc.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc);

            // close excel application
            vkExcelApp.Quit();

            return(saveFile);
        }
示例#6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ClientID"></param>
        /// <param name="ClientDocSetID"></param>
        public DocumentGeneration(int ClientID, int ClientDocSetID, IOutputMessage UIoutput = null,
                                  string OverrideDocuments = null)
        {
            if (overrideDocuments == null)
            {
                overrideDocuments = "N";
            }

            // Assign to internal variables
            //
            // iconMessage = IconMessage;

            // Set private attributes
            clientID          = ClientID;
            clientDocSetID    = ClientDocSetID;
            uioutput          = UIoutput;
            overrideDocuments = OverrideDocuments;

            // Instantiate Word
            //
            vkFalse = false;

            vkWordApp = new Word.Application();

            // Make it not visible
            vkWordApp.Visible = false;

            vkExcelApp = new Excel.Application();

            // Make it not visible
            vkExcelApp.Visible = false;

            // Get Metadata for client

            clientMetadata = new ReportMetadataList();

            // Daniel 31/12/2011
            //
            // clientMetadata.ListMetadataForClient(clientID);
            // The intention is to always use the full set of variables.
            // There is need to use all in order to replace the tags not used.
            //
            clientMetadata.ListDefault();

            ts = new List <WordDocumentTasks.TagStructure>();

            // Load variables/ metadata into memory
            //
            #region ClientMetadata
            foreach (ReportMetadata metadata in clientMetadata.reportMetadataList)
            {
                // Add client ID
                metadata.ClientUID = this.clientID;

                // Retrieve value for the field selected
                //
                string value = metadata.GetValue();

                // If the field is not enabled, the program has to replace the value with spaces.
                // 01-Jan-2012 - No longer necessary.
                // All the variables have to be used

                // var valueOfTag = metadata.Enabled == 'Y' ? value : string.Empty;

                // Set to the value. If value is null, set to spaces.
                var valueOfTag = string.IsNullOrEmpty(value) ? string.Empty : value;

                // When the field is an image and it is not enable, do not include the "No image" icon in the list
                //
                //if (metadata.InformationType == Utils.InformationType.IMAGE && metadata.Enabled == 'N')
                //    continue;

                // If the field is an image but it has no value, no need to include.
                // Regular fields must be included because they need to be replaced.
                // Images uses bookmarks, no need to be replace. It is not displayed in the document.
                //
                if (metadata.InformationType == Utils.InformationType.IMAGE)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        continue;
                    }
                }

                // Add label before value to print.
                //
                if (metadata.UseAsLabel == 'Y')
                {
                    valueOfTag = metadata.Description + " " + valueOfTag;
                }

                ts.Add(new WordDocumentTasks.TagStructure()
                {
                    TagType  = metadata.InformationType,
                    Tag      = metadata.FieldCode,
                    TagValue = valueOfTag
                });
            }
            #endregion ClientMetadata

            // Get Client Document Set Details
            // To get the source and destination folders
            cds = new ClientDocumentSet();
            cds.Get(clientID, clientDocSetID);

            fileprocessedcount  = 0;
            valueForProgressBar = 0;
            startTime           = System.DateTime.Now.ToString();
        }
示例#7
0
        // ---------------------------------------------
        //
        // ---------------------------------------------
        /// <summary>
        /// Create client document and replace document tags
        /// </summary>
        /// <param name="fromFileName"></param>
        /// <param name="destinationFileName"></param>
        /// <param name="tag"></param>
        /// <param name="vkWordApp"></param>
        /// <returns></returns>
        public static ResponseStatus CopyDocument(
            object fromFileName,
            object destinationFileName,
            List <WordDocumentTasks.TagStructure> tag,
            Word.Application vkWordApp,
            IOutputMessage uioutput,
            string processName, string userID
            )
        {
            ResponseStatus ret = new ResponseStatus();

            object saveFile = destinationFileName;

            object vkReadOnly = false;
            object vkVisible  = true;
            object vkFalse    = false;
            object vkTrue     = true;
            object vkDynamic  = 2;

            object vkMissing = System.Reflection.Missing.Value;

            // Let's make the word application not visible
            // vkWordApp.Visible = false;
            // vkWordApp.Activate();

            // Let's copy the document

            if (uioutput != null)
            {
                uioutput.AddOutputMessage("Copying file from: " + fromFileName + " to: " + destinationFileName, processName, userID);
            }

            File.Copy(fromFileName.ToString(), destinationFileName.ToString(), true);

            // Let's open the DESTINATION document

            Word.Document vkMyDoc;
            try
            {
                //vkMyDoc = vkWordApp.Documents.Open(
                //    ref destinationFileName, ref vkMissing, ref vkReadOnly,
                //    ref vkMissing, ref vkMissing, ref vkMissing,
                //    ref vkMissing, ref vkMissing, ref vkMissing,
                //    ref vkMissing, ref vkMissing, ref vkVisible );

                //vkMyDoc = vkWordApp.Documents.Open(
                //    ref destinationFileName, ref vkMissing, ref vkReadOnly,
                //    ref vkMissing, ref vkMissing, ref vkMissing,
                //    ref vkMissing, ref vkMissing, ref vkMissing,
                //    ref vkMissing, ref vkMissing, ref vkVisible );

                if (uioutput != null)
                {
                    uioutput.AddOutputMessage("Opening file: " + destinationFileName, processName, userID);
                }

                vkMyDoc = vkWordApp.Documents.Open(
                    FileName: destinationFileName,
                    ConfirmConversions: vkFalse,
                    ReadOnly: vkFalse,
                    AddToRecentFiles: vkMissing,
                    PasswordDocument: vkMissing,
                    PasswordTemplate: vkMissing,
                    Revert: vkMissing,
                    WritePasswordDocument: vkMissing,
                    WritePasswordTemplate: vkMissing,
                    Format: vkMissing,
                    Encoding: vkMissing,
                    Visible: vkFalse);
            }
            catch (Exception ex)
            {
                ret.ReturnCode = -1;
                ret.ReasonCode = 1000;
                ret.Message    = "Error opening file." + destinationFileName;
                ret.Contents   = ex;
                return(ret);
            }

            //
            // In case the file is still read-only...
            //
            if (uioutput != null)
            {
                uioutput.AddOutputMessage("Checking if file is read-only: " + destinationFileName, processName, userID);
            }
            if (vkMyDoc.ReadOnly)
            {
                uioutput.AddOutputMessage("(Word) File is Read-only contact support:  " + fromFileName, processName, userID);
                vkMyDoc.Close();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc);
                return(ret);
            }

            if (uioutput != null)
            {
                uioutput.AddOutputMessage("File is NOT read-only!!  " + destinationFileName, processName, userID);
            }

            if (uioutput != null)
            {
                uioutput.AddOutputMessage("Starting find and replace loop", processName, userID);
            }


            // 18/04/2013
            //
            vkMyDoc.Activate();

            foreach (var t in tag)
            {
                if (t.TagType == Helper.Utils.InformationType.FIELD || t.TagType == Helper.Utils.InformationType.VARIABLE)
                {
                    FindAndReplace(t.Tag, t.TagValue, 1, vkWordApp, vkMyDoc);
                    // ReplaceProperty(t.Tag, t.TagValue, 1, vkWordApp, vkMyDoc);
                }
                else
                {
                    insertPicture(vkMyDoc, t.TagValue, t.Tag);
                }
            }

            // 15/03/2013
            // Force field update
            if (uioutput != null)
            {
                uioutput.AddOutputMessage("Force field updates.", processName, userID);
            }
            foreach (Word.Range myStoryRange in vkMyDoc.StoryRanges)
            {
                myStoryRange.Fields.Update();
            }

            // 24/10/2010 - Modificado quando troquei a referencia do Word
            //
            //vkMyDoc.Sections.Item( 1 ).Headers.Item( Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ).Range.Fields.Update();
            //vkMyDoc.Sections.Item( 1 ).Footers.Item( Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ).Range.Fields.Update();

            try
            {
                if (vkMyDoc.ReadOnly)
                {
                    if (uioutput != null)
                    {
                        uioutput.AddOutputMessage("(Word) File is Read-only contact support:  " + fromFileName, processName, userID);
                    }
                }
                else
                {
                    if (uioutput != null)
                    {
                        uioutput.AddOutputMessage("Saving file, it is no read-only.", processName, userID);
                    }

                    vkMyDoc.Save();
                }
            }
            catch (Exception ex)
            {
                if (uioutput != null)
                {
                    uioutput.AddOutputMessage("(Word) ERROR Saving in file:  " + fromFileName + " --- Message: " + ex.ToString(), processName, userID);
                }
            }

            // close the new document
            try
            {
                if (uioutput != null)
                {
                    uioutput.AddOutputMessage("Closing file", processName, userID);
                }
                vkMyDoc.Close(SaveChanges: vkTrue);
            }
            catch (Exception ex)
            {
                if (uioutput != null)
                {
                    uioutput.AddOutputMessage("(Word) ERROR Closing file:  " + fromFileName + " --- Message: " + ex.ToString(), processName, userID);
                }
            }



            // Trying to release COM object
            if (uioutput != null)
            {
                uioutput.AddOutputMessage("Releasing COM object", processName, userID);
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc);

            return(ret);
        }
示例#8
0
 public FileSystemDataSourceInfo(IOutputMessage messages)
 {
     _messages = messages;
 }
示例#9
0
 public CxTextWriter(IOutputMessage outputMessageDevice)
 {
     OutputMessageDevice = outputMessageDevice;
 }
示例#10
0
 public FactoryOutputMessage CreateMessage(string text)
 {
     message = new BaseOutputMessage(text);
     return(this);
 }
示例#11
0
        public WordReport(int ClientID, int ClientDocSetID, IOutputMessage UIoutput = null,
                          string OverrideDocuments = null)
        {
            row = 1;

            // Set private attributes
            clientID       = ClientID;
            clientDocSetID = ClientDocSetID;
            uioutput       = UIoutput;

            // Instantiate Word
            //
            vkFalse = false;

            vkWordApp = new Word.Application();

            // Make it not visible
            vkWordApp.Visible = false;

            vkExcelApp = new Excel.Application();

            // Make it not visible
            vkExcelApp.Visible = false;

            // Get Metadata for client

            clientMetadata = new ReportMetadataList();
            clientMetadata.ListMetadataForClient(clientID);

            ts = new List <WordDocumentTasks.TagStructure>();

            // Load variables/ metadata into memory
            //
            #region ClientMetadata
            foreach (ReportMetadata metadata in clientMetadata.reportMetadataList)
            {
                // Retrieve value for the field selected
                //
                string value = metadata.GetValue();

                // If the field is not enabled, the program has to replace the value with spaces.
                //
                var valueOfTag = metadata.Enabled == 'Y' ? value : string.Empty;

                // When the field is an image and it is not enable, do not include the "No image" icon in the list
                //
                if (metadata.InformationType == Utils.InformationType.IMAGE && metadata.Enabled == 'N')
                {
                    continue;
                }

                ts.Add(new WordDocumentTasks.TagStructure()
                {
                    TagType  = metadata.InformationType,
                    Tag      = metadata.FieldCode,
                    TagValue = valueOfTag
                });
            }
            #endregion ClientMetadata

            // Get Client Document Set Details
            // To get the source and destination folders
            cds = new ClientDocumentSet();
            cds.Get(clientID, clientDocSetID);

            valueForProgressBar = 0;
            startTime           = System.DateTime.Now.ToString();
        }
示例#12
0
 public Uploader(IFullDataSource originalDataSource, ISimpleDataSource incomingDataSource, IOutputMessage messages)
 {
     _originalDataSource = originalDataSource;
     _incomingDataSource = incomingDataSource;
     _messages           = messages;
 }
示例#13
0
 public CxTextWriter(IOutputMessage OutputMessageDevice)
 {
     outputMessageDevice = OutputMessageDevice;
 }
示例#14
0
        // ---------------------------------------------
        //             Copy Documents
        // ---------------------------------------------
        public static object CopyDocument(
            string fromFileName,
            string destinationFileName,
            List <WordDocumentTasks.TagStructure> tag,
            Excel.Application vkExcelApp,
            IOutputMessage uioutput
            )
        {
            // Excel.ApplicationClass vkExcelApp = new Excel.ApplicationClass();

            string saveFile = destinationFileName;

            object vkReadOnly = false;
            object vkVisible  = true;
            object vkFalse    = false;
            object vkTrue     = true;
            object vkDynamic  = 2;

            object vkMissing = System.Reflection.Missing.Value;

            // Let's make the excel application not visible
            // vkExcelApp.Visible = false;
            // vkExcelApp.Activate();

            // Let's copy the document
            File.Copy(fromFileName, destinationFileName, true);

            // Let's open the DESTINATION document
            //Word.Document vkMyDoc = vkExcelApp.Documents.Open(
            //    ref destinationFileName, ref vkMissing, ref vkReadOnly,
            //    ref vkMissing, ref vkMissing, ref vkMissing,
            //    ref vkMissing, ref vkMissing, ref vkMissing,
            //    ref vkMissing, ref vkMissing, ref vkVisible );

            Excel.Workbook vkMyDoc = vkExcelApp.Workbooks.Open(
                destinationFileName,
                vkMissing, false, vkMissing, vkMissing,
                vkMissing, true, vkMissing, "\t", vkMissing,
                vkMissing, vkMissing, vkMissing, vkMissing, vkMissing);

            foreach (var t in tag)
            {
                FindAndReplace(t.Tag, t.TagValue, 1, vkExcelApp, vkMyDoc);
            }

            try
            {
                vkMyDoc.Save();
            }
            catch (Exception ex)
            {
                uioutput.AddOutputMessage("(Excel) ERROR in file:  " + fromFileName + " --- Message: " + ex.ToString());
                uioutput.AddErrorMessage("(Excel) ERROR in file:  " + fromFileName + " --- Message: " + ex.ToString());
            }

            // close the new document
            vkMyDoc.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc);

            // close excel application
            // vkExcelApp.Quit();

            return(saveFile);
        }
示例#15
0
        private void decryptButton_Click(object sender, RoutedEventArgs e)
        {
            string      message     = null;
            int         imageHeight = 0;
            int         imageWidth  = 0;
            Bitmap      drawnImage  = null;
            MessageType messageType = MessageType.Plaintext;

            if (algorithmsComboBox.SelectedItem.ToString() == "LSB")
            {
                IOutputMessage messageInBits = LSB.Instance.Decode(new Bitmap(carrierViewer.filename));
                messageType = messageInBits.GetHeaderData().GetMessageType();
                string outputMessage = messageInBits.GetContent();
                switch (messageType)
                {
                case MessageType.Plaintext:
                    message = AlgorithmUtility.bitMessageToText(outputMessage, (int)LSBHeaderConstants.PlainTextHeaderLength);
                    break;

                case MessageType.BinaryImage:
                    message     = outputMessage.Substring((int)LSBHeaderConstants.BinaryImageHeaderLength);
                    imageHeight = messageInBits.GetHeaderData().GetImageHeight();
                    imageWidth  = messageInBits.GetHeaderData().GetImageWidth();
                    drawnImage  = ImageDrawer.Instance.DrawBinaryImage(message, imageWidth, imageHeight);
                    break;

                case MessageType.GrayscaleImage:
                    message     = outputMessage.Substring((int)LSBHeaderConstants.GrayscaleImageHeaderLength);
                    imageHeight = messageInBits.GetHeaderData().GetImageHeight();
                    imageWidth  = messageInBits.GetHeaderData().GetImageWidth();
                    drawnImage  = ImageDrawer.Instance.DrawGrayscaleImage(message, imageWidth, imageHeight);
                    break;

                case MessageType.ColorImage:
                    message     = outputMessage.Substring((int)LSBHeaderConstants.ColorImageHeaderLength);
                    imageHeight = messageInBits.GetHeaderData().GetImageHeight();
                    imageWidth  = messageInBits.GetHeaderData().GetImageWidth();
                    drawnImage  = ImageDrawer.Instance.DrawColorImage(message, imageWidth, imageHeight);
                    break;
                }
            }

            else if (algorithmsComboBox.SelectedItem.ToString() == "Histogram shifting")
            {
                HSSettings     tab           = settingsTabControl.SelectedContent as HSSettings;
                int            minIndex      = tab.getMinIndex();
                int            maxIndex      = tab.getMaxIndex();
                IOutputMessage messageInBits = HS.Instance.Decode(new Bitmap(carrierViewer.filename), minIndex, maxIndex);
                messageType = messageInBits.GetHeaderData().GetMessageType();
                string outputMessage = messageInBits.GetContent();
                switch (messageType)
                {
                case MessageType.Plaintext:
                    message = AlgorithmUtility.bitMessageToText(outputMessage, (int)HSHeaderConstants.PlainTextHeaderLength);
                    break;

                case MessageType.BinaryImage:
                    message     = outputMessage.Substring((int)HSHeaderConstants.BinaryImageHeaderLength);
                    imageHeight = messageInBits.GetHeaderData().GetImageHeight();
                    imageWidth  = messageInBits.GetHeaderData().GetImageWidth();
                    drawnImage  = ImageDrawer.Instance.DrawBinaryImage(message, imageWidth, imageHeight);
                    break;

                case MessageType.GrayscaleImage:
                    message     = outputMessage.Substring((int)HSHeaderConstants.GrayscaleImageHeaderLength);
                    imageHeight = messageInBits.GetHeaderData().GetImageHeight();
                    imageWidth  = messageInBits.GetHeaderData().GetImageWidth();
                    drawnImage  = ImageDrawer.Instance.DrawGrayscaleImage(message, imageWidth, imageHeight);
                    break;

                case MessageType.ColorImage:
                    message     = outputMessage.Substring((int)HSHeaderConstants.ColorImageHeaderLength);
                    imageHeight = messageInBits.GetHeaderData().GetImageHeight();
                    imageWidth  = messageInBits.GetHeaderData().GetImageWidth();
                    drawnImage  = ImageDrawer.Instance.DrawColorImage(message, imageWidth, imageHeight);
                    break;
                }
            }

            // need to change this dynamically
            if (messageType == MessageType.Plaintext)
            {
                messageTabControl.SelectedItem = messageTextBox;
                TextBox tab = messageTabControl.SelectedContent as TextBox;
                tab.Text = message;
                //messageTextBox.selec = message;
            }
            else
            {
                messageTabControl.SelectedItem = messageImage;
                Image tab = messageTabControl.SelectedContent as Image;
                tab.Source = ToBitmapImage(drawnImage);
            }
        }
示例#16
0
        // ---------------------------------------------
        //
        // ---------------------------------------------
        /// <summary>
        /// Create client document and replace document tags
        /// </summary>
        /// <param name="fromFileName"></param>
        /// <param name="destinationFileName"></param>
        /// <param name="tag"></param>
        /// <param name="vkWordApp"></param>
        /// <returns></returns>
        public static ResponseStatus CopyDocument(
            object fromFileName,
            object destinationFileName,
            List <WordDocumentTasks.TagStructure> tag,
            Word.Application vkWordApp,
            IOutputMessage uioutput
            )
        {
            ResponseStatus ret = new ResponseStatus();

            object saveFile = destinationFileName;

            object vkReadOnly = false;
            object vkVisible  = true;
            object vkFalse    = false;
            object vkTrue     = true;
            object vkDynamic  = 2;

            object vkMissing = System.Reflection.Missing.Value;

            // Let's make the word application not visible
            // vkWordApp.Visible = false;
            // vkWordApp.Activate();

            // Let's copy the document
            File.Copy(fromFileName.ToString(), destinationFileName.ToString(), true);

            // Let's open the DESTINATION document

            Word.Document vkMyDoc;
            try
            {
                vkMyDoc = vkWordApp.Documents.Open(
                    ref destinationFileName, ref vkMissing, ref vkReadOnly,
                    ref vkMissing, ref vkMissing, ref vkMissing,
                    ref vkMissing, ref vkMissing, ref vkMissing,
                    ref vkMissing, ref vkMissing, ref vkVisible);
            }
            catch (Exception ex)
            {
                ret.ReturnCode = -1;
                ret.ReasonCode = 1000;
                ret.Message    = "Error copying file.";
                ret.Contents   = ex;
                return(ret);
            }

            foreach (var t in tag)
            {
                if (t.TagType == Utils.InformationType.FIELD || t.TagType == Utils.InformationType.VARIABLE)
                {
                    FindAndReplace(t.Tag, t.TagValue, 1, vkWordApp, vkMyDoc);
                }
                else
                {
                    insertPicture(vkMyDoc, t.TagValue, t.Tag);
                }
            }

            // 24/10/2010 - Modificado quando troquei a referencia do Word
            //
            //vkMyDoc.Sections.Item( 1 ).Headers.Item( Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ).Range.Fields.Update();
            //vkMyDoc.Sections.Item( 1 ).Footers.Item( Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ).Range.Fields.Update();


            try
            {
                vkMyDoc.Save();
            }
            catch (Exception ex)
            {
                uioutput.AddOutputMessage("(Word) ERROR in file:  " + fromFileName + " --- Message: " + ex.ToString());
            }

            // close the new document
            vkMyDoc.Close();

            // Trying to release COM object
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc);

            return(ret);
        }