Exemple #1
0
        /// <summary>
        /// Очистка строки от secure-данных
        /// </summary>
        /// <exception cref="ArgumentException"></exception>
        /// <param name="secureString">Очищаемая строка</param>
        /// <returns>Результат очистки</returns>
        public CleanResult CleanString(string secureString)
        {
            var cleanString = Regex.Replace(secureString, @"\s", String.Empty);
            var matches     = _regexTemplate.Matches(cleanString);

            if (matches.Count == 0)
            {
                throw new ArgumentException("Invalid string");
            }
            var cleanResult = new CleanResult();

            foreach (var groupName in _valueGroupNames)
            {
                Group secureValue = matches[0].Groups[groupName];
                cleanString = cleanString.Remove(secureValue.Index, secureValue.Length);
                cleanString = cleanString.Insert(secureValue.Index, new String(Replacement, secureValue.Length));
                cleanResult.SecureData.Add(new SecureData
                {
                    Key   = groupName,
                    Value = secureValue.Value
                });
            }
            cleanResult.CleanString = cleanString;
            return(cleanResult);
        }
        public string CleanUrl(string secureUrl)
        {
            CleanResult cleanResult = _urlCleanMode == null ? null : _urlCleanMode.CleanString(secureUrl);

            if (cleanResult == null)
            {
                return(secureUrl);
            }
            if (DataSaver != null)
            {
                DataSaver.Invoke(cleanResult);
            }
            return(cleanResult.CleanString);
        }
        public string CleanResBody(string secureResBody)
        {
            CleanResult cleanResult = _responseCleanMode == null ? null : _responseCleanMode.CleanString(secureResBody);

            if (cleanResult == null)
            {
                return(secureResBody);
            }
            if (DataSaver != null)
            {
                DataSaver.Invoke(cleanResult);
            }
            return(cleanResult.CleanString);
        }
Exemple #4
0
 private static void SecureDataSaver(CleanResult result)
 {
     lock (SyncFileAccessObject)
     {
         using (StreamWriter sw = File.AppendText(ResultFileName))
         {
             sw.WriteLine(result.CleanString);
             foreach (var secureData in result.SecureData)
             {
                 sw.WriteLine("{0} : {1}", secureData.Key, secureData.Value);
             }
             sw.WriteLine("---");
         }
     }
 }
 private static void PerformRemove(CleanResult result, FileInfo file)
 {
     try
     {
         if (!file.IsReadOnly)
         {
             file.Delete();
             result.CleanedDirectories++;
         }
     }
     catch (Exception ex)
     {
         result.ErrorList.Add(file.FullName, ex.Message);
     }
 }
        void OnGUI()
        {
            includePackages = EditorGUILayout.Toggle("Include packages", includePackages);
            skipErrorShader = EditorGUILayout.Toggle("Skip error shader", skipErrorShader);

            EditorGUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("清理", GUILayout.Height(40f)))
                {
                    outputInfo = "正在清理中,请稍候。。。";

                    List <string> searchFolders = new List <string>();
                    searchFolders.Add("Assets");
                    if (includePackages)
                    {
                        searchFolders.Add("Packages");
                    }

                    result = SearchAndCleanUnusedProperties(searchFolders.ToArray(), skipErrorShader, true);

                    outputInfo = $"Total materials: {result.SearchCount}\nCleaned materials: {result.CleanCount}\n" + result.DetailInfo;
                    EditorUtility.DisplayDialog(c_Dialog_Title, $"Cleaned {result.CleanCount} materials", "Ok");
                }
                //if (GUILayout.Button("保存结果到文件", GUILayout.Height(40f)))
                //{
                //    if (isCleanButtonClicked)
                //    {
                //        EditorToolsHelper.SaveStringToLocal("RegisterOnClick查询结果", cleanResultString);
                //        outputInfo = "查询结果已保存至桌面";
                //    }
                //    else
                //    {
                //        outputInfo = "请先查找";
                //    }
                //}
            }
            EditorGUILayout.EndHorizontal();

            //禁止交互、自动扩展大小、自动隐藏滚动条
            scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Height(this.position.height - 88));
            {
                EditorGUILayout.LabelField(outputInfo, EditorStyles.textArea, GUILayout.ExpandHeight(true));
            }
            EditorGUILayout.EndScrollView();
        }
        public async Task <CleanResult> DeleteAsync(IEnumerable <FileInfo> paths)
        {
            return(await Task.Run(() =>
            {
                var result = new CleanResult();

                foreach (FileInfo file in paths)
                {
                    PerformRemove(result, file);
                }

                if (result.ErrorList.Any())
                {
                    result.Success = false;
                }

                return result;
            }));
        }
Exemple #8
0
        public void OnItemComplete(string sBaseFile, string sAPICleaned, string sBinCleaned, string sInfo, CleanResult APIresult, CleanResult LSresult)
        {
            CancelWatchDog();

            if (InvokeRequired)
            {
                this.BeginInvoke(new ItemCompleteEventHandler(OnItemComplete), new object[] { sBaseFile, sAPICleaned, sBinCleaned, sInfo, APIresult, LSresult });
                return;
            }

            CleanedDocInfo cdi = new CleanedDocInfo();
            cdi.APICleanedFileName = sAPICleaned;
            cdi.BaseFileName = sBaseFile;
            cdi.BinCleanedFileName = sBinCleaned;
            cdi.detailedResults = this.ResultsText.Text;

            UpdateCounts(APIresult, LSresult);

            ListViewItem lvi = new ListViewItem(new FileInfo(sBaseFile).Name);
            lvi.Tag = cdi;
            lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, sInfo));
            lvi.ForeColor = GetForegroundColor(APIresult, LSresult);
            ListView lvTarget = listViewOkFiles;
            if (lvi.ForeColor != Color.Black)
            {
                lvi.ToolTipText = ConstructToolTip(sBaseFile, LSresult, sInfo);
                lvTarget = listViewProblemFiles;
            }

            lvTarget.Items.Add(lvi);

            lvTarget.EnsureVisible(lvTarget.Items.Count - 1);

            if (m_threadCleaning != null)
                ResetWatchDog();

        }
        private void CollateFailures(string sBaseFile, CleanResult cleanResult, string detail)
        {
            InitResultsFolder();
            string destPath;
            switch (cleanResult)
            {
                case CleanResult.CleanedOK:
                    return;

                case CleanResult.CleanIncomplete:
                    destPath = m_resultsFolders.Incomplete;
                    break;

                case CleanResult.CorruptedDoc:
                case CleanResult.Crashed:
                    destPath = m_resultsFolders.Corrupted;
                    break;

                default:
                    //must be a new value on the enum...
                    throw new ArgumentException();
            }

            string copy = Path.Combine(destPath, Path.GetFileName(sBaseFile));

            File.Copy(sBaseFile,
                      copy, true);

            WriteFileSummary(copy, detail);            
        }
        private void ItemComplete(string sBaseFile, 
            string sApiCleaned, 
            string sBinCleaned, 
            string sInfo, 
            CleanResult apiResult, 
            CleanResult lsResult,
            string detail)
        {
            m_formParent.OnItemComplete(sBaseFile, sApiCleaned, sBinCleaned, sInfo, apiResult, lsResult);

            if (m_advancedOptions.CollateFailures)
            {
                CollateFailures(sBaseFile, lsResult, detail);

                WriteCsv(sBaseFile, sInfo);
            }
        }
Exemple #11
0
        private void UpdateCounts(CleanResult APIresult, CleanResult LSresult)
        {
            m_iDocumentsProcessed++;

            switch (APIresult)
            {
                case CleanResult.CleanedOK:
                    break;
                case CleanResult.CleanIncomplete:
                    m_iAPICleanIncompletes++;
                    break;
                case CleanResult.CorruptedDoc:
                    break;
                case CleanResult.Crashed:
                    m_iAPICleanCrashes++;
                    break;
            }

            switch (LSresult)
            {
                case CleanResult.CleanedOK:
                    break;
                case CleanResult.CleanIncomplete:
                    m_iLightSpeedCleanIncompletes++;
                    break;
                case CleanResult.CorruptedDoc:
                    m_iLightSpeedCorruptedDocs++;
                    break;
                case CleanResult.Crashed:
                    m_iLightSpeedCleanCrashes++;
                    break;
            }

            labelLightSpeedSummary.Text = BuildLightSpeedSummaryText();
            labelAPISummary.Text = BuildAPISummaryText();

        }
Exemple #12
0
 private Color GetForegroundColor(CleanResult APIresult, CleanResult LSresult)
 {
     switch (LSresult)
     {
         case CleanResult.CleanedOK:
             return Color.Black;
         case CleanResult.CleanIncomplete:
             return Color.Blue;
         case CleanResult.CorruptedDoc:
         case CleanResult.Crashed:
             return Color.Red;
     }
     return Color.Black;
 }
Exemple #13
0
 private static void RaiseDirectoryCleanedEvent(string path, CleanResult result)
 {
     DirectoryCleanedEventHandler temp = DirectoryCleaned;
     if (temp != null)
     {
         DirectoryCleanedEventArgs eventArgs = new DirectoryCleanedEventArgs(path, result);
         temp(eventArgs);
     }
 }
Exemple #14
0
        public static CleanResult Clean(IFileSystem fileSystem, string targetPath, string sourcePath, 
            string pattern = "*.*", FileAttributes attributes = FileAttributes.Normal)
        {
            // If the target path is null, throw an exception.
            if (targetPath == null)
            {
                throw new ArgumentNullException("targetPath", "TargetPath null.");
            }

            // If the source path is null, throw an exception.
            if (sourcePath == null)
            {
                throw new ArgumentNullException("sourcePath", "SourcePath null.");
            }

            // If the target directory doesn't exist, throw an exception.
            if (!fileSystem.Directory.Exists(targetPath))
            {
                throw new SyncDirectoryNotFoundException(targetPath);
            }

            // If the source directory doesn't exist, throw an exception.
            if (!fileSystem.Directory.Exists(sourcePath))
            {
                throw new SyncDirectoryNotFoundException(sourcePath);
            }

            CleanResult result = new CleanResult();
            IEnumerable<string> sourceFilePaths = fileSystem.Directory.GetFiles(sourcePath);
            IEnumerable<string> sourceDirectoryPaths = fileSystem.Directory.GetDirectories(sourcePath);

            // Loop through each file in the target directory.
            foreach (string targetFilePath in fileSystem.Directory.GetFiles(targetPath, pattern))
            {
                FileInfoBase targetFileInfo = fileSystem.FileInfo.FromFileName(targetFilePath);
                if ((targetFileInfo.Attributes & attributes) != attributes)
                {
                    continue;
                }

                // If it matches a file in the source directory, skip it.
                string sourceFilePath = Path.Combine(sourcePath, targetFileInfo.Name);//use FullName?? check if Name includes Extension
                if (fileSystem.File.Exists(sourceFilePath))
                {
                    result.MatchedFiles.Add(targetFileInfo.Name);
                    RaiseEntryEvent(FileMatched, targetFilePath);
                    continue;
                }
                // Otherwise, try to delete it.
                try
                {
                    targetFileInfo.Delete();
                    RaiseEntryEvent(EntryDeleted, targetFilePath);
                    result.DeletedEntries.Add(targetFileInfo.Name);
                }
                catch (Exception ex)
                {
                    RaiseErrorEvent(targetFilePath, ex);
                    result.FailedEntries.Add(targetFileInfo.Name, ex);
                }
            }

            // Loop through each sub-directory in the target directory.
            foreach (string targetDirectoryPath in fileSystem.Directory.GetDirectories(targetPath))
            {
                // If it matches a subdirectory in the source, clean it as well.
                DirectoryInfoBase targetDirectoryInfo = fileSystem.DirectoryInfo.FromDirectoryName(targetDirectoryPath);
                string sourceDirectoryPath = Path.Combine(sourcePath, targetDirectoryInfo.Name);
                if (fileSystem.Directory.Exists(sourceDirectoryPath))
                {
                    CleanResult subDirectoryResult = Clean(fileSystem, targetDirectoryPath, sourceDirectoryPath, pattern, attributes);
                    result.DirectoryResults.Add(targetDirectoryInfo.Name, subDirectoryResult);
                    continue;
                }
                // Otherwise, try to delete it.
                try
                {
                    targetDirectoryInfo.Delete();
                    RaiseEntryEvent(EntryDeleted, targetDirectoryPath);
                    result.DeletedEntries.Add(targetDirectoryInfo.Name);
                }
                catch (Exception ex)
                {
                    RaiseErrorEvent(targetDirectoryPath, ex);
                    result.FailedEntries.Add(targetDirectoryInfo.Name, ex);
                }
            }

            // Flag up the clean.
            RaiseDirectoryCleanedEvent(targetPath, result);
            return result;
        }
Exemple #15
0
 public DirectoryCleanedEventArgs(string path, CleanResult result)
     : base(path)
 {
     Result = result;
 }
Exemple #16
0
        private string ConstructToolTip(string sBaseFile, CleanResult LSresult, string sInfo)
        {
            if (sBaseFile.ToLower().EndsWith("xls") && LSresult == CleanResult.CorruptedDoc)
            {
                return "Some xls files with macros report as corrupt using this tool (cannot save), but seem to be OK when tested manually";
            }

            if (sBaseFile.ToLower().EndsWith("doc") && LSresult == CleanResult.Crashed)
            {
                return "Common causes of LightSpeed redact failure are Word 6/95 .doc files, or RTF files with a .DOC extension";
            }

            if (sBaseFile.ToLower().EndsWith("doc") && LSresult == CleanResult.CorruptedDoc && sInfo.Contains("The disk is full"))
            {
                return "Sometimes cleaned documents fail to save under Automation with a 'The disk is full' message. The cleaned document usually saves correctly when opened manually.";
            }

            if (sBaseFile.ToLower().EndsWith("doc") && LSresult == CleanResult.CorruptedDoc && sInfo.Contains("macro storage"))
            {
                return "Sometimes cleaned templates fail to open under Automation with a 'could not open macro storage' message. The cleaned template usually opens correctly from the UI.";
            }

            //Debug.Assert(false);

            return "";
        }
Exemple #17
0
        public static string MakePrediction(PredictionEngine <ModelInput, Prediction> predEngine, float[] labelsArray, CleanResult cleanResult)
        {
            string predictedString = "";
            var    shapes          = cleanResult.Shapes.OrderBy(s => s.MinX).ToArray();

            foreach (var shape in shapes)
            {
                int shapeWidth  = shape.MaxX - shape.MinX + 1;
                int shapeHeight = shape.MaxY - shape.MinY + 1;

                if (shapeWidth > SAMPLE_WIDTH || shapeHeight > SAMPLE_HEIGHT)
                {
                    continue;
                }

                int offsetX = (SAMPLE_WIDTH - shapeWidth) / 2;
                int offsetY = (SAMPLE_HEIGHT - shapeHeight) / 2;

                bool[,] mask = new bool[SAMPLE_WIDTH, SAMPLE_HEIGHT];

                for (int y = shape.MinY; y <= shape.MaxY; y++)
                {
                    for (int x = shape.MinX; x <= shape.MaxX; x++)
                    {
                        var col = cleanResult.Result.GetPixel(x, y);
                        if (col.R == 255 && col.G == 255 && col.B == 255)
                        {
                            mask[x - shape.MinX + offsetX, y - shape.MinY + offsetY] = true;
                        }
                    }
                }

                float[] flattenedMask = new float[SAMPLE_WIDTH * SAMPLE_HEIGHT];
                int     idx           = 0;
                for (int y = 0; y < SAMPLE_HEIGHT; y++)
                {
                    for (int x = 0; x < SAMPLE_WIDTH; x++)
                    {
                        flattenedMask[idx] = mask[x, y] ? 1 : 0;
                        idx++;
                    }
                }

                var sample = new ModelInput()
                {
                    Pixels = flattenedMask
                };


                var result = predEngine.Predict(sample);

                int   maxIdx   = -1;
                float maxScore = float.MinValue;
                for (int i = 0; i < result.Score.Length; i++)
                {
                    if (maxScore < result.Score[i])
                    {
                        maxScore = result.Score[i];
                        maxIdx   = i;
                    }
                }

                var predictedLabel = labelsArray[maxIdx];

                predictedString += predictedLabel + "";
            }

            return(predictedString);
        }