Esempio n. 1
0
        public static async Task <DataTable> GetDataTableAsync(IMatFileUploadEntry file, List <GridColumnBase> columnList)
        {
            System.Data.DataTable dataResult = new System.Data.DataTable();
            using (var stream = new MemoryStream())
            {
                await file.WriteToStreamAsync(stream);

                using (XLWorkbook workbook = new XLWorkbook(stream))
                {
                    IXLWorksheet worksheet = workbook.Worksheet(1);
                    bool         FirstRow  = true;
                    string       readRange = "1:1";
                    foreach (IXLRow row in worksheet.RowsUsed())
                    {
                        if (FirstRow)
                        {
                            readRange = GetColumnsNames(columnList, dataResult, row);
                            FirstRow  = false;
                        }
                        else
                        {
                            AddDatatableRow(dataResult, readRange, row);
                        }
                    }
                    if (FirstRow)
                    {
                        throw new System.Exception("No rows in excel");
                    }
                }
            }
            return(dataResult);
        }
Esempio n. 2
0
        private async Task PlaceImageInCanvas(IMatFileUploadEntry file)
        {
            using MemoryStream memoryStream = new MemoryStream();
            await file.WriteToStreamAsync(memoryStream);

            ImageController.SetImage(memoryStream);

            await _drawGrid.PlaceImage(ImageController);
        }
Esempio n. 3
0
        public async Task UploadUserImageAsync(IMatFileUploadEntry file, User user)
        {
            using (var stream = new MemoryStream())
            {
                await file.WriteToStreamAsync(stream);

                user.ImageBase64 = Convert.ToBase64String(stream.ToArray());
            }
            UpdateUser(user);
        }
        public static async Task <string> ToBase64(this IMatFileUploadEntry file)
        {
            string imageBase64;

            using (var stream = new MemoryStream())
            {
                await file.WriteToStreamAsync(stream);

                imageBase64 = Convert.ToBase64String(stream.ToArray());
            }
            return(imageBase64);
        }
        public async Task <ImageFormat> CheckImageType(IMatFileUploadEntry fileUploadEntry)
        {
            byte[] fileBytes;
            using (var ms = new MemoryStream())
            {
                await fileUploadEntry.WriteToStreamAsync(ms);

                fileBytes = ms.ToArray();
            }

            return(ImageHelper.ValidateImageFormat(fileBytes));
        }
Esempio n. 6
0
        public async Task <FileUploadEntry> FromMat(IMatFileUploadEntry entry)
        {
            MemoryStream memory = new MemoryStream();
            await entry.WriteToStreamAsync(memory);

            memory.Position = 0;
            return(new FileUploadEntry
            {
                LastModified = entry.LastModified,
                Name = entry.Name,
                Size = entry.Size,
                Type = entry.Type,
                StreamData = memory
            });
        }
Esempio n. 7
0
        public async Task UploadFile(IMatFileUploadEntry[] files)
        {
            try
            {
                if (files.Count() == 1)
                {
                    IMatFileUploadEntry fileMat = files.FirstOrDefault();

                    if (fileMat.Type.Contains("image/jpeg") ||
                        fileMat.Type.Contains("image/png"))
                    {
                        using (var streamTemp = new MemoryStream())
                        {
                            await fileMat.WriteToStreamAsync(streamTemp);

                            // Convertion de l'image en thumbnail
                            using (Image newImgThumbnail = GetReducedImage(200, 200, streamTemp))
                            {
                                using (MemoryStream thumbStream = new MemoryStream())
                                {
                                    newImgThumbnail.Save(thumbStream, System.Drawing.Imaging.ImageFormat.Png);
                                    UpdateProduit.ImgContent = thumbStream.ToArray();

                                    ImageUpdateEnString = "data:image/png;base64," + Convert.ToBase64String(UpdateProduit.ImgContent);
                                }
                            }
                        }

                        HaveUpdateImage = true;
                    }
                    else
                    {
                        Notification.Notify(NotificationSeverity.Warning, "Erreur", "Accepte format JPG ou PNG.");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "UploadFiles - Erreur sur le changement de l'image");
                Notification.Notify(NotificationSeverity.Error, "Erreur", "Erreur sur le changement de l'image");
                HaveUpdateImage = false;
            }
        }
Esempio n. 8
0
        public async Task UploadImage(IMatFileUploadEntry entry)
        {
            using (var stream = new MemoryStream())
            {
                await entry.WriteToStreamAsync(stream);

                FileModel model = new FileModel
                {
                    ContentType = entry.Type,
                    Content     = stream,
                    FileName    = entry.Name,
                    Size        = entry.Size
                };

                var result = await _fileService.Upload(entry);

                ImageId = result;
            }
            return;
        }
Esempio n. 9
0
        public ResultFromOCRBindingModel GetData(
            ResultFromOCRBindingModel model, IMatFileUploadEntry file)
        {
            ResultFromOCRBindingModel result =
                new ResultFromOCRBindingModel();

            Regex snRegex = SerialNumberRegexes
                            .GetSNRegex(model.ApplianceBrand);

            Regex modelRegex = LGModels
                               .GetModelRegex(model.ApplianceType);

            ImageAnnotatorClient client =
                ImageAnnotatorClient.Create();

            MemoryStream stream = new MemoryStream();

            file.WriteToStreamAsync(stream);

            Google.Cloud.Vision.V1.Image image =
                Google.Cloud.Vision.V1.Image.FromStream(stream);

            var annotations = client.DetectText(image);

            foreach (var annotation in annotations)
            {
                if (snRegex.Match(annotation.Description)
                    .Success)
                {
                    result.ApplianceSerialNumber =
                        annotation.Description;
                }
                else if (modelRegex.Match(annotation.Description)
                         .Success)
                {
                    result.ApplianceModel = annotation.Description;
                }
            }

            return(result);
        }
Esempio n. 10
0
        public async Task <Guid> Upload(IMatFileUploadEntry entry)
        {
            await using var ms = new MemoryStream();
            await entry.WriteToStreamAsync(ms);

            var model = new FileModel
            {
                Content     = ms,
                FileName    = entry.Name,
                ContentType = entry.Type,
                Size        = entry.Size
            };

            (Guid Guid, string Message)result = await _repository.UploadFile(model);

            if (!string.IsNullOrWhiteSpace(result.Message))
            {
                Error = result.Message.ToString();
            }
            return(result.Guid);
        }
Esempio n. 11
0
        public async Task <List <VideoModel> > Import(IMatFileUploadEntry file)
        {
            var filename = file.Name;

            Console.WriteLine($"Filename is {filename}");
            Console.WriteLine($"File type is {file.Type}");
            if (!file.Name.Contains(".xls"))
            {
                return(null);
            }
            var videos = new List <VideoModel>();

            using (var stream = new MemoryStream())
            {
                var sw = Stopwatch.StartNew();
                await file.WriteToStreamAsync(stream);

                sw.Stop();
                CreatePlaylistSheet(videos, stream);
            }
            return(videos);
        }
Esempio n. 12
0
        public async Task UploadLog(IMatFileUploadEntry[] files)
        {
            file = files.FirstOrDefault();
            if (file is null)
            {
                return;
            }
            if (file.Type != "text/csv" && file.Type != "application/vnd.ms-excel")
            {
                await MatDialogService.AlertAsync("Log has to be in csv");

                return;
            }

            try
            {
                _stream = new MemoryStream();

                await file.WriteToStreamAsync(_stream);

                _stream.Seek(0, SeekOrigin.Begin);
                GetUploadContent();
                _stream.Seek(0, SeekOrigin.Begin);
                _imported   = CsvLogImporter.LoadLog(_stream);
                headersDict = _imported.Headers.ToDictionary(x => x, HeaderTypeSet);

                uploadMode = true;
            }
            catch
            {
                await MatDialogService.AlertAsync(
                    "There was an error while uploading file. Check that file is .csv format");
            }
            finally
            {
                await InvokeAsync(StateHasChanged);
            }
        }
Esempio n. 13
0
 public Task WriteToStreamAsync(Stream stream)
 {
     return(fileUploadEntry.WriteToStreamAsync(stream));
 }
Esempio n. 14
0
        /// <summary>
        /// 上傳 Ios Android 安裝檔案
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <param name="uploadFile"></param>
        /// <returns></returns>
        public async Task <TResult <AppOsInfo> > UploadInstallFile(AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            //存放多載點 plist 檔案名稱
            List <DownloadUrlList> downloadUrlList = new List <DownloadUrlList>();

            #region 驗證檔案格式

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (string.IsNullOrEmpty(appOsInfo.Version))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_VERSIONREQUIRED, "必須輸入 版本號碼"));
            }

            if (appOsInfo.Photo.Where(p => p.FileNumber == 5).FirstOrDefault() == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "必須上傳 Icon 圖片"));
            }

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();

            //驗證 Ios 是否符合格式 目前只看.ipa 檔案
            if (appOsInfo.OSType == OsType.Ios && !extension.Equals(".ipa"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  IOS 安裝檔應為 .ipa 格式"));
            }

            //驗證 Android 是否符合格式 目前只看.apk 檔案
            if (appOsInfo.OSType == OsType.Android && !extension.Equals(".apk"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  Android 安裝檔應為 .apk 格式"));
            }

            #endregion

            string fileName = $"{appOsInfo.Version}-{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath   = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Install");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            #region 如果是 IOS 必須做出 Plist 檔案 和多載點 plist

            //如果是IOS 除了上傳.ipa 檔案 還要上傳 Plist xml file
            if (appOsInfo.OSType == OsType.Ios)
            {
                //圖片 url 路徑
                AppPhotoContent iosIconPhoto = appOsInfo.Photo.Where(P => P.FileNumber == 5).FirstOrDefault();

                //多載點 plist
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    // 組plist 黨案名稱
                    string pListFileName = $"{Guid.NewGuid().ToString("N")}{".plist"}";

                    // 組 ipa url 路徑
                    string ipaPath = $"{endPoint.Url}/{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                    // 組圖片 url 路徑
                    string iconPath = iosIconPhoto != null ? $"{endPoint.Url}/{iosIconPhoto.FilePath.Replace(" ", "")}" : "";

                    //做出 plist xml 內容物
                    string plistXml = UploadFileHepler.GetPlistXml(ipaPath, iconPath, appOsInfo.PackageName, appOsInfo.Version, appOsInfo.AppNameEn);

                    //存入 Plist 實體路徑
                    File.WriteAllText(Path.Combine(filePath, pListFileName), plistXml);

                    //原始路徑 存在Wis_AppOS table
                    if (endPoint.Site == "WHQ")
                    { //原始載點不加入 DownloadUrlList
                      //為 plist 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}";

                        //為 .ipa 檔案路徑
                        appOsInfo.FileName = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";
                    }
                    else
                    {//多載點資訊 存在 Wis_AppOs_Other
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}"//plist 路徑
                        });
                    }
                }

                //前端必須按下儲存按鈕  url資訊才會寫入 DB
                //Ios 上傳檔案路徑 是 plist檔案路徑
                appOsInfo.DownloadUrlList = downloadUrlList;
            }

            #endregion

            #region Android 處理檔案 路徑

            //Android 直接存放 apk 檔案路徑
            if (appOsInfo.OSType == OsType.Android)
            {
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    //Wis_AppOS url 路徑處理
                    if (endPoint.Site == "WHQ")
                    {
                        //為 .apk 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                        //為 .apk 原檔案名稱
                        appOsInfo.FileName = uploadFile.Name;
                    }
                    else
                    {//Wis_AppOs_Other 資訊
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}"//.apk 檔案路徑
                        });
                    }
                }
                //Android 上傳檔案路徑 是apk檔案路徑 與原本路徑一模一樣
                appOsInfo.DownloadUrlList = downloadUrlList;
            }
            #endregion

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }
Esempio n. 15
0
        /// <summary>
        /// 上傳圖片檔案 對象物件 AppOsInfo 裡的 AppPhotoContent
        /// </summary>
        /// <param name="fileNumber">記錄圖檔上傳位置 5 為安裝檔案Icon圖片</param>
        /// <param name="osType">IOS = 1 Android=2</param>
        /// <param name="appIos"></param>
        /// <param name="uploadFile"></param>
        /// <returns>實體路徑圖片</returns>
        public async Task <TResult <AppOsInfo> > UploadImageFile(int fileNumber, AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            #region 驗證圖片檔案格式

            //驗證圖片是否符合格式  目前只接受 PNG JPEG
            ImageFormat imageType = await _uploadFileService.CheckImageType(uploadFile);

            if (imageType == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_IMAGEFORMATTYPE, "檔案格式限制: jpg、jpeg、png"));
            }

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            #endregion

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();
            string fileName  = $"{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath    = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath  = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Images");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            AppPhotoContent appPhotoContent = new AppPhotoContent
            {
                AppID      = appOsInfo.AppID,
                AppOS      = appOsInfo.OSType,
                FileNumber = fileNumber,
                FileName   = fileName,
                //exapmle Wistron%20Ark\IOS\Images\5-623cefb49e3946a28198464dd72b5bb4.png 子目錄位址
                FilePath  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Images"}/{fileName}",
                PhotoType = fileNumber == 5 ? PhotoType.IconType : PhotoType.NormalType
            };

            //把有存在編號的 去除 在Add更新過後的 但還未更新資料庫 等待 按下儲存按鈕
            AppPhotoContent existed = appOsInfo.Photo.Where(p => p.FileNumber == fileNumber).FirstOrDefault();
            if (existed != null)
            {
                appOsInfo.Photo.Remove(existed);
                appOsInfo.Photo.Add(appPhotoContent);
            }
            else
            {
                appOsInfo.Photo.Add(appPhotoContent);
            }

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }