예제 #1
0
        /// <summary>
        /// Method with logic of execution the Console Application which created shell to process
        /// data.
        /// </summary>
        /// <param name="args">Represents the command-line arguments.</param>
        /// <param name="shell">Represents the main manager of the library.</param>
        private static async Task Run(IReadOnlyList <string> args, ShellAsync shell)
        {
            ServiceStatus status;

            if (args.Count == 1)
            {
                status = await shell.Run(args[0]);
            }
            else
            {
                GlobalMessageHandler.OutputMessage(
                    "Enter filename which contains the Things: "
                    );
                status = await shell.Run(GlobalMessageHandler.GetMessage());
            }

            if (status == ServiceStatus.Nothing)
            {
                GlobalMessageHandler.OutputMessage("Result is empty. Closing...");
            }
            else
            {
                GlobalMessageHandler.OutputMessage("Work was finished! Press enter to exit...");
            }
            GlobalMessageHandler.GetMessage();
        }
예제 #2
0
        /// <summary>
        /// Method with logic of execution the Console Application which created shell to process data.
        /// </summary>
        /// <param name="args">Represents the command-line arguments.</param>
        /// <param name="shell">Represents the main manager of the library.</param>
        private static void Run(string[] args, ShellAsync shell)
        {
            ServiceStatus status;

            if (args.Length == 1)
            {
                status = shell.Run(args[0]).Result;
            }
            else
            {
                GlobalMessageHandler.OutputMessage(
                    "Enter filename which contains the Things: "
                    );
                status = shell.Run(GlobalMessageHandler.GetMessage()).Result;
            }

            if (status == ServiceStatus.Nothing)
            {
                GlobalMessageHandler.OutputMessage("Result is empty. Closing...");
            }
            else
            {
                GlobalMessageHandler.OutputMessage("Work was finished! Press enter to exit...");
            }
            GlobalMessageHandler.GetMessage();
        }
        public async Task <ProcessingResponse> ProcessRequest(RequestData requestData)
        {
            var builderDirector = ShellAsync.CreateBuilderDirector(
                XmlConfigCreator.TransformConfigToXDocument(requestData.ConfigurationXml)
                );
            var shell = builderDirector.MakeShell();

            var inputTransmitter = new CInputTransmitterAsync(requestData.ThingNames);

            shell.InputManagerAsync.Add(inputTransmitter);

            var outputTransmitter = new OutputTransmitterAsync();

            shell.OutputManagerAsync.Add(outputTransmitter);

            ServiceStatus status = await shell.Run("Processing response");

            var results  = outputTransmitter.GetResults();
            var response = new ProcessingResponse
            {
                MetaData = new ResponseMetaData
                {
                    CommonResultsNumber = results.Aggregate(
                        0, (counter, rating) => counter + rating.Count
                        ),
                    CommonResultCollectionsNumber = results.Count,
                    ResultStatus = status,
                    OptionalData = CreateOptionalData()
                },
                RatingDataContainers = results
            };

            return(response);
        }
예제 #4
0
        private async Task <IReadOnlyList <ServiceStatus> > ExecuteSpecifiedNumberOfTimes(
            ShellAsync shell)
        {
            var statuses = new List <ServiceStatus>(ExecutionsNumber);

            int executedCount = 0;

            while (true)
            {
                ServiceStatus status = await shell.Run("Processing request data.");

                statuses.Add(status);

                ++executedCount;

                if (executedCount == ExecutionsNumber)
                {
                    break;
                }

                await Task.Delay(DelayTime);
            }

            return(statuses);
        }
예제 #5
0
        /// <summary>
        /// Main method of the Console Application which using config to manipulate Shell.
        /// </summary>
        /// <param name="args">Represents the command-line arguments.</param>
        private static void MainXDocument(string[] args)
        {
            // Show the case when we have a movies to appraise.
            var builderDirector = ShellAsync.CreateBuilderDirector(
                XmlConfigCreator.CreateDefaultXmlConfigAsXDocument()
                );
            var shell = builderDirector.MakeShell();

            Run(args, shell);
        }
예제 #6
0
        /// <summary>
        /// Main method of the Console Application which using config to manipulate Shell.
        /// </summary>
        /// <param name="args">Represents the command-line arguments.</param>
        private static async Task MainXDocument(IReadOnlyList <string> args)
        {
            // Show the case when we have a movies to appraise.
            var builderDirector = ShellAsync.CreateBuilderDirector(
                XmlConfigCreator.CreateDefaultXmlConfigAsXDocument()
                );
            var shell = builderDirector.MakeShell();

            await Run(args, shell);
        }
예제 #7
0
        public async Task <IReadOnlyList <ServiceStatus> > ExecuteAsync(RequestData requestData,
                                                                        IInputterAsync additionalInputterAsync, IOutputterAsync additionalOutputterAsync)
        {
            ShellAsyncBuilderDirector builderDirector = ShellAsync.CreateBuilderDirector(
                XmlConfigCreator.TransformConfigToXDocument(requestData.ConfigurationXml)
                );

            using ShellAsync shell = builderDirector.MakeShell();

            shell.InputManagerAsync.Add(additionalInputterAsync);
            shell.OutputManagerAsync.Add(additionalOutputterAsync);

            return(await ExecuteSpecifiedNumberOfTimes(shell));
        }