Esempio n. 1
0
        public async Task <ge_data> CreateData(Guid projectId, string UserId, IAGSGroupTables tables, string filename, string description, string format = "ags")
        {
            AGSWriter writer = new AGSWriter(tables);

            string s1 = writer.CreateAGS404String(null);

            var _data = new ge_data {
                Id              = Guid.NewGuid(),
                projectId       = projectId,
                createdId       = UserId,
                createdDT       = DateTime.Now,
                editedDT        = DateTime.Now,
                editedId        = UserId,
                filename        = filename,
                filesize        = s1.Length,
                fileext         = ".ags",
                filetype        = "text/plain",
                filedate        = DateTime.Now,
                encoding        = "utf-8",
                datumProjection = datumProjection.NONE,
                pstatus         = PublishStatus.Uncontrolled,
                cstatus         = ConfidentialityStatus.RequiresClientApproval,
                version         = "P01.1",
                vstatus         = VersionStatus.Intermediate,
                qstatus         = QualitativeStatus.AECOMFactual,
                description     = description,
                operations      = "Read;Download;Update;Delete",
                file            = new ge_data_file {
                    data_string = s1
                }
            };

            return(await CreateData(_data));
        }
Esempio n. 2
0
        public async Task <IAGSGroupTables> SetLibraryAGSData(Guid Id, string[] groups = null)
        {
            if (groups == null)
            {
                groups = new string[] { "ABBR", "UNIT", "TYPE", "DICT" };
            }

            _library = await GetAGSData(Id, groups);

            return(_library);
        }
Esempio n. 3
0
        public async Task <IAGSGroupTables> GetAGSData(Guid Id, string[] groups)
        {
            string[] _lines = await GetFileAsLines(Id);

            if (_lines == null)
            {
                return(null);
            }

            AGSReader       reader     = new AGSReader(_lines);
            IAGSGroupTables ags_tables = reader.CreateAGS404GroupTables(groups);

            return(ags_tables);
        }
Esempio n. 4
0
        public async Task <IAGSGroupTables> CreateAGS(Guid Id, Guid tablemapId, string[] agstables, string options, IDataService _dataService)
        {
            ge_data_table dt = await _dataService.GetFileAsClass <ge_data_table>(Id);

            ge_table_map map = await _dataService.GetFileAsClass <ge_table_map>(tablemapId);

            if (dt != null && map != null)
            {
                IAGSGroupTables ags_file = CreateAGS(dt, map, agstables, options);
                return(ags_file);
            }

            return(null);
        }
        public async Task <IActionResult> CreateAGS(Guid Id,
                                                    Guid tablemapId,
                                                    string[] agstables,
                                                    string options,
                                                    string format = "view",
                                                    Boolean save  = false)
        {
            if (Id == Guid.Empty || tablemapId == Guid.Empty)
            {
                return(NotFound());
            }

            var _data = await _dataTableFileService.GetDataByIdWithAll(Id);

            var _tablemapId = await _dataTableFileService.GetDataByIdWithAll(tablemapId);

            var _user = await GetUserAsync();

            if (_data == null || _tablemapId == null)
            {
                return(NotFound());
            }

            ITableFileAGSService _tableFileAGSService = new TableFileAGSService();

            IAGSGroupTables _ags_tables = await _tableFileAGSService.CreateAGS(Id, tablemapId, agstables, options, _dataTableFileService);

            if (save == true)
            {
                await _dataAGSService.CreateData(_data.projectId,
                                                 _user.Id,
                                                 _ags_tables,
                                                 _data.FileNameNoExtention() + ".ags",
                                                 $"AGS Conversion from data table {_data.filename} using table map {_tablemapId.filename}",
                                                 "ags");
            }

            if (format == "view")
            {
                return(View(_ags_tables));
            }

            return(Ok(_ags_tables));
        }
Esempio n. 6
0
        public async Task <IActionResult> ReadFile(Guid Id,
                                                   string[] tables,
                                                   string format = "view",
                                                   Boolean save  = false)
        {
            IUnitOfWork     _unit        = new UnitOfWork(_context);
            IDataAGSService _dataservice = new DataAGSService(_unit);
            IAGSGroupTables ags_tables   = await _dataservice.GetAGSData(Id, tables);

            if (format == "view")
            {
                return(View(ags_tables));
            }

            if (format == "json")
            {
                return(Json(ags_tables));
            }

            return(Ok(ags_tables));
        }
Esempio n. 7
0
        public async Task <IActionResult> Read(Guid Id,
                                               string[] tables,
                                               string format = "view",
                                               Boolean save  = false)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            var _data = await _dataService.GetDataById(Id);

            if (_data == null)
            {
                return(NotFound());
            }

            IAGSGroupTables ags_tables = await _dataService.GetAGSData(Id, tables);

            if (save == true)
            {
            }

            if (format == "view")
            {
                return(View(ags_tables));
            }

            if (format == "json")
            {
                return(Json(ags_tables));
            }


            return(Ok(ags_tables));
        }
Esempio n. 8
0
 public AGSWriter(IAGSGroupTables tables)
 {
     _tables = tables;
 }
Esempio n. 9
0
        public async Task <int> AddLibraryAGSData(IAGSGroupTables tables, Guid?LibraryAGSDataId)
        {
            if (LibraryAGSDataId != null)
            {
                await SetLibraryAGSData(LibraryAGSDataId.Value);
            }

            if (_library == null)
            {
                return(-1);
            }

            AGS404GroupTables ags404_lib = (AGS404GroupTables)_library;
            AGS404GroupTables _tables    = (AGS404GroupTables)tables;

            // ABBR

            if (_tables.ABBR != null)
            {
                foreach (ABBR abbr in _tables.ABBR.values)
                {
                    ABBR abbr_lib = ags404_lib.ABBR.values.Find(e => e.ABBR_CODE == abbr.ABBR_CODE &&
                                                                e.ABBR_HDNG == abbr.ABBR_HDNG);
                    if (abbr_lib != null)
                    {
                        abbr.ABBR_DESC = abbr_lib.ABBR_DESC;
                        abbr.ABBR_REM  = abbr_lib.ABBR_REM;
                    }
                }
            }

            if (_tables.UNIT != null)
            {
                foreach (UNIT unit in _tables.UNIT.values)
                {
                    UNIT unit_lib = ags404_lib.UNIT.values.Find(e => e.UNIT_UNIT == unit.UNIT_UNIT);
                    if (unit_lib != null)
                    {
                        unit.UNIT_DESC = unit_lib.UNIT_DESC;
                        unit.UNIT_REM  = unit_lib.UNIT_REM;
                    }
                }
            }

            if (_tables.TYPE != null)
            {
                foreach (TYPE type in _tables.TYPE.values)
                {
                    TYPE type_lib = ags404_lib.TYPE.values.Find(e => e.TYPE_TYPE == type.TYPE_TYPE);
                    if (type_lib != null)
                    {
                        type.TYPE_DESC = type_lib.TYPE_DESC;
                        //    type.TYPE_REM = type_lib.TYPE_REM;
                    }
                }
            }

            if (_tables.DICT != null)
            {
                foreach (DICT dict in _tables.DICT.values)
                {
                    DICT dict_lib = ags404_lib.DICT.values.Find(e => e.DICT_HDNG == dict.DICT_HDNG &&
                                                                e.DICT_PGRP == dict.DICT_PGRP);
                    if (dict_lib != null)
                    {
                        dict.DICT_DESC = dict_lib.DICT_DESC;
                        dict.DICT_DTYP = dict_lib.DICT_DTYP;
                        dict.DICT_EXMP = dict_lib.DICT_EXMP;
                        dict.DICT_REM  = dict_lib.DICT_REM;
                    }
                }
            }

            return(1);
        }
        public async Task <IActionResult> ProcessFileToAGS(Guid Id,
                                                           Guid?templateId,
                                                           string table,
                                                           string sheet,
                                                           Guid?tablemapId,
                                                           string[] agstables,
                                                           Guid?agslibraryId,
                                                           string options = "",
                                                           string format  = "view",
                                                           Boolean save   = false)
        {
            Boolean save_file = true;
            Boolean save_ags  = save;

            if (options == null)
            {
                options = "";
            }

            if (options.Contains("background"))
            {
                if (save == true && !options.Contains("save_ags"))
                {
                    options += ",save_ags";
                }

                return(await ProcessFileBackground(Id,
                                                   templateId,
                                                   table,
                                                   sheet,
                                                   tablemapId,
                                                   agstables,
                                                   options));
            }

            if (options.Contains("read_file_only"))
            {
                save_file = false;
            }

            var calc_resp = await ReadFile(Id, templateId.Value, table, sheet, "", save_file);

            var okResult = calc_resp as OkObjectResult;

            if (okResult == null)
            {
                var vwResult = calc_resp as ViewResult;

                if (vwResult == null)
                {
                    return(Json(calc_resp));
                }

                return(calc_resp);
                // return View ("OperationRequest",calc_resp);
            }

            ge_data_table _dt_file = okResult.Value as ge_data_table;

            if (options.Contains("view_file"))
            {
                if (format == "view")
                {
                    return(View("ReadData", _dt_file));
                }

                if (format == "json")
                {
                    return(Json(_dt_file));
                }

                return(Ok(_dt_file));
            }

            if (save_file == false)
            {
                ITableFileAGSService _tableFileAGSService = new TableFileAGSService();
                ge_table_map         _tm = await _dataTableFileService.GetFileAsClass <ge_table_map>(tablemapId.Value);

                if (_tm == null)
                {
                    return(Json($"table map for field not found for id={tablemapId.Value}"));
                }

                IAGSGroupTables _ags_tables = _tableFileAGSService.CreateAGS(_dt_file, _tm, agstables, options);

                if (agslibraryId != null)
                {
                    await _dataAGSService.SetLibraryAGSData(agslibraryId.Value, null);
                }

                await _dataAGSService.AddLibraryAGSData(_ags_tables, null);

                if (save_ags == true)
                {
                    var _data = await _dataTableFileService.GetDataByIdWithAll(Id);

                    var _tablemap = await _dataTableFileService.GetDataByIdWithAll(tablemapId.Value);

                    var _user = await GetUserAsync();

                    await _dataAGSService.CreateData(_data.projectId,
                                                     _user.Id,
                                                     _ags_tables,
                                                     _data.FileNameNoExtention() + ".ags",
                                                     $"AGS Conversion from data table {_data.filename} using table map {_tablemap.filename}",
                                                     "ags");
                }

                if (format == "view")
                {
                    return(View(_ags_tables));
                }

                if (format == "json")
                {
                    return(Json(_ags_tables));
                }

                return(Ok(_ags_tables));
                // return await View  (mond, format);
            }

            return(await CreateAGS(Id, tablemapId.Value, agstables, options, format, save_ags));
        }