Ejemplo n.º 1
0
        public async Task <AttachmentInfo> LoadFileGet(String pathInfo, Action <ExpandoObject> setParams)
        {
            var rm = await RequestModel.CreateFromBaseUrl(_host, Admin, pathInfo);

            var ru = rm.GetFile();

            ExpandoObject loadPrms = new ExpandoObject();

            setParams?.Invoke(loadPrms);
            loadPrms.Set("Id", ru.Id);
            loadPrms.RemoveKeys("export,Export,token,Token");

            switch (ru.type)
            {
            case RequestFileType.sql:
            case RequestFileType.azureBlob:
            {
                var ai = await _dbContext.LoadAsync <AttachmentInfo>(ru.CurrentSource, ru.FileProcedureLoad, loadPrms);

                if (!String.IsNullOrEmpty(ai.BlobName))
                {
                    var azureClient = new AzureStorageRestClient();
                    var blobName    = Path.GetFileName(ai.BlobName);
                    var container   = Path.GetDirectoryName(ai.BlobName);
                    ai.Stream = await azureClient.Get(ru.azureSource, container, blobName);
                }
                return(ai);
            }

            default:
                throw new InvalidOperationException($"Invalid type for file: '{ru.type.ToString()}'");
            }
        }
Ejemplo n.º 2
0
        public async Task <AttachmentInfo> LoadFileGet(String pathInfo, Action <ExpandoObject> setParams, String token)
        {
            var rm = await RequestModel.CreateFromBaseUrl(_host, pathInfo);

            var ru = rm.GetFile();

            ru.CheckPermissions(_userStateManager?.GetUserPermissions(), _host.IsDebugConfiguration);

            ExpandoObject loadPrms = new ExpandoObject();

            setParams?.Invoke(loadPrms);
            loadPrms.Set("Id", ru.Id);
            loadPrms.RemoveKeys("export,Export,token,Token");

            switch (ru.type)
            {
            case RequestFileType.json:
                var dm = await _dbContext.LoadModelAsync(ru.CurrentSource, ru.LoadProcedure, loadPrms);

                var json = JsonConvert.SerializeObject(dm.Root, JsonHelpers.StandardSerializerSettings);
                return(new AttachmentInfo()
                {
                    SkipToken = true,
                    Mime = MimeTypes.Application.Json,
                    Stream = Encoding.UTF8.GetBytes(json),
                    Name = ru.outputFileName
                });

            case RequestFileType.sql:
            case RequestFileType.azureBlob:
            {
                if (token == null)
                {
                    throw new InvalidOperationException("There is no access token for image");
                }
                var ai = await _dbContext.LoadAsync <AttachmentInfo>(ru.CurrentSource, ru.FileProcedureLoad, loadPrms);

                if (!String.IsNullOrEmpty(ai.BlobName))
                {
                    var azureClient = new AzureStorageRestClient();
                    var blobName    = Path.GetFileName(ai.BlobName);
                    var container   = Path.GetDirectoryName(ai.BlobName);
                    ai.Stream = await azureClient.Get(ru.azureSource, container, blobName);
                }
                return(ai);
            }

            default:
                throw new InvalidOperationException($"Invalid type for file: '{ru.type}'");
            }
        }