コード例 #1
0
        public async Task <string> SaveFile(IFormFile formFile, string relativeParentFolderPath, int parentFolderId)
        {
            if (formFile.Length > 0 && FileNameUtility.FileFolderNameIsValid(name: formFile.FileName))
            {
                var relativePath = Path.Combine(relativeParentFolderPath, $"{parentFolderId}-{formFile.FileName}");
                var filePath     = Path.Combine(
                    _env.ContentRootPath, _configuration["UsersFilesPath"], relativePath);

                var parentFolderPath = Path.Combine(
                    _env.ContentRootPath, _configuration["UsersFilesPath"], relativeParentFolderPath);

                if (!Directory.Exists(parentFolderPath))
                {
                    Directory.CreateDirectory(parentFolderPath);
                }

                using (var stream = File.Create(filePath))
                {
                    await formFile.CopyToAsync(stream);
                }

                // Returns the relative path
                return(relativePath);
            }

            return(null);
        }
コード例 #2
0
        private void CreateAppThumbs(QlikApp qlikApp, Uri uri)
        {
            var appName    = qlikApp.Name;
            var appId      = qlikApp.Id;
            var streamName = qlikApp.StreamName;

            _counterHashSet.Add("STREAM/" + streamName);
            _counterHashSet.Add("APP/" + appId);

            _log.Information("Creating thumbs for {0}", appName);

            var appDir = _thumbOutputPath + Path.DirectorySeparatorChar
                         + FileNameUtility.EscapeFilenameWindows(streamName)
                         + Path.DirectorySeparatorChar +
                         FileNameUtility.EscapeFilenameWindows(appName);

            if (Directory.Exists(appDir) == false)
            {
                Directory.CreateDirectory(appDir);
            }

            var retrieveAppSheets = _qlikEngineService.RetrieveAppSheets(qlikApp.Id, qlikApp.Name);

            foreach (QlikSheet qlikSheet in retrieveAppSheets)
            {
                var sheetPath = qlikSheet.EngineObjectId;
                var sheetName = qlikSheet.Name;

                _counterHashSet.Add("SHEET/" + sheetPath);

                string url = uri.AbsoluteUri + "sense/app/" + appId + "/sheet/" + sheetPath + "/state/analysis";

                _webDriver.Navigate().GoToUrl(url);

                ((IJavaScriptExecutor)_webDriver).ExecuteScript(QlikThumbProcessorJs.WaitForSheetLoadJsChrome);
                var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(20));
                wait.Until(s =>
                           ((IJavaScriptExecutor)_webDriver).ExecuteScript("return window.oneSecondPastLastEvent();")
                           .Equals(true));

                var fileName = FileNameUtility.EscapeFilenameWindows(streamName + "_" + appName + "_" + sheetName);
                var filePath = appDir + Path.DirectorySeparatorChar + fileName + ".jpg";

                _log.Information("Writing out the thumb for Stream:{0}, App:{1}, Sheet:{2}", streamName, appName,
                                 sheetName);

                ITakesScreenshot scrShot = ((ITakesScreenshot)_webDriver);
                scrShot.GetScreenshot().SaveAsFile(filePath);

                if (string.IsNullOrWhiteSpace(_qlikThumbModel.TaskType) == false &&
                    _qlikThumbModel.TaskType.Equals(QlikThumbModel.TaskContentDirectorySave))
                {
                    _log.Information("Uploading the thumb for Stream:{0}, App:{1}, Sheet:{2} Content Library {3}",
                                     streamName, appName, sheetName, _qlikThumbModel.ContentLibrary.Name);

                    _qlikEngineService.UploadFileToContentDirectory(_qlikThumbModel.ContentLibrary.Name, filePath);
                }
            }
        }
コード例 #3
0
ファイル: Experiment.cs プロジェクト: bhrnjica/gpdotnetv4
        /// <summary>
        /// Retrieve content from file as array of rows
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="delimeter"></param>
        /// <returns></returns>
        private static string[] GetRowsFromText(string filePath, char delimeter)
        {
            var buffer = "";


            buffer = FileNameUtility.ReadTextFile(filePath);

            //define the row
            string[] rows;

            //extract data but remove comments
            rows = buffer.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Where(x => (x != null && x.Length > 0 && x[0] != '!')).Select(x => x).ToArray();

            return(rows);
        }
コード例 #4
0
        public async Task <IActionResult> AddFolder([FromBody] AddFolderRequest request)
        {
            var userIdString = JWTUtility.GetUserId(User);

            if (userIdString == null)
            {
                return(BadRequest());
            }

            var userId = int.Parse(userIdString);

            if (request.ParentFolder != null)
            {
                // Check if the parent folder does belong to the user
                if (!await _registerService.DoesFolderBelongToUser(
                        userId, folderId: request.ParentFolder.Value))
                {
                    return(BadRequest());
                }
            }

            // Check if the folder name is valid
            if (!FileNameUtility.FileFolderNameIsValid(request.Name))
            {
                return(BadRequest(Texts.INVALID_FILE_NAME));
            }

            // Check if the folder does not exist
            if (await _registerService.DoesFileOrFolderAlreadyExist(userId, name: request.Name, parentFolder: request.ParentFolder))
            {
                return(BadRequest(Texts.FILE_FOLDER_ALREADY_EXISTS));
            }

            var folderAdded = await _registerService.AddFolder(userId, parentFolder : request.ParentFolder, request);

            if (folderAdded == null)
            {
                return(StatusCode(statusCode: 500, value: Texts.ERROR_CREATING_FOLDER));
            }

            return(Ok(folderAdded));
        }
コード例 #5
0
        public async Task <IActionResult> ChangeRegisterName([FromBody] ChangeRegisterNameRequest request)
        {
            var userIdString = JWTUtility.GetUserId(User);

            if (userIdString == null)
            {
                return(BadRequest());
            }

            var userId = int.Parse(userIdString);

            // Check if the register does belong to the user.
            if (!await _registerService.DoesRegisterBelongToUser(userId, registerId: request.RegisterId))
            {
                return(BadRequest());
            }

            // Check if the new name is valid.
            if (!FileNameUtility.FileFolderNameIsValid(request.NewName))
            {
                return(BadRequest(Texts.INVALID_FILE_NAME));
            }

            // Check if the new name already exists in the parent folder.
            var parentFolderId = await _registerService.GetParentFolderForRegister(request.RegisterId);

            if (await _registerService.DoesFileOrFolderAlreadyExist(userId, name: request.NewName, parentFolder: parentFolderId))
            {
                return(BadRequest(Texts.FILE_FOLDER_ALREADY_EXISTS));
            }

            var registerChanged = await _registerService.ChangeRegisterName(userId, request);

            if (registerChanged == null)
            {
                return(StatusCode(statusCode: 500, value: Texts.ERROR_MODIFYING_REGISTER));
            }

            return(Ok(registerChanged));
        }
コード例 #6
0
        public Task <string> CreateFolder(string folderName, string relativeParentFolderPath, int parentFolderId)
        {
            if (FileNameUtility.FileFolderNameIsValid(name: folderName))
            {
                var relativePath = Path.Combine(relativeParentFolderPath, $"{parentFolderId}-{folderName}");
                var folderPath   = Path.Combine(
                    _env.ContentRootPath, _configuration["UsersFilesPath"], relativePath);

                // To indicates that this method does not create this folder
                if (Directory.Exists(folderPath))
                {
                    return(null);
                }

                Directory.CreateDirectory(folderPath);

                // Returns the relative path
                return(Task.FromResult(relativePath));
            }

            return(null);
        }
コード例 #7
0
        /// <summary>
        /// 将文件按照指定的格式保存到文件夹中
        /// </summary>
        /// <param name="filePtr">文件句柄</param>
        /// <param name="fileFormat">文件类型,后缀名</param>
        /// <returns>文件全路径名</returns>
        public static string SaveSingleImageToFile(IntPtr filePtr, ref String fileFormat, bool isGroup4, int resolution)
        {
            String fileHeader = Config.GetImageDir();   // 文件路径
            Guid   clsid;                               // 保存图像类型的GUID

            if (!GetCodecClsid(ref fileFormat, out clsid))
            {
                MessageBox.Show("Unknown picture format for extension " + Path.GetExtension(fileFormat),
                                "Image Codec");
                return(null);
            }

            IntPtr dibhand = (IntPtr)filePtr;
            IntPtr bmpptr  = GlobalLock(dibhand);
            IntPtr pixptr  = GetPixelInfo(bmpptr);

            IntPtr imgData = IntPtr.Zero;
            int    st      = GdipCreateBitmapFromGdiDib(bmpptr, pixptr, ref imgData);

            if ((st != 0) || (imgData == IntPtr.Zero))
            {
                return(null);
            }

            String fileName = fileHeader + FileNameUtility.GetOnlyOneFileName(fileFormat);

            st = GdipBitmapSetResolution(imgData, resolution, resolution);
            st = GdipSaveImageToFile(imgData, fileName, ref clsid, IntPtr.Zero); // 将图像保存为JPEG文件

            GdipDisposeImage(imgData);                                           //
            GlobalFree(dibhand);                                                 // 释放从扫描源产生的图像内存块
            dibhand = IntPtr.Zero;

            if (isGroup4)
            {
                System.Drawing.Bitmap newImage = new Bitmap(fileName);
                //newImage.SetResolution(resolution, resolution);
                EncoderParameters encParams = new EncoderParameters();
                Encoder           encCompress;
                encCompress = new Encoder(Encoder.Compression.Guid);
                EncoderParameter encParamCompress = new EncoderParameter(encCompress, (long)GetBestTIFFCompression(newImage.PixelFormat));
                encParams.Param[0] = encParamCompress;
                string tmpFileName = fileName;
                fileName = fileHeader + FileNameUtility.GetOnlyOneFileName(fileFormat);
                newImage.Save(fileName, GetCodecInfo(ImageFormat.Tiff), encParams);
                newImage.Dispose();
                File.Delete(tmpFileName);
                GC.Collect();
            }
            else
            {
                System.Drawing.Bitmap newImage = new Bitmap(fileName);
                //newImage.SetResolution(resolution, resolution);
                string tmpFileName = fileName;
                fileName = fileHeader + FileNameUtility.GetOnlyOneFileName(fileFormat);
                newImage.Save(fileName);
                newImage.Dispose();
                File.Delete(tmpFileName);
                GC.Collect();
            }
            return(fileName);
        }