Beispiel #1
0
 private ICollection <TElement> ProcessArrayType(string[] dataList)
 {
     TElement[] collection = CreateElementArray(dataList.Length);
     for (int i = 0; i < dataList.Length; i++)
     {
         string tempItem = _trimWhitespace ? dataList[i].Trim() : dataList[i];
         collection[i] = (TElement)_elementProcessor.Process(tempItem);
     }
     return(collection);
 }
Beispiel #2
0
        public DataObject Process(ResourceID ID, ResourceManager ResourceManager)
        {
            IDataProcessor processor = ResourceManager.GetDataProcessor("burngfxmap");
            MapData        data      = processor.Process(ID, ResourceManager) as MapData;

            return(data);
        }
Beispiel #3
0
        public async Task Process()
        {
            var jobs = await _jobRepository.FindAllByState(JobState.Waiting);

            foreach (var job in jobs)
            {
                RegisterStarted(job, DateTime.Now);

                foreach (var dataPoint in job.DataPoints)
                {
                    try
                    {
                        var result = await _processor.Process(dataPoint.Data);

                        RegisterSuccess(job, result, DateTime.Now);
                    }
                    catch (Exception e)
                    {
                        RegisterError(job, e.Message, DateTime.Now);

                        if (!job.CanContinue())
                        {
                            RegisterJobCanceled(job, DateTime.Now);
                            break;
                        }
                    }
                }

                RegisterJobFinished(job, DateTime.Now);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Invoked for each piece of data from the source file
 /// </summary>
 /// <param name="data">The data to be processed</param>
 public void Process(BaseData data)
 {
     if (_predicate(data))
     {
         _processor.Process(data);
     }
 }
        public DataObject GetData(ResourceID id, ResourceLoadType loadType)
        {
            DataObject obj;

            if (dataObjects.ContainsKey(id))
            {
                obj = dataObjects[id];
            }
            else if (loadType == ResourceLoadType.Now)
            {
                IDataProcessor processor = GetDataProcessor(id.Format);

                engine.IncreaseLoadingCount();
                obj = processor.Process(id, this);
                Log.Debug("load \"" + id + "\"");
                obj.resourceManager = this;
                obj.DataName        = id;
                obj.PostProcess();
                engine.DecreaseLoadingCount();

                dataObjects.Add(id, obj);
            }
            else
            {
                obj = new NullDataObject(id, this);
            }

            return(obj);
        }
Beispiel #6
0
        public void Run()
        {
            var inputModels = _inputStrategy.Load();

            var outputModels = _dataProcessor.Process(inputModels);

            _outputWriter.Write(outputModels);
        }
        /// <summary>
        /// Processes the data
        /// </summary>
        /// <param name="data">A processing data</param>
        /// <returns>Processed data</returns>
        public string Process(string data)
        {
            _logger.Info("Try to process a data");
            var length = _lengthDataProcessor.Process(data);

            _logger.Info("A data processed");

            return(JsonConvert.SerializeObject(new { length = length }));
        }
Beispiel #8
0
        public string Handle(string data)
        {
            string processedData = _processor.Process(data);

            if (_db != null)
            {
                _db.SaveCollection(processedData, CollectionName, Database);
            }
            return(processedData);
        }
        private async Task ProcessMessageAsync(Orderbook item)
        {
            try
            {
                _dataProcessor.Process(item);
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(OrderbookSubscriber), nameof(ProcessMessageAsync), ex);

                throw;
            }
        }
        public async Task <int> Run()
        {
            try
            {
                await processor.Process();

                return(0);
            }
            catch (Exception exception)
            {
                logger.LogCritical($"Unexpected error: {exception}");
                return(1);
            }
        }
Beispiel #11
0
        public DataObject Process(ResourceID ID, ResourceManager ResourceManager)
        {
            IDataProcessor processor = ResourceManager.GetDataProcessor("burngfxmap");
            MapData        data      = processor.Process(ID, ResourceManager) as MapData;

            int map = 0;

            if (ID.Custom != null)
            {
                map = int.Parse(ID.Custom);
            }

            for (int i = 0; i < data.Tiles.Length; i++)
            {
                data.Tiles[i].Image = ResourceManager.GetImage("burngfxtile@zei_" + data.Tiles[i].Section.ToString("D3") + ".raw?" + data.Tiles[i].Item.ToString() + "?" + map, ResourceLoadType.Delayed);
            }

            return(data);
        }
        /// <summary>
        /// Handles the <see cref="IDataConsolidator.DataConsolidated"/> event
        /// </summary>
        private void OnDataConsolidated(object sender, BaseData args)
        {
            _destination.Process(args);

            // we've already checked this frontier time, so don't scan the consolidators
            if (_frontier >= args.EndTime)
            {
                return;
            }
            _frontier = args.EndTime;

            // check the other consolidators to see if they also need to emit
            foreach (var consolidator in _consolidators.Values)
            {
                // back up the time a single instance, this allows data at exact same
                // time to still come through
                consolidator.Scan(args.EndTime.AddTicks(-1));
            }
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Paste endpoint address like: 'net.pipe://127.0.0.1/RandomizerPipe1234' to connect to.");
            string endpoint = Console.ReadLine();
            ChannelFactory <IDataProcessor> dataProcessorFactory = new ChannelFactory <IDataProcessor>(new NetNamedPipeBinding(),
                                                                                                       new EndpointAddress(endpoint));//Do not recreate everytime

            while (true)
            {
                Console.WriteLine("Press [Enter] to process;");
                Console.ReadLine();
                var       msg = new DataMessage();
                Stopwatch s   = new Stopwatch();
                s.Start();
                IDataProcessor dataProceesorProxy = dataProcessorFactory.CreateChannel(); //Can be recreated everytime when required
                var            res = dataProceesorProxy.Process(msg);                     //Make rpc via ipc call.
                s.Stop();
                Console.WriteLine("It took " + res.Throws + " attempts to get rnd.Next(0, 10000000) == 500000.");
                Console.WriteLine("Last processing call took " + res.ServerTime + "ms on server");
                Console.WriteLine("Last processing call took " + (s.ElapsedMilliseconds - res.ServerTime) + "ms for data transfer");
            }
        }
        private static string ValidateAndProcess <T>(IDataProcessor <T> processor, JObject dataObject)
        {
            string errors = string.Empty;

            ValidationResult validationResult = processor.Validator.Validate(dataObject);

            if (!validationResult.IsValid)
            {
                foreach (var error in validationResult.Errors)
                {
                    errors += error.ErrorMessage + "\n";
                }
            }
            else
            {
                try
                {
                    var result = processor.Process(dataObject);

                    if (result == null)
                    {
                        errors += "Failed to process object of type: " + dataObject.GetType() + " Reason: Processor failed to return valid DatabaseAction object";
                    }
                    else
                    {
                        _queuedDBChanges.Enqueue(result);
                    }
                }
                catch (Exception ex)
                {
                    errors += "Failed to process object of type: " + dataObject.GetType() + " Reason: " + ex.ToMessageAndCompleteStacktrace();
                }
            };

            return(errors);
        }
        public async Task <IActionResult> Upload()
        {
            if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
            {
                return(BadRequest($"Expected a multipart request, but got {Request.ContentType}"));
            }

            var filePath = Directory.GetCurrentDirectory() + @"\UploadedFiles";

            Directory.CreateDirectory(filePath);
            var targetFilePath = filePath + @"\" + "test.csv";

            // Used to accumulate all the form url encoded key value pairs in the request.
            var formAccumulator = new KeyValueAccumulator();

            var boundary = MultipartRequestHelper.GetBoundary(
                MediaTypeHeaderValue.Parse(Request.ContentType),
                DefaultFormOptions.MultipartBoundaryLengthLimit);
            var reader = new MultipartReader(boundary, HttpContext.Request.Body);

            var section = await reader.ReadNextSectionAsync();

            while (section != null)
            {
                var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);

                if (hasContentDispositionHeader)
                {
                    if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition))
                    {
                        //targetFilePath =Path.GetTempFileName();
                        using (var targetStream = System.IO.File.Create(targetFilePath))
                        {
                            await section.Body.CopyToAsync(targetStream);

                            _logger.LogInformation($"Copied the uploaded file '{targetFilePath}'");
                        }
                    }
                    else if (MultipartRequestHelper.HasFormDataContentDisposition(contentDisposition))
                    {
                        // Content-Disposition: form-data; name="key" value
                        // Do not limit the key name length here because the
                        // multipart headers length limit is already in effect.
                        var key      = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
                        var encoding = GetEncoding(section);
                        using (var streamReader = new StreamReader(
                                   section.Body,
                                   encoding,
                                   detectEncodingFromByteOrderMarks: true,
                                   bufferSize: 1024,
                                   leaveOpen: true))
                        {
                            // The value length limit is enforced by MultipartBodyLengthLimit
                            var value = await streamReader.ReadToEndAsync();

                            if (String.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase))
                            {
                                value = String.Empty;
                            }

                            formAccumulator.Append(key.ToString(), value);

                            if (formAccumulator.ValueCount > DefaultFormOptions.ValueCountLimit)
                            {
                                throw new InvalidDataException($"Form key count limit {DefaultFormOptions.ValueCountLimit} exceeded.");
                            }
                        }
                    }
                }

                // Drains any remaining section body that has not been consumed and
                // reads the headers for the next section.
                section = await reader.ReadNextSectionAsync();
            }

            // Bind form data to a model
            var upload            = new Upload();
            var formValueProvider = new FormValueProvider(
                BindingSource.Form,
                new FormCollection(formAccumulator.GetResults()),
                CultureInfo.CurrentCulture);

            var bindingSuccessful = await TryUpdateModelAsync(upload, prefix : "", valueProvider : formValueProvider);

            if (!bindingSuccessful)
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
            }

            var uploadedData = new UploadedData()
            {
                FilePath = targetFilePath
            };

            _processor.Process(uploadedData);

            return(Ok(new { filePath = uploadedData.FilePath }));
        }
Beispiel #16
0
        public DataObject Process(ResourceID ID, ResourceManager ResourceManager)
        {
            MapData data = new MapData();

            data.DataName = ID;
            Map map = new Map(ID.File);

            data.Width    = map.width;
            data.Height   = map.height;
            data.TileSize = new Vector2(32, 32);

            data.Tiles = new MapTile[data.Width * data.Height];
            for (int i = 0; i < map.data.Length; i++)
            {
                data.Tiles[i].Section = (short)(map.data[i] & 0xff);
                data.Tiles[i].Item    = (short)(map.data[i] >> 8);
            }

            data.Entrances = new MapEntrance[map.Doors.Count];
            for (int i = 0; i < map.Doors.Count; i++)
            {
                data.Entrances[i].Area = map.Doors[i].Area;
                if (map.Doors[i].RoomID < 4)
                {
                    data.Entrances[i].RoomType = RoomType.Normal;
                }
                else if (map.Doors[i].RoomID < 9)
                {
                    data.Entrances[i].RoomType = RoomType.WaterSource;
                }
                else if (map.Doors[i].RoomID == 9)
                {
                    data.Entrances[i].RoomType = RoomType.Rope;
                }
                else if (map.Doors[i].RoomID == 16)
                {
                    data.Entrances[i].RoomType = RoomType.Church;
                }
                else if (map.Doors[i].RoomID == 0xd || map.Doors[i].RoomID == 0x11)
                {
                    data.Entrances[i].RoomType = RoomType.Trader;
                }
                else if (map.Doors[i].RoomID == 14 || map.Doors[i].RoomID == 23)
                {
                    data.Entrances[i].RoomType = RoomType.Pub;
                }
                else if (map.Doors[i].RoomID == 20)
                {
                    data.Entrances[i].RoomType = RoomType.Doctor;
                }
                else if (map.Doors[i].RoomID == 22 || map.Doors[i].RoomID == 24)
                {
                    data.Entrances[i].RoomType = RoomType.Restaurant;
                }
                else
                {
                    data.Entrances[i].RoomType = RoomType.Scene;
                }
                data.Entrances[i].Background = map.Doors[i].RoomID;
                data.Entrances[i].TitleId    = "burn?" + (660 + map.Doors[i].RoomID);
            }

            data.Mask = new PathMask(data.Width * 4, data.Height * 4, 8);

            foreach (Vector2 pos in new Rect(0, 0, data.Width, data.Height))
            {
                String         res       = "burngfxtilemask@zei_" + data[pos].Section.ToString("D3") + ".raw?" + data[pos].Item;
                IDataProcessor processor = ResourceManager.GetDataProcessor("burngfxtilemask");
                TileMaskData   tile      = processor.Process(res, ResourceManager) as TileMaskData;

                foreach (Vector2 sub in new Rect(0, 0, 4, 4))
                {
                    //data.Mask[pos * 4 + sub] = !(pos.x == 0 && sub.x == 0 || pos.y == 0 && sub.y == 0 || (pos.x == data.Width - 1 && sub.x == 3) || (pos.y == data.Height - 1 && sub.y == 3));
                    //data.Mask[pos * 4 + sub] &= tile[sub];
                    data.Mask[pos * 4 + sub] = tile[sub];
                }
            }

            return(data);
        }
Beispiel #17
0
        public DataObject Process(ResourceID id, ResourceManager ResourceManager)
        {
            int map = 0;

            if (id.Custom != null)
            {
                map = int.Parse(id.Custom);
            }

            IDataProcessor processor = ResourceManager.GetDataProcessor("burngfxmap");
            MapData        raw       = null;

            if (FileSystem.ExistsFile(System.IO.Path.GetFileNameWithoutExtension(id.File) + ".raw"))
            {
                raw = processor.Process(System.IO.Path.GetFileNameWithoutExtension(id.File) + ".raw??" + map, ResourceManager) as MapData;
            }

            MapData data = new MapData();

            Burntime.Platform.IO.File file = Burntime.Platform.IO.FileSystem.GetFile(id.File);
            BinaryReader reader            = new BinaryReader(file);

            if (reader.ReadString() != "Burntime Map")
            {
                return(null);
            }
            String ver = reader.ReadString();

            if (ver != "0.2")
            {
                return(null);
            }

            // header
            data.Width    = reader.ReadInt32();
            data.Height   = reader.ReadInt32();
            data.TileSize = Vector2.One * reader.ReadInt32();

            data.Tiles = new Burntime.Data.BurnGfx.MapTile[data.Width * data.Height];
            data.Mask  = new Burntime.Data.BurnGfx.PathMask(data.Width * 4, data.Height * 4, 8);

            // set indices
            List <String> indices = new List <string>();
            int           count   = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                indices.Add(reader.ReadString());
            }

            ConfigFile settings = new ConfigFile();

            if (FileSystem.ExistsFile(id.File.Replace(".burnmap", ".txt")))
            {
                settings.Open(FileSystem.GetFile(id.File.Replace(".burnmap", ".txt")));
            }
            else
            {
                settings = null;
            }

            //Dictionary<String, int> indices2 = new Dictionary<string, int>();
            //for (int i = 0; i < TileSets.Count; i++)
            //    indices2.Add(TileSets[i].Name, i);

            // tiles
            for (int y = 0; y < data.Height; y++)
            {
                for (int x = 0; x < data.Width; x++)
                {
                    byte _id    = reader.ReadByte();
                    byte subset = reader.ReadByte();
                    byte set    = reader.ReadByte();

                    if (subset == 0)
                    {
                    }
                    else
                    {
                        Burntime.Data.BurnGfx.MapTile tile = new Burntime.Data.BurnGfx.MapTile();
                        tile.Item    = _id;
                        tile.Section = subset;

                        data.Tiles[x + y * data.Width] = tile;

                        String maskFile = "gfx/tiles/" + subset.ToString("D3") + "_" + _id.ToString("D2") + ".txt";
                        if (Burntime.Platform.IO.FileSystem.ExistsFile(maskFile))
                        {
                            Burntime.Platform.IO.File maskfile = Burntime.Platform.IO.FileSystem.GetFile(maskFile);
                            TextReader maskreader = new StreamReader(maskfile);

                            for (int k = 0; k < 4; k++)
                            {
                                String line = maskreader.ReadLine();
                                if (line.Length < 4)
                                {
                                    continue;
                                }

                                char[] chrs = line.ToCharArray();
                                data.Mask[4 * x + 0, 4 * y + k] = (chrs[0] != '1');
                                data.Mask[4 * x + 1, 4 * y + k] = (chrs[1] != '1');
                                data.Mask[4 * x + 2, 4 * y + k] = (chrs[2] != '1');
                                data.Mask[4 * x + 3, 4 * y + k] = (chrs[3] != '1');
                            }

                            maskreader.Close();
                            maskfile.Close();
                        }
                        else
                        {
                            for (int k = 0; k < 4; k++)
                            {
                                data.Mask[4 * x + 0, 4 * y + k] = true;
                                data.Mask[4 * x + 1, 4 * y + k] = true;
                                data.Mask[4 * x + 2, 4 * y + k] = true;
                                data.Mask[4 * x + 3, 4 * y + k] = true;
                            }
                        }
                    }
                }
            }

            foreach (Vector2 pos in new Rect(0, 0, data.Width, data.Height))
            {
                if (data[pos].Section >= 90)
                {
                    foreach (Vector2 sub in new Rect(0, 0, 4, 4))
                    {
                        data.Mask[pos * 4 + sub] &= !(pos.x == 0 && sub.x == 0 || pos.y == 0 && sub.y == 0 ||
                                                      (pos.x == data.Width - 1 && sub.x == 3) || (pos.y == data.Height - 1 && sub.y == 3));
                    }
                }
                else
                {
                    String         res  = "burngfxtilemask@zei_" + data[pos].Section.ToString("D3") + ".raw?" + data[pos].Item;
                    IDataProcessor p    = ResourceManager.GetDataProcessor("burngfxtilemask");
                    TileMaskData   tile = p.Process(res, ResourceManager) as TileMaskData;

                    foreach (Vector2 sub in new Rect(0, 0, 4, 4))
                    {
                        data.Mask[pos * 4 + sub] = !(pos.x == 0 && sub.x == 0 || pos.y == 0 && sub.y == 0 ||
                                                     (pos.x == data.Width - 1 && sub.x == 3) || (pos.y == data.Height - 1 && sub.y == 3));
                        data.Mask[pos * 4 + sub] &= tile[sub];
                    }
                }
            }

            // fixed items
            //string[] items = settings[""].GetStrings("fixed_item");
            //bool[] items_room = settings[""].GetBools("fixed_item_room");
            //Vector2[] items_pos = settings[""].GetVector2s("fixed_item_pos");

            //data.FixedItems = new FixedItem[items.Length];
            //for (int i = 0; i < items.Length; i++)
            //{
            //    data.FixedItems[i].Item = items[i];
            //    data.FixedItems[i].Room = items_room[i] ? items_pos[i].x : -1;
            //    data.FixedItems[i].Position = items_room[i] ? Vector2.Zero : items_pos[i];
            //}

            // entrances
            count          = reader.ReadByte();
            data.Entrances = new MapEntrance[count];

            for (int i = 0; i < count; i++)
            {
                MapEntrance e = new MapEntrance();

                // take data from original Burntime as default
#warning        // TODO this should be only temporary
                if (raw != null && raw.Entrances.Length > i)
                {
                    e = raw.Entrances[i];
                }

//                e.RoomType = Burntime.Data.BurnGfx.RoomType.Normal;

                e.Area.Left   = reader.ReadInt32();
                e.Area.Top    = reader.ReadInt32();
                e.Area.Width  = reader.ReadInt32();
                e.Area.Height = reader.ReadInt32();

//#warning TODO insert proper images and titles
//                e.Background = 0;// settings["room" + i].GetString("image");
                if (settings != null)
                {
                    e.TitleId = settings["room" + i].GetString("title");
                }
//                //e.Key = settings["room" + i].GetString("key");

                data.Entrances[i] = e;
            }

            //if (ver == "0.2")
            //{
            //    count = reader.ReadInt32();
            //    for (int i = 0; i < count; i++)
            //    {
            //        Way way = new Way();
            //        way.Days = reader.ReadByte();
            //        way.Entrance[0] = reader.ReadByte();
            //        way.Entrance[1] = reader.ReadByte();

            //        int wpc = reader.ReadByte();
            //        for (int j = 0; j < wpc; j++)
            //        {
            //            Point pt = new Point();
            //            pt.X = reader.ReadInt32();
            //            pt.Y = reader.ReadInt32();
            //            way.Points.Add(pt);
            //        }
            //    }
            //}

            file.Close();

            for (int i = 0; i < data.Tiles.Length; i++)
            {
                if (data.Tiles[i].Section >= 90)
                {
                    data.Tiles[i].Image = ResourceManager.GetImage("gfx/tiles/" + data.Tiles[i].Section.ToString("D3") + "_" + data.Tiles[i].Item.ToString("D2") + ".png", ResourceLoadType.Delayed);
                }
                else
                {
                    data.Tiles[i].Image = ResourceManager.GetImage("burngfxtile@zei_" + data.Tiles[i].Section.ToString("D3") + ".raw?" + data.Tiles[i].Item.ToString() + "?" + map, ResourceLoadType.Delayed);
                }
            }

            return(data);
        }