/// <summary> /// Performs refinement on the given file in order for same quality /// shapes present in the library. /// <para> /// The refinement process works as follows: /// <list type="number"> /// <item><description> /// First of the shape will be moved to a temporary directory where /// all the refinement operations will be performed. /// </description></item> /// <item><description> /// Next the shape will be refined one step at a time for a maximum /// of <see cref="Settings.MaxRefineIterations"/> attempts. If the /// shapes is not refined at so many attempts then it is assumed /// that the shape can not be fixed. /// </description></item> /// <item><description> /// Lastly the shape will be moved to a specified directory depending /// on the success of the refinement operation. If the shape was /// successfully refined then it will be move to the /// <paramref name="successMap"/>, if it could not be refined then /// instead it will be moved to the <paramref name="failureMap"/>. /// If one of these maps is not specified then it will be placed /// back into its original folder and will stil be loaded in by the /// application. /// </description></item> /// </list> /// </para> /// </summary> /// <param name="file">Information about the file which needs to be refined. /// The file will be modified in the process of refining the shape and the /// original file will be lost.</param> /// <param name="successMap">The directory where the shape should be /// moved to after a successful refinement.</param> /// <param name="failureMap">The directory where the shape should be /// moved to after it could no longer be refined for further analysis.</param> private void Refine(ref FileInfo file, string successMap = null, string failureMap = null) { if (file == null || !file.Exists) { throw new ArgumentNullException(nameof(file)); } // Remember the original map for later. string originalMap = file.Directory.Parent.FullName; // All modifications happen in the temp map. MoveFile(ref file, Settings.ShapeTempDir); // Refine it a maximum of X amounts of time. int attempts = Settings.MaxRefineIterations; while (!Refiner.RefineFile(file) && --attempts >= 0) { ; } // If it is refined then we add it to the final map. // If it is not refined then we add it to the failed map. if (attempts < 0 && failureMap != null) { MoveFile(ref file, failureMap); } else if (attempts >= 0 && successMap != null) { MoveFile(ref file, successMap); } else { MoveFile(ref file, originalMap); } }