コード例 #1
0
        private static void FixedWidthSortMurgePurge <T>(string dbConnPath, string line,
                                                         MasterFixedWidthFileSource <T> master,
                                                         DelimitedFileSource <T> detail,
                                                         MergePurgeParam mgPurgeParam,
                                                         Action <MergePurgeParam> processData,
                                                         MergePurgeResults mgPurgeResults,
                                                         DataMode processMode,
                                                         StreamWriter[] actionWriters)
        {
            SortKey <T> srtKey = null;

            using (SqliteRepository <T> sqlRepo = new SqliteRepository <T>(dbConnPath))
            {
                srtKey = sqlRepo.KeyInDb(detail.GetKey(mgPurgeParam.DetailFields, line));
            }
            mgPurgeParam.KeyFound = srtKey.Found;
            string masterData = !srtKey.Found ? string.Empty : srtKey.Data;

            if (mgPurgeParam.KeyFound)
            {
                mgPurgeParam.MasterFields = GetMasterFields <T>(master, masterData);
            }
            if (processData != null)
            {
                processData(mgPurgeParam);
                mgPurgeResults.IncrementAction(mpAction: mgPurgeParam.DataAction);
                string detailLine    = GetDetailLine <T>(detail, mgPurgeParam);
                string newMasterData = GetNewMasterDataFixedWidth(GetMasterLine <T>(master, mgPurgeParam));
                PerformDataActionForPassiveModeWriter(mgPurgeParam.DataAction, mgPurgeParam.KeyFound, processMode, detailLine, actionWriters);
                PerformDataAction(mgPurgeParam, dbConnPath, processMode, newMasterData, srtKey);
            }
        }
コード例 #2
0
        private static string[] GetMasterFields <T>(MasterFixedWidthFileSource <T> master, string data)
        {
            string outLine = SortFileHelpers.UnEscapeByDelimiter(data.Decompress(), Constants.Delimiters.Tab);

            string[] results = null;
            FileParser.ParseFixedWidthString(new StringReader(outLine), (fields, lNum) =>
            {
                results = fields;
            }, master.FixedWidths);
            return(results);
        }
コード例 #3
0
 internal static SortResults SortFixedWidth <T>(MasterFixedWidthFileSource <T> master, string destinationFolder)
 {
     return(SortFile.SortFixedWidthByKeyCore <T>(sourcefilePath: master.SourceFilePath,
                                                 getKey: master.GetKey,
                                                 destinationFolder: destinationFolder,
                                                 hasHeader: master.HasHeader,
                                                 isUniqueKey: false,
                                                 sortDir: master.SortDirection,
                                                 deleteDbConnPath: false,
                                                 writeOutSortFile: false));
 }
コード例 #4
0
        public static MergePurgeResults MergePurge <T>(MasterFixedWidthFileSource <T> master,
                                                       DelimitedFileSource <T> detail,
                                                       Action <MergePurgeParam> processData,
                                                       string destinationFolder = null,
                                                       DataMode processMode     = DataMode.Passive)
        {
            ArgumentValidation <T>(master, detail, processData, destinationFolder);
            MergePurgeResults mgPurgeResults = new MergePurgeResults();
            SortVars          mstSortVars    = new SortVars(master.SourceFilePath, destinationFolder);
            SortResults       srtResults     = SortFixedWidth <T>(master, mstSortVars.DestFolder);

            mgPurgeResults.InitFilePaths(master.SourceFilePath, detail.SourceFilePath, mstSortVars.DestFolder);
            try
            {
                string hdr = string.Empty;
                using (StreamReader reader = new StreamReader(detail.SourceFilePath))
                    using (StreamWriter addSw = new StreamWriter(mgPurgeResults.AddsFilePath))
                        using (StreamWriter delSw = new StreamWriter(mgPurgeResults.DeletesFilePath))
                            using (StreamWriter updSw = new StreamWriter(mgPurgeResults.UpdatesFilePath))
                                using (StreamWriter ignSw = new StreamWriter(mgPurgeResults.IgnoredFilePath))
                                {
                                    StreamWriter[] actionWriters = { addSw, delSw, updSw, ignSw };
                                    string         line;
                                    hdr = GetHeader(detail.HasHeader, reader);
                                    WriteHeaderToActionWriters(processMode, detail.HasHeader, hdr, actionWriters);
                                    while ((line = reader.ReadLine()) != null)
                                    {
                                        MergePurgeParam mgPurgeParam = new MergePurgeParam();
                                        FileParser.ParseDelimitedString(new StringReader(line), (fields, lNum) =>
                                        {
                                            mgPurgeParam.DetailFields = fields;
                                            mgPurgeParam.DataAction   = MergePurgeAction.Ignore;
                                        }, detail.Delimiter);
                                        FixedWidthSortMurgePurge <T>(srtResults.DbConnPath, line, master, detail, mgPurgeParam, processData, mgPurgeResults, processMode, actionWriters);
                                    }
                                }
                mgPurgeResults.ClearSubFilesIfNoCount();
                if (processMode == DataMode.Active)
                {
                    mgPurgeResults.RemoveSubFilesAndFilePaths();
                }
                srtResults.SortedFilePath = mgPurgeResults.NewMasterFilePath;
                srtResults.WriteOutSorted(dbConnPath: srtResults.DbConnPath, header: srtResults.Header, sortDir: master.SortDirection, delimiter: Constants.Delimiters.Tab, compressed: true, deleteDb: true);
            }
            catch (Exception)
            {
                ExceptionCleanUp(srtResults.DbConnPath, mgPurgeResults);
                throw;
            }

            return(mgPurgeResults);
        }
コード例 #5
0
 private static void ArgumentValidation <T>(MasterFixedWidthFileSource <T> master, DelimitedFileSource <T> detail, Action <MergePurgeParam> processData, string destinationFolder = null)
 {
     if ((master.GetKey != null && detail.GetKey == null) || (master.GetKey == null && detail.GetKey != null))
     {
         throw new ArgumentException("Master and Detail must have the same GetKey function type defined.");
     }
     if (master.GetKey == null)
     {
         throw new ArgumentException("The Master File Source must have a GetKey function defined.");
     }
     if (detail.GetKey == null)
     {
         throw new ArgumentException("The Detail File Source must have a GetKey function defined.");
     }
     ArgumentValidation <T>(master);
     ArgumentValidation <T>(detail);
     ArgumentValidation(processData);
     ArgumentValidation(destinationFolder);
     ArgumentValidation((IFileSource)master);
     ArgumentValidation((IFileSource)detail);
 }
コード例 #6
0
 private static string GetMasterLine <T>(MasterFixedWidthFileSource <T> master, MergePurgeParam mgPurgeParam)
 {
     return(mgPurgeParam.MasterFields != null?mgPurgeParam.MasterFields.SerializeToFixedWidth(master.FixedWidths) : string.Empty);
 }