Exemple #1
0
        //**** client code that does not need to be changed  ***
        public static void ShipBook(IBookStore s)
        {
            //LDAF003
            IDistributor d = s.GetDistributor();

            d.ShipBook();
        }
Exemple #2
0
 public Clock(SynchronizationContext context, IDistributor distributor)
 {
     _context = context;
     _subscribers = new List<IClockedElement>();
     _distributor = distributor;
     _locker = new object();
 }
        public EmailDistributorTests(IOptionsMonitor <EmailDistributorSettings> options
                                     , ILogger <EmailDistributor> log)
        {
            EmailDistributor ed = new EmailDistributor(options, log);

            _distributor = ed;
        }
Exemple #4
0
 static void Main(string[] args)
 {
     try
     {
         ParseArguments(args);
         if (!request.Validate(true))
         {
             Environment.Exit(ResultCodeEnum.ERROR_INPUT.Value());
             return;
         }
         IDistributor distributor = GetDistributor(request);
         if (distributor == null)
         {
             Environment.Exit(ResultCodeEnum.ERROR_UNEXPECTED.Value());
             return;
         }
         UpdateBuilder  updateBuilder = new UpdateBuilder(distributor);
         ResultCodeEnum resultCode    = updateBuilder.ReleaseNewVersion(request);
         Environment.Exit(resultCode.Value());
     }
     catch (Exception ex)
     {
         ex.Message.WriteErrorToConsole();
         Environment.Exit(ResultCodeEnum.ERROR_UNEXPECTED.Value());
     }
 }
Exemple #5
0
        public Smoulder <TProcessData, TDistributeData> Build <TProcessData, TDistributeData>(
            ILoader <TProcessData> providedLoader = null,
            IProcessor <TProcessData, TDistributeData> providedProcessor = null,
            IDistributor <TDistributeData> providedDistributor           = null, int processorQueueBound = 0,
            int distributorQueueBound = 0) where TProcessData : new() where TDistributeData : new()
        {
            var loader      = providedLoader ?? new LoaderBase <TProcessData>();
            var processor   = providedProcessor ?? new ProcessorBase <TProcessData, TDistributeData>();
            var distributor = providedDistributor ?? new DistributorBase <TDistributeData>();

            //Create Queues
            ConcurrentQueue <TProcessData>    underlyingProcessQueue = new ConcurrentQueue <TProcessData>();
            BlockingCollection <TProcessData> processorQueue         = processorQueueBound > 0
                ? new BlockingCollection <TProcessData>(underlyingProcessQueue, processorQueueBound)
                : new BlockingCollection <TProcessData>(underlyingProcessQueue);

            ConcurrentQueue <TDistributeData>    underlyingDistributorQueue = new ConcurrentQueue <TDistributeData>();
            BlockingCollection <TDistributeData> distributorQueue           = distributorQueueBound > 0
                ? new BlockingCollection <TDistributeData>(underlyingDistributorQueue, distributorQueueBound)
                : new BlockingCollection <TDistributeData>(underlyingDistributorQueue);

            //Hooks units up to Queues
            loader.RegisterProcessorQueue(processorQueue);
            processor.RegisterProcessorQueue(processorQueue, underlyingProcessQueue);

            processor.RegisterDistributorQueue(distributorQueue);
            distributor.RegisterDistributorQueue(distributorQueue, underlyingDistributorQueue);

            //Creates a Smoulder encapsulating the units
            var smoulder = new Smoulder <TProcessData, TDistributeData>(loader, processor, distributor, processorQueue, distributorQueue);

            //Returns the Smoulder
            return(smoulder);
        }
Exemple #6
0
        public void CheckButton(IDistributor distributor)
        {
            ConsoleKeyInfo button = Console.ReadKey();

            if (button.Key == ConsoleKey.NumPad1 || button.KeyChar == '1')
            {
                Operation operation = MakeOperation("Доход");
                distributor.AddNewOperation(operation);
            }
            else if (button.Key == ConsoleKey.NumPad2 || button.KeyChar == '2')
            {
                Operation operation = MakeOperation("Расход");
                operation.IsOperationIncome = false;
                distributor.AddNewOperation(operation);
            }
            else if (button.Key == ConsoleKey.F2)
            {
                Console.WriteLine($"\nСредняя сумма траты составляет - {Math.Round(distributor.GetMeanCosts(), 2)}\n" +
                                  $"Средняя сумма дохода составляет - {Math.Round(distributor.GetMeanIncome(), 2)}\n\n" +
                                  $"Для возобновления работы программы нажмите любую клавишу...");

                Console.ReadKey();
            }
            else if (button.Key == ConsoleKey.F3)
            {
                Console.WriteLine($"\nДельта - {Math.Round(distributor.GetDelta(), 2)}\n\n" +
                                  $"Для возобновления работы программы нажмите любую клавишу...");
                Console.ReadKey();
            }
        }
        static async Task Main(string[] args)
        {
            FileSystemMonitorConfigSection config = ConfigurationManager.GetSection("fileSystemSection") as FileSystemMonitorConfigSection;

            if (config != null)
            {
                ReadConfiguration(config);
            }
            else
            {
                Console.Write(Strings.ConfigNotFounded);
                return;
            }

            Console.WriteLine(config.Culture.DisplayName);

            ILogger logger = new Logger();

            _distributor = new FilesDistributor(_rules, config.Rules.DefaultDirectory, logger);
            ILocationsWatcher <FileModel> watcher = new FilesWatcher(_directories, logger);

            watcher.Created += OnCreated;

            CancellationTokenSource source = new CancellationTokenSource();

            Console.CancelKeyPress += (o, e) =>
            {
                watcher.Created -= OnCreated;
                source.Cancel();
            };

            await Task.Delay(TimeSpan.FromMilliseconds(-1), source.Token);
        }
 public InitializableObject(IDistributor parent, TKey key, bool direct) : base(parent, key, direct)
 {
     if (parent is IInitialDataProvider <TKey, TInternal> provParent)
     {
         SetInitialDataProvider(provParent);
     }
 }
Exemple #9
0
        public static IDistributor <T> Trace <T>(
            this IDistributor <T> distributor,
            Action <Lease <T> > onLeaseAcquired  = null,
            Action <Lease <T> > onLeaseReleasing = null)
        {
            if (distributor == null)
            {
                throw new ArgumentNullException("distributor");
            }

            return(Create(
                       start: () =>
            {
                System.Diagnostics.Trace.WriteLine("[Distribute] Start");
                return distributor.Start();
            },
                       onReceive: receive =>
            {
                onLeaseAcquired = onLeaseAcquired ?? TraceOnLeaseAcquired;
                onLeaseReleasing = onLeaseReleasing ?? TraceOnLeaseReleasing;

                // FIX: (Trace) this doesn't do anything if OnReceive was called before Trace, so a proper pipeline model may be better here.
                distributor.OnReceive(async lease =>
                {
                    onLeaseAcquired(lease);
                    await receive(lease);
                    onLeaseReleasing(lease);
                });
            }, stop: () =>
            {
                System.Diagnostics.Trace.WriteLine("[Distribute] Stop");
                return distributor.Stop();
            }, distribute: distributor.Distribute));
        }
Exemple #10
0
    // This is the main entry point of a deployment script
    public void Main(IDistributor distributor)
    {
        var node = distributor.ConnectTo("127.0.0.1");

        node.CopyFile("CommandLine.xml", @"X:\CommandLine.xml");
        //node.CopyFiles(new[] {"CommandLine.xml"}, "%temp%");
        //node.CopyDirectory(".", "%temp%");
    }
Exemple #11
0
        public void Run()
        {
            var distribute = Distribute;

            this.Distribute = null;
            distribute.Distribute(this);    // clear distribute in case we're submitting to cluster. That's a lot of command line junk to send to the cluster for no reason!
            this.Distribute = distribute;
        }
Exemple #12
0
 public Smoulder(ILoader <TProcessData> loader, IProcessor <TProcessData, TDistributeData> processor, IDistributor <TDistributeData> distributor,
                 BlockingCollection <TProcessData> processorQueue, BlockingCollection <TDistributeData> distributorQueue)
 {
     _loader           = loader;
     _processor        = processor;
     _distributor      = distributor;
     _processorQueue   = processorQueue;
     _distributorQueue = distributorQueue;
 }
Exemple #13
0
        public UpdateBuilder(IDistributor distributor)
        {
            if (distributor == null)
            {
                throw new ArgumentNullException("distributor cannot be null");
            }

            _distributor = distributor;
        }
Exemple #14
0
        protected virtual bool RegisterDistributor(IDistributor distributor)
        {
            if (distributor == null)
            {
                throw new ArgumentNullException(nameof(distributor));
            }

            return(_distributors.TryAdd(distributor, new byte()));
        }
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, IDistributor distributor)
        {
            IWorkerAvailability <TMessage> workerAvailability = distributor.GetWorkerAvailability <TMessage>();

            // TODO we need to make a saga worker availability so that we can split saga load by correlation id
            IWorkerSelector <TMessage> workerSelector = _workerSelectorFactory.GetSelector <TMessage>();

            var sink = new DistributorMessageSink <TMessage>(workerAvailability, workerSelector);

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <TMessage>()));
        }
Exemple #16
0
        public MySynchNodeInstance()
        {
            LoggingManager.Debug("Initialize the service");
            _distributor = new Distributor();
            _timer = new Timer();
            _timer.Interval = 60000;
            InitializeComponent();
            ReadTheNodeConfiguration();

            LoggingManager.Debug("Initializion Ok with distribution Map: "+ _distributorMapFile);
        }
Exemple #17
0
 /// <summary>
 /// Distributes a stream catchup the among one or more partitions using a specified distributor.
 /// </summary>
 /// <remarks>If no distributor is provided, then distribution is done in-process.</remarks>
 public static IStreamCatchup <TData, TCursor> DistributeAmong <TData, TCursor, TPartition>(
     this IPartitionedStream <TData, TCursor, TPartition> streams,
     IEnumerable <IStreamQueryPartition <TPartition> > partitions,
     int?batchSize = null,
     FetchAndSaveProjection <ICursor <TCursor> > cursorPerPartition = null,
     IDistributor <IStreamQueryPartition <TPartition> > distributor = null)
 {
     return(new DistributedStreamCatchup <TData, TCursor, TPartition>(
                streams,
                partitions,
                batchSize,
                cursorPerPartition,
                distributor));
 }
Exemple #18
0
        static IDistributor GetLocalDistributor(string distributionPath)
        {
            IDistributor distributor = null;

            if (string.IsNullOrEmpty(distributionPath))
            {
                "Distribution path has  to be provided".WriteErrorToConsole();
                Environment.Exit(ResultCodeEnum.ERROR_INPUT.Value());
                return(distributor);
            }


            distributor = new LocalDistributor(distributionPath);
            return(distributor);
        }
        public IDistributor GetDistributor()
        {
            IDistributor distributor = null;

            switch (_location)
            {
            case CustomerLocation.EastCoast:
                distributor = new EastCoastDistributor();
                break;

            case CustomerLocation.WestCoast:
                distributor = new WestCoastDistributor();
                break;
            }
            return(distributor);
        }
Exemple #20
0
        static IDistributor GetDistributor(RelaseRequest request)
        {
            IDistributor distributor = null;

            switch (request.DistributonType)
            {
            case Models.DistributionTypeEnum.AWS:
                distributor = GetAwsDistributor(request.DistributonPath);
                break;

            case Models.DistributionTypeEnum.Local:
                distributor = GetLocalDistributor(request.DistributonPath);
                break;
            }
            return(distributor);
        }
 public HerbTranService(
     string path,
     ILogger logger,
     ICsvReader <FileProcess> fileReader,
     ICsvReader <Price> priceReader,
     ICsvReader <DayRate> dayRateReader,
     IDistributor distributor,
     IOutputService outputService)
 {
     _path          = path;
     _logger        = logger;
     _fileReader    = fileReader;
     _priceReader   = priceReader;
     _dayRateReader = dayRateReader;
     _distributor   = distributor;
     _outputService = outputService;
 }
Exemple #22
0
        //LDF002 client code does not need to be changed if the logic for choosing the distributor
        // in each BookStore will change
        public static void ShipBook(IBookStore s)
        {
            /*
             * The key is your customer should not care which distributor you choose because they will get their books
             * regardless. It is completely hidden from the customer's point of view and they should not be concerned
             * about it. You, the online bookstore, are the one that determines the distributor to use.
             */
            // the book store guy say that he need of a distributor for a specific location, but
            // he doesn't know which real distributor will be implemented.

            // FACTORY METHOD //the client gets the distributor without having to know which distributor is being used
            //LDF003 Notice that this client code don’t need to care which distributor is being created,
            //and this is the key to the factory method pattern.
            IDistributor d = s.GetDistributor();

            // IN a second time the distributor implemented will ship the book.
            d.ShipBook();
        }
Exemple #23
0
        static IDistributor GetAwsDistributor(string distributionPath)
        {
            IDistributor distributor = null;

            if (string.IsNullOrEmpty(distributionPath))
            {
                "Amazon bucket has to be provided".WriteErrorToConsole();
                Environment.Exit(ResultCodeEnum.ERROR_INPUT.Value());
                return(distributor);
            }

            string region = Environment.GetEnvironmentVariable(AmazonDistributor.AWS_REGION);

            if (string.IsNullOrWhiteSpace(region))
            {
                $"{AmazonDistributor.AWS_REGION} enviroment variable has to set".WriteErrorToConsole();
                Environment.Exit(ResultCodeEnum.ERROR_INPUT.Value());
                return(distributor);
            }

            string awsKey = Environment.GetEnvironmentVariable(Amazon.Runtime.EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_ACCESSKEY);

            if (string.IsNullOrWhiteSpace(awsKey))
            {
                $"{Amazon.Runtime.EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_ACCESSKEY} enviroment variable has to set".WriteErrorToConsole();
                Environment.Exit(ResultCodeEnum.ERROR_INPUT.Value());
                return(distributor);
            }

            string awsSecret = Environment.GetEnvironmentVariable(Amazon.Runtime.EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_SECRETKEY);

            if (string.IsNullOrWhiteSpace(awsSecret))
            {
                $"{Amazon.Runtime.EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_SECRETKEY} enviroment variable has to set".WriteErrorToConsole();
                Environment.Exit(ResultCodeEnum.ERROR_INPUT.Value());
                return(distributor);
            }


            Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(awsKey, awsSecret, Amazon.RegionEndpoint.GetBySystemName(region));

            distributor = new AmazonDistributor(distributionPath, client);
            return(distributor);
        }
        public DistributedStreamCatchup(
            IPartitionedStream <TData, TCursor, TPartition> partitionedStream,
            IEnumerable <IStreamQueryPartition <TPartition> > partitions,
            int?batchSize = null,
            FetchAndSaveProjection <ICursor <TCursor> > manageCursor       = null,
            IDistributor <IStreamQueryPartition <TPartition> > distributor = null) : base(batchSize)
        {
            if (partitionedStream == null)
            {
                throw new ArgumentNullException("partitionedStream");
            }
            if (partitions == null)
            {
                throw new ArgumentNullException("partitions");
            }

            this.partitionedStream = partitionedStream;

            this.distributor = distributor ?? partitions.DistributeQueriesInProcess();

            manageCursor = manageCursor ?? ((id, aggregate) => aggregate(null));

            this.distributor
#if DEBUG
            .Trace()     // TODO: (DistributedStreamCatchup) figure out a way to let people Trace this distributor
#endif
            .OnReceive(async lease =>
            {
                await manageCursor(lease.ResourceName, async cursor =>
                {
                    var catchup = new SingleStreamCatchup <TData, TCursor>(
                        await partitionedStream.GetStream(lease.Resource),
                        initialCursor: cursor,
                        batchSize: batchSize,
                        subscriptions: new ConcurrentDictionary <Type, IAggregatorSubscription>(aggregatorSubscriptions));

                    return(await catchup.RunSingleBatch());
                });
            });
        }
Exemple #25
0
        private static void ShipBook(IBookStore bookStore)
        {
            IDistributor obj = bookStore.GetDistributor();

            obj.ShipBook();
        }
Exemple #26
0
 public ISubscriptionReference Connect(IInboundPipelineConfigurator configurator, IDistributor distributor)
 {
     return(_referenceFactory(_connectors.Select(x => x.Connect(configurator, distributor))
                              .Aggregate <UnsubscribeAction, UnsubscribeAction>(() => true, (seed, x) => () => seed() && x())));
 }
Exemple #27
0
        //**** client code that does not need to be changed  ***
        private static void ShipBook(IBookStore s)
        {
            IDistributor d = s.GetDistributor();

            d.ShipBook();
        }
Exemple #28
0
 public async Task ExecuteDistributor(IDistributor distributor, dynamic config)
 {
     await distributor.ReconcilePool(config);
 }
Exemple #29
0
 public void AddDistributor(string name, IDistributor distributor)
 {
     _distributors[name] = distributor;
 }
Exemple #30
0
 public ConsoleApplication()
 {
     distributor = container.GetService <IDistributor>();
 }
Exemple #31
0
 public MarketPresenter(IDistributor parent, string symbol, bool direct) : base(parent, symbol, direct)
 {
     Symbol = symbol;
     PresentationService.RegisterService(this);
 }
Exemple #32
0
 public virtual void setup()
 {
     ObjectFactory.Configure(x => x.AddRegistry<DomainRegistry>());
     distributor = ObjectFactory.GetInstance<IDistributor>();
 }
 public ISubscriptionReference Connect(IInboundPipelineConfigurator configurator, IDistributor distributor)
 {
     return(_referenceFactory(_messageConnector.Connect(configurator, distributor)));
 }
Exemple #34
0
 public Router(ISwitchingMatrix switchingMatrix)
 {
     this.switchingMatrix = switchingMatrix;
     this.distributor = ObjectFactory.GetInstance<IDistributor>();
 }
Exemple #35
0
 public CalcEngine(ICalculator calculator, IDistributor distributor)
 {
     this.calculator = calculator;
     this.distributor = distributor;
 }