Exemplo n.º 1
0
        /// <summary>
        /// Use to process post translate actions
        /// </summary>
        private void TranslateComplete()
        {
            //US & CA are both in the same path
            countryConfig = new CountryConfig("0");
            //Get a complete list of temp folders.
            DirectoryInfo tmpInfo = new DirectoryInfo(base.TranslatedFileLocation + "\\" + countryConfig.SaveDirectoryLocation);

            List <DirectoryInfo> tmpdirs = new List <DirectoryInfo>();

            if (Directory.Exists(tmpInfo.FullName))
            {
                tmpdirs = tmpInfo.GetDirectories("*.TMP", SearchOption.TopDirectoryOnly).ToList();
            }

            //Consignment
            countryConfig = new CountryConfig("2");
            //Get a complete list of temp folders.
            tmpInfo = new DirectoryInfo(base.TranslatedFileLocation + "\\" + countryConfig.SaveDirectoryLocation);

            if (Directory.Exists(tmpInfo.FullName))
            {
                tmpdirs.AddRange(tmpInfo.GetDirectories("*.TMP", SearchOption.TopDirectoryOnly).ToList());
            }


            foreach (DirectoryInfo dirInfo in tmpdirs)
            {
                //If a directory exists that wasn't created on this run of the translate store it to keep files from not being fed into auditworks.
                if (!OutputDirectoriesCreated.Contains(dirInfo.FullName))
                {
                    OutputDirectoriesCreated.Add(dirInfo.FullName);
                }
            }



            foreach (string dir in OutputDirectoriesCreated)
            {
                if (!Directory.Exists(dir))
                {
                    continue;
                }

                //Rename the temp file to the extension required by auditworks
                string NewDir = dir.Replace(".TMP", ".IP");
                //Create the Done file requred by auditworks
                try
                {
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "CreatingDoneFile"), dir));
                    using (File.Create(String.Format("{0}\\{1}", dir, "DONE.DONE")))
                    {
                    }
                }
                catch (Exception ex)
                {
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "DoneFileError"), ex.Message));
                    continue;
                }

                try
                {
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "RenameDir"), dir, NewDir));
                    System.IO.Directory.Move(dir, NewDir);
                }
                catch (Exception ex)
                {
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "RenameDirError"), ex.Message));
                }
            }
            System.Threading.Thread.Sleep(3000);
            LogMessage(ResourceHelper.Instance.GetString(ResFile, "AppDone"));
            System.Threading.Thread.Sleep(2000);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method does the validation and is the entry point for the translating.
        /// </summary>
        /// <param name="file">The file to be translated and validated</param>
        private void TranslateFile(FileInfo file)
        {
            ConvertedTLogDoc = null;
            this._SourceFile = file.FullName;
            if (ExcludeHelper == null)
            {
                ExcludeHelper = new ExcludeFileHelper(PluginConfig.GetValue("TranslateExludeFile"), PluginConfig.GetValue("TranslateExludePath"), PluginConfig.GetValue("TranslateExludeType_BeforeTrans").Split(','));
            }

            if (_SourceDocument == null)
            {
                _SourceDocument = new XmlDocument();
                using (XmlReader SourceReader = SourceDocument)
                {
                    SourceReader.MoveToContent();
                    _SourceDocument.LoadXml(SourceReader.ReadOuterXml());
                }
            }

            bool     isvalid            = true;
            Validate TranslateValidator = null;
            bool     validate           = (PluginConfig.GetValue("ValidateTLog") == "") ? false : Convert.ToBoolean(PluginConfig.GetValue("ValidateTLog"));

            if (validate)
            {
                try
                {
                    TranslateValidator = new SpencerGifts.TlogCommon.Validate();

                    //Before we can process the file we need to check to make sure its a valid tlog\
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "ValidateFile"), file.Name));
                    //isvalid = TranslateValidator.isValidTLog(_SourceDocument, _SourceFile);
                    isvalid = TranslateValidator.isValidTLog(_SourceDocument, file.FullName);
                }
                catch (Exception ex)
                {
                    LogMessage("Validator Exception " + ex.Message + " " + ex.StackTrace);
                    //Defaulting to true since the validator blew up and we don't necessarly want to prevent tlogs from getting held up
                    isvalid = true;
                }
            }
            if (!isvalid)
            {
                string BadTlogLocation = PluginConfig.GetValue("BadTlogLocation");

                if (TranslateValidator != null)
                {
                    Console.WriteLine(TranslateValidator.ErrorMessage);
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "InvalidFile"), file.Name));
                    LogMessage("\r\n------------------------------------------\r\n" + TranslateValidator.ErrorMessage + "------------------------------------------");
                    //Logging.LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "MovingBadTLog"), BadTlogLocation));
                }

                File.Move(_SourceFile, BadTlogLocation + "\\" + file.Name);
            }
            else
            {
                //We need to check the exclude file first before we translate.  If the store is in the exclude file and
                //has a type that specifies not to translate the file then move it to the appropriate non translating directory.
                if (!ExcludeHelper.ShouldTranslate(file.Name.Substring(4, 5)))
                {
                    MoveFile(file, ExcludeHelper.NonTranslateSavePath);
                    return;
                }

                LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "FileIsValid"), file.Name));
                LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "TranslatingFile"), file.Name));
                try
                {
                    StoreCountryCode = _SourceDocument.SelectSingleNode("//L10/@country").Value;
                    if (isConsignmentStore(file.Name))
                    {
                        countryConfig = new CountryConfig(PluginConfig.GetValue("ConsignmentCountryCode"));
                    }
                    else
                    {
                        countryConfig = new CountryConfig(StoreCountryCode);
                    }

                    base.Process();
                    //now we need to check the exclude file again to verify we can move the translated file to the backup location
                    if (ExcludeHelper.OkToBackup(file.Name.Substring(4, 5)))
                    {
                        BackupFile(file);
                    }
                    else
                    {
                        MoveFile(file, ExcludeHelper.NonTranslateSavePath);
                    }
                }
                catch (RuleConditionException ex)
                {
                    PropertyInfo[] info = ex.GetType().GetProperties();
                    LogException(info, ex);
                    throw ex;
                }
                catch (RuleActionException ex)
                {
                    PropertyInfo[] info = ex.GetType().GetProperties();
                    LogException(info, ex);
                    throw ex;
                }
                catch (RuleMappingException ex)
                {
                    PropertyInfo[] info = ex.GetType().GetProperties();
                    LogException(info, ex);
                    throw ex;
                }
                catch (Exception ex)
                {
                    LogMessage(String.Format(ResourceHelper.Instance.GetString(ResFile, "UnHandledException"), file.Name, ex.ToString()));
                    throw ex;
                }
                finally
                {
                    _SourceDocument   = null;
                    _SourceDocumentMS = null;
                }
            }
        }