async Task <ExpandoObject> SaveFlat(String format, RequestFile rf, Stream stream, ExpandoObject prms)
        {
            if (_externalDataProvider == null)
            {
                throw new ArgumentNullException(nameof(_externalDataProvider));
            }
            IFormatProvider formatProvider = CultureInfo.InvariantCulture;
            var             rdr            = _externalDataProvider.GetReader(format, null, null);

            if (String.IsNullOrEmpty(rf.CurrentModel))
            {
                return(rdr.CreateDataModel(stream));
            }
            else
            {
                var dm = await _dbContext.SaveModelAsync(rf.CurrentSource, rf.UpdateProcedure, null, prms,
                                                         (table) =>
                {
                    if (!String.IsNullOrEmpty(rf.locale))
                    {
                        table.FormatProvider = CultureInfo.GetCultureInfo(rf.locale);
                    }
                    return(rdr.ParseFile(stream, table));
                },
                                                         rf.commandTimeout
                                                         );

                return(dm?.Root);
            }
        }
Example #2
0
        async Task <Object> SaveFilesSql(RequestFile ru, ExpandoObject prms, HttpFileCollectionBase files)
        {
            AttachmentUpdateInfo ii = new AttachmentUpdateInfo()
            {
                UserId = prms.Get <Int64>("UserId")
            };

            if (_host.IsMultiTenant)
            {
                ii.TenantId = prms.Get <Int32>("TenantId");
            }
            var resultList = new List <AttachmentUpdateResult>();

            for (Int32 i = 0; i < files.Count; i++)
            {
                HttpPostedFileBase file = files[i];
                ii.Name   = Path.GetFileName(file.FileName);
                ii.Mime   = file.ContentType;
                ii.Stream = file.InputStream;
                var result = await _dbContext.ExecuteAndLoadAsync <AttachmentUpdateInfo, AttachmentUpdateResult>(ru.CurrentSource, ru.FileProcedureUpdate, ii);

                resultList.Add(result);
            }
            return(resultList);
        }
Example #3
0
        async Task <ExpandoObject> SaveJson(RequestFile rf, Stream stream, ExpandoObject prms)
        {
            using (var sr = new StreamReader(stream)) {
                String json = sr.ReadToEnd();
                var    data = JsonConvert.DeserializeObject <ExpandoObject>(json);
                var    res  = await _dbContext.SaveModelAsync(rf.CurrentSource, rf.UpdateProcedure, data, prms);

                return(res.Root);
            }
        }
        async Task <IDataModel> SaveExcel(RequestFile ru, Stream stream, ExpandoObject prms)
        {
            using (var xp = new ExcelParser())
            {
                xp.ErrorMessage = "UI:@[Error.FileFormatException]";
                IDataModel dm = await _dbContext.SaveModelAsync(ru.CurrentSource, ru.UpdateProcedure, null, prms, (table) => {
                    return(xp.ParseFile(stream, table));
                });

                return(dm);
            }
        }
Example #5
0
        async Task <Object> DoUploadClr(RequestFile ru, ExpandoObject prms)
        {
            var    invoker = new ClrInvoker();
            Object result;

            if (ru.async)
            {
                result = await invoker.InvokeAsync(ru.clrType, prms);
            }
            else
            {
                result = invoker.Invoke(ru.clrType, prms);
            }
            return(result);
        }
        async Task <ExpandoObject> SaveExcel(RequestFile ru, Stream stream, ExpandoObject prms, String fileName)
        {
            if (ru.availableModels != null)
            {
                using (var xp = new ExcelParser())
                {
                    if (fileName != null)
                    {
                        prms.Set("FileName", fileName);
                    }
                    var    epr  = xp.CreateDataModel(stream);
                    String cols = String.Join("|", epr.Columns);
                    var    fm   = ru.FindModel(null, cols);
                    if (fm == null)
                    {
                        throw new RequestModelException($"There is no model for columns='{cols}'");
                    }
                    prms.Append(fm.parameters);
                    var dm = await _dbContext.SaveModelAsync(fm.CurrentSource(ru), fm.UpdateProcedure(ru), epr.Data, prms);

                    return(dm?.Root);
                }
            }
            else if (String.IsNullOrEmpty(ru.CurrentModel))
            {
                using (var xp = new ExcelParser())
                {
                    var epr = xp.CreateDataModel(stream);
                    return(epr.Data);
                }
            }
            else
            {
                using (var xp = new ExcelParser())
                {
                    xp.ErrorMessage = "UI:@[Error.FileFormatException]";
                    IDataModel dm = await _dbContext.SaveModelAsync(ru.CurrentSource, ru.UpdateProcedure, null, prms, (table) =>
                    {
                        return(xp.ParseFile(stream, table).Data);
                    });

                    return(dm?.Root);
                }
            }
        }
        async Task <Object> SaveFilesAzureStorage(RequestFile ru, ExpandoObject prms, HttpFileCollectionBase files)
        {
            AttachmentUpdateInfo ii = new AttachmentUpdateInfo()
            {
                UserId = prms.Get <Int64>("UserId")
            };

            if (_host.IsMultiTenant)
            {
                ii.TenantId = prms.Get <Int32>("TenantId");
            }
            var resultList  = new List <AttachmentUpdateIdToken>();
            var azureClient = new AzureStorageRestClient();

            for (Int32 i = 0; i < files.Count; i++)
            {
                HttpPostedFileBase file = files[i];
                var blobName            = $"{Guid.NewGuid()}_{Path.GetFileName(file.FileName)}";

                var azureStream = file.InputStream;
                if (ru.imageCompress != null && IsImageForCompress(ru.imageCompress, file))
                {
                    azureStream = CompressImage(file.InputStream, file.ContentType, ru.imageCompress.quality);
                }

                await azureClient.Put(ru.azureSource, ru.container, blobName, azureStream, azureStream.Length);

                ii.Name     = Path.GetFileName(file.FileName);
                ii.Mime     = file.ContentType;
                ii.Stream   = null;
                ii.BlobName = $"{ru.container}/{blobName}";
                var result = await _dbContext.ExecuteAndLoadAsync <AttachmentUpdateInfo, AttachmentUpdateOutput>(ru.CurrentSource, ru.FileProcedureUpdate, ii);

                resultList.Add(new AttachmentUpdateIdToken()
                {
                    Id    = result.Id,
                    Name  = ii.Name,
                    Mime  = ii.Mime,
                    Token = result != null ? _tokenProvider.GenerateToken(result.Token) : null
                }
                               );
            }
            return(resultList);
        }
        async Task <Object> SaveFilesSql(RequestFile ru, ExpandoObject prms, HttpFileCollectionBase files)
        {
            AttachmentUpdateInfo ii = new AttachmentUpdateInfo()
            {
                UserId = prms.Get <Int64>("UserId")
            };

            if (_host.IsMultiTenant)
            {
                ii.TenantId = prms.Get <Int32>("TenantId");
            }

            ImageSettings compress = ru.imageCompress;

            var resultList = new List <AttachmentUpdateIdToken>();

            for (Int32 i = 0; i < files.Count; i++)
            {
                HttpPostedFileBase file = files[i];
                ii.Name = Path.GetFileName(file.FileName);
                ii.Mime = file.ContentType;
                if (compress != null && IsImageForCompress(compress, file))
                {
                    ii.Stream = CompressImage(file.InputStream, file.ContentType, compress.quality);
                }
                else
                {
                    ii.Stream = file.InputStream;
                }
                var result = await _dbContext.ExecuteAndLoadAsync <AttachmentUpdateInfo, AttachmentUpdateOutput>(ru.CurrentSource, ru.FileProcedureUpdate, ii);

                resultList.Add(new AttachmentUpdateIdToken()
                {
                    Id    = result.Id,
                    Name  = ii.Name,
                    Mime  = ii.Mime,
                    Token = result != null ? _tokenProvider.GenerateToken(result.Token) : null
                }
                               );
            }
            return(resultList);
        }
Example #9
0
        async Task <ExpandoObject> SaveFlat(String format, RequestFile ru, Stream stream, ExpandoObject prms)
        {
            if (_externalDataProvider == null)
            {
                throw new ArgumentNullException(nameof(_externalDataProvider));
            }
            var rdr = _externalDataProvider.GetReader(format, null, null);

            if (String.IsNullOrEmpty(ru.CurrentModel))
            {
                return(rdr.CreateDataModel(stream));
            }
            else
            {
                var dm = await _dbContext.SaveModelAsync(ru.CurrentSource, ru.UpdateProcedure, null, prms, (table) =>
                {
                    return(rdr.ParseFile(stream, table));
                });

                return(dm?.Root);
            }
        }
Example #10
0
        public String UpdateProcedure(RequestFile file)
        {
            var sch = String.IsNullOrEmpty(schema) ? file.CurrentSchema : schema;

            return($"[{sch}].[{model}.Update]");
        }
Example #11
0
 public String CurrentSource(RequestFile file)
 {
     return(String.IsNullOrEmpty(source) ? file.CurrentSource : source);
 }