示例#1
0
        private void Initialize()
        {
            if (generatorFolder == null)
            {
                throw new InvalidOperationException("The RemoteAppDomainTestGeneratorFactory has to be configured with the Setup() method before initialization.");
            }

            AppDomainSetup appDomainSetup = new AppDomainSetup {
                ApplicationBase = generatorFolder
            };

            appDomainSetup.ShadowCopyFiles = "true";
            appDomain = AppDomain.CreateDomain("AppDomainForTestGeneration", null, appDomainSetup);

            var testGeneratorFactoryTypeFullName = typeof(TestGeneratorFactory).FullName;

            Debug.Assert(testGeneratorFactoryTypeFullName != null);

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

            var generatorFactoryObject = appDomain.CreateInstanceAndUnwrap(remoteGeneratorAssemblyName, testGeneratorFactoryTypeFullName);

            remoteTestGeneratorFactory = generatorFactoryObject as ITestGeneratorFactory;

            if (remoteTestGeneratorFactory == null)
            {
                throw new InvalidOperationException("Could not load test generator factory.");
            }

            usageCounter = new UsageCounter(LoseReferences);
            tracer.Trace("AppDomain for generator created", "RemoteAppDomainTestGeneratorFactory");
        }
示例#2
0
 public void TestInstanceName()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
         Assert.AreEqual("some global name", counter.Name);
     using (UsageCounter counter = new UsageCounter(@"{0}\Item-{1}", "Global", 1))
         Assert.AreEqual(@"Global\Item-1", counter.Name);
 }
        public void TestSingleCounter()
        {
            bool bcalled;
            ThreadStart call = delegate() { bcalled = true; };

            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
                bcalled = false;
                counter.Increment(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Increment(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(2, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }
示例#4
0
        public void TestSingleCounter()
        {
            bool        bcalled;
            ThreadStart call = delegate() { bcalled = true; };

            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
                bcalled = false;
                counter.Increment(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Increment(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(2, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }
示例#5
0
        private static bool IsValidCounter(UsageCounter uc)
        {
            var dtNow       = DateTime.Now;
            var counterDate = new DateTime(uc.Year, uc.Month, uc.Day);

            return(counterDate.AddDays(30) >= dtNow);
        }
示例#6
0
        private static void ReportManually()
        {
            Console.WriteLine("You can also call `SmartAssembly.ReportUsage.UsageCounter.ReportUsage` method to manually report usage of a feature.");
            UsageCounter.ReportUsage("manually reported feature");

            Console.WriteLine("You can also call `SmartAssembly.ReportUsage.PlatformData.*` methods to report additional information about the user's machine.");
            PlatformData.ReportNumberOfMonitors();
        }
 public InvitationRevokedEvent(InvitationId invitationId, GroupId groupId, InvitationCode invitationCode, ExpirationTime expirationTime, UsageCounter usageCounter)
 {
     InvitationId   = invitationId;
     GroupId        = groupId;
     InvitationCode = invitationCode;
     ExpirationTime = expirationTime;
     UsageCounter   = usageCounter;
 }
示例#8
0
 public void TestTooManyDecrements()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         counter.Increment();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
         counter.Decrement();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
         counter.Decrement();
     }
 }
 public void TestTooManyDecrements()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         counter.Increment();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
         counter.Decrement();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
         counter.Decrement();
     }
 }
示例#10
0
    public static void Main(string[] args)
    {
        Type    t  = Type.GetType(args[0], true);
        dynamic g  = Activator.CreateInstance(t);
        dynamic cg = new UsageCounter(g);

        Console.WriteLine(cg.Meet("Jack"));         //duck-typing, compiler creates a DLR call site
        Console.WriteLine(cg.Leave("Jack"));
        //Console.WriteLine(cg.Kill("Jack"));
        Console.WriteLine("Number of usage = {0}", cg.CountUsage());
    }
示例#11
0
        public void TestMultipleCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
            }

            //Someone has to hold onto at least one counter, or all will be cleared
            using (UsageCounter counter = new UsageCounter("some global name"))
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
        }
示例#12
0
        public void TestEventArguments()
        {
            Value val = new Value();

            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.Increment(delegate(Value v) { v.Number++; }, val);
                counter.Increment(delegate(Value v) { v.Number++; }, val);
                counter.Decrement(delegate(Value v) { v.Number++; }, val);
                counter.Decrement(delegate(Value v) { v.Number++; }, val);
                Assert.AreEqual(2, val.Number);
            }
        }
示例#13
0
        public void TestMultipleNestedCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                using (UsageCounter counter2 = new UsageCounter("some global name"))
                    counter2.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                using (UsageCounter counter2 = new UsageCounter("some global name"))
                {
                    counter2.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
                    counter2.Decrement();
                }
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }
示例#14
0
 public void TestInstanceCount()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         Assert.AreEqual(0, counter.InstanceCount);
         counter.Increment();
         Assert.AreEqual(1, counter.InstanceCount);
         counter.Increment();
         Assert.AreEqual(2, counter.InstanceCount);
         using (UsageCounter copy = new UsageCounter("some global name"))
             Assert.AreEqual(0, copy.InstanceCount);
         counter.Decrement();
         Assert.AreEqual(1, counter.InstanceCount);
         counter.Decrement();
         Assert.AreEqual(0, counter.InstanceCount);
     }
 }
示例#15
0
        private void Initialize()
        {
            if (generatorFolder == null)
            {
                throw new InvalidOperationException("The RemoteAppDomainTestGeneratorFactory has to be configured with the Setup() method before initialization.");
            }


            AppDomainSetup appDomainSetup = new AppDomainSetup {
                ApplicationBase = generatorFolder
            };

            appDomainSetup.ShadowCopyFiles = "true";

            //set configuration for generator app domain to have assembly redirects
            var appConfigFile = Path.Combine(generatorFolder, "plugincompability.config");

            if (File.Exists(appConfigFile))
            {
                appDomainSetup.ConfigurationFile = appConfigFile;
            }
            tracer.Trace(string.Format("AppDomainSetup - ApplicationBase: {0}; ConfigFile: {1}", generatorFolder, appDomainSetup.ConfigurationFile ?? "not specified"), LogCategory);

            appDomain = AppDomain.CreateDomain("AppDomainForTestGeneration", null, appDomainSetup);

            var testGeneratorFactoryTypeFullName = typeof(TestGeneratorFactory).FullName;

            Debug.Assert(testGeneratorFactoryTypeFullName != null);

            tracer.Trace(string.Format("TestGeneratorFactory: {0}", testGeneratorFactoryTypeFullName), LogCategory);

            tracer.Trace("AssemblyResolve Event added", LogCategory);
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

            var generatorFactoryObject = appDomain.CreateInstanceAndUnwrap(remoteGeneratorAssemblyName, testGeneratorFactoryTypeFullName);

            remoteTestGeneratorFactory = generatorFactoryObject as ITestGeneratorFactory;

            if (remoteTestGeneratorFactory == null)
            {
                throw new InvalidOperationException("Could not load test generator factory.");
            }

            usageCounter = new UsageCounter(LoseReferences);
            tracer.Trace("AppDomain for generator created", LogCategory);
        }
        private void Initialize()
        {
            if (_info.GeneratorFolder == null)
            {
                throw new InvalidOperationException(
                          "The RemoteAppDomainTestGeneratorFactory has to be configured with the Setup() method before initialization.");
            }


            var appDomainSetup = new AppDomainSetup
            {
                ShadowCopyFiles = "true",
            };

            _appDomain = System.AppDomain.CreateDomain("AppDomainForTestGeneration", null, appDomainSetup);

            var testGeneratorFactoryTypeFullName = typeof(TestGeneratorFactory).FullName;

            Debug.Assert(testGeneratorFactoryTypeFullName != null);

            _tracer.Trace(string.Format("TestGeneratorFactory: {0}", testGeneratorFactoryTypeFullName), LogCategory);

            _tracer.Trace("AssemblyResolve Event added", LogCategory);
            System.AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;


            var remoteAppDomainAssembly = _remoteAppDomainResolverType.Assembly;

            _remoteAppDomainResolver = (RemoteAppDomainResolver)_appDomain.CreateInstanceFromAndUnwrap(remoteAppDomainAssembly.Location, _remoteAppDomainResolverType.FullName, true, BindingFlags.Default, null, null, null, null);
            _remoteAppDomainResolver.Init(_info.GeneratorFolder);

            var generatorFactoryObject = _appDomain.CreateInstanceAndUnwrap(_info.RemoteGeneratorAssemblyName, testGeneratorFactoryTypeFullName);

            _remoteTestGeneratorFactory = generatorFactoryObject as ITestGeneratorFactory;

            if (_remoteTestGeneratorFactory == null)
            {
                throw new InvalidOperationException("Could not load test generator factory.");
            }

            _usageCounter = new UsageCounter(LoseReferences);
            _tracer.Trace("AppDomain for generator created", LogCategory);
        }
示例#17
0
        public void Initialize()
        {
            AppDomainSetup appDomainSetup = new AppDomainSetup {
                ApplicationBase = generatorFolder
            };

            appDomain = AppDomain.CreateDomain("AppDomainForTestGeneration", null, appDomainSetup);

            var remoteGeneratorAssemblyName      = typeof(ITestGeneratorFactory).Assembly.GetName().Name;
            var testGeneratorFactoryTypeFullName = typeof(TestGeneratorFactory).FullName;

            Debug.Assert(testGeneratorFactoryTypeFullName != null);

            remoteTestGeneratorFactory = appDomain.CreateInstanceAndUnwrap(remoteGeneratorAssemblyName, testGeneratorFactoryTypeFullName) as ITestGeneratorFactory;

            if (remoteTestGeneratorFactory == null)
            {
                throw new InvalidOperationException("Could not load test generator factory.");
            }

            usageCounter = new UsageCounter(Cleanup);
        }
        private void Initialize()
        {
            if (generatorFolder == null)
                throw new InvalidOperationException("The RemoteAppDomainTestGeneratorFactory has to be configured with the Setup() method before initialization.");

            AppDomainSetup appDomainSetup = new AppDomainSetup { ApplicationBase = generatorFolder };
            appDomain = AppDomain.CreateDomain("AppDomainForTestGeneration", null, appDomainSetup);

            var testGeneratorFactoryTypeFullName = typeof(TestGeneratorFactory).FullName;
            Debug.Assert(testGeneratorFactoryTypeFullName != null);

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

            var generatorFactoryObject = appDomain.CreateInstanceAndUnwrap(remoteGeneratorAssemblyName, testGeneratorFactoryTypeFullName);
            remoteTestGeneratorFactory = generatorFactoryObject as ITestGeneratorFactory;

            if (remoteTestGeneratorFactory == null)
                throw new InvalidOperationException("Could not load test generator factory.");

            usageCounter = new UsageCounter(Cleanup);
            tracer.Trace("AppDomain for generator created", "RemoteAppDomainTestGeneratorFactory");
        }
        public void TestMultipleCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
            }

            //Someone has to hold onto at least one counter, or all will be cleared
            using (UsageCounter counter = new UsageCounter("some global name"))
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
        }
        private void Initialize()
        {
            if (generatorFolder == null)
                throw new InvalidOperationException("The RemoteAppDomainTestGeneratorFactory has to be configured with the Setup() method before initialization.");

            AppDomainSetup appDomainSetup = new AppDomainSetup { ApplicationBase = generatorFolder };
            appDomainSetup.ShadowCopyFiles = "true";

            //set configuration for generator app domain to have assembly redirects
            var appConfigFile = Path.Combine(generatorFolder, "plugincompability.config");
            if (File.Exists(appConfigFile))
            {
                appDomainSetup.ConfigurationFile = appConfigFile;
            }

            appDomain = AppDomain.CreateDomain("AppDomainForTestGeneration", null, appDomainSetup);

            var testGeneratorFactoryTypeFullName = typeof(TestGeneratorFactory).FullName;
            Debug.Assert(testGeneratorFactoryTypeFullName != null);

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

            var generatorFactoryObject = appDomain.CreateInstanceAndUnwrap(remoteGeneratorAssemblyName, testGeneratorFactoryTypeFullName);
            remoteTestGeneratorFactory = generatorFactoryObject as ITestGeneratorFactory;

            if (remoteTestGeneratorFactory == null)
                throw new InvalidOperationException("Could not load test generator factory.");

            usageCounter = new UsageCounter(LoseReferences);
            tracer.Trace("AppDomain for generator created", "RemoteAppDomainTestGeneratorFactory");
        }
 public void TestInstanceName()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
         Assert.AreEqual("some global name", counter.Name);
     using (UsageCounter counter = new UsageCounter(@"{0}\Item-{1}", "Global", 1))
         Assert.AreEqual(@"Global\Item-1", counter.Name);
 }
        public void TestInstanceCount()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                Assert.AreEqual(0, counter.InstanceCount);
                counter.Increment();
                Assert.AreEqual(1, counter.InstanceCount);
                counter.Increment();
                Assert.AreEqual(2, counter.InstanceCount);
                using (UsageCounter copy = new UsageCounter("some global name"))
                    Assert.AreEqual(0, copy.InstanceCount);
                counter.Decrement();
                Assert.AreEqual(1, counter.InstanceCount);
                counter.Decrement();
                Assert.AreEqual(0, counter.InstanceCount);
            }

        }
 public void TestEventArguments()
 {
     Value val = new Value();
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         counter.Increment(delegate(Value v) { v.Number++; }, val);
         counter.Increment(delegate(Value v) { v.Number++; }, val);
         counter.Decrement(delegate(Value v) { v.Number++; }, val);
         counter.Decrement(delegate(Value v) { v.Number++; }, val);
         Assert.AreEqual(2, val.Number);
     }
 }
        public void TestMultipleNestedCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                using (UsageCounter counter2 = new UsageCounter("some global name"))
                    counter2.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                using (UsageCounter counter2 = new UsageCounter("some global name"))
                {
                    counter2.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
                    counter2.Decrement();
                }
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }