Beispiel #1
0
        /// <summary>
        /// Logging queue processing run function
        /// </summary>
        private async Task RunLogging(CancellationToken cancelToken)
        {
            try
            {
                while (!cancelToken.IsCancellationRequested)
                {
                    await NotifyAddedLog.WaitAsync(cancelToken);

                    List <LogEventArgs> allEvents = new List <LogEventArgs>();
                    while (!LogsQueue.IsEmpty)
                    {
                        if (LogsQueue.TryDequeue(out var nextLog))
                        {
                            allEvents.AddRange(GenerateLogsForLogEvent(nextLog));
                        }
                    }

                    LoggedEvents?.Invoke(this, allEvents);

                    LogToLog4(allEvents);
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine($"Exception in logging: {e}.");
            }
        }
Beispiel #2
0
        public void End_WithDisposedTimedScope_ShouldLogError()
        {
            FailOnErrors = false;

            Mock <ITimedScopeLogger>        timedScopeLoggerMock       = new Mock <ITimedScopeLogger>();
            Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>();
            Mock <ICallContextManager>      callContextManagerMock     = new Mock <ICallContextManager>();

            IMachineInformation     machineInformation     = new UnitTestMachineInformation();
            ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation);

            using (TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager))
            {
                Assert.True(scope.IsScopeActive, "Timer should be active.");

                scope.Dispose();

                Assert.False(scope.IsScopeActive, "Dispose should turn off timer.");

                scope.End();

                Assert.Equal(TraceErrors.Count(), 1);
                LoggedEvents.Clear();
            }
        }
Beispiel #3
0
        public void DefaultTimedScopeResult_LogsAsSystemError()
        {
            LoggedEvents.Clear();

            CorrelationData data = new CorrelationData();

            UnitTestTimedScopeLogger        unitTestTimedScopeLogger   = new UnitTestTimedScopeLogger();
            Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>();
            Mock <ICallContextManager>      callContextManagerMock     = new Mock <ICallContextManager>();

            IMachineInformation     machineInformation     = new UnitTestMachineInformation();
            ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation);

            using (TimedScope.Create(data, machineInformation, TestHooks.DefaultTimedScopeName, "description", unitTestTimedScopeLogger,
                                     replyEventConfiguratorMock.Object, timedScopeStackManager, default(TimedScopeResult)))
            {
            }

            TimedScopeLogEvent evt = unitTestTimedScopeLogger.SingleTimedScopeEvent(TestHooks.DefaultTimedScopeName);

            if (VerifyNotNullAndReturn(evt, "A scope event has been logged"))
            {
                Assert.Equal(TimedScopeResult.SystemError, evt.Result);
            }
        }
Beispiel #4
0
 public void OnGUI()
 {
     using (var scroll = new GUILayout.ScrollViewScope(scrollPosition))
     {
         scrollPosition = scroll.scrollPosition;
         LoggedEvents.DrawGUI();
     }
 }
 private void Clear(object sender, RoutedEventArgs e)
 {
     LoggedEvents.Clear();
     if (_mw == null)
     {
         return;
     }
     _mw.UpdateLoggerCounts();
 }
Beispiel #6
0
 public void ClearCollections()
 {
     LoggedEvents.Clear();
     LoggedMetricEvents.Clear();
     MetricEventsBegan.Clear();
     EventsBegan.Clear();
     MetricEventsEnded.Clear();
     EventsEnded.Clear();
 }
 private void ClearDebug(object sender, RoutedEventArgs e)
 {
     LoggedEvents.RemoveAll(x => x.Level == "DEBUG");
     if (_mw == null)
     {
         return;
     }
     _mw.UpdateLoggerCounts();
 }
 private void ClearDebug(object sender, RoutedEventArgs e)
 {
     LoggedEvents.RemoveAll(x => x.Level == DebugString || x.Level == VerboseString);
     if (_mw == null)
     {
         return;
     }
     _mw.UpdateLoggerCounts();
 }
        bool ILogProvider.CausedByPaste(Event dc)
        {
            int index = LoggedEvents.IndexOf(dc);

            if (index < 0)
            {
                return(false);
            }

            return(index + 1 < LoggedEvents.Count && LoggedEvents[index + 1] is PasteCommand);
        }
Beispiel #10
0
        public void Save <T>(T theEvent) where T : Event
        {
            var loggedEvent = new LoggedEvents()
            {
                Action      = theEvent.Name,
                AggregateId = theEvent.SagaId,
                Cargo       = new JavaScriptSerializer().Serialize(theEvent)
            };

            EventRepository.Store(loggedEvent);
        }
Beispiel #11
0
    int Execute(AuroraObject caller, NCSScript script, NCSContext context, int scriptVar, bool isConditional = false)
    {
        Debug.Log("Executing script: '" + script.scriptName + "'");
        LoggedEvents.Log("Run Script", script.scriptName);

        if (pauseOnScript)
        {
            Debug.Log("Pausing before script " + script.scriptName);
            Debug.Break();
        }

        // Add a new level of nesting to ObjectSelfStack and events
        events.Add(new List <AuroraEvent>());
        assignedCommands.Add(new List <AuroraCommand>());
        contexts.Push(context);
        scriptVars.Add(scriptVar);

        context.objectSelf = caller;

        int value = -1;

        //try
        //{
        if (isConditional)
        {
            value = script.RunConditional(context);
        }
        else
        {
            script.Run(context);
        }
        //}
        //catch (Exception e)
        //{
        //    CreateStackTrace();
        //    Debug.LogError(e.Message + "\n" + e.Source + "\n" + e.StackTrace + "\n " + e.InnerException);
        //}

        RunEvents();
        RunAssignedCommands();

        scriptVars.RemoveAt(scriptVars.Count - 1);
        contexts.Pop();
        assignedCommands.RemoveAt(assignedCommands.Count - 1);
        events.RemoveAt(events.Count - 1);

        LoggedEvents.Log("Finished Script", script.scriptName);

        return(value);
    }
        bool ILogProvider.CausedByAssist(DocumentChange dc)
        {
            Replace replace = dc as Replace;

            if (replace == null)
            {
                return(false);
            }

            int index = LoggedEvents.IndexOf(dc);

            if (index < 0)
            {
                return(false);
            }

            return(index > 0 && LoggedEvents[index - 1] is AssistCommand);
        }
Beispiel #13
0
        public void AddLoggingValue_WithNullKey_ShouldLogError()
        {
            FailOnErrors = false;

            Mock <ITimedScopeLogger>        timedScopeLoggerMock       = new Mock <ITimedScopeLogger>();
            Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>();
            Mock <ICallContextManager>      callContextManagerMock     = new Mock <ICallContextManager>();

            IMachineInformation     machineInformation     = new UnitTestMachineInformation();
            ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation);

            using (TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager))
            {
                scope.AddLoggingValue(null, "My Application.");

                Assert.Equal(TraceErrors.Count(), 1);
                LoggedEvents.Clear();
            }
        }
Beispiel #14
0
        public void GetUserGroups_TestGroupsDataSetIsNull_ReturnsEmptyListAndLogs()
        {
            FailOnErrors = false;

            using (IConfigurationDataSetLoader <TestGroupsDataSet> loader =
                       new UnitTestDataSetLoader <TestGroupsDataSet>(new LocalCache(), new UnitTestResourceMonitor()))
            {
                TestGroups testGroups = new TestGroups(loader);

                LoggedEvents.Clear();
                Assert.False(testGroups.GetUserGroups("*****@*****.**").Any(),
                             "Returns empty list if currently loaded TestGroupsDataSet is null");
                IEnumerable <LogEventArgs> events = LoggedEvents;

                Assert.NotNull(events);
                Assert.Equal(1, events.Count(e => e.Level == Levels.Error));
                Assert.Equal(1, events.Count(e => e.Level == Levels.Warning));
            }
        }
Beispiel #15
0
        /// <summary>
        /// Process the logging queue
        /// </summary>
        void ProcessLogs()
        {
            try
            {
                //  empty the queue
                List <LogEventArgs> allEvents = new List <LogEventArgs>();
                while (!LogsQueue.IsEmpty)
                {
                    if (LogsQueue.TryDequeue(out var nextLog))
                    {
                        allEvents.AddRange(GenerateLogsForLogEvent(nextLog));
                    }
                }

                //  send event
                LoggedEvents?.Invoke(this, allEvents);

                LogToLog4(allEvents);

                //  broadcast to listeners
                foreach (var nextLog in allEvents)
                {
                    if (nextLog.Level >= LogLevelDisplay)
                    {
                        var test      = new RemoteLogEventArgs(nextLog);
                        var test2     = test.Sender.ToString();
                        var sendBytes = Encoding.UTF8.GetBytes($"log?sender={NetworkUtilities.GetHostName()}&log={JsonConvert.SerializeObject(new RemoteLogEventArgs(nextLog))}\n");
                    }

                    LogBuffer.Enqueue(nextLog);
                }

                while (LogBuffer.Count > 333)
                {
                    LogBuffer.TryDequeue(out var discard);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine($"Exception in logging {e}");
            }
        }
Beispiel #16
0
        public void Start_DisposedTimedScope_ShoudLogError()
        {
            FailOnErrors = false;

            Mock <ITimedScopeLogger>        timedScopeLoggerMock       = new Mock <ITimedScopeLogger>();
            Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>();
            Mock <ICallContextManager>      callContextManagerMock     = new Mock <ICallContextManager>();

            IMachineInformation     machineInformation     = new UnitTestMachineInformation();
            ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation);

            TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager);

            scope.Dispose();

            scope.Start();

            Assert.Equal(TraceErrors.Count(), 1);
            LoggedEvents.Clear();
        }
        bool ILogProvider.CausedByAutoFormatting(Event dc)
        {
            int index = LoggedEvents.IndexOf(dc);

            if (index < 0)
            {
                return(false);
            }

            EclipseCommand cmd = LoggedEvents.GetRange(index + 1, LoggedEvents.Count - index - 1)
                                 .OfType <Command>().FirstOrDefault() as EclipseCommand;

            if (cmd != null)
            {
                if (cmd.CommandID == "org.eclipse.jdt.ui.edit.text.java.format")
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #18
0
        public void NotSettingTimedScopeResult_ChangesToSystemError()
        {
            LoggedEvents.Clear();

            UnitTestTimedScopeLogger        unitTestTimedScopeLogger   = new UnitTestTimedScopeLogger();
            Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>();
            Mock <ICallContextManager>      callContextManagerMock     = new Mock <ICallContextManager>();

            IMachineInformation     machineInformation     = new UnitTestMachineInformation();
            ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation);

            using (TimedScope scope = TestHooks.CreateDefaultTimedScope(unitTestTimedScopeLogger, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager))
            {
            }

            TimedScopeLogEvent evt = unitTestTimedScopeLogger.SingleTimedScopeEvent(TestHooks.DefaultTimedScopeName);

            if (VerifyNotNullAndReturn(evt, "A scope event has been logged"))
            {
                Assert.Equal(evt.Result, TimedScopeResult.SystemError);
            }
        }
        bool ILogProvider.CausedByInsertString(DocumentChange dc)
        {
            Insert insert = dc as Insert;

            if (insert == null)
            {
                return(false);
            }

            int index = LoggedEvents.IndexOf(dc);

            if (index < 0)
            {
                return(false);
            }

            if (index + 1 >= LoggedEvents.Count)
            {
                return(false);
            }

            return(LoggedEvents[index + 1] is InsertStringCommand);
        }
 public void LogEvent(string eventName, string functionName = null)
 {
     LoggedEvents.Add(MetricsEventManager.GetAggregateKey(eventName, functionName));
 }
 public void Store(LoggedEvents eventToLog)
 {
     eventToLog.TimeStamp = DateTime.Now;
     _db.LoggedEvents.Add(eventToLog);
     _db.SaveChanges();
 }
Beispiel #22
0
        // Runs an engine function (defined in nwscript.nss)
        public override void Run(NCSContext context)
        {
            context.Log("Calling " + args[1]);

            // Get the function definition for the action
            int method_idx = int.Parse(args[1]);

            string method_name = NWScript_Actions.ACTIONS[method_idx];

            UnityEngine.Debug.Log("Calling action " + method_name);

            MethodInfo m = nwscript.GetMethod(method_name);

            UnityEngine.Debug.Log("Action " + method_name + " has MethodInfo " + m);
            // MethodInfo[] methods = typeof(AuroraEngine.NWScript).GetMethods(BindingFlags.Public | BindingFlags.Static);
            // UnityEngine.Debug.Log("Calling method " + method_idx + " of " + methods.Length);
            // MethodInfo m = methods[method_idx];
            // UnityEngine.Debug.Log("Calling method no " + method_idx + ": " + m.Name);

            if (m == null)
            {
                Debug.LogError("Warning: could not find method " + args[1]);
            }

            int paramCount = int.Parse(args[2]);

            object[] parameters = new object[m.GetParameters().Length];

            context.Log("Method " + m.Name + " has " +
                        m.GetParameters().Length + " parameter(s)" +
                        " and providing " + paramCount
                        );

            ParameterInfo[] paramInfo = m.GetParameters();
            for (int i = 0; i < paramCount; i++)
            {
                ParameterInfo p = paramInfo[i];

                if (p.ParameterType == typeof(NCSContext))
                {
                    context.Log("Getting parameter from store state stack");
                    parameters[i] = context.GetState();
                }
                else if (p.ParameterType == typeof(AuroraVector))
                {
                    context.Log("Getting vector from stack");

                    context.Log(context.stack.Last());
                    float x = (float)context.Pop();
                    context.Log(context.stack.Last());
                    float y = (float)context.Pop();
                    context.Log(context.stack.Last());
                    float z = (float)context.Pop();

                    parameters[i] = new AuroraVector(x, y, z);
                }
                else
                {
                    context.Log("Getting parameter from stack");
                    parameters[i] = context.Pop();
                }
                context.Log("Parameter " + i + ": " + parameters[i]);
            }

            // Add any optional parameters if we need to
            for (int i = paramCount; i < m.GetParameters().Length; i++)
            {
                parameters[i] = Type.Missing;
            }

            // Generate the function call signature
            string signature = args[1] + "(";

            for (int i = 0; i < parameters.Length; i++)
            {
                signature += parameters[i];
                if (i != parameters.Length - 1)
                {
                    signature += ",";
                }
            }

            signature += ")";

            object return_value;

            try
            {
                return_value = m.Invoke(null, parameters);
            }
            catch (Exception e)
            {
                LoggedEvents.Log("  Action", "FAILED: " + signature);
                throw e;
            }

            LoggedEvents.Log("  Action", signature + " = " + return_value);

            context.Log(m.Name + " returned with value " + return_value);

            if (m.ReturnType == typeof(void))
            {
            }
            else if (m.ReturnType == typeof(AuroraVector))
            {
                AuroraVector vec = (AuroraVector)return_value;
                context.Push(vec.z);
                context.Push(vec.y);
                context.Push(vec.x);
            }
            else
            {
                context.Push(return_value);
            }
        }