public void ShouldUseConfigurableProperties()
        {
            var          actionMock = new Mock <INamedAction>();
            INamedAction action     = (INamedAction)actionMock.Object;

            ConfigurablePlugin plugin = new ConfigurablePlugin();

            plugin.LinkDescription = "My Plugin";
            plugin.NamedActions    = new INamedAction[] { action };

            Assert.AreEqual("My Plugin", plugin.LinkDescription);
            Assert.AreEqual(1, plugin.NamedActions.Length);
            Assert.AreEqual(action, plugin.NamedActions[0]);
        }
        public void ShouldUseConfigurableProperties()
        {
            DynamicMock  actionMock = new DynamicMock(typeof(INamedAction));
            INamedAction action     = (INamedAction)actionMock.MockInstance;

            ConfigurablePlugin plugin = new ConfigurablePlugin();

            plugin.LinkDescription = "My Plugin";
            plugin.NamedActions    = new INamedAction[] { action };

            Assert.AreEqual("My Plugin", plugin.LinkDescription);
            Assert.AreEqual(1, plugin.NamedActions.Length);
            Assert.AreEqual(action, plugin.NamedActions[0]);
        }
Пример #3
0
 private void ActionCompleted(bool success, INamedAction namedAction)
 {
     if (success)
     {
         Log.Debug("Action {0} completed successfully after {1} tries.", namedAction.ActionName, ((IActionPerformer)this).NumberOfRetries + 1);
     }
     else
     {
         Log.Debug("Action {0} failed after {1} tries.", namedAction.ActionName, ((IActionPerformer)this).NumberOfRetries + 1);
     }
     if (InvokeActionCompleted != null)
     {
         InvokeActionCompleted.Invoke(this, new ActionCompletionEventArgs(success));
     }
 }
Пример #4
0
 private void PerformAction(INamedAction namedAction, int retryCount)
 {
     try
     {
         Log.Debug("Invoking action.");
         namedAction.Action.Invoke();
     }
     catch (Exception ex)
     {
         ActionPerformerException exception = new ActionPerformerException(ex, namedAction.ActionName, retryCount, ((IActionPerformer)this).NumberOfRetries, ((IActionPerformer)this).RetryDelay);
         lock (_lockExceptionList)
             ((IActionPerformer)this).Exceptions.Add(exception);
         throw exception;
     }
 }
        public void Setup()
        {
            serverSpecifier   = new DefaultServerSpecifier(serverName);
            projectSpecifier  = new DefaultProjectSpecifier(serverSpecifier, projectName);
            buildSpecifier    = new DefaultBuildSpecifier(projectSpecifier, buildName);
            linkFactoryMock   = new Mock <ILinkFactory>();
            configurationMock = new Mock <IPluginConfiguration>();
            Plugins           = new DefaultPluginLinkCalculator((ILinkFactory)linkFactoryMock.Object, (IPluginConfiguration)configurationMock.Object);

            pluginMock1 = new Mock <IPlugin>();
            pluginMock2 = new Mock <IPlugin>();
            action1     = new ImmutableNamedAction("Action Name 1", null);
            action2     = new ImmutableNamedAction("Action Name 2", null);
            action3     = new ImmutableNamedAction("Action Name 3", null);
            pluginMock1.SetupGet(plugin => plugin.LinkDescription).Returns("Description 1").Verifiable();
            pluginMock1.SetupGet(plugin => plugin.NamedActions).Returns(new INamedAction[] { action1 }).Verifiable();
            pluginMock2.SetupGet(plugin => plugin.LinkDescription).Returns("Description 2").Verifiable();
            pluginMock2.SetupGet(plugin => plugin.NamedActions).Returns(new INamedAction[] { action2 }).Verifiable();
            link1 = (IAbsoluteLink) new Mock <IAbsoluteLink>().Object;
            link2 = (IAbsoluteLink) new Mock <IAbsoluteLink>().Object;
        }
Пример #6
0
        public void Setup()
        {
            serverSpecifier   = new DefaultServerSpecifier(serverName);
            projectSpecifier  = new DefaultProjectSpecifier(serverSpecifier, projectName);
            buildSpecifier    = new DefaultBuildSpecifier(projectSpecifier, buildName);
            linkFactoryMock   = new DynamicMock(typeof(ILinkFactory));
            configurationMock = new DynamicMock(typeof(IPluginConfiguration));
            Plugins           = new DefaultPluginLinkCalculator((ILinkFactory)linkFactoryMock.MockInstance, (IPluginConfiguration)configurationMock.MockInstance);

            pluginMock1 = new DynamicMock(typeof(IPlugin));
            pluginMock2 = new DynamicMock(typeof(IPlugin));
            action1     = new ImmutableNamedAction("Action Name 1", null);
            action2     = new ImmutableNamedAction("Action Name 2", null);
            action3     = new ImmutableNamedAction("Action Name 3", null);
            pluginMock1.ExpectAndReturn("LinkDescription", "Description 1");
            pluginMock1.ExpectAndReturn("NamedActions", new INamedAction[] { action1 });
            pluginMock2.ExpectAndReturn("LinkDescription", "Description 2");
            pluginMock2.ExpectAndReturn("NamedActions", new INamedAction[] { action2 });
            link1 = (IAbsoluteLink) new DynamicMock(typeof(IAbsoluteLink)).MockInstance;
            link2 = (IAbsoluteLink) new DynamicMock(typeof(IAbsoluteLink)).MockInstance;
        }
		public void Setup()
		{
			serverSpecifier = new DefaultServerSpecifier(serverName);
			projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName);
			buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, buildName);
			linkFactoryMock = new DynamicMock(typeof (ILinkFactory));
			configurationMock = new DynamicMock(typeof (IPluginConfiguration));
			Plugins = new DefaultPluginLinkCalculator((ILinkFactory) linkFactoryMock.MockInstance, (IPluginConfiguration) configurationMock.MockInstance);

			pluginMock1 = new DynamicMock(typeof (IPlugin));
			pluginMock2 = new DynamicMock(typeof (IPlugin));
			action1 = new ImmutableNamedAction("Action Name 1", null);
			action2 = new ImmutableNamedAction("Action Name 2", null);
			action3 = new ImmutableNamedAction("Action Name 3", null);
			pluginMock1.ExpectAndReturn("LinkDescription", "Description 1");
			pluginMock1.ExpectAndReturn("NamedActions", new INamedAction[] {action1});
			pluginMock2.ExpectAndReturn("LinkDescription", "Description 2");
			pluginMock2.ExpectAndReturn("NamedActions", new INamedAction[] {action2});
			link1 = (IAbsoluteLink) new DynamicMock(typeof (IAbsoluteLink)).MockInstance;
			link2 = (IAbsoluteLink) new DynamicMock(typeof (IAbsoluteLink)).MockInstance;
		}
Пример #8
0
        void IActionPerformer.InvokeAction(INamedAction namedAction)
        {
            bool success = false;

            try
            {
                Interlocked.Increment(ref _numberOfCurrentlyPerformingTasks);
                ActionStarted();

                int retryCount = 0;
                while ((retryCount <= ((IActionPerformer)this).NumberOfRetries) && (success == false))
                {
                    try
                    {
                        PerformAction(namedAction, retryCount);
                        success = true;
                    }
                    catch (ActionPerformerException ex)
                    {
                        //swallow
                        Log.Debug("ActionPerformer caught an exception when invoking the action {0}. Attempt {1} of {2}. Retrydelay: {3}. Exception: {4}", namedAction.ActionName, retryCount + 1, ((IActionPerformer)this).NumberOfRetries + 1, ((IActionPerformer)this).RetryDelay.ToString(), ex.InnerException.Message);
                        //Wait if there are retries left
                        if (retryCount < ((IActionPerformer)this).NumberOfRetries)
                        {
                            Thread.Sleep(((IActionPerformer)this).RetryDelay);
                        }
                    }
                    finally
                    {
                        retryCount++;
                    }
                }
            }
            finally
            {
                Interlocked.Decrement(ref _numberOfCurrentlyPerformingTasks);
                ActionCompleted(success, namedAction);
            }
        }
Пример #9
0
        void IActionPerformer.InvokeAction(INamedAction namedAction)
        {
            bool success = false;
            try
            {
                Interlocked.Increment(ref _numberOfCurrentlyPerformingTasks);
                ActionStarted();

                int retryCount = 0;
                while ((retryCount <= ((IActionPerformer)this).NumberOfRetries) && (success == false))
                {
                    try
                    {
                        PerformAction(namedAction, retryCount);
                        success = true;
                    }
                    catch (ActionPerformerException ex)
                    {
                        //swallow
                        Log.Debug("ActionPerformer caught an exception when invoking the action {0}. Attempt {1} of {2}. Retrydelay: {3}. Exception: {4}", namedAction.ActionName, retryCount + 1, ((IActionPerformer)this).NumberOfRetries + 1, ((IActionPerformer)this).RetryDelay.ToString(), ex.InnerException.Message);
                        //Wait if there are retries left
                        if (retryCount < ((IActionPerformer)this).NumberOfRetries)
                            Thread.Sleep(((IActionPerformer)this).RetryDelay);
                    }
                    finally
                    {
                        retryCount++;
                    }
                }
            }
            finally
            {
                Interlocked.Decrement(ref _numberOfCurrentlyPerformingTasks);
                ActionCompleted(success, namedAction);
            }
        }
Пример #10
0
        void IActionPerformer.InvokeActionAsync(INamedAction namedAction)
        {
            Action a = () => ((IActionPerformer)this).InvokeAction(namedAction);

            a.BeginInvoke(null, null);
        }
Пример #11
0
 private DecoratableByType AddActionInstance(INamedAction action)
 {
     return(_objectionManager.AddInstanceForName(action.ActionName.ToLowerInvariant(), action.Action));
 }
Пример #12
0
 private void PerformAction(INamedAction namedAction, int retryCount)
 {
     try
     {
         Log.Debug("Invoking action.");
         namedAction.Action.Invoke();
     }
     catch (Exception ex)
     {
         ActionPerformerException exception = new ActionPerformerException(ex, namedAction.ActionName, retryCount, ((IActionPerformer)this).NumberOfRetries, ((IActionPerformer)this).RetryDelay);
         lock (_lockExceptionList)
             ((IActionPerformer)this).Exceptions.Add(exception);
         throw exception;
     }
 }
Пример #13
0
 void IActionPerformer.InvokeActionAsync(INamedAction namedAction)
 {
     Action a = () => ((IActionPerformer)this).InvokeAction(namedAction);
     a.BeginInvoke(null, null);
 }
Пример #14
0
 private void ActionCompleted(bool success, INamedAction namedAction)
 {
     if (success)
         Log.Debug("Action {0} completed successfully after {1} tries.", namedAction.ActionName, ((IActionPerformer)this).NumberOfRetries + 1);
     else
         Log.Debug("Action {0} failed after {1} tries.", namedAction.ActionName, ((IActionPerformer)this).NumberOfRetries + 1);
     if (InvokeActionCompleted != null)
         InvokeActionCompleted.Invoke(this, new ActionCompletionEventArgs(success));
 }
		private DecoratableByType AddActionInstance(INamedAction action)
		{
			return _objectionManager.AddInstanceForName(action.ActionName.ToLowerInvariant(), action.Action);
		}