コード例 #1
0
ファイル: Main.cs プロジェクト: kwagner/Tor-Weather-Django
 public static void MessageTest(object sender, MessageEventArgs args)
 {
     Console.WriteLine(":: {0} :: {1}", args.Severity, args.Msg);
 }
コード例 #2
0
        protected void HandleEvent(ArrayList events)
        {
            foreach (ReplyLine line in events) {
                int idx = line.Msg.IndexOf(" ");
                string tp = line.Msg.Substring(0, idx).ToUpper();

                string rest = line.Msg.Substring(idx+1);

                if (tp == "CIRC") {
                    if (this.CircuitStatus != null) {
                        string[] pars = rest.Split(' ');
                        CircuitStatusEventArgs args = new CircuitStatusEventArgs(pars[1],
                                                                                 pars[0],
                                                                                 pars[2]);

                        CircuitStatus(this, args);
                    }
                } else if (tp == "STREAM") {
                    if (this.StreamStatus != null) {
                        string[] pars = rest.Split(' ');
                        StreamStatusEventArgs args = new StreamStatusEventArgs(pars[1],
                                                                               pars[0],
                                                                               pars[3]);

                        StreamStatus(this, args);
                    }
                } else if (tp == "ORCONN") {
                    if (this.OrConnStatus != null) {
                        string[] pars = rest.Split(' ');
                        OrConnStatusEventArgs args = new OrConnStatusEventArgs(pars[1],
                                                                               pars[0]);

                        OrConnStatus(this, args);
                    }
                } else if (tp == "BW") {
                    if (this.BandwidthUsed != null) {
                        string[] pars = rest.Split(' ');
                        BandwidthUsedEventArgs args = new BandwidthUsedEventArgs(long.Parse(pars[0]),
                                                                                 long.Parse(pars[1]));

                        BandwidthUsed(this, args);
                    }
                } else if (tp == "NEWDESC") {
                    if (this.NewDescriptors != null) {
                        IList lst = Bytes.SplitStr(null, rest);
                        NewDescriptorsEventArgs args = new NewDescriptorsEventArgs(lst);

                        NewDescriptors(this, args);
                    }
                } else if (tp == "DEBUG"  ||
                           tp == "INFO"   ||
                           tp == "NOTICE" ||
                           tp == "WARN"   ||
                           tp == "ERR") {
                    if (this.Message != null) {
                        MessageEventArgs args = new MessageEventArgs(tp, rest);

                        Message(this, args);
                    }
                } else {
                    if (this.Unrecognized != null) {
                        UnrecognizedEventArgs args = new UnrecognizedEventArgs(tp, rest);

                        Unrecognized(this, args);
                    }
                }
            }
        }
コード例 #3
0
        protected void HandleEvent(Cmd c)
        {
            TorControl.Event type = (TorControl.Event)Bytes.GetU16(c.Body, 0);

            switch (type) {
                case TorControl.Event.CircSatus:
                    if (this.CircuitStatus != null) {
                        CircuitStatusEventArgs args;
                        args = new CircuitStatusEventArgs(TorControl.StreamStatusNames[c.Body[2]],
                                                          Bytes.GetU32S(c.Body, 3),
                                                          Bytes.GetNulTerminatedStr(c.Body, 7));
                        CircuitStatus(this, args);
                    }
                    break;
                case TorControl.Event.StreamStatus:
                    if (this.StreamStatus != null) {
                        StreamStatusEventArgs args;
                        args = new StreamStatusEventArgs(TorControl.StreamStatusNames[c.Body[2]],
                                                         Bytes.GetU32S(c.Body, 3).ToString(),
                                                         Bytes.GetNulTerminatedStr(c.Body, 7));
                        StreamStatus(this, args);
                    }
                    break;
                case TorControl.Event.OrConnStatus:
                    if (this.OrConnStatus != null) {
                        OrConnStatusEventArgs args;
                        args = new OrConnStatusEventArgs(TorControl.ORConnStatusNames[c.Body[2]],
                                                         Bytes.GetNulTerminatedStr(c.Body, 3));
                        OrConnStatus(this, args);
                    }
                    break;
                case TorControl.Event.Bandwidth:
                    if (this.BandwidthUsed != null) {
                        BandwidthUsedEventArgs args;
                        args = new BandwidthUsedEventArgs(Bytes.GetU32(c.Body, 2),
                                                          Bytes.GetU32(c.Body, 6));
                        BandwidthUsed(this, args);
                    }
                    break;
                case TorControl.Event.NewDescriptor:
                    if (this.NewDescriptors != null) {
                        IList lst = new ArrayList();
                        Bytes.SplitStr(lst, c.Body, 2, (byte)',');
                        NewDescriptorsEventArgs args;
                        args = new NewDescriptorsEventArgs(lst);

                        NewDescriptors(this, args);
                    }
                    break;
                case TorControl.Event.MsgDebug:
                    if (this.Message != null) {
                        MessageEventArgs args;
                        args = new MessageEventArgs("DEBUG", Bytes.GetNulTerminatedStr(c.Body, 2));
                        Message(this, args);
                    }
                    break;
                case TorControl.Event.MsgInfo:
                    if (this.Message != null) {
                        MessageEventArgs args;
                        args = new MessageEventArgs("INFO", Bytes.GetNulTerminatedStr(c.Body, 2));
                        Message(this, args);
                    }
                    break;
                case TorControl.Event.MsgNotice:
                    if (this.Message != null) {
                        MessageEventArgs args;
                        args = new MessageEventArgs("NOTICE", Bytes.GetNulTerminatedStr(c.Body, 2));
                        Message(this, args);
                    }
                    break;
                case TorControl.Event.MsgWarn:
                    if (this.Message != null) {
                        MessageEventArgs args;
                        args = new MessageEventArgs("WARN", Bytes.GetNulTerminatedStr(c.Body, 2));
                        Message(this, args);
                    }
                    break;
                case TorControl.Event.MsgError:
                    if (this.Message != null) {
                        MessageEventArgs args;
                        args = new MessageEventArgs("ERR", Bytes.GetNulTerminatedStr(c.Body, 2));
                        Message(this, args);
                    }
                    break;
                default:
                    if (this.Unrecognized != null) {
                        // TODO: Check if this is practicable
                        UnrecognizedEventArgs args;
                        args = new UnrecognizedEventArgs("UNKNOWN",
                                                         Bytes.GetNulTerminatedStr(c.Body, 3));
                        Unrecognized(this, args);
                    }
                    break;
            }
        }