示例#1
0
        public void RecoverTest()
        {
            Document           doc  = Application.DocumentManager.MdiActiveDocument;
            DocumentCollection docs = Application.DocumentManager;
            Editor             ed   = doc.Editor;

#if !acad2013
            ed.WriteMessage("Not supported in ACAD versions lower than 2015.");
            return;
#else
            var oldValue = Application.GetSystemVariable("PROXYNOTICE");
            Application.SetSystemVariable("PROXYNOTICE", 0);


            var errorsFile = @"errors.csv";
            var content    = File.ReadAllLines(errorsFile).Select(x => x.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries));
            var forRepair  = content.Where(x => x[1].Equals("eDwgNeedsRecovery")).Select(x => x[0]);
            using (var errorLogger = new StreamWriter("Errors_Recovery.csv", true)
            {
                AutoFlush = true
            })
            {
                foreach (var file in forRepair)
                {
                    //var path = $@"\\?\{file}";
                    try
                    {
                        var path = Path.Combine(@"D:\DwgWork", file.Substring(49));
                        //path = $@"\\?\{path}";
                        docs.AppContextRecoverDocument(path);
                        Application.DocumentManager.MdiActiveDocument.CloseAndSave(path);
                    }
                    catch (System.Exception e)
                    {
                        errorLogger.WriteLine($"{file} -> {e.Message}");
                    }
                }
            }

            Application.SetSystemVariable("PROXYNOTICE", oldValue);
#endif
        }