예제 #1
0
        /// <summary>
        /// 查找全景图
        /// </summary>
        /// <param name="panoFile">全景图文件</param>
        /// <param name="product">归属产品</param>
        /// <param name="scene">归属场景</param>
        private static void FindPano(CustomFileInfo panoFile, ProductInfo product, SceneInfo scene)
        {
            string errorCode = errorPath;

            errorPath = "FindPano_" + panoFile.FullPath;

            PanoInfo pano = new PanoInfo();

            pano.Name = scene.Name + "_" + product.Name;
            if (panoFile.FileName.IndexOf("scene") != -1)
            {
                pano.PanoType = "全景图";
            }
            else
            {
                pano.PanoType = "平面图";
            }
            pano.PanoTexturePath = panoFile.FullPath;

            product.relatedPanoNames.Add(pano.Name);
            scene.includePanoNames.Add(pano.Name);

            panoList.Add(pano);
            errorPath = errorCode;
        }
예제 #2
0
        /// <summary>
        /// 递归查找所有文件夹以及文件,填满字典
        /// </summary>
        /// <param name="dirPath">查找的目录</param>
        private static void RecursiveDirs(string dirPath)
        {
            errorPath = "init_" + dirPath;
            string[] files = Directory.GetFiles(dirPath);
            for (int i = 0; i < files.Length; i++)
            {
                CustomFileInfo item = new CustomFileInfo(files[i], Guid.NewGuid().ToString());
                if (fileDic.ContainsKey(files[i]))
                {
                    fileDic[files[i]] = item;
                }
                else
                {
                    fileDic.Add(files[i], item);
                }
            }

            string[] dirs = Directory.GetDirectories(dirPath);
            for (int i = 0; i < dirs.Length; i++)
            {
                CustomDirectoryInfo item = new CustomDirectoryInfo(dirs[i], Guid.NewGuid().ToString());
                if (dirDic.ContainsKey(dirs[i]))
                {
                    dirDic[dirs[i]] = item;
                }
                else
                {
                    dirDic.Add(dirs[i], item);
                }
                RecursiveDirs(dirs[i]);
            }
        }
예제 #3
0
        public string DeleteFile(string fileName)
        {
            try
            {
                //调用文件服务
                ServiceFileClient.ServiceFileClient client = new ServiceFileClient.ServiceFileClient();
                CustomFileInfo customFileInfo = new CustomFileInfo();
                customFileInfo.NewName = fileName;

                customFileInfo = client.DeleteFile(customFileInfo);

                if (customFileInfo.State == 0)
                {
                    return(ResponseJson.Success(customFileInfo, "删除成功"));
                }
                else
                {
                    return(ResponseJson.Error("删除失败"));
                }
            }
            catch (Exception ex)
            {
                return(ResponseJson.Error(ex.Message));
            }
        }
예제 #4
0
 internal static void SafeNameUpdate(this CustomFileInfo fileInfo, string path, string originalName,
                                     string newName)
 {
     if (fileInfo == null)
     {
         return;
     }
     CreateWrapper(fileInfo).SafeNameUpdate(path, originalName, newName);
 }
        private void BtnGetLog_Click(object sender, RoutedEventArgs e)
        {
            procWitStt();

            var    txt = textBox.Text;
            Thread t   = new Thread(new ThreadStart(() =>
            {
                var spNl = new string[] { Environment.NewLine };
                var spTb = new string[] { "\t" };

                var fls = txt.Split(spNl, StringSplitOptions.None)
                          .Select(s => s.Split(spTb, StringSplitOptions.None)[0]);
                var sb = new StringBuilder();
                foreach (var fl in fls)
                {
                    if (this.intRptFlg)
                    {
                        /*
                         * Dispatcher.Invoke(new Action(() =>
                         * {
                         * this.textBox.Text = txt;
                         * procWitEnd();
                         * }), new object[] { });
                         */
                        Dispatcher.Invoke(
                            this._dlgSetTxtBoxTxt,
                            new object[] { txt });
                        return;
                    }

                    if (fl.Length > 0)
                    {
                        var cfo = new CustomFileInfo(fl);
                        sb.Append(string.Format("{0}\t{1}\t{2}\t{3}{4}"
                                                , cfo.path, cfo.fileName, cfo.lastWriteTime, cfo.hashOfFileContent, Environment.NewLine));
                    }
                    else
                    {
                        sb.Append(Environment.NewLine);
                    }
                }

                /*
                 * Dispatcher.Invoke(new Action(() =>
                 * {
                 * this.textBox.Text = sb.ToString();
                 * procWitEnd();
                 * }), new object[] { });
                 */
                Dispatcher.Invoke(
                    this._dlgSetTxtBoxTxt,
                    new object[] { sb.ToString() });
            }));

            t.Start();
        }
예제 #6
0
        public void AddFile(string dirName, CustomFileInfo file)
        {
            var name = dirName.Equals("")
                ? file.ResultName
                : dirName + Path.DirectorySeparatorChar + file.ResultName;

            var entry = _archive.CreateEntry(name);

            Copy(entry, file.Src);
        }
예제 #7
0
        public CustomFileInfo GetFileInfo(string filePath)
        {
            FileInfo       fileInfo       = new FileInfo(filePath);
            CustomFileInfo customFileInfo = new CustomFileInfo()
            {
                Name     = fileInfo.Name,
                FullName = fileInfo.FullName,
                Length   = fileInfo.Length
            };

            return(customFileInfo);
        }
예제 #8
0
 public bool DownFile(CustomFileInfo currentDownFile)
 {
     lock (obj)
     {
         if (down != null)
         {
             down.Invoke(currentDownFile);
             return(true);
         }
         return(false);
     }
 }
        private static void GrepResult(CustomFileInfo fileInfo, FileSettings fileSettings)
        {
            var fileContent = File.ReadLines(fileInfo.FullPath);
            var colors      = new Dictionary <string, string>();

            if ((bool)fileSettings.only_bad_lines)
            {
                colors.Add(fileSettings.bad_regex, Beaprint.ansi_color_bad);
                fileContent = fileContent.Where(l => Regex.IsMatch(l, fileSettings.bad_regex, RegexOptions.IgnoreCase));
            }
            else
            {
                string lineGrep = null;

                if ((bool)fileSettings.remove_empty_lines)
                {
                    fileContent = fileContent.Where(l => !string.IsNullOrWhiteSpace(l));
                }

                if (!string.IsNullOrWhiteSpace(fileSettings.remove_regex))
                {
                    var pattern = GetRegexpFromString(fileSettings.remove_regex);
                    fileContent = fileContent.Where(l => !Regex.IsMatch(l, pattern, RegexOptions.IgnoreCase));
                }

                if (!string.IsNullOrWhiteSpace(fileSettings.good_regex))
                {
                    colors.Add(fileSettings.good_regex, Beaprint.ansi_color_good);
                }
                if (!string.IsNullOrWhiteSpace(fileSettings.bad_regex))
                {
                    colors.Add(fileSettings.bad_regex, Beaprint.ansi_color_bad);
                }
                if (!string.IsNullOrWhiteSpace(fileSettings.line_grep))
                {
                    lineGrep = SanitizeLineGrep(fileSettings.line_grep);
                }

                fileContent = fileContent.Where(line => (!string.IsNullOrWhiteSpace(fileSettings.good_regex) && Regex.IsMatch(line, fileSettings.good_regex, RegexOptions.IgnoreCase)) ||
                                                (!string.IsNullOrWhiteSpace(fileSettings.bad_regex) && Regex.IsMatch(line, fileSettings.bad_regex, RegexOptions.IgnoreCase)) ||
                                                (!string.IsNullOrWhiteSpace(lineGrep) && Regex.IsMatch(line, lineGrep, RegexOptions.IgnoreCase)));
            }

            var content = string.Join(Environment.NewLine, fileContent);

            Beaprint.AnsiPrint(content, colors);

            if (content.Length > 0)
            {
                Console.WriteLine();
            }
        }
        private static bool ProcessResult(
            CustomFileInfo fileInfo,
            Helpers.YamlConfig.YamlConfig.SearchParameters.FileSettings fileSettings,
            ref int resultsCount)
        {
            // print depending on the options here
            resultsCount++;

            if (resultsCount > ListFileLimit)
            {
                return(false);
            }


            if (fileSettings.type == "f")
            {
                var colors = new Dictionary <string, string>();
                colors.Add(fileInfo.Filename, Beaprint.ansi_color_bad);
                Beaprint.AnsiPrint($"File: {fileInfo.FullPath}", colors);

                if (!(bool)fileSettings.just_list_file)
                {
                    GrepResult(fileInfo, fileSettings);
                }
            }
            else if (fileSettings.type == "d")
            {
                var colors = new Dictionary <string, string>();
                colors.Add(fileInfo.Filename, Beaprint.ansi_color_bad);
                Beaprint.AnsiPrint($"Folder: {fileInfo.FullPath}", colors);

                // just list the directory
                if ((bool)fileSettings.just_list_file)
                {
                    string[] files = Directory.GetFiles(fileInfo.FullPath, "*", SearchOption.TopDirectoryOnly);

                    foreach (var file in files)
                    {
                        Beaprint.BadPrint($"    {file}");
                    }
                }
                else
                {
                    // should not happen
                }
            }

            return(true);
        }
        public static List <CustomFileInfo> GetFilesFast(string folder, string pattern = "*", HashSet <string> excludedDirs = null, bool isFoldersIncluded = false)
        {
            ConcurrentBag <CustomFileInfo> files             = new ConcurrentBag <CustomFileInfo>();
            IEnumerable <DirectoryInfo>    startDirs         = GetStartDirectories(folder, files, pattern, isFoldersIncluded);
            IList <DirectoryInfo>          startDirsExcluded = new List <DirectoryInfo>();
            IList <string> known_dirs = new List <string>();

            if (excludedDirs != null)
            {
                foreach (var startDir in startDirs)
                {
                    bool   shouldAdd     = true;
                    string startDirLower = startDir.FullName.ToLower();

                    shouldAdd = !excludedDirs.Contains(startDirLower);

                    if (shouldAdd)
                    {
                        startDirsExcluded.Add(startDir);
                    }
                }
            }
            else
            {
                startDirsExcluded = startDirs.ToList();
            }

            Parallel.ForEach(startDirsExcluded, (d) =>
            {
                Parallel.ForEach(GetStartDirectories(d.FullName, files, pattern, isFoldersIncluded), (dir) =>
                {
                    GetFiles(dir.FullName, pattern).ForEach(
                        (f) => {
                        CustomFileInfo file_info = new CustomFileInfo(f.Name, f.Extension, f.FullName, false);
                        files.Add(file_info);

                        CustomFileInfo file_dir = new CustomFileInfo(f.Directory.Name, "", f.Directory.FullName, true);
                        if (!known_dirs.Contains(file_dir.FullPath))
                        {
                            known_dirs.Add(file_dir.FullPath);
                            files.Add(file_dir);
                        }
                    }
                        );
                });
            });

            return(files.ToList());
        }
예제 #12
0
        public string UploadImg()
        {
            try
            {
                FileInfo file      = new FileInfo(Request.Files[0].FileName);
                string   extension = file.Extension;
                string   fileName  = file.Name;

                string[] allowExt = { ".jpg", ".jpge", ".gif", ".png" };
                if (!allowExt.Contains(extension.ToLower()))
                {
                    return(ResponseJson.Error("文件格式不正确"));
                }

                int    FileLen  = Request.Files[0].ContentLength;
                byte[] bytes    = new byte[FileLen];
                Stream MyStream = Request.Files[0].InputStream;
                MyStream.Read(bytes, 0, FileLen);
                MyStream.Close();

                //调用文件服务
                //FtpUtil.Upload(file, FileLen, bytes);

                ServiceFileClient.ServiceFileClient client = new ServiceFileClient.ServiceFileClient();
                CustomFileInfo customFileInfo = new CustomFileInfo
                {
                    OldName  = fileName,
                    SendByte = bytes
                };
                string baseFileString = Convert.ToBase64String(bytes);
                customFileInfo.SendByteStr = baseFileString;
                customFileInfo.Extension   = extension;

                customFileInfo = client.UpLoadFileInfo(customFileInfo);

                return(ResponseJson.Success(customFileInfo, "上传成功"));
            }
            catch (Exception ex)
            {
                return(ResponseJson.Error(ex.Message));
            }
        }
예제 #13
0
 JsonResult IDriver.CryptInfo(string target)
 {
     try
     {
         target = this.GetCorectTarget(target);
         target = this.DecodeTarget(target);
         DirInfo dirInfo = client.GetInfo(target);
         if (dirInfo == null)
         {
             throw new ElFinderFileNotExists();
         }
         CustomFileInfo info = service.GetFileInfo(target, token);
         return(Json(info));
     }
     catch (ElFinderFileNotExists ex)
     {
         throw;
     }
     catch (Exception ex)
     {
         return(Error.Message("Connector.WebDavDriver: Ошибка сервиса при получении информации о сертификатах!"));
     }
 }
예제 #14
0
        internal static void PartyFileListCtrlAddListPrefix(CustomFileListCtrl __instance, CustomFileInfo info)
        {
            try
            {
                Translation.Hooks.FileListCtrlAddListPrefix(__instance, CharaFileInfoWrapper.CreateWrapper(info));
            }

            catch (Exception err)
            {
                Logger.LogException(err, __instance, nameof(PartyFileListCtrlAddListPrefix));
            }
        }
예제 #15
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            string path = e.Argument.ToString();

            System.IO.FileInfo fileInfoIO = new System.IO.FileInfo(path);
            // 要上传的文件地址
            FileStream fs = File.OpenRead(fileInfoIO.FullName);
            // 实例化服务客户的
            ServiceFileClient client = new ServiceFileClient();

            try
            {
                int maxSiz = 1024 * 100;
                // 根据文件名获取服务器上的文件
                CustomFileInfo file = client.GetFileInfo(fileInfoIO.Name);
                if (file == null)
                {
                    file        = new CustomFileInfo();
                    file.OffSet = 0;
                }
                file.Name   = fileInfoIO.Name;
                file.Length = fs.Length;
                if (file.Length > Int32.MaxValue)
                {
                    MessageBox.Show("上传文件大小不能超过2G");
                }
                else
                {
                    if (file.Length == file.OffSet) //如果文件的长度等于文件的偏移量,说明文件已经上传完成
                    {
                        MessageBox.Show("该文件已存在");
                        e.Result = false;   // 设置异步操作结果为false
                    }
                    else
                    {
                        while (file.Length != file.OffSet)
                        {
                            file.SendByte = new byte[file.Length - file.OffSet <= maxSiz ? file.Length - file.OffSet : maxSiz]; //设置传递的数据的大小

                            fs.Position = file.OffSet;                                                                          //设置本地文件数据的读取位置
                            fs.Read(file.SendByte, 0, file.SendByte.Length);                                                    //把数据写入到file.Data中
                            file = client.UpLoadFileInfo(file);                                                                 //上传
                            //int percent = (int)((double)file.OffSet / (double)((long)file.Length)) * 100;
                            int percent = (int)(((double)file.OffSet / (double)((long)file.Length)) * 100);
                            (sender as BackgroundWorker).ReportProgress(percent);
                        }
                        // 移动文件到临时目录(此部分创建可以使用sqlserver数据库代替)
                        string address = string.Format(@"{0}\{1}", Helper.ServerFolderPath, file.Name);
                        fileInfoIO.CopyTo(address, true);
                        LoadUpLoadFile();
                        e.Result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                fs.Close();
                fs.Dispose();
                client.Close();
                client.Abort();
            }
        }
예제 #16
0
        void upLoad(object parame)
        {
            try
            {
                string path   = parame.ToString();
                int    maxSiz = 1024 * 100;

                System.IO.FileInfo fileInfoIO = new System.IO.FileInfo(path);
                // 要上传的文件地址
                FileStream fs = File.OpenRead(fileInfoIO.FullName);
                // 实例化服务客户的
                ServiceFileClient client = new ServiceFileClient();

                // 根据文件名获取服务器上的文件

                CustomFileInfo file = client.GetFileInfo(fileInfoIO.Name);

                if (file == null)
                {
                    file        = new CustomFileInfo();
                    file.OffSet = 0;
                }
                file.Name   = fileInfoIO.Name;
                file.Length = fs.Length;

                if (file.Length == file.OffSet) //如果文件的长度等于文件的偏移量,说明文件已经上传完成
                {
                    MessageBox.Show("该文件已存在");
                }
                else
                {
                    //MessageBox.Show("1");

                    while (file.Length != file.OffSet)
                    {
                        file.SendByte = new byte[file.Length - file.OffSet <= maxSiz ? file.Length - file.OffSet : maxSiz]; //设置传递的数据的大小

                        fs.Position = file.OffSet;                                                                          //设置本地文件数据的读取位置
                        fs.Read(file.SendByte, 0, file.SendByte.Length);                                                    //把数据写入到file.Data中
                        // MessageBox.Show("2");
                        file = client.UpLoadFileInfo(file);                                                                 //上传
                        //int percent = (int)((double)file.OffSet / (double)((long)file.Length)) * 100;
                        int percent = (int)(((double)file.OffSet / (double)((long)file.Length)) * 100);

                        if (progressBar.InvokeRequired)
                        {
                            // MessageBox.Show("3");
                            progressBar.Invoke((ThreadStart) delegate
                            {
                                progressBar.Value = percent;
                                progressBar.Update();
                            });
                        }
                        else
                        {
                            //MessageBox.Show("4");
                            progressBar.Value = percent;
                            progressBar.Update();
                        }
                    }
                    // 移动文件到临时目录(此部分创建可以使用sqlserver数据库代替)
                    string address = string.Format(@"{0}\{1}", Helper.ServerFolderPath, file.Name);

                    fileInfoIO.CopyTo(address, true);
                    LoadUpLoadFile();
                    MessageBox.Show("success");
                }
                fs.Close();
                client.Close();
                //if (this.btnUpload.InvokeRequired)
                //{
                //    this.btnUpload.Invoke((ThreadStart)delegate
                //    {
                //        this.btnUpload.Enabled = true;
                //    });
                //}
                //else
                //{
                this.btnUpload.Enabled = true;
                this.btnUpload.Update();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #17
0
 /// <summary>
 /// 获取文件字符串形式的版本号
 /// </summary>
 /// <param name="fileFullPath">文件全路径</param>
 /// <returns></returns>
 public static string GetFileVersionString(string fileFullPath)
 {
     return(CustomFileInfo.GetCustomFileInfo(fileFullPath).FileVersionString);
 }