예제 #1
0
        public void StartPublish()
        {
            startTime = DateTime.Now;
            counter   = 0;

            timer1.Start();

            pubEvent.EventNum = 0;

            pubEventType         = pubEvent.InstanceId;
            pubObservable        = new WspEventObservable(pubEventType, false);
            pubObservableDispose = pubObservable.Subscribe(this);

            while (true)
            {
                try
                {
                    eventPush.OnNext(new WspEvent(pubEvent.EventType, null, pubEvent.Serialize()));

                    break;
                }
                catch
                {
                    Thread.Sleep(2);
                }
            }
        }
예제 #2
0
        public void StartSubscribe()
        {
            startTime = DateTime.Now;
            counter   = 0;

            timer1.Start();

            subEventType         = pubEvent.EventType;
            subObservable        = new WspEventObservable(subEventType, false);
            subObservableDispose = subObservable.Subscribe(this);
        }
예제 #3
0
파일: Program.cs 프로젝트: epowers/pubsub
        internal void Run()
        {
            int          input;
            char         ch;
            WebpageEvent webPageEvent = new WebpageEvent();
            IDisposable  eventDispose = null;

            try
            {
                sub = new WspEventObservable(webPageEvent.EventType, false, Program.filterPattern, null, null);

                eventDispose = sub.Subscribe(this);

                while (true)
                {
                    input = Console.Read();

                    ch = Convert.ToChar(input);

                    if (ch == 'q' || ch == 'Q')
                    {
                        break;
                    }
                }
            }
            catch
            {
                //intentionally left blank
            }
            finally
            {
                if (eventDispose != null)
                {
                    eventDispose.Dispose();
                }

                Thread.CurrentThread.Abort();
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: epowers/pubsub
        static void Main(string[] args)
        {
            IDisposable responseDispose = null;

            bool showHelp = false;

            char[] splitChar = { '=' };

            CommandRequest commandRequest = new CommandRequest();

            commandRequest.EventType          = new Guid("C8EDEB22-7E4A-4441-B7B4-419DDB856321");
            commandRequest.EventIdForResponse = Guid.NewGuid();
            commandRequest.CorrelationID      = Guid.NewGuid();
            commandRequest.Command            = string.Empty;

            if (args.Length == 0)
            {
                showHelp = true;
            }
            else
            {
                commandRequest.Command = args[0].ToLower();

                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i].StartsWith("/") == true)
                    {
                        string option = args[i].Split(splitChar)[0].ToLower();

                        switch (option)
                        {
                        case "/eventtype":
                            try
                            {
                                commandRequest.EventType = new Guid(args[i].Split(splitChar)[1]);
                            }
                            catch
                            {
                                ConsoleColor currColor = Console.ForegroundColor;
                                Console.ForegroundColor = ConsoleColor.Red;

                                Console.WriteLine("ERROR: Bad 'EventType' parameter");

                                Console.ForegroundColor = currColor;

                                return;
                            }

                            break;

                        case "/target":
                            try
                            {
                                commandRequest.TargetMachineFilter = args[i].Split(splitChar)[1];
                            }
                            catch
                            {
                                ConsoleColor currColor = Console.ForegroundColor;
                                Console.ForegroundColor = ConsoleColor.Red;

                                Console.WriteLine("ERROR: Bad 'Target' parameter");

                                Console.ForegroundColor = currColor;

                                return;
                            }

                            break;

                        case "/role":
                            try
                            {
                                commandRequest.TargetRoleFilter = args[i].Split(splitChar)[1];
                            }
                            catch
                            {
                                ConsoleColor currColor = Console.ForegroundColor;
                                Console.ForegroundColor = ConsoleColor.Red;

                                Console.WriteLine("ERROR: Bad 'Role' parameter");

                                Console.ForegroundColor = currColor;

                                return;
                            }

                            break;

                        default:
                            showHelp = true;

                            break;
                        }
                    }
                    else
                    {
                        commandRequest.Arguments.Add(args[i]);
                    }
                }
            }


            try
            {
                responseObservable = new WspEventObservable(commandRequest.EventIdForResponse, false);
            }
            catch (PubSubQueueDoesNotExistException)
            {
                ConsoleColor currColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine("Error: the WspEventRouter service is not running");

                Console.ForegroundColor = currColor;

                return;
            }

            responseDispose = responseObservable.Subscribe(new ResponseObservable());

            WspEventPublish eventPush = new WspEventPublish();

            switch (commandRequest.Command)
            {
            case "wsp_processcommands":
                if (commandRequest.Arguments.Count == 0)
                {
                    commandRequest.Arguments.Add("true");
                }
                else
                {
                    if (commandRequest.Arguments.Count > 1 ||
                        (string.Compare((string)commandRequest.Arguments[0], "true", true) != 0 &&
                         string.Compare((string)commandRequest.Arguments[0], "false", true) != 0))
                    {
                        ConsoleColor currColor = Console.ForegroundColor;
                        Console.ForegroundColor = ConsoleColor.Red;

                        Console.WriteLine("ERROR: Invalid arguments");

                        Console.ForegroundColor = currColor;

                        responseDispose.Dispose();

                        return;
                    }
                }

                break;

            case "wsp_getdeviceinfo":
            case "wsp_getprocessinfo":
            case "wsp_getserviceinfo":
            case "wsp_getnetworkinfo":
            case "wsp_getdriveinfo":
            case "wsp_geteventloginfo":
            case "wsp_getwspassemblyinfo":
            case "wsp_getsysteminfo":
                if (commandRequest.Arguments.Count > 0)
                {
                    ConsoleColor currColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("ERROR: Invalid arguments");

                    Console.ForegroundColor = currColor;

                    responseDispose.Dispose();

                    return;
                }

                break;

            case "wsp_getperformancecounters":
            case "wsp_getfileversioninfo":
            case "wsp_getregistrykeys":
                if (commandRequest.Arguments.Count == 0)
                {
                    ConsoleColor currColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("ERROR: Argument list is empty");

                    Console.ForegroundColor = currColor;

                    responseDispose.Dispose();

                    return;
                }

                break;

            default:
                showHelp = true;
                break;
            }

            if (showHelp == true)
            {
                ConsoleColor currColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;

                Console.Write("\nCommand Format:\n\n");
                Console.Write("\tWspCommand <cmd> [argsIn] [/target=<regex filter>] [/role=<Wsp Role>] [/eventtype=<Guid>]\n\n\n");
                Console.Write("\tCommands:\n\n");
                Console.Write("\t\tWsp_GetDeviceInfo\n");
                Console.Write("\t\tWsp_GetDriveInfo\n");
                Console.Write("\t\tWsp_GetEventLogInfo\n");
                Console.Write("\t\tWsp_GetFileVersionInfo <argsIn>\n");
                Console.Write("\t\tWsp_GetNetworkInfo\n");
                Console.Write("\t\tWsp_GetPerformanceCounters <argsIn>\n");
                Console.Write("\t\tWsp_GetProcessInfo\n");
                Console.Write("\t\tWsp_GetRegistryKeys <argsIn>\n");
                Console.Write("\t\tWsp_GetServiceInfo\n");
                Console.Write("\t\tWsp_GetSystemInfo\n");
                Console.Write("\t\tWsp_GetWspAssemblyInfo\n");

                Console.ForegroundColor = currColor;

                responseDispose.Dispose();

                return;
            }

            eventPush.OnNext(new WspEvent(commandRequest.EventType, null, commandRequest.Serialize()));

            Console.WriteLine();

            ConsoleColor c = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Red;

            Console.WriteLine("---- Press any key to end ----");

            Console.ForegroundColor = c;

            Console.ReadKey();

            responseDispose.Dispose();

            return;
        }