public async Task <ge_AGS_Client.enumStatus> NewAGSClientAsync(ags_config Config,
                                                                Guid Id,
                                                                String UserId)
 {
     return(await Task.Run(() => NewAGSClient (Config,
                                               Id,
                                               UserId)));
 }
        public ge_AGS_Client.enumStatus NewAGSClient(ags_config Config,
                                                     Guid Id,
                                                     String UserId)
        {
            var          scope    = _serviceScopeFactory.CreateScope();
            ge_DbContext _context = scope.ServiceProvider.GetService <ge_DbContext>();

            IUnitOfWork  _unit        = new UnitOfWork(_context);
            IDataService _dataService = new DataService(_unit);

            ge_AGS_Client ac = new ge_AGS_Client(Config,
                                                 Id,
                                                 _dataService,
                                                 UserId);

            if (!ac.IsConnected())
            {
                return(AGS_Client_Base.enumStatus.NotConnected);
            }

            ac.start();

            return(AGS_Client_Base.enumStatus.Connected);
        }
        public async Task <IActionResult> CreateXML(Guid Id, string dictionary_file, string data_structure, string options = "")
        {
            if (Id == null)
            {
                // return NotFound();
                return(Json("Id not found"));
            }

            ge_data data = await _dataService.GetDataByIdWithAll(Id);

            Boolean ignore_pflag = options.Contains("ignore_pflag");

            if (data == null)
            {
                // return NotFound();
                return(Json("data not found"));
            }

            if (data.fileext != FileExtension.AGS)
            {
                return(RedirectToPageMessage(msgCODE.AGS_UNKNOWN_FILE));
            }

            if (data.pflag == pflagCODE.PROCESSING && ignore_pflag == false)
            {
                return(RedirectToPageMessage(msgCODE.AGS_PROCESSING_FILE));
            }

            if (_agsConfig == null)
            {
                // return NotFound();
                return(Json("agsConfig not found"));
            }

            ags_config config = _agsConfig.Value;

            if (data_structure != null)
            {
                config.data_structure = data_structure;
            }

            if (dictionary_file != null)
            {
                config.dictionary_file = dictionary_file;
            }

            ge_user user = await GetUserAsync();

            var _OperationRequest = await _userService.GetOperationRequest(user.Id, data);

            if (_OperationRequest.AreProjectOperationsAllowed("Download;Create") == false)
            {
                return(View("OperationRequest", _OperationRequest));
            }

            IAGSConvertXMLService _agsConvertXml = new AGSConvertXMLService(_serviceScopeFactory);

            var resp = _agsConvertXml.NewAGSClientAsync(config, Id, user.Id);

            return(Ok($"AGS Processing File {data.filename} ({data.filesize} bytes), the pflag status will remain as 'Processing' until this workflow is complete"));
        }