private static IReadOnlyList <IOperationProvider> SetupOperations(IEngineEnvironmentSettings environmentSettings, IParameterSet parameters, IGlobalRunConfig runConfig)
        {
            // default operations
            List <IOperationProvider> operations = new List <IOperationProvider>();

            operations.AddRange(runConfig.Operations);

            // replacements
            if (runConfig.Replacements != null)
            {
                foreach (IReplacementTokens replaceSetup in runConfig.Replacements)
                {
                    IOperationProvider replacement = ReplacementConfig.Setup(environmentSettings, replaceSetup, parameters);
                    if (replacement != null)
                    {
                        operations.Add(replacement);
                    }
                }
            }

            if (runConfig.VariableSetup.Expand)
            {
                operations?.Add(new ExpandVariables(null));
            }

            return(operations);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Sleep for 3 seconds.");
                Thread.Sleep(TimeSpan.FromSeconds(3));

                Console.WriteLine("Configuring Remoting environment...");
                System.Configuration.ConfigurationSettings.GetConfig("DNS");
                RemotingConfiguration.Configure("Client.exe.config");

                Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

                Console.WriteLine("Invoking a long-duration operation...");
                IOperationProvider iOperationProvider = (IOperationProvider)Activator.GetObject(typeof(IOperationProvider),
                                                                                                ConfigurationSettings.AppSettings["RemoteHostUri"] + "/OperationProvider.rem");
                Console.WriteLine(iOperationProvider.Do());

                Console.WriteLine("Press ENTER to exit.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
            }
        }
        /// <summary>
        /// Gets the <see cref="IOperationProvider"/> to use when creating or executing the operator for the given symbol.
        /// </summary>
        /// <param name="symbol">The symbol to get the <see cref="IOperationProvider"/> for.</param>
        /// <returns>An <see cref="IOperationProvider"/>, or null if none was found for the given symbol.</returns>
        public IOperationProvider GetProvider(char symbol)
        {
            IOperationProvider provider = null;
            bool containsKey            = false;

            lock (this.providerCache)
            {
                if (this.providerCache.ContainsKey(symbol))
                {
                    provider    = this.providerCache[symbol];
                    containsKey = true;
                }
                else
                {
                    containsKey = false;
                }
            }

            if (!containsKey)
            {
                provider = (from p in this.providers
                            where p.CanCreateOperator(symbol)
                            select p).FirstOrDefault();

                lock (this.providerCache)
                {
                    this.providerCache[symbol] = provider;
                }
            }

            return(provider);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConvertViewModel" /> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="options">The options.</param>
        public ConvertViewModel(IEventAggregator eventAggregator, IConverterOptions options,
                                IOperationProvider operationProvider)
            : base(eventAggregator, options)
        {
            this.operationProvider = operationProvider;

            this.operationProvider.RegisterOperation(new SaveConfigurationOperation(
                                                         options,
                                                         new DirectoryHelper(),
                                                         new FileProxy(),
                                                         new FolderProxy(),
                                                         new OutputConfigurationFileHelper(new FileProxy(), new EnvironmentProxy())));

            this.operationProvider.RegisterOperation(new ExtractSaveOperation(
                                                         Options,
                                                         new CompressedSaveChecker(),
                                                         new ZipFileHelper(
                                                             new ZipFileProxy(),
                                                             new FileProxy(),
                                                             new MessageBoxProxy()),
                                                         new EnvironmentProxy(),
                                                         new FileProxy(),
                                                         new FolderProxy()));

            this.operationProvider.RegisterOperation(new ConvertSaveOperation(Options, new FileProxy(), new DirectoryHelper()));

            this.operationProvider.RegisterOperation(new CopyModOperation(Options));

            getOrCreateCancellationTokenSource = () => { return(CancellationTokenSource); };
        }
 public Validator(
     ILogger <Validator> logger,
     IOperationProvider operationProvider)
 {
     _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
     _operationProvider = operationProvider ?? throw new ArgumentNullException(nameof(operationProvider));
 }
Exemple #6
0
        /// <summary>
        /// Runs a delegate in the context of an operation.
        /// </summary>
        /// <typeparam name="TCorrelationContext">The type of correlation context that will be used by the provider.</typeparam>
        /// <param name="provider">The Operation Provider that will create operations.</param>
        /// <param name="operationName">The name of the operation that will be created.</param>
        /// <param name="ctx">The correlation context to restore for this operation.</param>
        /// <param name="action">The delegate Action</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task RunAsync <TCorrelationContext>(this IOperationProvider <TCorrelationContext> provider, string operationName, TCorrelationContext ctx, RunOperationAsyncDelegate action)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (string.IsNullOrWhiteSpace(operationName))
            {
                throw new ArgumentNullException(nameof(operationName));
            }

            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            using (IOperation createdOperation = provider.CreateOperation(operationName, ctx))
            {
                try
                {
                    await action(createdOperation);

                    createdOperation.SetOperationResult(OperationResult.Success);
                }
                catch (Exception ex)
                {
                    createdOperation.SetOperationResult(ex);
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
                    throw ex;
                }
            }
        }
        private IEnumerable <IOperationProvider> GetSetupOperationProviders(
            IEnumerable <Type> hierarchyTypes,
            IEnumerable <Type> behaviorTypes,
            object suite,
            Type suiteType)
        {
            var establishAndCleanupOperationProviders = hierarchyTypes.Select(x => GetEstablishOperationProviderOrNull(x, GetInstance(x, suite)));

            var becauseFields = GetFields <Because>(suiteType).ToList();

            Trace.Assert(becauseFields.Count <= 1, "Multiple 'Because' fields provided.");
            var becauseOperationProvider =
                becauseFields.Select(x => OperationProvider.Create <Operation>(OperationType.Action, "Because", CreateUnwrappingAction(x, suite)));

            IOperationProvider fieldsCopyingOperationProvider = null;
            var behaviorTypeList = behaviorTypes.ToList();

            if (behaviorTypeList.Count > 0)
            {
                fieldsCopyingOperationProvider = OperationProvider.Create <Operation>(
                    OperationType.Action,
                    "<CopyBehaviorFields>",
                    GetFieldsCopyingAction(suiteType, behaviorTypeList));
            }

            return(establishAndCleanupOperationProviders
                   .Concat(becauseOperationProvider)
                   .Concat(fieldsCopyingOperationProvider)
                   .WhereNotNull());
        }
Exemple #8
0
        /// <summary>
        /// Runs a delegate in the context of an operation.
        /// </summary>
        /// <typeparam name="T">The return type from the function.</typeparam>
        /// <typeparam name="TCorrelationContext">The type of correlation context that will be used by the provider.</typeparam>
        /// <param name="provider">The Operation Provider that will create operations.</param>
        /// <param name="operationName">The name of the operation that will be created.</param>
        /// <param name="function">The delegate Action</param>
        public static T Run <T, TCorrelationContext>(this IOperationProvider <TCorrelationContext> provider, string operationName, RunOperationDelegate <T> function)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (string.IsNullOrWhiteSpace(operationName))
            {
                throw new ArgumentNullException(nameof(operationName));
            }

            if (function == null)
            {
                throw new ArgumentNullException(nameof(function));
            }

            using (IOperation createdOperation = provider.CreateOperation(operationName))
            {
                try
                {
                    T result = function(createdOperation);
                    createdOperation.SetOperationResult(OperationResult.Success);
                    return(result);
                }
                catch (Exception ex)
                {
                    createdOperation.SetOperationResult(ex);
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
                    throw ex;
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Runs a delegate in the context of an operation.
        /// </summary>
        /// <typeparam name="TCorrelationContext">The type of correlation context that will be used by the provider.</typeparam>
        /// <param name="provider">The Operation Provider that will create operations.</param>
        /// <param name="operationName">The name of the operation that will be created.</param>
        /// <param name="action">The delegate Action</param>
        public static void Run(this IOperationProvider provider, string operationName, RunOperationDelegate action)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (string.IsNullOrWhiteSpace(operationName))
            {
                throw new ArgumentNullException(nameof(operationName));
            }

            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            using (IOperation createdOperation = provider.CreateOperation(operationName))
            {
                try
                {
                    action(createdOperation);
                    createdOperation.SetOperationResult(OperationResult.Success);
                }
                catch (Exception ex)
                {
                    createdOperation.SetOperationResult(ex);
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
                    throw ex;
                }
            }
        }
 public BuilderExpression(
     ILogger <BuilderExpression> logger,
     IOperationProvider operationProvider)
 {
     _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
     _operationProvider = operationProvider ?? throw new ArgumentNullException(nameof(operationProvider));
 }
 public OperationModule(ICommandDispatcher commandDispatcher,
                        IValidatorResolver validatorResolver,
                        IOperationProvider operationProvider)
     : base(commandDispatcher, validatorResolver, modulePath: "operations")
 {
     Get("{requestId}", args => Fetch <GetOperation, Operation>
             (async x => await operationProvider.GetAsync(x.RequestId)).HandleAsync());
 }
Exemple #12
0
        public static void InvokeOperation()
        {
            Console.WriteLine("Invoking a long-duration operation...");
            IOperationProvider iOperationProvider = (IOperationProvider)Activator.GetObject(typeof(IOperationProvider),
                                                                                            ConfigurationSettings.AppSettings["RemoteHostUri"] + "/OperationProvider.rem");

            Console.WriteLine(iOperationProvider.Do());
        }
Exemple #13
0
 public Operation(Guid logGuid, IOperationProvider operationProvider)
 {
     LogGuid           = logGuid;
     OperationProvider = operationProvider;
     // this.AllowedAmmount = new List<decimal>(ConfigurationManager.AppSettings.Get("AllowedAmmount")
     // .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
     //     .Select(amount => Decimal.Parse(amount, NumberStyles.Integer, new CultureInfo("ru-Ru"))));
 }
Exemple #14
0
 public InformationProvider(IOperationProvider operationProvider, IHttpClient httpClient, IJsonParser jsonParser)
 {
     IsCacheEmtpy = true;
     FullyLoadApiInformationCache = true; //add config and read this from it.
     this._operationProvider      = operationProvider;
     _httpClient = httpClient;
     _jsonParser = jsonParser;
 }
Exemple #15
0
 public IOperationResult CreatePassedOperationResult(IOperationProvider provider)
 {
     return(new OperationResult(
                provider.Identity,
                provider.Text,
                provider.Type,
                State.Passed,
                ExceptionDescriptor.None));
 }
Exemple #16
0
 private static T GenericNextPowerOf2 <T>(T value, IOperationProvider <T> provider) where T : struct
 {
     value = provider.Subtract(value, 1);
     for (var i = 1; i <= provider.NumBits; i <<= 1)
     {
         value = provider.Or(value, provider.ShiftRight(value, i));
     }
     return(provider.Add(value, 1));
 }
Exemple #17
0
 public IOperationResult CreateFailedOperationResult(IOperationProvider provider, Exception exception)
 {
     return(new OperationResult(
                provider.Identity,
                provider.Text,
                provider.Type,
                State.Failed,
                ExceptionDescriptor.Create(exception)));
 }
Exemple #18
0
 public IOperationResult CreateInconclusiveOperationResult(IOperationProvider provider)
 {
     return(new OperationResult(
                provider.Identity,
                provider.Text,
                provider.Type,
                State.Inconclusive,
                ExceptionDescriptor.None));
 }
 public RunOperationsCommand(
     IOperationProcessor processor,
     IOperationProvider provider,
     Action beforeStart,
     Action afterCompletion,
     Func <CancellationTokenSource> tokenSourceFunc)
 {
     this.processor       = processor;
     this.provider        = provider;
     _beforeStart         = beforeStart;
     _afterCompletion     = afterCompletion;
     this.tokenSourceFunc = tokenSourceFunc;
 }
Exemple #20
0
 private OperationProvider(
     string text,
     Type descriptor,
     OperationType type,
     Action action,
     [CanBeNull] IOperationProvider cleanupProvider)
     : base(s_identity, text, ignoreReason: null)
 {
     Descriptor      = descriptor;
     Type            = type;
     Action          = action;
     CleanupProvider = cleanupProvider;
 }
 public RunOperationsCommand(
     IOperationProcessor processor,
     IOperationProvider provider,
     Action beforeStart,
     Action afterCompletion,
     Func<CancellationTokenSource> tokenSourceFunc)
 {
     this.processor = processor;
     this.provider = provider;
     _beforeStart = beforeStart;
     _afterCompletion = afterCompletion;
     this.tokenSourceFunc = tokenSourceFunc;
 }
 private OperationProvider(
     string text,
     Type descriptor,
     OperationType type,
     Action action,
     [CanBeNull] IOperationProvider cleanupProvider)
     : base(new Identity("<OPERATION>"), text, ignored: false)
 {
     _descriptor      = descriptor;
     _type            = type;
     _action          = action;
     _cleanupProvider = cleanupProvider;
 }
 public ServiceOperationProvider(IOperationRepository operationRepository, IOperationProvider operationProvider)
 {
     if (operationRepository == null)
     {
         throw new ArgumentNullException("operationRepository");
     }
     if (operationProvider == null)
     {
         throw new ArgumentNullException("operationProvider");
     }
     _operationProvider = operationProvider;
     _operationRepository = operationRepository;
 }
Exemple #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationMutator"/> class using the
 /// specified bus instance and operation provider.
 /// </summary>
 /// <param name="bus">The current NServiceBus instance.</param>
 /// <param name="operationProvider">The provider to use for creating and retrieving
 /// operations.</param>
 public OperationMutator(IBus bus, IOperationProvider operationProvider)
 {
     if (bus == null)
     {
         throw new ArgumentNullException("bus");
     }
     if (operationProvider == null)
     {
         throw new ArgumentNullException("operationProvider");
     }
     this.bus = bus;
     this.operationProvider = operationProvider;
 }
Exemple #25
0
 public ServiceOperationProvider(IOperationRepository operationRepository, IOperationProvider operationProvider)
 {
     if (operationRepository == null)
     {
         throw new ArgumentNullException("operationRepository");
     }
     if (operationProvider == null)
     {
         throw new ArgumentNullException("operationProvider");
     }
     _operationProvider   = operationProvider;
     _operationRepository = operationRepository;
 }
        public IOperationResult Run(IOperationProvider provider)
        {
            if (provider.Action == OperationProvider.NotImplemented)
            return _resultFactory.CreateInconclusiveOperationResult(provider);

              try
              {
            provider.Action();
            return _resultFactory.CreatePassedOperationResult(provider);
              }
              catch (Exception exception)
              {
            return _resultFactory.CreateFailedOperationResult(provider, exception);
              }
        }
Exemple #27
0
        public void AddSetupCleanup <TSetup, TCleanup> (string setupText, Action setup, string cleanupText, Action cleanup)
            where TSetup : IActionDescriptor
            where TCleanup : ICleanupDescriptor
        {
            // TODO: shared code with TestController
            IOperationProvider cleanupProvider = null;

            if (cleanup != null)
            {
                cleanupProvider = OperationProvider.Create <TCleanup>(OperationType.Action, cleanupText, cleanup);
            }
            var setupProvider = OperationProvider.Create <TSetup>(OperationType.Action, setupText, setup, cleanupProvider);
            var unsortedOperationProviders = cleanupProvider.Concat(_provider.ContextProviders).Concat(setupProvider).WhereNotNull();

            _provider.ContextProviders = _operationSorter.Sort(unsortedOperationProviders);
        }
Exemple #28
0
        public IOperationResult Run(IOperationProvider provider)
        {
            if (provider.Action == OperationProvider.NotImplemented)
            {
                return(_resultFactory.CreateNotImplementedOperationResult(provider));
            }

            try
            {
                provider.Action();
                return(_resultFactory.CreatePassedOperationResult(provider));
            }
            catch (Exception exception)
            {
                return(_resultFactory.CreateFailedOperationResult(provider, exception));
            }
        }
        public ConnectionManagerInterceptor(
            [NotNull] IOperationProvider operationProvider,
            [NotNull] IConnectionManager connectionManager,
            IsolationLevel defaultTransactionIsolationLevel)
        {
            if (operationProvider == null)
            {
                throw new ArgumentNullException(nameof(operationProvider));
            }
            if (connectionManager == null)
            {
                throw new ArgumentNullException(nameof(connectionManager));
            }

            _operationProvider = operationProvider;
            _connectionManager = connectionManager;
            _defaultTransactionIsolationLevel = defaultTransactionIsolationLevel;
        }
Exemple #30
0
        public void AddSetupCleanup <TSetup, TCleanup> (
            string setupText,
            Action <ITestContext> setup,
            [CanBeNull] string cleanupText,
            [CanBeNull] Action <ITestContext> cleanup)
            where TSetup : IActionDescriptor
            where TCleanup : ICleanupDescriptor
        {
            // TODO: shared code with SuiteController
            IOperationProvider cleanupProvider = null;

            if (cleanup != null)
            {
                cleanupProvider = OperationProvider.Create <TCleanup>(OperationType.Action, cleanupText.NotNull(), InjectContextAndGuardAction(cleanup));
            }
            var setupProvider = OperationProvider.Create <TSetup>(OperationType.Action, setupText, InjectContextAndGuardAction(setup), cleanupProvider);
            var unsortedOperationProviders = cleanupProvider.Concat(_provider.OperationProviders).Concat(setupProvider).WhereNotNull();

            _provider.OperationProviders = _operationSorter.Sort(unsortedOperationProviders);
        }
        private IOperationProvider GetEstablishOperationProviderOrNull(Type type, object instance)
        {
            var setupField   = GetFields <Establish>(type).SingleOrDefault();
            var cleanupField = GetFields <Cleanup>(type).SingleOrDefault();

            if (setupField == null && cleanupField == null)
            {
                return(null);
            }

            IOperationProvider cleanupProvider = null;

            if (cleanupField != null)
            {
                var cleanupAction = CreateUnwrappingAction(cleanupField, instance);
                cleanupProvider = OperationProvider.Create <Operation>(OperationType.Action, "Cleanup " + type.Name, cleanupAction);
            }

            var setupAction = setupField != null?CreateUnwrappingAction(setupField, instance) : () => { };

            return(OperationProvider.Create <Operation>(OperationType.Action, "Establish " + type.Name, setupAction, cleanupProvider));
        }
Exemple #32
0
        /// <summary>
        /// Reads an operator from the given string expression, starting at the given position.
        /// </summary>
        /// <param name="expr">The expression to read the operator from.</param>
        /// <param name="pos">The position to start reading at.</param>
        /// <returns>The result of the read.</returns>
        internal ReadResult ReadOperator(string expr, int pos)
        {
            ReadResult result = new ReadResult()
            {
                Position = pos
            };
            char c = expr[pos];

            if (!char.IsWhiteSpace(c))
            {
                IOperationProvider provider = this.providerFactory.GetProvider(c);

                if (provider != null)
                {
                    result.Token    = provider.CreateOperator(c);
                    result.Position = pos + 1;
                    result.Success  = true;
                }
            }

            return(result);
        }
        public Operation CreateOperation(Guid logGuid, TransactionOperation transactionOperation, IOperationProvider operationProvider)
        {
            Operation operation = null;

            if (operationProvider != null)
            {
                OperationProvider = operationProvider;
            }
            else
            {
                throw new ArgumentException("Provider cann't be null");
            }
            switch (transactionOperation)
            {
            case TransactionOperation.CheckPayment:
                operation = new CheckOperation(logGuid, OperationProvider);
                break;

            case TransactionOperation.IPayment:
                operation = new IPaymentOperation(logGuid, OperationProvider);
                break;

            case TransactionOperation.ICommit:
                operation = new ICommitOperation(logGuid, OperationProvider);
                break;

            case TransactionOperation.Cancel:
                operation = new CancelOperation(logGuid, OperationProvider);
                break;

            default:
                string msg = $"TransactionOperation {OperationProvider} not supported";
                Logger.WriteLoggerError(msg);
                throw new ArgumentOutOfRangeException(msg);
            }
            return(operation);
        }
		public OperationController(IOperationProvider operationProvider)
		{
			_operationProvider = operationProvider;
		}
		public FancyTreeOperController(IOperationProvider provider)
		{
			_provider = provider;
		}
 public PostfixExecutor(IOperationProvider provider)
 {
     _provider = provider;
 }
 public PostfixConverterSortStation(IOperationProvider operationProvider)
 {
     _operationProvider = operationProvider;
 }
		public void Start()
		{
			Provider = Container.Resolve<IOperationProvider>();
		}