Ejemplo n.º 1
0
 public TimeReporterTests(TimeReporter reporter)
     : base(new List <IReporter> {
     reporter
 })
 {
     this.reporter = reporter;
 }
        public void StartReporterThread()
        {
            var settings = new Settings(new SettingsReader("ActivityLogger.ini"));

            ActivityReport  = new ActivityReport();
            _activityLogger = ActivityLogger.Instance(ActivityReport, settings);

            var mouseClickLogger   = MouseClickLogger.Instance();
            var mouseClickReporter = MouseClickReporter.Instance(_activityLogger);

            mouseClickReporter.Subscribe(mouseClickLogger);

            var keyLogger   = KeyLogger.Instance();
            var keyReporter = KeyReporter.Instance(_activityLogger);

            keyReporter.Subscribe(keyLogger);

            Task.Factory.StartNew(() =>
            {
                var activityReporter = new ActivityReporter(_activityReceiver);
                activityReporter.Subscribe(_activityLogger);

                var mouseLogger   = new MouseLogger();
                var mouseReporter = new MouseReporter(_activityLogger);
                mouseReporter.Subscribe(mouseLogger);

                var processLogger   = new ProcessLogger();
                var processReporter = new ProcessReporter(_activityLogger);
                processReporter.Subscribe(processLogger);

                var timeLogger   = new TimeLogger();
                var timeReporter = new TimeReporter(_activityLogger);
                timeReporter.Subscribe(timeLogger);

                var activityTypeLogger   = new ActivityTypeLogger(settings);
                var activityTypeReporter = new ActivityTypeReporter(_activityLogger);
                activityTypeReporter.Subscribe(activityTypeLogger);

                while (true)
                {
                    Thread.Sleep(1000);

                    // KeyLogger & MouseClickLogger will log when keystrokes/clicks are
                    // recorded, so no need to tell it to log here.

                    mouseLogger.Log();
                    processLogger.Log();
                    timeLogger.Log();

                    activityTypeLogger.DetermineActivityType(
                        processReporter.ProcessReport, mouseReporter.MouseReport,
                        MouseClickReporter.Instance().MouseClickReport, KeyReporter.Instance().KeyReport);
                    activityTypeLogger.Log();

                    _activityLogger.Log();
                }
            });
        }
Ejemplo n.º 3
0
        public void A02_GetSumTaskDurationTest()
        {
            var testTaskPhaseSet = testTaskPhaseSetOne;
            var expectedDuration = new TimeSpan(1, 2, 50, 20);

            ITimeReporter reporter       = new TimeReporter();
            var           actualDuration = reporter.GetTaskPhasesDuration(testTaskPhaseSet);

            Assert.AreEqual(expectedDuration, actualDuration);
        }
Ejemplo n.º 4
0
        public void A04_GetSumTaskDurationByOneDateOnly()
        {
            var testTaskPhaseSet = testTaskPhaseSetOne;
            var expectedDuration = new TimeSpan(0, 10, 20);

            var reporter       = new TimeReporter();
            var actualDuration = reporter.GetTaskPhasesDuration(testTaskPhaseSet, new DateTime(2015, 10, 03), new DateTime(2015, 10, 04));

            Assert.AreEqual(expectedDuration, actualDuration);
        }
Ejemplo n.º 5
0
        public void A05_GetSumTaskDurationByFateRangePassingNull()
        {
            var testTaskPhaseSet = testTaskPhaseSetOne;
            var expectedDuration = new TimeSpan(1, 2, 50, 20);

            var reporter = new TimeReporter();

            // Pass null instead of fromDate > sum without filter
            var actualDuration = reporter.GetTaskPhasesDuration(testTaskPhaseSet, null, new DateTime(2015, 10, 04));

            Assert.AreEqual(expectedDuration, actualDuration);
            // Pass null instead of endDate > sum without filter
            actualDuration = reporter.GetTaskPhasesDuration(testTaskPhaseSet, new DateTime(2015, 10, 03), null);
            Assert.AreEqual(expectedDuration, actualDuration);
            // Pass null instead of fromDate and endDate > sum wihtout filter
            actualDuration = reporter.GetTaskPhasesDuration(testTaskPhaseSet, null, null);
            Assert.AreEqual(expectedDuration, actualDuration);
        }
Ejemplo n.º 6
0
        public void A01_GetTaskDurationTest()
        {
            Fixture fixture = new Fixture();

            var startDate        = new DateTime(2015, 10, 1, 12, 00, 00);
            var endDate          = new DateTime(2015, 10, 3, 13, 00, 00);
            var expectedDuration = new TimeSpan(2, 1, 0, 0);

            ITask testTask = new TaskModel
            {
                Id           = 1,
                Name         = fixture.Create <string>(),
                CreationDate = fixture.Create <DateTime>(),
                State        = TaskState.DONE,
                StartDate    = startDate,
                DoneDate     = endDate
            };

            ITimeReporter reporter       = new TimeReporter();
            var           actualDuration = reporter.GetTaskDuration(testTask);

            Assert.AreEqual(expectedDuration, actualDuration);
        }
Ejemplo n.º 7
0
        //
        // Main compilation method
        //
        public bool Compile(out AssemblyBuilder outAssembly, AppDomain domain, bool generateInMemory)
        {
            var settings = ctx.Settings;

            outAssembly = null;
            //
            // If we are an exe, require a source file for the entry point or
            // if there is nothing to put in the assembly, and we are not a library
            //
            if (settings.FirstSourceFile == null &&
                ((settings.Target == Target.Exe || settings.Target == Target.WinExe || settings.Target == Target.Module) ||
                 settings.Resources == null))
            {
                Report.Error(2008, "No files to compile were specified");
                return(false);
            }

            if (settings.Platform == Platform.AnyCPU32Preferred && (settings.Target == Target.Library || settings.Target == Target.Module))
            {
                Report.Error(4023, "Platform option `anycpu32bitpreferred' is valid only for executables");
                return(false);
            }

            TimeReporter tr = new TimeReporter(settings.Timestamps);

            ctx.TimeReporter = tr;
            tr.StartTotal();

            var module = new ModuleContainer(ctx);

            RootContext.ToplevelTypes = module;

            tr.Start(TimeReporter.TimerType.ParseTotal);
            Parse(module);
            tr.Stop(TimeReporter.TimerType.ParseTotal);

            if (Report.Errors > 0)
            {
                return(false);
            }

            if (settings.TokenizeOnly || settings.ParseOnly)
            {
                tr.StopTotal();
                tr.ShowStats();
                return(true);
            }

            var    output_file = settings.OutputFile;
            string output_file_name;

            /* if (output_file == null)
             * {
             *   var source_file = settings.FirstSourceFile;
             *
             *   if (source_file == null)
             *   {
             *       Report.Error(1562, "If no source files are specified you must specify the output file with -out:");
             *       return false;
             *   }
             *
             *   output_file_name = source_file.Name;
             *   int pos = output_file_name.LastIndexOf('.');
             *
             *   if (pos > 0)
             *       output_file_name = output_file_name.Substring(0, pos);
             *
             *   output_file_name += settings.TargetExt;
             *   output_file = output_file_name;
             * }
             * else
             * {*/
            output_file_name = Path.GetFileName(output_file);

            /*  if (string.IsNullOrEmpty(Path.GetFileNameWithoutExtension(output_file_name)) ||
             *    output_file_name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
             * {
             *    Report.Error(2021, "Output file name is not valid");
             *    return false;
             * }
             * }*/


            var assembly = new AssemblyDefinitionDynamic(module, output_file_name, output_file);

            module.SetDeclaringAssembly(assembly);

            var importer = new ReflectionImporter(module, ctx.BuiltinTypes);

            assembly.Importer = importer;

            var loader = new DynamicLoader(importer, ctx);

            loader.LoadReferences(module);

            if (!ctx.BuiltinTypes.CheckDefinitions(module))
            {
                return(false);
            }

            if (!assembly.Create(domain, AssemblyBuilderAccess.RunAndSave))
            {
                return(false);
            }

            module.CreateContainer();

            loader.LoadModules(assembly, module.GlobalRootNamespace);

            module.InitializePredefinedTypes();

            if (settings.GetResourceStrings != null)
            {
                module.LoadGetResourceStrings(settings.GetResourceStrings);
            }

            tr.Start(TimeReporter.TimerType.ModuleDefinitionTotal);
            module.Define();
            tr.Stop(TimeReporter.TimerType.ModuleDefinitionTotal);

            if (Report.Errors > 0)
            {
                return(false);
            }

            if (settings.DocumentationFile != null)
            {
                var doc = new DocumentationBuilder(module);
                doc.OutputDocComment(output_file, settings.DocumentationFile);
            }

            assembly.Resolve();

            if (Report.Errors > 0)
            {
                return(false);
            }


            tr.Start(TimeReporter.TimerType.EmitTotal);
            assembly.Emit();
            tr.Stop(TimeReporter.TimerType.EmitTotal);

            if (Report.Errors > 0)
            {
                return(false);
            }

            tr.Start(TimeReporter.TimerType.CloseTypes);
            module.CloseContainer();
            tr.Stop(TimeReporter.TimerType.CloseTypes);

            tr.Start(TimeReporter.TimerType.Resouces);
            if (!settings.WriteMetadataOnly)
            {
                assembly.EmbedResources();
            }
            tr.Stop(TimeReporter.TimerType.Resouces);

            if (Report.Errors > 0)
            {
                return(false);
            }


            if (!generateInMemory)
            {
                assembly.Save();
            }
            outAssembly = assembly.Builder;


            tr.StopTotal();
            tr.ShowStats();

            return(Report.Errors == 0);
        }
Ejemplo n.º 8
0
        public bool Compile(out AssemblyBuilder assembly, AppDomain domain, bool generateInMemory)
        {
            // Get the current settings
            CompilerSettings settings = context.Settings;

            // Set the result for quick exit
            assembly = null;

            // Check if any source files were supplied
            if (settings.FirstSourceFile == null && (((MCSTarget)settings.Target == MCSTarget.Exe || (MCSTarget)settings.Target == MCSTarget.WinExe || (MCSTarget)settings.Target == MCSTarget.Module) || settings.Resources == null))
            {
                Report.Error(2008, "No source files specified");
                return(false);
            }

            // Check for any invalid settings
            if (settings.Platform == Platform.AnyCPU32Preferred && ((MCSTarget)settings.Target == MCSTarget.Library || (MCSTarget)settings.Target == MCSTarget.Module))
            {
                Report.Error(4023, "The preferred platform '{0}' is only valid on executable outputs", Platform.AnyCPU32Preferred.ToString());
                return(false);
            }

            // Create the time reporter
            TimeReporter time = new TimeReporter(settings.Timestamps);

            context.TimeReporter = time;
            time.StartTotal();

            // Create the module
            ModuleContainer module = new ModuleContainer(context);

            RootContext.ToplevelTypes = module;

            // Start timing the parse stage
            time.Start(TimeReporter.TimerType.ParseTotal);
            {
                // Begin parse
                Parse(module);
            }
            time.Stop(TimeReporter.TimerType.ParseTotal);

            // Check for any errors
            if (Report.Errors > 0)
            {
                return(false);
            }

            // Check for partial compilation
            if (settings.TokenizeOnly == true || settings.ParseOnly == true)
            {
                time.StopTotal();
                time.ShowStats();
                return(true);
            }

            // Get the output file
            string output     = settings.OutputFile;
            string outputName = Path.GetFileName(output);

            // Create an assembly defenition
            AssemblyDefinitionDynamic defenition = new AssemblyDefinitionDynamic(module, outputName, output);

            module.SetDeclaringAssembly(defenition);

            ReflectionImporter importer = new ReflectionImporter(module, context.BuiltinTypes);

            defenition.Importer = importer;

            DynamicLoader loader = new DynamicLoader(importer, context);

            loader.LoadReferences(module);

            // Validate built in types
            if (context.BuiltinTypes.CheckDefinitions(module) == false)
            {
                return(false);
            }

            // Create the assmbly in domain
            if (defenition.Create(domain, AssemblyBuilderAccess.RunAndSave) == false)
            {
                return(false);
            }

            module.CreateContainer();
            loader.LoadModules(defenition, module.GlobalRootNamespace);
            module.InitializePredefinedTypes();

            // Check for any resource strings
            if (settings.GetResourceStrings != null)
            {
                module.LoadGetResourceStrings(settings.GetResourceStrings);
            }

            // Time the module defenition
            time.Start(TimeReporter.TimerType.ModuleDefinitionTotal);
            {
                try
                {
                    // Begin defining
                    module.Define();
                }
                catch
                {
                    // Failed to define module
                    return(false);
                }
            }
            time.Stop(TimeReporter.TimerType.ModuleDefinitionTotal);

            // Check for any errors
            if (Report.Errors > 0)
            {
                return(false);
            }

            // Check for documentation
            if (settings.DocumentationFile != null)
            {
                // Build the xml docs file
                DocumentationBuilder docs = new DocumentationBuilder(module);
                docs.OutputDocComment(output, settings.DocumentationFile);
            }

            defenition.Resolve();

            // Check for documentation errors
            if (Report.Errors > 0)
            {
                return(false);
            }

            // Finally emit the defenition into something useful
            time.Start(TimeReporter.TimerType.EmitTotal);
            {
                // Emit assembly
                defenition.Emit();
            }
            time.Stop(TimeReporter.TimerType.EmitTotal);

            // Check for any emit errors
            if (Report.Errors > 0)
            {
                return(false);
            }

            // Module cleanup
            time.Start(TimeReporter.TimerType.CloseTypes);
            {
                module.CloseContainer();
            }
            time.Stop(TimeReporter.TimerType.CloseTypes);

            // Check for embedded resources
            time.Start(TimeReporter.TimerType.Resouces);
            {
                if (settings.WriteMetadataOnly == false)
                {
                    defenition.EmbedResources();
                }
            }
            time.Stop(TimeReporter.TimerType.Resouces);

            // Embedd errors
            if (Report.Errors > 0)
            {
                return(false);
            }

            // Check for generate in memory
            if (generateInMemory == false)
            {
                defenition.Save();
            }

            // Store the result
            assembly = defenition.Builder;

            time.StopTotal();
            time.ShowStats();

            // Check for errors
            return(Report.Errors == 0);
        }