Ejemplo n.º 1
0
        private async Task <HubInfo> UploadFileInternalAsync(HubInfo request, ContentData hubFileData, bool isUpdate = false)
        {
            try
            {
                if (request == null)
                {
                    logger.Debug($"The request is null.");
                    return(null);
                }

                logger.Debug($"Upload type {request.Type}");
                var httpMethod   = HttpMethod.Post;
                var pathAndQuery = "sharedcontent";
                if (isUpdate == true)
                {
                    httpMethod    = HttpMethod.Put;
                    pathAndQuery += $"/{request.Id.Value}";
                }

                var jsonStr = JsonConvert.SerializeObject(request);
                var data    = Encoding.UTF8.GetBytes(jsonStr);
                var result  = await SendRequestAsync(pathAndQuery, httpMethod,
                                                     new ContentData()
                {
                    ContentType = "application/json", FileData = data
                });

                var hubInfo = JsonConvert.DeserializeObject <HubInfo>(result);

                //Upload File
                if (hubFileData != null)
                {
                    logger.Debug("Upload content data.");
                    if (isUpdate == false)
                    {
                        pathAndQuery += $"/{hubInfo.Id.Value}";
                    }

                    pathAndQuery = $"{pathAndQuery}/uploadfile?externalpath={hubFileData.ExternalPath}";
                    result       = await SendRequestAsync(pathAndQuery, HttpMethod.Post, hubFileData);
                }
                else
                {
                    logger.Debug("The content data is empty.");
                }

                return(hubInfo);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "File upload was failed.");
                return(null);
            }
        }
Ejemplo n.º 2
0
        public async Task <HubInfo> CreateSharedContentAsync(HubCreateRequest request)
        {
            try
            {
                var hubInfo = new HubInfo()
                {
                    Type        = request.ReportType,
                    Description = request.Description,
                    Name        = request.Name,
                    MetaData    = new List <MetaData>()
                    {
                        new MetaData()
                        {
                            Id    = Guid.NewGuid().ToString(),
                            Key   = "ser-type",
                            Value = "report",
                        }
                    }
                };

                if (request.Tags != null && request.Tags.Count > 0)
                {
                    var tagJson = SendRequestAsync("tag/full", HttpMethod.Get).Result;
                    var tagList = JsonConvert.DeserializeObject <List <Tag> >(tagJson);
                    hubInfo.Tags = new List <Tag>();
                    foreach (var tag in request.Tags)
                    {
                        var qlikTag = tagList.FirstOrDefault(t => t.Name == tag.Name);
                        if (qlikTag != null)
                        {
                            hubInfo.Tags.Add(qlikTag);
                        }
                    }
                }

                return(await UploadFileInternalAsync(hubInfo, request.Data));
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"The method \"{nameof(CreateSharedContentAsync)}\" with hub info failed.");
                return(null);
            }
        }