Пример #1
0
        protected virtual ICollection <DateTime> readAllTimestamps()
        {
            ICollection <DateTime> collection = new XLinkedList <DateTime>();
            var md = this.mainDirectory;

            try
            {
                if (!Directory.Exists(md))
                {
                    Directory.CreateDirectory(md);
                }
            }
            catch
            {
                return(collection);
            }

            string[] allDataFiles;
            try
            {
                allDataFiles = Directory.GetFiles(md);
            }
            catch
            {
                return(collection);
            }

            foreach (var filePath in allDataFiles)
            {
                IEnumerable <string> lines;
                try
                {
                    lines = File.ReadAllLines(filePath);
                }
                catch
                {
                    continue;
                }

                foreach (var line in lines)
                {
                    if (!long.TryParse(line, out var ticks))
                    {
                        continue;
                    }

                    collection.Add(new DateTime(ticks));
                }
            }

            collection = EnumerableHelpers.OrderBy(
                collection,
                timestamp => timestamp);

            return(collection);
        }
Пример #2
0
        public virtual bool ConvertToSingleFile()
        {
            var md = this.mainDirectory;

            try
            {
                if (!Directory.Exists(md))
                {
                    Directory.CreateDirectory(md);
                    return(true);
                }
            }
            catch
            {
                return(false);
            }

            try
            {
                var files = Directory.GetFiles(md);
                if (files.Length == 1 &&
                    files[0].Contains(DataFileName))
                {
                    return(true);
                }
            }
            catch
            {
                return(false);
            }

            ICollection <string> times = new XLinkedList <string>();

            try
            {
                foreach (var file in Directory.GetFiles(md))
                {
                    foreach (var line in File.ReadAllLines(file))
                    {
                        times.Add(line);
                    }
                }
            }
            catch
            {
                return(false);
            }

            try
            {
                File.WriteAllLines(
                    Path.Combine(md, DataFileName),
                    EnumerableHelpers.ToArray(
                        times));
                foreach (var file in Directory.GetFiles(md))
                {
                    if (file.Contains(DataFileName))
                    {
                        continue;
                    }

                    File.Delete(file);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }