Esempio n. 1
0
        public void StartGame(GameConfig config, IInterfaceService interfaceService)
        {
            var outputService = new OutputService(interfaceService, config);

            var solution = EntryGenerator.Generate(config.NumbersInSolution, config.MaxNumber);

            _board = new Board(solution);

            outputService.WriteNewGame();

            for (var guessNumber = 1; guessNumber <= config.NumberOfGuesses; guessNumber++)
            {
                outputService.WriteGuessNumber(guessNumber);
                var userGuesses = outputService.GetGuesses();
                if (EndgameChecker.UserHasWon(userGuesses, solution))
                {
                    outputService.WriteUserWins();
                    return;
                }

                var response = userGuesses.Select((guess, i) => _board.GetResultForGuess(guess, i));
                outputService.WriteResponse(response);
            }
            outputService.WriteUserLoses();
            outputService.WriteSolution(solution);
        }
Esempio n. 2
0
 // Task1
 public static void Run(double value)
 {
     OutputService.ShowMessage($"Grams = {value}\n");
     OutputService.ShowMessage($"Kilograms = {ValueConverter.GetCalcResult(value, (int)CoefEnum.kilograms)}\n");
     OutputService.ShowMessage($"Centners = {ValueConverter.GetCalcResult(value, (int)CoefEnum.centners)}\n");
     OutputService.ShowMessage($"Tons = {ValueConverter.GetCalcResult(value, (int)CoefEnum.tons)}\n");
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            bool run = true;

            while (run)
            {
                OutputService.ShowMessage("Input index:\n" +
                                          "0 - exit\n" +
                                          "1 - Convert dinosaur weight\n" +
                                          "2 - Convert file size\n" +
                                          "3 - Convert distance\n" +
                                          "4 - Swap numbers\n" +
                                          "5 - Candies shop\n");
                string index = InputService.GetUserMsg();
                switch (index)
                {
                case "0": run = false; break;

                case "1": TaskExecutor.Task1(); break;

                case "2": TaskExecutor.Task2(); break;

                case "3": TaskExecutor.Task3(); break;

                case "4": TaskExecutor.Task4(); break;

                case "5": TaskExecutor.Task5(); break;

                default: OutputService.ShowMessage("Incorrect index\n"); break;
                }
            }
        }
Esempio n. 4
0
 public Generator(FileManager <ConfigurationModel> configFile, SpocrService spocr, OutputService output, IReportService reportService)
 {
     _configFile    = configFile;
     _spocr         = spocr;
     _output        = output;
     _reportService = reportService;
 }
Esempio n. 5
0
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            string outputApplication = WebConfigurationManager.AppSettings["OutputApplication"];

            Output output = new Output();

            OutputService service;

            switch (outputApplication)
            {
            case "CONSOLE":
                service = new OutputService(new ConsoleOutput());
                break;

            case "DATABASE":
                service = new OutputService(new DatabaseOutput());
                break;

            default:
            {
                service = new OutputService(new ScreenOutput());
                break;
            }
            }

            service.ProcessOutput(output);

            ViewBag.Output = output;
            return(View());
        }
Esempio n. 6
0
 public CalculatorReplLoop()
 {
     commandInputParser = new CommandInputParser();
     calculator         = new Calculator();
     inputService       = new InputService();
     outputService      = new OutputService();
 }
Esempio n. 7
0
        private bool SetColor(OutputConfiguration outputConfig, ColorF colorToSet, bool isResend)
        {
            OutputService outputService = outputConfig.OutputService;

            IList <ColorTransformerContext> colorTransformerContexts = outputConfig.ColorTransformerContexts;

            var outputColor = _colorTransformerService.Transform(colorTransformerContexts, colorToSet);

            if (!isResend && outputConfig.LastColor.HasValue && outputService.ColorsEqual(outputColor, outputConfig.LastColor.Value))
            {
                return(false);
            }

            outputConfig.LastColor        = outputColor;
            outputConfig.LastColorSetTime = DateTime.UtcNow;

            if (isResend)
            {
                outputConfig.ResendCount++;
            }
            else
            {
                outputConfig.ResendCount = 0;
            }

            outputService.SetColor(outputColor, outputConfig.OutputInfo);
            return(true);
        }
Esempio n. 8
0
        public void Start()
        {
            while (true)
            {
                OutputService.ShowMessage("1 - Count the number of dragon heads and eyes;\n" +
                                          "2 - \"The Greatest\" (get min/max value);\n" +
                                          "3 - Is the number a multiple of the numbers?(2, 3, 5, 7, 11, 13, 17, 19);\n" +
                                          "4 - determine whether the given sides are sides of a triangle;\n" +
                                          "5 - Description of the mark.\n");
                IO.GetNumber(out int index, "Enter index");
                switch (index)
                {
                case 1: OutputService.ShowMessage(TaskExecutor.Common1(IO)); break;

                case 2: OutputService.ShowMessage(TaskExecutor.Common2(IO)); break;

                case 3: OutputService.ShowMessage(TaskExecutor.Common3(IO)); break;

                case 4: OutputService.ShowMessage(TaskExecutor.IndividualA(IO)); break;

                case 5: OutputService.ShowMessage(TaskExecutor.IndividualB(IO)); break;

                default: OutputService.ShowMessage("Incorrect index"); break;
                }
            }
        }
Esempio n. 9
0
 public SpocrManager(
     IConfiguration configuration,
     SpocrService spocr,
     OutputService output,
     Generator engine,
     SpocrProjectManager projectManager,
     IReportService reportService,
     SchemaManager schemaManager,
     FileManager <GlobalConfigurationModel> globalConfigFile,
     FileManager <ConfigurationModel> configFile,
     DbContext dbContext,
     AutoUpdaterService autoUpdaterService
     )
 {
     _spocr              = spocr;
     _output             = output;
     _engine             = engine;
     _projectManager     = projectManager;
     _reportService      = reportService;
     _schemaManager      = schemaManager;
     _globalConfigFile   = globalConfigFile;
     _configFile         = configFile;
     _dbContext          = dbContext;
     _autoUpdaterService = autoUpdaterService;
 }
Esempio n. 10
0
        public static int GetPersonId()
        {
            Person person = new Person();
            int    id     = -1;

            OutputService.DisplayConsole("Are you registered");
            NoYes     input     = (NoYes)InputService.GetValidatedUserChoice(new NoYes());
            DBService dbService = new DBService();

            switch (input)
            {
            case NoYes.No:

                OutputService.DisplayConsole("Write your name");
                person.PersonName = StringValidation.ValidateLength(MAX_LENGTH_RESPONSIBLE);
                OutputService.DisplayConsole("Enter your phone number (ex. 0991231212, 099-123-12-12, +1-099-123-12-12)");
                person.PhoneNumber = StringValidation.ValidatePhone();
                id = dbService.CreatePerson(person);
                dbService.Dispose();
                return(id);

            case NoYes.Yes:
                while (dbService.PersonExist(person) == null)
                {
                    OutputService.DisplayConsole("Write your name");
                    person.PersonName = StringValidation.ValidateLength(MAX_LENGTH_RESPONSIBLE);
                    OutputService.DisplayConsole("Enter your phone number (ex. 0991231212, 099-123-12-12, +1-099-123-12-12)");
                    person.PhoneNumber = StringValidation.ValidatePhone();
                    id = dbService.PersonExist(person).Id;
                }
                return(id);
            }
            return(-1);
        }
Esempio n. 11
0
 public OutputController(OutputService outputService,
                         IMappingServiceProvider mapper,
                         ILogger logger) : base(logger)
 {
     _outputService = outputService;
     _mapper        = mapper;
 }
Esempio n. 12
0
        private void CopySmart(ProjectData project)
        {
            if (!project.Include)
            {
                return;
            }
            OutputService.WriteOutputWithContext($"Start copy to Smart: {project.Name}");
            var smartDirectory = new DirectoryInfo(SmartDirectory);

            if (!smartDirectory.Exists)
            {
                OutputService.WriteOutputWithContext($"Copy to Smart failed: Path does not Exists -> {smartDirectory.FullName}");
            }
            else
            {
                var assembly       = new FileInfo(project.FullAssemblyPath);
                var targetAssembly = new FileInfo(Path.Combine(smartDirectory.FullName, assembly.Name));

                assembly.CopyTo(targetAssembly.FullName, true);

                if (assembly.ToFileHash() != targetAssembly.ToFileHash())
                {
                    OutputService.WriteOutputWithContext($"Error: the File {assembly.Name} doesn't match the Source.");
                    OutputService.WriteOutputWithContext(
                        $"Hash: Source {assembly.ToFileHash()} <> Target {targetAssembly.ToFileHash()}");
                }
            }

            OutputService.WriteOutputWithContext($"Finished copy to Smart: {project.Name}");
        }
Esempio n. 13
0
        public async Task DeployAsync()
        {
            try
            {
                await Task.Run(() => SaveConfigToXml());

                if (configuration.CopyToUpdate)
                {
                    await data.ForEachAsync(CopyAssembly);
                }

                if (configuration.CopyToBin)
                {
                    await Data.ForEachAsync(CopyBin);
                }

                if (configuration.CopyToSmart)
                {
                    await Data.ForEachAsync(CopySmart);
                }
            }
            catch (Exception ex)
            {
                OutputService.WriteOutputWithContext($"Error: {ex.Message}");
            }
        }
Esempio n. 14
0
        private void LoadLatestVersion()
        {
            if (!configuration.DoCheckout)
            {
                return;
            }
            try
            {
                var solution     = service.Solution;
                var solutionFile = solution.FullName;

                solution.Close(true);

                OutputService.WriteOutputWithContext($"<TFS>Get latest Version of: {solutionPath.DirectoryName}");
                tfsServer.UpdateProject(solutionPath.DirectoryName);

                if (tfsServer.Failures?.Length > 0)
                {
                    OutputService.WriteOutputWithContext($"<TFS>Sync failed: {solutionPath.DirectoryName}");

                    foreach (var fail in tfsServer.Failures)
                    {
                        OutputService.WriteOutputWithContext($"<TFS>{fail.GetFormattedMessage()}");
                    }
                }

                solution.Open(solutionFile);
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.Message);
                OutputService.WriteOutputWithContext($"Error: {ex.Message}");
            }
        }
Esempio n. 15
0
        public void Extractor_RangeIsInvalid_ThrowsArgumentOutOfRangeException(int start, int end)
        {
            var       extractor  = new TaskExtractor(OutputService.GetInstance(), InputService.GetInstance());
            const int ARRAY_SIZE = 40;

            Assert.Throws <ArgumentOutOfRangeException>(() => extractor.GetRandomDoubleEnumerable(count: ARRAY_SIZE, startRange: start, endRange: end));
        }
        public MainViewModel(IEnumerable <IInputStream> streams, IEnumerable <ITextProcessor> processors, ILogService logger, IStreamService streamer, IOutputService outputHandler, IDialogService dialogHandler)
        {
            // fields and properties
            Streams                          = new ObservableCollection <IInputStream>(streams);
            Processors                       = new ObservableCollection <ITextProcessor>(processors);
            OrderByTextItemList              = new string[] { manualOrderingDescription, "TimeStamp", "Text" };
            StreamedItems                    = new ObservableCollection <TextItemViewModel>();
            StreamedItemsView                = new ListCollectionView(StreamedItems);
            outputService                    = outputHandler as OutputService;
            dialogService                    = dialogHandler;
            logService                       = logger;
            streamService                    = streamer;
            OrderByTextItem                  = OrderByTextItemList.FirstOrDefault();
            SelectedStream                   = Streams.FirstOrDefault();
            SelectedProcessor                = Processors.FirstOrDefault();
            StreamedItems.CollectionChanged += (s, e) => updateOutput();

            #region initialize services internal functions

            // set up the logger for binding
            IObservableLogger loggerWithEntries = null;
            if (logService != null && (loggerWithEntries = logService as IObservableLogger) != null)
            {
                LogEntries = new ListCollectionView(loggerWithEntries.Entries);
                loggerWithEntries.Entries.CollectionChanged += (s, e) => refreshLogCounters();
                refreshLogCounters();
            }

            // set the callback for the stream service
            (streamService as StreamService).ReceiveStreamText = streamedText =>
            {
                StreamedItems.Add(new TextItemViewModel(streamedText, outputService));
                CommandManager.InvalidateRequerySuggested();

                // NOTE:  updateOutput is called on the CollectionChanged event of StreamedItems
            };

            // set up output service
            outputService.RefreshAction = updateOutput;

            #endregion

            // commands
            StartCommand       = CreateCommand(startCommand_Execute, startCommand_CanExecute);
            StopCommand        = CreateCommand(stopCommand_Execute, stopCommand_CanExecute);
            SelectAllCommand   = CreateCommand(selectAllCommand_Execute, selectAllCommand_CanExecute);
            DeselectAllCommand = CreateCommand(deselectAllCommand_Execute, deselectAllCommand_CanExecute);
            DeleteCommand      = CreateCommand(deleteCommand_Execute, deleteCommand_CanExecute);
            MoveUpCommand      = CreateCommand(moveUpCommand_Execute, moveUpCommand_CanExecute);
            MoveDownCommand    = CreateCommand(moveDownCommand_Execute, moveDownCommand_CanExecute);
            CopyOutputCommand  = CreateCommand(copyOutputCommand_Execute, copyOutputCommand_CanExecute);
            HelpCommand        = CreateCommand(helpCommand_Execute);

            // enable the control used to select an input stream
            IsIdle        = true;
            loadCompleted = true;
            updateOutput();
            refreshStreamStateLabel();
        }
Esempio n. 17
0
        /// <summary>
        /// reads 2 Folder Inputs, compares all files including subfolders and simulates all operations needed to make the second destination equal to the second destination
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //retrieve the logging instance
            NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

            //retrieve the associated service
            IFileSystemCompareService _FileSystemCompareService = new FileSystemCompareService();

            Logger.Info("Application started");
            Console.WriteLine("#### Filesystem Diff Simulator - Willkommen ####");

            IEnumerable <FileSystemCompareOperation> _Items;     //holds the result from the service

            // iterate logic until user stops execution
            do
            {
                _Items = null;

                Console.Write("Enter first Destination Path: ");
                string _Path1 = Console.ReadLine();

                Console.Write("Enter second Destination Path: ");
                string _Path2 = Console.ReadLine();

                Logger.Debug(string.Concat("Input 1: ", _Path1));         //Log Input1
                Logger.Debug(string.Concat("Input 2: ", _Path2));         //Log Input2

                try
                {
                    //retrieve result from the associated Service
                    _Items = _FileSystemCompareService.CompareFolder(_Path1, _Path2);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Logger.Error(ex.Message);       //Log Exception as Error
                    Console.WriteLine(ex.Message);  //here we can continue execution
                }
                catch (Exception ex)
                {
                    Logger.Fatal(ex.Message);       //Log Exception
                    throw;
                }

                if (_Items != null)
                {
                    //provide console output of the items
                    OutputService.Output(_Items);
                }

                // get the user input for every iteration, allowing to exit at will
                Console.Write("Continue [y|n]?");
                var text = Console.ReadLine();
                if (text.Equals("n"))
                {
                    // exit the method.
                    break;
                }
            }while (true);
        }
Esempio n. 18
0
 internal static void Exit()
 {
     Sara.Common.Debug.Shutdown.Set();
     _mDocumentMapViewModel.Exit();
     OutputService.Exit();
     Log.Exit(new TimeSpan(0, 0, 30));
     _queue.Exit();
 }
Esempio n. 19
0
        public void GetNumber_ConsoleInputIsInvalid_ReturnsFalse(string str)
        {
            Console.SetIn(new StringReader(str));
            var  extractor    = Substitute.For <TaskExtractor>(OutputService.GetInstance(), InputService.GetInstance());
            bool actualResult = extractor.GetNumber(out _, string.Empty);

            Assert.IsFalse(actualResult);
        }
Esempio n. 20
0
        public string GetTaskResult(TaskExtractor extractor)
        {
            string taskResult;

            if (extractor.GetNumber(out int number, new string[] { "Input number", "Input number must be greater than zero:" }) && number > 0)
            {
                taskResult = $"Fibonachi sequence = {OutputService.ConvertIEnumerableToString(FindFibonachiSequence(number))}";
            }
Esempio n. 21
0
        public LogViewModel(IServiceProvider serviceProvider)
            : base("LogView", serviceProvider)
        {
            _outputService              = serviceProvider.GetRequiredService <OutputService>();
            _outputService.TextChanged += delegate { PropertyChanged("OutputText"); };

            Caption = "Log";
        }
Esempio n. 22
0
        static void Main()
        {
            var arrayService  = new ArrayService();
            var fileService   = new FileService();
            var cacheService  = new CacheService();
            var outputService = new OutputService(cacheService);

            try
            {
                var listOfArrays = fileService.ReadArray();

                var path = new List <int>();

                foreach (var array in listOfArrays)
                {
                    var pathFromCache = cacheService.GetCacheByArray(array);
                    if (pathFromCache == null)
                    {
                        path = arrayService.FindPath(array);

                        if (!arrayService.Failure) // don't save to cache if it's unreachable
                        {
                            cacheService.AddCacheToRepository(array, path);
                        }
                    }
                    else
                    {
                        path = pathFromCache;
                    }

                    Console.Write(outputService.PrepareOutput(array, path, arrayService.Failure));
                    arrayService.Failure = false;
                }

                Console.WriteLine("Would you like to see all of the cached arrays? Y/N");

                ConsoleKey response;
                do
                {
                    //Console.Write("Are you sure you want to choose this as your login key? [y/n] ");
                    response = Console.ReadKey(false).Key;   // true is intercept key (dont show), false is show
                    if (response != ConsoleKey.Enter)
                    {
                        Console.WriteLine(Environment.NewLine);
                    }
                } while (response != ConsoleKey.Y && response != ConsoleKey.N);

                if (response == ConsoleKey.Y)
                {
                    Console.WriteLine(outputService.PrepareCacheOutput());
                }
            }

            catch
            {
                Console.WriteLine("Error");
            }
        }
Esempio n. 23
0
        public int GetNumber_ConsoleInputIsValid_ReturnsResult(string str)
        {
            Console.SetIn(new StringReader(str));
            var  extractor    = Substitute.For <TaskExtractor>(OutputService.GetInstance(), InputService.GetInstance());
            bool actualResult = extractor.GetNumber(out var result, string.Empty);

            Assert.IsTrue(actualResult);
            return(result);
        }
Esempio n. 24
0
 public static void SetCurrent(DocumentViewModel value)
 {
     if (value == null)
     {
         return;
     }
     OutputService.Log($"SET Current request for {value.Model.File.Path}");
     _queue.Add(value);
 }
Esempio n. 25
0
        public void Render(string model)
        {
            _renderComplete.Reset();
            var r = new ReleaseUI($"Render ReleaseUI for {ViewModel.Model.File.Path}", true);

            ViewModel.RenderStarted();
            SuspendLayout();
            try
            {
                if (model == null)
                {
                    Log.WriteError("Model is NULL, this should not happen!", typeof(DocumentWindow).FullName, MethodBase.GetCurrentMethod().Name);
                    return;
                }


                if (InvokeRequired)
                {
                    Invoke(new Action <string>(Render), model);
                    return;
                }

                PerformanceService.StartEvent($"{PerformanceService.CONST_RenderDocument}{ViewModel.Model.File.Path}");
                OutputService.Log($"Document Render for {ViewModel.Model.File.Path}");
                Log.WriteEnter(typeof(DocumentWindow).FullName, MethodBase.GetCurrentMethod().Name);

                // Setting SelectionChangedDelayedEnabled for the first time
                if (!fctbDocument.SelectionChangedDelayedEnabled)
                {
                    fctbDocument.SelectionChangedDelayedEnabled = true;
                }
                scBase.Panel1Collapsed = !XmlDal.DataModel.Options.DocumentSourceInfo;
                PreCachePropertyLineData();
                r.DoEvents();
                sourceInfo.Render(ViewModel.Model.File);
                fctbDocument.ClearCache();
                r.DoEvents();
                fctbDocument.Text = model;
                r.DoEvents();
                ApplyFolding();
                // Force the control to paint itself now

                fctbDocument.Invalidate();
                StatusUpdate(StatusModel.Completed);
                Log.WriteTrace("Document Render Complete...", typeof(DocumentWindow).FullName, MethodBase.GetCurrentMethod().Name);
                PerformanceService.StopEvent($"Rebuild Active Document for {ViewModel.Model.File.Path}", true);
                PerformanceService.StopEvent($"{PerformanceService.CONST_RenderDocument}{ViewModel.Model.File.Path}", true);
                r.Stop();
            }
            finally
            {
                ResumeLayout();
                ViewModel.DocumentRenderComplete();
                _renderComplete.Set();
            }
        }
Esempio n. 26
0
        public string Run()
        {
            var extract = new ExtractForTasks(InputService.GetInstance(), OutputService.GetInstance());

            uint[] arrValue = extract.IndividualB5();
            uint   year     = arrValue[0],
                   mounth   = arrValue[1];

            return(IndividualTaskB5(mounth, year));
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            var inputSerivce  = new InputService();
            var outputService = new OutputService();
            var ioService     = new IOService(inputSerivce, outputService);

            var mainController = new MainController(ioService, outputService);

            mainController.Start();
        }
Esempio n. 28
0
        public static void Main(string[] args)
        {
            ServiceSelector selector = new ServiceSelector();

            IMessageService service = selector.SelectMessageService(ConfigurationManager.AppSettings["InMemoryMessageService"]);
            var             message = service.GetMessage();

            OutputService output = selector.SelectOutput(ConfigurationManager.AppSettings["ConsoleOutput"]);

            output.Write(message);
        }
Esempio n. 29
0
        static void Main(string[] args)
        {
            var inputService   = new InputService();
            var checkerService = new BingoCheckerService();
            var outputService  = new OutputService();

            bool[][] bingoMatrix = inputService.InputBingo();
            bool     isBingo     = checkerService.IsBingo(bingoMatrix);

            outputService.ShowResult(isBingo);
        }
Esempio n. 30
0
        public string Run()
        {
            var extract = new ExtractForTasks(InputService.GetInstance(), OutputService.GetInstance());

            int[] arrValue = extract.Additional1();
            int   day      = arrValue[0],
                  mounth   = arrValue[1],
                  year     = arrValue[2];

            return(AdditionalTask1(day, mounth, year));
        }