Пример #1
0
        static void Main(string[] args)
        {
            WspEventPublish eventPush = new WspEventPublish();

            LogEntry e1 = new LogEntry();
            LogEntry e2;

            byte[] eSerialized = e1.Serialize();

            e2 = new LogEntry(eSerialized);

            eventPush.OnNext(new WspEvent(e1.EventType, null, eSerialized));
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();

            pubEvent            = new PublishEvent();
            pubEvent.InstanceId = instanceId;

            subEvent = new SubscribeEvent();

            eventPush = new WspEventPublish();

            stopPubSubButton.Checked = true;
            stopPubSubButton.Select();
        }
Пример #3
0
        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;
        }
Пример #4
0
            public override void Start()
            {
                WspEventPublish eventPush = null;
                QueueElement    element;
                QueueElement    newElement = new QueueElement();
                bool            elementRetrieved;

                PubSubManager.ReturnCode rc;

                try
                {
                    try
                    {
                        Manager.ThreadInitialize.Release();
                    }
                    catch
                    {
                        // If the thread is restarted, this could throw an exception but just ignore
                    }

                    while (true)
                    {
                        try
                        {
                            if (hubRole == true)
                            {
                                eventPush = new WspEventPublish((uint)configSettings.HubRoleSettings.ThisRouter.Timeout);
                            }
                            else
                            {
                                eventPush = new WspEventPublish((uint)configSettings.NodeRoleSettings.ParentRouter.Timeout);
                            }


                            break;
                        }
                        catch (SharedQueueException)
                        {
                            Thread.Sleep(10000);
                        }
                    }

                    while (true)
                    {
                        try
                        {
                            element = rePublisherQueue.Dequeue();

                            if (element == default(QueueElement))
                            {
                                element          = newElement;
                                elementRetrieved = false;
                            }
                            else
                            {
                                elementRetrieved = true;
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            element          = newElement;
                            elementRetrieved = false;
                        }

                        while (elementRetrieved == true)
                        {
                            try
                            {
                                eventPush.OnNext(element.WspEvent, out rc);

                                if (rc == PubSubManager.ReturnCode.Success)
                                {
                                    break;
                                }
                                else
                                {
                                    Thread.Sleep(1);
                                }
                            }
                            catch
                            {
                                rePublisherQueue.Enqueue(element);
                            }
                        }
                    }
                }

                catch (ThreadAbortException)
                {
                    // Another thread has signalled that this worker
                    // thread must terminate.  Typically, this occurs when
                    // the main service thread receives a service stop
                    // command.
                }

                catch (Exception e)
                {
                    EventLog.WriteEntry("WspEventRouter", e.ToString(), EventLogEntryType.Warning);
                }
            }
Пример #5
0
            public void SendEvents()
            {
                ReturnCode rc;

                try
                {
                    eventPush = new WspEventPublish();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }

                WebpageEvent localEvent = new WebpageEvent();

                localEvent.ActiveXControls   = true;
                localEvent.AnonymousId       = Guid.NewGuid();
                localEvent.Aol               = true;
                localEvent.BackgroundSounds  = true;
                localEvent.Beta              = false;
                localEvent.Browser           = @"IE 6.0";
                localEvent.Cdf               = false;
                localEvent.ClrVersion        = new Version(@"1.2.3.4");
                localEvent.Cookies           = true;
                localEvent.Crawler           = false;
                localEvent.EcmaScriptVersion = new Version(@"1.2.3.4");
                localEvent.Ext               = string.Empty;
                localEvent.Frames            = true;
                localEvent.HostDomain        = @"microsoft";
                localEvent.JavaApplets       = true;
                localEvent.LogicalUri        = new Uri(@"http://www.microsoft.com");
                localEvent.MajorVersion      = 1;
                localEvent.MinorVersion      = 2.3;
                localEvent.MSDomVersion      = new Version(@"1.2.3.4");
                localEvent.Platform          = @"Windows XP";
                localEvent.RequestType       = @"Page Request";
                localEvent.Source            = @"source";
                localEvent.SourceServer      = @"sourceserver";
                localEvent.StatusCode        = 0;
                localEvent.SubDirectory      = @"eventcollection";
                localEvent.Tables            = true;
                localEvent.Type              = @"type";
                localEvent.UriHash           = new System.Security.Cryptography.MD5CryptoServiceProvider();
                localEvent.UriHash.Initialize();
                localEvent.UriQuery          = new Uri(@"http://www.microsoft.com/test");
                localEvent.UriStem           = new Uri(@"http://www.microsoft.com");
                localEvent.UrlReferrer       = new Uri(@"http://www.microsoft.com");
                localEvent.UrlReferrerDomain = @"microsoft.com";
                localEvent.UserAgent         = @"useragent kasgfig;lkartpoiwhtlnvoaing;oakng;aih;akng;lna;kn";
                localEvent.UserHostAddress   = new IPAddress(0x2414188f);
                localEvent.VBScript          = true;
                localEvent.Version           = @"1.2.3.4";
                localEvent.VirtualRoot       = @"http://www.microsoft.com/test";
                localEvent.W3CDomVersion     = new Version(@"1.2.3.4");
                localEvent.Win16             = false;
                localEvent.Win32             = true;

                Dictionary <byte, string> pb = new Dictionary <byte, string>();

                MD5 md5Hasher = MD5.Create();

                Random rdm = new Random(10000);

                try
                {
                    for (int i = 0; i < numIterations; i++)
                    {
                        byte[] body     = localEvent.Serialize();
                        byte[] bodyHash = md5Hasher.ComputeHash(body);

                        pb[100] = "test" + rdm.Next(10000).ToString();
                        pb[101] = Convert.ToBase64String(bodyHash);

                        WspEvent wspEvent = new WspEvent(localEvent.EventType, pb, body);
                        eventPush.OnNext(wspEvent, out rc);

                        // Verifying that serialization/deserialization work
                        byte[]       serializedEvent = wspEvent.SerializedEvent;
                        WspEvent     dupEvent        = new WspEvent(serializedEvent);
                        WebpageEvent dupWebPageEvent = new WebpageEvent(dupEvent.Body);

                        if (rc != ReturnCode.Success)
                        {
                            Thread.Sleep(0);
                            Console.WriteLine("Item: " + i.ToString() + @"    Return Code: " + rc.ToString());
                            i--;
                        }
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine(@"Exception: " + e.Message);
                }

                DateTime stopTime  = DateTime.Now;
                TimeSpan totalTime = new TimeSpan(stopTime.Ticks - startTime.Ticks);

                Console.WriteLine("Total time was: " + totalTime.TotalSeconds.ToString() + " seconds");
                Console.WriteLine((numIterations / totalTime.TotalSeconds).ToString() + " events per second");

                localEvent.UriHash.Clear();
                localEvent.UriHash = null;
            }
Пример #6
0
            public override void Start()
            {
                bool             elementRetrieved;
                WspBuffer        serializedEvent;
                long             currentTick;
                long             configFileTick;
                long             localConfigFileTick;
                PersistEventInfo eventInfo;
                string           eventFieldTerminator = @",";
                StreamWriter     eventStream;

                PubSubManager.ReturnCode rc;

                string propName;
                byte   propType;
                object propValue;

                try
                {
                    Manager.ThreadInitialize.Release();
                }
                catch
                {
                    // If the thread is restarted, this could throw an exception but just ignore
                }

                try
                {
                    eventPush = new WspEventPublish();

                    while (true)
                    {
                        currentTick = DateTime.UtcNow.Ticks;

                        if (currentTick > nextConfigFileCheckTick)
                        {
                            nextConfigFileCheckTick = currentTick + 300000000;

                            configFileTick      = Configurator.GetConfigFileTick();
                            localConfigFileTick = Configurator.GetLocalConfigFileTick();

                            if (configFileTick != lastConfigFileTick || localConfigFileTick != lastLocalConfigFileTick)
                            {
                                nextCopyTick = 0;

                                foreach (PersistEventInfo eInfo in persistEvents.Values)
                                {
                                    eInfo.Loaded = false;
                                }

                                lock (configFileLock)
                                {
                                    Configurator.LoadLogSettings();
                                    Configurator.LoadLocalLogSettings();
                                }

                                foreach (PersistEventInfo eInfo in persistEvents.Values)
                                {
                                    if (eInfo.Loaded == false)
                                    {
                                        eInfo.InUse        = false;
                                        eInfo.NextCopyTick = currentTick - 1;

                                        eInfo.subscription.Subscribe = false;

                                        WspEvent wspEvent = new WspEvent(Subscription.SubscriptionEvent, null, eInfo.subscription.Serialize());
                                        eventPush.OnNext(wspEvent, out rc);
                                    }
                                }

                                lastConfigFileTick      = configFileTick;
                                lastLocalConfigFileTick = localConfigFileTick;
                            }

                            foreach (PersistEventInfo eInfo in persistEvents.Values)
                            {
                                if (eInfo.InUse == true)
                                {
                                    eInfo.subscription.Subscribe = true;

                                    WspEvent wspEvent = new WspEvent(Subscription.SubscriptionEvent, null, eInfo.subscription.Serialize());
                                    eventPush.OnNext(wspEvent, out rc);
                                }
                            }
                        }

                        try
                        {
                            element = persisterQueue.Dequeue();

                            if (element == default(QueueElement))
                            {
                                elementRetrieved = false;
                            }
                            else
                            {
                                elementRetrieved = true;
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            elementRetrieved = false;
                        }

                        currentTick = DateTime.UtcNow.Ticks;

                        if (currentTick > nextCopyTick)
                        {
                            nextCopyTick = long.MaxValue;

                            foreach (PersistEventInfo persistEventInfo in persistEvents.Values)
                            {
                                if (currentTick > persistEventInfo.NextCopyTick)
                                {
                                    persistEventInfo.NextCopyTick = currentTick + persistEventInfo.CopyIntervalTicks;

                                    if (persistEventInfo.OutStream != null)
                                    {
                                        persistEventInfo.OutStream.Close();

                                        SendPersistEvent(PersistFileState.Close, persistEventInfo, persistEventInfo.OutFileName);

                                        persistEventInfo.OutStream = null;
                                    }

                                    if (persistEventInfo.InUse == true)
                                    {
                                        persistEventInfo.OutFileName = persistEventInfo.TempFileDirectory + fileNameBase + DateTime.UtcNow.ToString("u").Replace(":", "-") + fileNameSuffix;

                                        if (File.Exists(persistEventInfo.OutFileName) == true)
                                        {
                                            persistEventInfo.OutStream = new StreamWriter(File.Open(persistEventInfo.OutFileName, FileMode.Append, FileAccess.Write, FileShare.None), Encoding.Unicode);
                                        }
                                        else
                                        {
                                            persistEventInfo.OutStream = new StreamWriter(File.Open(persistEventInfo.OutFileName, FileMode.Create, FileAccess.Write, FileShare.None), Encoding.Unicode);
                                        }

                                        SendPersistEvent(PersistFileState.Open, persistEventInfo, persistEventInfo.OutFileName);
                                    }
                                }

                                if (persistEventInfo.NextCopyTick < nextCopyTick)
                                {
                                    nextCopyTick = persistEventInfo.NextCopyTick;
                                }
                            }

                            if (copyInProcess == false)
                            {
                                Thread copyThread = new Thread(new ThreadStart(CopyFile));

                                copyInProcess = true;

                                copyThread.Start();
                            }
                        }

                        if (elementRetrieved == true)
                        {
                            eventInfo = persistEvents[element.WspEvent.EventType];

                            if (eventInfo.InUse == true)
                            {
                                eventFieldTerminator = eventInfo.FieldTerminator.ToString();

                                eventStream = eventInfo.OutStream;

                                if (eventStream == null)
                                {
                                    eventInfo.NextCopyTick = DateTime.UtcNow.Ticks + eventInfo.CopyIntervalTicks;

                                    eventInfo.OutFileName = eventInfo.TempFileDirectory + fileNameBase + DateTime.UtcNow.ToString("u").Replace(":", "-") + fileNameSuffix;

                                    if (File.Exists(eventInfo.OutFileName) == true)
                                    {
                                        eventInfo.OutStream = new StreamWriter(File.Open(eventInfo.OutFileName, FileMode.Append, FileAccess.Write, FileShare.None), Encoding.Unicode);
                                    }
                                    else
                                    {
                                        eventInfo.OutStream = new StreamWriter(File.Open(eventInfo.OutFileName, FileMode.Create, FileAccess.Write, FileShare.None), Encoding.Unicode);
                                    }

                                    eventStream = eventInfo.OutStream;

                                    if (eventInfo.NextCopyTick < nextCopyTick)
                                    {
                                        nextCopyTick = eventInfo.NextCopyTick;
                                    }

                                    SendPersistEvent(PersistFileState.Open, eventInfo, eventInfo.OutFileName);
                                }

                                eventStream.Write(eventInfo.BeginObjectSeparator);

                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write("OriginatingRouterName");
                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write(eventInfo.KeyValueSeparator.ToString());
                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write(CleanseString(element.WspEvent.OriginatingRouterName, eventInfo));
                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write(eventInfo.FieldTerminator.ToString());

                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write("InRouterName");
                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write(eventInfo.KeyValueSeparator.ToString());
                                eventStream.Write(eventInfo.StringDelimiter.ToString());
                                eventStream.Write(CleanseString(element.WspEvent.InRouterName, eventInfo));
                                eventStream.Write(eventInfo.StringDelimiter.ToString());

                                serializedEvent = new WspBuffer(element.WspEvent.Body);

                                while (serializedEvent.Position < serializedEvent.Size)
                                {
                                    if (serializedEvent.Read(out propName) == false)
                                    {
                                        throw new EventDeserializationException("Error reading PropertyName from buffer");
                                    }

                                    eventStream.Write(eventInfo.FieldTerminator.ToString());
                                    eventStream.Write(eventInfo.StringDelimiter.ToString());
                                    eventStream.Write(CleanseString(propName, eventInfo));
                                    eventStream.Write(eventInfo.StringDelimiter.ToString());
                                    eventStream.Write(eventInfo.KeyValueSeparator.ToString());

                                    if (serializedEvent.Read(out propType) == false)
                                    {
                                        throw new EventDeserializationException("Error reading PropertyType from buffer");
                                    }

                                    switch (propType)
                                    {
                                    case (byte)PropertyType.StringDictionary:

                                        WriteStringDictionary(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.ObjectDictionary:

                                        WriteObjectDictionary(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.StringList:
                                        WriteStringList(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.ObjectList:
                                        WriteObjectList(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.ByteArray:
                                        WriteByteArray(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.CharArray:
                                        WriteCharArray(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.DateTime:
                                        WriteDateTime(eventStream, serializedEvent, eventInfo);
                                        break;

                                    case (byte)PropertyType.Int64:
                                        if (string.Compare(propName, "EventTime", true) == 0)
                                        {
                                            WriteDateTime(eventStream, serializedEvent, eventInfo);
                                        }
                                        else
                                        {
                                            if (serializedEvent.Read((PropertyType)propType, out propValue) == false)
                                            {
                                                throw new EventDeserializationException("Error reading PropertyValue from buffer");
                                            }

                                            eventStream.Write(eventInfo.StringDelimiter.ToString());
                                            eventStream.Write(CleanseString(propValue.ToString(), eventInfo));
                                            eventStream.Write(eventInfo.StringDelimiter.ToString());
                                        }
                                        break;

                                    default:
                                        if (serializedEvent.Read((PropertyType)propType, out propValue) == false)
                                        {
                                            throw new EventDeserializationException("Error reading PropertyValue from buffer");
                                        }

                                        eventStream.Write(eventInfo.StringDelimiter.ToString());
                                        eventStream.Write(CleanseString(propValue.ToString(), eventInfo));
                                        eventStream.Write(eventInfo.StringDelimiter.ToString());
                                        break;
                                    }
                                }

                                eventStream.Write(eventInfo.EndObjectSeparator);

                                eventStream.Write(eventInfo.RowTerminator);

                                if (eventStream.BaseStream.Length >= eventInfo.MaxFileSize)
                                {
                                    eventInfo.NextCopyTick = currentTick - 1;
                                    nextCopyTick           = eventInfo.NextCopyTick;
                                }
                            }
                        }
                    }
                }

                catch (IOException e)
                {
                    EventLog.WriteEntry("WspEventRouter", e.ToString(), EventLogEntryType.Error);
                    Thread.Sleep(60000);
                }

                catch (ThreadAbortException)
                {
                    // Another thread has signalled that this worker
                    // thread must terminate.  Typically, this occurs when
                    // the main service thread receives a service stop
                    // command.
                }

                catch (Exception e)
                {
                    EventLog.WriteEntry("WspEventRouter", e.ToString(), EventLogEntryType.Error);
                    throw e;
                }
            }