Пример #1
0
        public async Task <ActionResult> CreateFilesInSharedDrive([FromBody] ReportValuesViewModel reportValuesViewModel)
        {
            try
            {
                DocumentBytes    bytes = _documentService.GeneretaNewFiles(reportValuesViewModel);
                List <DriveItem> drive = await _graphServiceFiles.CreateFilesInSharedDrive(Token, reportValuesViewModel.Name, bytes);

                return(Json(drive));
            }
            catch (ServiceException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Пример #2
0
        public byte[] getExcelFile(string scope, string application)
        {
            try
            {
                var           reluri     = String.Format("/{0}/{1}/resourcedata", scope, application);
                DocumentBytes pathObject = _client.Get <DocumentBytes>(reluri, true);

                return(pathObject.Content);
            }
            catch (Exception ioEx)
            {
                _logger.Error(ioEx.Message);
                throw ioEx;
            }
        }
Пример #3
0
        ///Done by: Ganesh Bisht: Polaris
        /// <summary>
        /// Will get the file content in byte array
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="application"></param>
        /// <param name="fileName"></param>
        /// <param name="ext"></param>
        /// <returns>byte array</returns>
        public byte[] getFile(string scope, string application, string fileName, string ext)
        {
            try
            {
                var reluri = String.Format("/{0}/{1}/File/{2}/{3}", scope, application, fileName, ext);

                WebHttpClient client = CreateWebClient(_adapterServiceUri);

                DocumentBytes pathObject = client.Get <DocumentBytes>(reluri, true);

                return(pathObject.Content);
            }
            catch (Exception ioEx)
            {
                _logger.Error(ioEx.Message);
                throw ioEx;
            }
        }
Пример #4
0
        public DocumentBytes GetResourceData()
        {
            try
            {
                string        spreadsheetPath = Path.Combine(_settings["BaseDirectoryPath"], _settings["AppDataPath"], string.Format("SpreadsheetData.{0}.xlsx", _settings["Scope"]));
                FileStream    fsSrc           = new FileStream(spreadsheetPath, FileMode.Open, FileAccess.Read);
                DocumentBytes document        = new DocumentBytes();
                document.DocumentPath = spreadsheetPath;

                using (FileStream fsSource = fsSrc)
                {
                    // Read the source file into a byte array.
                    byte[] bytes          = new byte[fsSource.Length];
                    int    numBytesToRead = (int)fsSource.Length;
                    int    numBytesRead   = 0;
                    while (numBytesToRead > 0)
                    {
                        // Read may return anything from 0 to numBytesToRead.
                        int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);

                        // Break when the end of the file is reached.
                        if (n == 0)
                        {
                            break;
                        }

                        numBytesRead   += n;
                        numBytesToRead -= n;
                    }
                    numBytesToRead   = bytes.Length;
                    document.Content = bytes;
                    return(document);
                }
            }
            catch (Exception ioEx)
            {
                _logger.Error(ioEx.Message);
                throw ioEx;
            }
        }
Пример #5
0
        private async Task PushFilesToDrive(string nameFile, int reportTypeId, List <ReportLabelModel> values, int driveType)
        {
            nameFile = Helpers.GetNameFileWithCurrentDate(nameFile);
            DocumentBytes bytes = _documentService.GeneretaNewFiles(new ReportValuesViewModel {
                ReportTypeId = reportTypeId, Values = values
            });

            switch (driveType)
            {
            case (int)DriveTypeEnum.Private:
                await _graphServiceFiles.CreateFilesInDrive(Token, nameFile, bytes);

                break;

            case (int)DriveTypeEnum.Shared:
                await _graphServiceFiles.CreateFilesInSharedDrive(Token, nameFile, bytes);

                break;

            default:
                break;
            }
        }
Пример #6
0
        public async Task <List <DriveItem> > CreateFilesInSharedDrive(string token, string nameFile, DocumentBytes documentBytes)
        {
            nameFile = ReplaceName(nameFile);

            GraphServiceClient graphClient = GetGraphServiceClient(token);

            List <DriveItem> driveItems = new List <DriveItem>();

            using (MemoryStream fileContentStream = new MemoryStream(documentBytes.DocumentsBytes))
            {
                try
                {
                    DriveItem resultSavedDocx = await graphClient.Drive.Root.ItemWithPath(nameFile + ".docx").Content.Request().PutAsync <DriveItem>(fileContentStream);

                    driveItems.Add(resultSavedDocx);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }
            }

            using (MemoryStream fileContentStream = new MemoryStream(documentBytes.PdfBytes))
            {
                try
                {
                    DriveItem resultSavePdf = await graphClient.Drive.Root.ItemWithPath(nameFile + ".pdf").Content.Request().PutAsync <DriveItem>(fileContentStream);

                    driveItems.Add(resultSavePdf);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }
            }

            return(driveItems);
        }
Пример #7
0
        public override DocumentBytes GetResourceData()
        {
            DocumentBytes sc = _provider.GetResourceData();

            return(sc);
        }
        Task <HttpResponseMessage> ExecuteAsync(CodeActivityContext context)
        {
            MultipartFormDataContent formData = new MultipartFormDataContent();
            FileStream fs = null;

            var basePath = BasePath.Get(context);
            var request  = new HttpRequestMessage()
            {
                RequestUri = new Uri(basePath + "/parseDocument"),
                Method     = HttpMethod.Post,
            };

            var apiKey = APIKey.Get(context);

            request.Headers.Add("X-Auth-Key", apiKey);

            var documentURL = DocumentURL.Get(context);

            if (documentURL != null && !documentURL.Equals(""))
            {
                formData.Add(new StringContent(documentURL, Encoding.UTF8), "url");
            }

            var template = Template.Get(context);

            if (template != null && !template.Equals(""))
            {
                formData.Add(new StringContent(template, Encoding.UTF8), "template");
            }

            var pdfTextExtraction = PDFTextExtraction.Get(context);

            if (pdfTextExtraction == PDFTextExtractionType.Fast)
            {
                formData.Add(new StringContent("fast", Encoding.UTF8), "pdf_text_extraction");
            }
            else if (pdfTextExtraction == PDFTextExtractionType.Full)
            {
                formData.Add(new StringContent("full", Encoding.UTF8), "pdf_text_extraction");
            }

            var userData = UserData.Get(context);

            if (userData != null && !userData.Equals(""))
            {
                formData.Add(new StringContent(userData, Encoding.UTF8), "user_data");
            }

            var userDataSetExternalID = UserDataSetExternalID.Get(context);

            if (userDataSetExternalID != null && !userDataSetExternalID.Equals(""))
            {
                formData.Add(new StringContent(userDataSetExternalID, Encoding.UTF8), "user_data_set_external_id");
            }

            var documentFilename = DocumentFilename.Get(context);
            var documentBytes    = DocumentBytes.Get(context);
            var documentPath     = DocumentPath.Get(context);
            var documentStream   = DocumentStream.Get(context);

            if (documentBytes != null && documentBytes.Length > 0)
            {
                formData.Add(new ByteArrayContent(documentBytes), "document", documentFilename);
            }
            else if (documentPath != null && !documentPath.Equals(""))
            {
                fs = File.OpenRead(documentPath);
                formData.Add(new StreamContent(fs), "document", Path.GetFileName(documentPath));
            }
            else if (documentStream != null && documentStream.Length > 0)
            {
                formData.Add(new StreamContent(documentStream), "document", documentFilename);
            }

            request.Content = formData;
            request.Properties["RequestTimeout"] = TimeSpan.FromSeconds(600);

            return(httpClient.SendAsync(request));
        }