예제 #1
0
        public void Load(string fileSpec, InterpretationEnum interpretation)
        {
            ImportedRowCount = 0;
            this.Clear();
            StreamReader sr   = null;
            string       line = string.Empty;

            Administrator.Tracer.WriteLine();
            Administrator.Tracer.WriteMsg("I", String.Format(@"Importing from file  ""{0}""", fileSpec));
            try
            {
                sr = new StreamReader(fileSpec);
                if (sr.Peek() > -1)
                {
                    line = sr.ReadLine();
                    do
                    {
                        line = sr.ReadLine();
                        ImportedRowCount++;
                        List <string> values = CsvSplitter.Split(line);
                        if (values.Count > 1)
                        {
                            AdvancedDirectoryEntry entry = new AdvancedDirectoryEntry();
                            entry.StdHlq  = values[0];
                            entry.StdDir  = values[1];
                            entry.StdFile = values[2];
                            int size = 0;
                            int.TryParse(values[3], out size);
                            entry.StdSize = size;
                            DateTime stdDateTime = DateTime.MinValue;
                            DateTime.TryParse(values[4], out stdDateTime);
                            entry.StdDate = stdDateTime;
                            DateTime sourceDateTime = DateTime.MinValue;
                            DateTime.TryParse(values[5], out sourceDateTime);
                            entry.SourceDate = sourceDateTime;
                            DateTime targetDateTime = DateTime.MinValue;
                            DateTime.TryParse(values[6], out targetDateTime);
                            entry.TargetDate               = targetDateTime;
                            entry.SourceHlq                = values[7];
                            entry.SourceFile               = values[8];
                            entry.TargetHlq                = values[9];
                            entry.TargetFile               = values[10];
                            entry.StdType                  = values[11];
                            entry.FolderGroup              = values[12];
                            entry.FolderGroupMatchPath     = values[13];
                            entry.FolderGroupMatchStem     = values[14];
                            entry.FolderGroupMatchFileSpec = values[15];
                            entry.FolderGroupFullPath      = values[16];
                            entry.FolderGroupFullStem      = values[17];
                            entry.FolderGroupFullFileSpec  = values[18];
                            entry.CtlComparison            = values[19];
                            // When using a snapshot taken from the source to represent a projected snapshot that should exist at the target after synchronization
                            // then we must edit the StdHlq to make it appear to have come from the target so that the comparison will not think everything has changed.
                            if (interpretation == InterpretationEnum.Target)
                            {
                                entry.StdHlq = entry.TargetHlq;
                            }
                            this.Add(entry);
                        }
                        else
                        {
                            Administrator.Tracer.WriteTimedMsg("W", String.Format(@"Logical error in method ""{0}"" : line number ""{1}"", number of data fields is insufficient, line ignored", MethodBase.GetCurrentMethod().Name, ImportedRowCount));
                        }
                    } while (sr.Peek() > -1);
                }
            }
            catch (Exception ex)
            {
                Administrator.Tracer.WriteTimedMsg("E", String.Format(@"Exception in method ""{0}"" : {1}", MethodBase.GetCurrentMethod().Name, ex.Message));
            }
            finally
            {
                Administrator.Tracer.WriteTimedMsg("I", String.Format("Imported Rows: {0}", ImportedRowCount.ToString().PadLeft(9)));
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                }
            }
        }