Example #1
0
        /// <summary>
        /// Transforms to temporary file.
        /// </summary>
        /// <param name="transformationFileName">Name of the transofrmation file.</param>
        /// <param name="transformationFilePattern">The transformation file pattern.</param>
        /// <param name="transformationFileSourceMatchIndex">Index of the tranformation file source match.</param>
        /// <returns>Name of the source and transformed file if there was no error, otherwise null</returns>
        public static Tuple <string, string> TransformToTemporaryFile(string transformationFileName, string transformationFilePattern, int transformationFileSourceMatchIndex)
        {
            string sourceFileName;

            var result = CheckTransformationFileAndGetSourceFileFromIt(transformationFileName, transformationFilePattern,
                                                                       transformationFileSourceMatchIndex, out sourceFileName);

            if (!result)
            {
                Logger.LogInfo(Resources.InvalidTransformationFileName);
                return(null);
            }

            var tempTargetFileName = GetTemporaryFileFullName(TransformationTempFileName);

            try
            {
                DeleteFile(tempTargetFileName);
                Logger.LogInfo(string.Format(Resources.DeletionOfTemporaryFileDone, tempTargetFileName));


                result = TransformationManager.Transform(sourceFileName, transformationFileName, tempTargetFileName, new TransformationLogger());

                if (result)
                {
                    Logger.LogInfo(string.Format(Resources.TransformationOfFileSuccessfullyDone, sourceFileName,
                                                 transformationFileName, tempTargetFileName));

                    FormatFile(tempTargetFileName);

                    return(new Tuple <string, string>(sourceFileName, tempTargetFileName));
                }

                //else error
                Logger.LogInfo(string.Format(Resources.TransformationProcessError, sourceFileName, transformationFileName,
                                             tempTargetFileName));

                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(string.Format(Resources.ErrorWhileTransformingFile, sourceFileName, transformationFileName, tempTargetFileName));
                Logger.LogError(ex);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Transforms the specified transofrmation file name.
        /// </summary>
        /// <param name="transformationFileName">Name of the transofrmation file.</param>
        /// <param name="transformationFilePattern">The transformation file pattern.</param>
        /// <param name="transformationFileSourceMatchIndex">Index of the tranformation file source match.</param>
        public static void Transform(string transformationFileName, string transformationFilePattern, int transformationFileSourceMatchIndex)
        {
            string sourceFileName;

            var result = CheckTransformationFileAndGetSourceFileFromIt(transformationFileName, transformationFilePattern,
                                                                       transformationFileSourceMatchIndex, out sourceFileName);

            if (!result)
            {
                Logger.LogInfo(Resources.InvalidTransformationFileName);
                return;
            }

            if (IsFileReadOnly(sourceFileName))
            {
                Logger.LogInfo(string.Format(Resources.FileIsReadOnly, sourceFileName));
                MessageBox.Show(string.Format(Resources.FileIsReadOnlyChange, sourceFileName), Resources.ApplicationCaption, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                return;
            }

            var backupFileName = GetBackupFileNameOfFile(sourceFileName);

            try
            {
                DeleteFile(backupFileName);
                Logger.LogInfo(string.Format(Resources.DeletionOfTemporaryFileDone, backupFileName));

                CreateBackupFileOfFile(sourceFileName, backupFileName);
                Logger.LogInfo(string.Format(Resources.CopyOfSourceFileDone, sourceFileName, backupFileName));

                result = TransformationManager.Transform(backupFileName, transformationFileName, sourceFileName, new TransformationLogger());
                Logger.LogInfo(result
                    ? string.Format(Resources.TransformationOfFileSuccessfullyDone, backupFileName,
                                    transformationFileName, sourceFileName)
                    : string.Format(Resources.TransformationProcessError, backupFileName, transformationFileName,
                                    sourceFileName));

                FormatFile(sourceFileName);
                DeleteFile(backupFileName);
                Logger.LogInfo(string.Format(Resources.DeletionOfTemporaryFileDone, backupFileName));
            }
            catch (Exception ex)
            {
                Logger.LogError(string.Format(Resources.ErrorWhileTransformingFile, backupFileName, transformationFileName, sourceFileName));
                Logger.LogError(ex);
            }
        }