Esempio n. 1
0
        private void ReadState(string filename)
        {
            using (Stream stream = File.Open(filename, FileMode.Open))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    lock (thisLock)
                    {
                        int nhistory = reader.ReadInt32();
                        for (int i = 0; i < nhistory; i++)
                        {
                            IPAddress addr = new IPAddress(reader.ReadBytes(16));
                            IFail     fail = null;

                            switch (history)
                            {
                            case HistoryType.ALL: fail = new FailAll(reader, findtime * TimeSpan.TicksPerSecond); break;

                            case HistoryType.ONE: fail = new FailOne(reader, findtime * TimeSpan.TicksPerSecond); break;

                            case HistoryType.FIXED: fail = new FailFixed(reader, findtime * TimeSpan.TicksPerSecond, history_fixed_count, history_fixed_decay); break;

                            case HistoryType.RRD: fail = new FailRRD(reader, findtime * TimeSpan.TicksPerSecond, history_rrd_count, history_rrd_repeat); break;
                            }

                            if (fail.Count > 0)
                            {
                                data[addr] = fail;
                            }
                        }
                    }
                }
        }
 private bool ExecuteHandler(object command, IFail executor)
 {
     try
     {
         return executor.Fail(command);
     }
     finally
     {
         _container.Release(executor);
     }
 }
 /// <summary>
 /// Ensures that there is a value. Throws if there is not.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <exception cref="ErrorException">The exception containing the error.</exception>
 public static void EnsureSuccess(this IResult result)
 {
     if (result.IsSuccess)
     {
         return;
     }
     else
     {
         IFail fail = result.AsFail();
         throw new ErrorException(fail.Error, fail.Error.Message ?? string.Empty);
     }
 }
Esempio n. 4
0
        public override void Debug(StreamWriter output)
        {
            base.Debug(output);

            output.WriteLine("config address: " + address);
            output.WriteLine("config findtime: " + findtime);
            output.WriteLine("config ipv4_prefix: " + ipv4_prefix);
            output.WriteLine("config ipv6_prefix: " + ipv6_prefix);
            output.WriteLine("config cleanup: " + cleanup);
            output.WriteLine("config history: " + history);
            output.WriteLine("config history_fixed_count: " + history_fixed_count);
            output.WriteLine("config history_fixed_decay: " + history_fixed_decay);
            output.WriteLine("config history_rrd_count: " + history_rrd_count);
            output.WriteLine("config history_rrd_repeat: " + history_rrd_repeat);
            foreach (Treshold treshold in tresholds)
            {
                output.WriteLine("config treshold " + treshold.Name + " function: " + treshold.Function);
                output.WriteLine("config treshold " + treshold.Name + " repeat: " + treshold.Repeat);
                output.WriteLine("config treshold " + treshold.Name + " maxretry: " + treshold.MaxRetry);
                output.WriteLine("config treshold " + treshold.Name + " bantime: " + treshold.Bantime);
                output.WriteLine("config treshold " + treshold.Name + " action: " + treshold.Action);
                output.Write("config treshold " + treshold.Name + " last(" + treshold.Last.Count + "): ");
                foreach (var kvs in treshold.Last)
                {
                    output.Write(kvs.Key + "(" + kvs.Value + "),");
                }
                output.WriteLine();
            }

            lock (thisLock)
            {
                foreach (var item in data)
                {
                    IPAddress addr = item.Key;
                    IFail     fail = item.Value;

                    output.WriteLine("status address " + addr);
                    fail.Debug(output);
                }
            }
        }
Esempio n. 5
0
        private void WriteState(string filename)
        {
            Cleanup();

            using (Stream stream = File.Open(filename, FileMode.Create))
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    lock (thisLock)
                    {
                        writer.Write(data.Count);
                        foreach (var item in data)
                        {
                            IPAddress addr = item.Key;
                            IFail     fail = item.Value;

                            writer.Write(addr.GetAddressBytes());
                            fail.Save(writer);
                        }
                    }
                }
        }
Esempio n. 6
0
 public IResponse <TData> CreateFault <TData>(IFail error) => new ResponseBase <TData>(error);
Esempio n. 7
0
 public IResponse <TData> CreateInstance <TData>(TData data, IFail error) => new ResponseBase <TData>(data, error);
Esempio n. 8
0
 public ResponseBase CreateFault(IFail error) => new ResponseBase(error);