Пример #1
0
 private void discoverToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Mantis.Discover();
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.Write("Enter network name: ");
            string network = Console.ReadLine();

            Console.Write("Enter network pass: "******"Enter brewer name: ");
            string brewerName = Console.ReadLine();

            object fileLock = new object();

            MantisDotNet.Mantis.OnDiagnosticsEvent += (sender, arg) =>
            {
                Console.WriteLine("DIAG: {0} {1}\t{2}", arg.Timestamp.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), arg.Level, arg.Message);
            };

            MantisDotNet.Mantis.Initialize();

            MantisDotNet.Network.NetworkPump.HookRawMessagePump((result) =>
            {
                lock (fileLock)
                {
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter("network.rec", true))
                    {
                        var record = new { TS = DateTime.Now, EP = result.RemoteEndPoint.ToString(), B = Encoding.ASCII.GetString(result.Buffer) };
                        file.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(record));
                    }
                }

                string message = Encoding.ASCII.GetString(result.Buffer);
                Console.WriteLine("Raw message from: {0} message: {1}", result.RemoteEndPoint, Encoding.ASCII.GetString(result.Buffer));
            });

            MantisDotNet.Network.NetworkPump.HookRawMessageSends((endpoint, data) =>
            {
                //string message = Encoding.ASCII.GetString(data);
                //Console.WriteLine("Raw message send to: {0} len: {1} message: {2}", endpoint, message.Length, message);
            });

            MantisDotNet.Network.NetworkPump.HookBreweryMessages((m) =>
            {
                //Console.WriteLine("Got {0} from {1} => {2}", m.MessageType, (m as Network.Protocol.IncomingMessage).SourceBreweryID, m.ToString());
            });

            Mantis.OnNewBrewery += (o, arg) =>
            {
                Console.WriteLine("New brewery discovered: {0}", arg.Brewery.ID);

                // arg.Brewery.OnNetworkMessage += (sender, bearg) => { Console.WriteLine("{0} Got a network message: {1}", bearg.Brewery.ID, bearg.Message.MessageType); };

                arg.Brewery.OnGoodbye          += (sender, bearg) => { Console.WriteLine("{0} said goodbye", bearg.Brewery.ID); };
                arg.Brewery.OnNetworksReceived += (sender, bearg) => { Console.WriteLine("{0} Got network list: {1} networks", bearg.Brewery.ID, bearg.Brewery.Networks.Count()); };
                arg.Brewery.OnPongReceived     += (sender, bearg) => { Console.WriteLine("{0} said Pong", bearg.Brewery.ID); };
                arg.Brewery.OnSettingsReceived += (sender, bearg) => { Console.WriteLine("{0} sent configuration: {1}", bearg.Brewery.ID, bearg.Brewery.Settings.ToString()); };
                arg.Brewery.OnStateReceived    += (sender, bearg) => { Console.WriteLine("{0} sent state: {1}", bearg.Brewery.ID, bearg.Brewery.RemoteState.ToString()); };
                arg.Brewery.OnStatusText       += (sender, bearg) => { Console.WriteLine("{0} said: {1}", bearg.Brewery.ID, bearg.Message); };
            };

            Mantis.OnBreweryLeave += (o, arg) =>
            {
                Console.WriteLine("Brewery leaving: {0}", arg.Brewery.ID);
            };

            Mantis.Discover();

            Console.ReadLine();

            foreach (Brewery brewery in Mantis.Breweries())
            {
                Console.WriteLine("Configuring {0}", brewery.ID);
                brewery.PushSettingsAsync(new Network.Protocol.SettingsData()
                {
                    BroadcastRate = 30000,
                    CustomBrewer  = brewerName,
                    LogoIndex     = 0,
                    Network       = network,
                    Password      = pass,
                }).Wait();
            }

            while (true)
            {
                Console.ReadLine();

                foreach (Brewery brewery in Mantis.Breweries())
                {
                    Console.WriteLine("Requesting refresh from {0}", brewery.ID);
                    brewery.RefreshStateAsync();
                    Console.WriteLine("Refresh request sent");
                }
            }
        }