示例#1
0
        public string GetCombination()
        {
            string combination = _readService.ReadLine();

            while (!_refereeService.IsValid(combination))
            {
                _writeService.Write("Rule 4 chars picked in this list: r,j,v,b,o,n :");
                combination = _readService.ReadLine();
            }

            return(combination);
        }
        public IActionResult Write([FromQuery(Name = "event")] string eventName, [FromQuery(Name = "data")] uint data)
        {
            eventName = eventName.ToUpper();
            _writeService.Write(eventName, data);

            var response = new WriteEventResponse(eventName, data);

            return(Ok(response));
        }
示例#3
0
        public void Start()
        {
            _writeService.Write("Hi bro, enter your 4 chars combination please :");
            string solution = _engineService.GetCombination();

            Board board = new Board(solution);

            while (!board.IsGameOver)
            {
                _writeService.Write("Hi bro, enter your 4 chars combination please :");
                string play          = _engineService.GetCombination();
                bool   isWinningMove = _engineService.UpdateBoard(board, play);
                if (isWinningMove)
                {
                    _writeService.Write("GG no re");
                    return;
                }

                _engineService.PrintBoard(board, play);
            }
        }
示例#4
0
        public async Task InvokeAsync(HttpContext context, IWriteService service)
        {
            context.Request.EnableBuffering();
            if (context.Request != null)
            {
                string path        = context.Request.Path;   // api/students
                string method      = context.Request.Method; // GET, POST
                string queryString = context.Request.QueryString.ToString();
                string bodyStr     = "";

                using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8, true, 1024, true))
                {
                    bodyStr = await reader.ReadToEndAsync();

                    context.Request.Body.Position = 0;
                }
                //zapisać do pliku
                service.Write(new string[] { DateTime.Now.ToString(), path, method, queryString, bodyStr });
            }
            if (_next != null)
            {
                await _next(context);
            }
        }
示例#5
0
 public void Execute(string pathToFolder, string sourceFileName, string resultFileName)
 {
     _lines = _readService.Read(pathToFolder + sourceFileName);
     _words = _splitService.Split(_lines);
     _writeService.Write(_words, pathToFolder, resultFileName);
 }
示例#6
0
        /// <summary>
        /// Upload a set of files defined by the settings.
        /// </summary>
        /// <param name="requestHandler">Request handler</param>
        /// <param name="settings">Upload settings</param>
        public void DoUpload(IRequestHandler requestHandler, UploadSettings settings)
        {
            var pathList = settings.FilePaths?.SelectMany(i =>
            {
                if (File.Exists(i))
                {
                    return(new[] { i });
                }

                if (Directory.Exists(i))
                {
                    return(Directory.GetFiles(i, "*", SearchOption.AllDirectories));
                }

                var dir = Path.GetDirectoryName(i);
                if (Directory.Exists(dir))
                {
                    return(Directory.GetFiles(dir, Path.GetFileName(i), SearchOption.AllDirectories));
                }

                Log.Warn($"{i} specified for upload but no matching files found.");
                return(new string[0]);
            }).ToArray() ?? new string[0];

            var templateList = pathList.Select(i =>
            {
                var fileExtension     = Path.GetExtension(i);
                var metadataExtractor = _metadataExtractorFactory.GetExtractor(fileExtension);
                if (metadataExtractor == null)
                {
                    Log.Warn($"Unsupported filetype {i}.");
                    return(null);
                }

                var raw      = File.ReadAllText(i);
                var template = metadataExtractor.ExtractMetadata(raw);

                if (template.Metadata == null)
                {
                    Log.Warn($"No metadata found in {i}.");
                    return(new Tuple <string, Template>(i, template));
                }
                else if (template.Metadata.Schema == null)
                {
                    Log.Warn($"No schema found in {i}.");
                    return(new Tuple <string, Template>(i, template));
                }
                else if (template.Metadata.Name == null)
                {
                    Log.Warn($"No name found in {i}.");
                    return(new Tuple <string, Template>(i, template));
                }

                return(new Tuple <string, Template>(i, template));
            }).Where(i => i != null && i.Item2.Metadata != null && i.Item2.Metadata.Schema != null && i.Item2.Metadata.Name != null)
                               .ToArray();

            if (settings.TestMode)
            {
                Log.Info($"{templateList.Count()} files found:{Environment.NewLine}{string.Join(Environment.NewLine, templateList.Select(i => i.Item2.Metadata.Name))}");
            }
            else
            {
                var templateTotalCount     = templateList.Length;
                var templateProcessedCount = 0;
                var templateSuccessCount   = 0;
                foreach (var item in templateList)
                {
                    var filePath = item.Item1;
                    var template = item.Item2;
                    templateProcessedCount++;

                    // Get mapping for defined schema, and generate object for write
                    var mapping = _mappingFactory.GetMapping(template.Metadata.Schema.ToString());

                    // Get transformer, which is dependent on file type as well as entity type
                    var templateTransformer = mapping.GetTransformer(Path.GetExtension(filePath));

                    // The transformer may return multiple variants, each of which should be uploaded
                    var variants = templateTransformer != null
                     ? templateTransformer.Transform(template, new TransformParameters {
                        OriginalFileName = filePath,
                        ApplyTransforms  = settings.ApplyTransforms,
                    })
                     : new[] { template };

                    // Upload each variant
                    foreach (var variant in variants)
                    {
                        if (variant.Code != null && settings.Replacements != null)
                        {
                            foreach (var replacement in settings.Replacements)
                            {
                                variant.Code = variant.Code.Replace(replacement.Item1, replacement.Item2);
                            }
                        }

                        var persistable = mapping.GetPersistableItem(requestHandler, variant);

                        var response = _writeService.Write(requestHandler, persistable);
                        if (!response.Success)
                        {
                            Log.Warn($"Upload of {variant.Metadata.Name} failed: {response.Message}");
                        }
                        else
                        {
                            templateSuccessCount++;
                        }
                    }
                }

                Log.Info($"{templateSuccessCount} files uploaded.");

                // Build any schemas uploaded
                var schemaList = templateList.Where(i => i.Item2.Metadata.Schema.ToString() == Schema.EntitySchema).ToArray();
                if (schemaList.Any())
                {
                    var schemaTotalCount     = schemaList.Length;
                    var schemaProcessedCount = 0;
                    var schemaSuccessCount   = 0;
                    foreach (var item in schemaList)
                    {
                        var schema = item.Item2;
                        schemaProcessedCount++;

                        var response = _builderService.BuildSchema(requestHandler, schema.Metadata.Name);
                        if (!response.Success)
                        {
                            Log.Warn($"Build of {schema.Metadata.Name} failed: {response.Message}");
                        }
                        else
                        {
                            schemaSuccessCount++;
                        }
                    }

                    Log.Info($"{schemaSuccessCount} schemas built.");
                }

                // If any navigation hierarchies uploaded, build navigation hierarchy
                if (templateList.Any(i => i.Item2.Metadata.Schema.ToString() == NavigationHierarchy.EntitySchema))
                {
                    var response = _builderService.BuildNavigationHierarchy(requestHandler);
                    if (!response.Success)
                    {
                        Log.Warn($"Build of navigation hierarchy failed: {response.Message}");
                    }
                    else
                    {
                        Log.Info("Navigation hierarchy built.");
                    }
                }

                //
                if (settings.PublishDeliveryTemplates)
                {
                    var response = _publishingService.PublishTriggeredMessageInstances(requestHandler);
                    if (!response.Success)
                    {
                        Log.Warn($"Publishing of Message Center services failed: {response.Message}");
                    }
                    else if (response.Data != null && response.Data.Any(i => !i.Value))
                    {
                        Log.Warn($"Publishing of Message Center services failed for: {string.Join(", ", response.Data.Where(i => !i.Value).Select(i => i.Key))}");
                    }
                    else
                    {
                        Log.Info("Message Center services published.");
                    }
                }
            }
        }