예제 #1
0
        static void Main(string[] args)
        {
            string line;

            Console.WriteLine("Type HELP for a list of options.");
            Console.WriteLine();

            using (OutageLog log = new OutageLog())
            {
                log.FileName     = @"C:\Users\swills\test.txt";
                log.LogModified += (sender, arg) => Console.WriteLine("Modified!");
                log.Initialize();

                while (!(line = Console.ReadLine()).Equals("EXIT", StringComparison.OrdinalIgnoreCase))
                {
                    switch (line.ToUpper())
                    {
                    case "ADD":
                        log.Add(DateTimeOffset.UtcNow.AddSeconds(-1.0D), DateTimeOffset.UtcNow);
                        Console.WriteLine($"Count: {log.Count}");
                        break;

                    case "REMOVE":
                        log.Remove(log.First());
                        Console.WriteLine($"Count: {log.Count}");
                        break;

                    case "DUMP":
                        foreach (Outage outage in log.Outages)
                        {
                            Console.WriteLine($"{outage.Start:yyyy-MM-dd HH:mm:ss.fff};{outage.End:yyyy-MM-dd HH:mm:ss.fff}");
                        }

                        Console.WriteLine();
                        break;

                    case "STATUS":
                        Console.WriteLine(log.Status);
                        Console.WriteLine();
                        break;

                    case "HELP":
                        Console.WriteLine("ADD    - Adds a new outage to the log");
                        Console.WriteLine("REMOVE - Removes the first outage from the log");
                        Console.WriteLine("DUMP   - Displays the contents of the log");
                        Console.WriteLine("STATUS - Displays detailed status of the log");
                        Console.WriteLine("EXIT   - Exits this application");
                        Console.WriteLine();
                        break;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Removes a data gap from the outage log so that it will not be processed.
        /// </summary>
        /// <param name="startTime">Start time of data gap.</param>
        /// <param name="endTime">End time of data gap.</param>
        /// <returns>True if the data gap was successfully removed; false otherwise.</returns>
        public bool RemoveDataGap(DateTimeOffset startTime, DateTimeOffset endTime)
        {
            if (m_disposed)
            {
                throw new InvalidOperationException("Data gap recoverer has been disposed. Cannot log data gap for processing.");
            }

            if ((object)m_dataGapLog == null)
            {
                throw new InvalidOperationException("Data gap recoverer has not been initialized. Cannot log data gap for processing.");
            }

            // Since local clock may float we add some buffer around recovery window
            return(m_dataGapLog.Remove(new Outage(startTime, endTime)));
        }