private async void cmdSubmit_Click(object sender, RoutedEventArgs e) { try { var count = 0; string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath); await ClearData(sender); using (DatabaseCommands commands = new DatabaseCommands()) { var filtered = files.Where(p => p.EndsWith(".dwg", true, CultureInfo.InvariantCulture)); if (filtered.Any()) { commands.InsertIntoGeneralUseDwgs(filtered.ToList()); count = filtered.Count(); } } MessageBox.Show("Files Loaded: " + count, "Message"); } catch (Exception ex) { COMS.ShowMessageAndLog("Please select files!"); } }
public List <Logs> GetDrawings() { try { using (DatabaseCommands commands = new DatabaseCommands()) { var logs = _logs = commands.GetLastAllLogs(); if (logs.FirstOrDefault() == null) { return(null); } _drawings = new List <Logs>(logs.Where(l => l.Issue.Contains(".DWG") && (l.Issue.Contains("Process Drawing"))).OrderBy(o => o.Id)); } if (_drawings.FirstOrDefault() == null) { return(null); } else { return(_drawings.ToList()); } } catch (Exception ex) { COMS.LogException(ex); } return(null); }
public bool LogException(string message, Exception ex) { try { COMS.LogException(ex); } catch (Exception) { throw; } return(true); }
public bool AddLog(string message) { try { COMS.AddLog(message); } catch (Exception) { throw; } return(true); }
private async void Clear_Click(object sender, RoutedEventArgs e) { try { var checkbox = (System.Windows.Forms.CheckBox)sender; if (checkbox != null & checkbox.Checked == true) { await ClearData(sender); } } catch (Exception ex) { COMS.LogException(ex); } }
public static void AsyncDXFCall(string originalname, string filename, string coursecode, string hole, bool Is2013DXF, Autodesk.AutoCAD.DatabaseServices.Database db) { if (String.IsNullOrEmpty(filename)) { throw new ArgumentNullException(nameof(filename)); } if (String.IsNullOrEmpty(coursecode)) { throw new ArgumentNullException(nameof(coursecode)); } string name = ""; var doc = Application.DocumentManager.MdiActiveDocument; //Autodesk.AutoCAD.DatabaseServices.Database db = // Application.DocumentManager.MdiActiveDocument.Database; try { //Todo: A possible bug in IsZDrawing DXF //Todo: originalname to name ? if (IsZDrawing(filename)) { name = string.Format("z_{0}_{1}.dxf", coursecode, hole); filename = Path.Combine(Path.GetDirectoryName(filename), name); COMS.AddLog("Creating file Z-Surface DXF: " + name); originalname = filename; } else { COMS.AddLog("Creating file S-Surface DXF: " + name); } if (!Is2013DXF) { db.DxfOut(originalname.Replace(".DWG", ".dxf"), 16, DwgVersion.Current); } else { db.DxfOut(originalname.Replace(".DWG", ".dxf"), 16, DwgVersion.AC1027); } } catch (System.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } }
private void cmdGetDir_Click(object sender, RoutedEventArgs e) { folderBrowserDialog1 = new FolderBrowserDialog(); try { DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { txtDirectory.Text = folderBrowserDialog1.SelectedPath; } } catch (Exception ex) { COMS.LogException(ex); } }
public async Task <int> ClearData(object sender) { try { if (state) { using (DatabaseCommands commands = new DatabaseCommands()) { var delete = commands.DeleteAllFromGUStack(); } } } catch (Exception ex) { COMS.LogException(ex); } return(1); }
public void WriteReport(List <Logs> errors) { try { COMS.AddLog("*****************Batch Errors********************"); errors.All(p => { COMS.AddLog(String.Format("{0}: {1}", p.Source ?? "No Source Drawing Information", p.Issue)); return(true); }); COMS.AddLog("*****************Batch Errors********************"); } catch (Exception ex) { COMS.LogException(ex); } }
public static List <ObjectId> GetPolylineEntityIDs() { List <ObjectId> ids = null; try { // Get the document var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; using (var tran = db.TransactionManager.StartTransaction()) { var tbl = (BlockTable)tran.GetObject(db.BlockTableId, OpenMode.ForRead); var br = (BlockTableRecord)tran.GetObject(tbl[BlockTableRecord.ModelSpace], OpenMode.ForRead); var b = br.Cast <ObjectId>(); ids = (from id in b where id.ObjectClass.DxfName.ToUpper() == "POLYLINE" && id.ObjectClass.DxfName.ToUpper() == "POLYLINE2D" select id).ToList(); tran.Commit(); } } catch (System.Exception ex) { COMS.LogException(ex); } return(ids); }
public static void SynchExportDWGs() { List <ExportToCADStack> allExportToCadRecords = null; using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); bool Is2013Version = false; foreach (var file in allExportToCadRecords) { Is2013Version = commands.IsDXFVersionByDate ((DateTime)file.DateStamp); COMS.AddLog(string.Format ("Set the DXF file to version 2013: {0}", Is2013Version)); if (!commands.IsDWGStartedEprtToCad(file.Id) && !commands.IsDXFStartedExportToCad(file.Id) && !commands.IsCompletedExportToCad(file.Id)) { commands.SetStartFlagExportToCad(file.Id); if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var shole = GolfHoles.GetHoles((int)file.Hole); if (File.Exists(file.CompletePath)) { #region Use this if reading file var doc = Application.DocumentManager.Open (file.CompletePath, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; #endregion PGA.DrawingManager.Commands. CloseAllButActiveDocuments(); using (doc.LockDocument()) { var name = ""; if (IsZDrawing(file.CompletePath)) { name = GetDWGPrefix(file.CompletePath, file.Hole); } else { name = GetDWGPrefix(file.CompletePath, file.Hole); } LoopSurfaces(file.CompletePath, name, c.ToString(), shole, Is2013Version); } } } commands.SetDXFFlagExportToCad(file.Id); commands.SetCompletedFlagExportToCad(file.Id); } commands.DeleteAllExportToCadRecords(); } }
public static void AsyncExportDXFs() { List <ExportToCADStack> allExportToCadRecords = null; try { using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); if (allExportToCadRecords != null) { Application.SetSystemVariable("FILEDIA", 0); bool Is2013Version = false; bool SkipSDxf = false; foreach (var file in allExportToCadRecords) { if (!commands.IsDXFStartedExportToCad(file.Id) && !commands.IsCompletedExportToCad(file.Id)) { commands.SetDXFFlagExportToCad(file.Id); commands.LockFileExportToCad(file.Id); var s = commands.GetSettingsByDate((DateTime)file.DateStamp); SkipSDxf = commands.IsSkipDXFByDate ((DateTime)file.DateStamp); Is2013Version = commands.IsDXFVersionByDate ((DateTime)file.DateStamp); COMS.AddLog(string.Format ("Set the DXF file to version 2013: {0}", Is2013Version)); if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var shole = GolfHoles.GetHoles((int)file.Hole); var modifiedname = ModifyDwgName(file.CompletePath); // Skip DXF if (SkipSDxf) { if (!(IsZDrawing(file.CompletePath))) { COMS.AddLog("Skip DXF! Omitting S-Surface DXF."); commands.SetCompletedFlagExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } if (File.Exists(modifiedname)) { var doc = Application.DocumentManager.Open (modifiedname, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; using (doc.LockDocument()) { //PGA.DrawingManager.Commands. //CloseAllButActiveDocuments(); if (IsZDrawing(modifiedname)) { AsyncDXFCall(file.CompletePath, modifiedname, c.ToString(), shole, Is2013Version, db); COMS.AddLog("Done with file Z-Surface DXF: " + modifiedname); commands.SetCompletedFlagExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } else { if (!SkipSDxf) { if (s.SportVision == true) { var _modifiedname = ""; if (!String.IsNullOrEmpty(_modifiedname = (CheckAndCreateDirectory(file.CompletePath, shole, c, s.TourCode)))) { AsyncDXFCall(_modifiedname, file.CompletePath, c, shole, Is2013Version, db); COMS.AddLog("Done with file S-Surface DXF: " + _modifiedname); } } else { AsyncDXFCall(file.CompletePath, file.CompletePath, c.ToString(), shole, Is2013Version, db); } } commands.SetCompletedFlagExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } } } } } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } catch (System.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } }
public static void AsyncExportDWGs() { List <ExportToCADStack> allExportToCadRecords = null; try { using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); if (allExportToCadRecords != null) { Application.SetSystemVariable("FILEDIA", 0); foreach (var file in allExportToCadRecords) { if (!commands.IsDWGStartedEprtToCad(file.Id) && !commands.IsDXFStartedExportToCad(file.Id) && !commands.IsCompletedExportToCad(file.Id)) { commands.SetStartFlagExportToCad(file.Id); commands.LockFileExportToCad(file.Id); if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var shole = GolfHoles.GetHoles((int)file.Hole); var SkipSDxf = commands.IsSkipDXFByDate ((DateTime)file.DateStamp); bool DwgInsert = false; if (file.Function != null) { DwgInsert = file.Function.Contains("INSERT"); } COMS.AddLog("DwgInsert=" + DwgInsert); if (DwgInsert) { ExportToAutoCADCurrentDWG(file.CompletePath, file.Hole); commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } // Skip DXF and ACAD if (SkipSDxf) { if (!(IsZDrawing(file.CompletePath))) { commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } if (File.Exists(file.CompletePath)) { var doc = Application.DocumentManager.Open (file.CompletePath, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; using (doc.LockDocument()) { try { //PGA.MessengerManager.MessengerManager.AddLog("Starting Snapshot!"); // try // { // PGA.PlotManager.PrintCommands.PublishLayouts(file.CompletePath, // file.Hole.ToString()); // } // catch (System.Exception ex) // { // PGA.MessengerManager.MessengerManager.AddLog(ex.Message); // } // try // { // PGA.PlotManager.PlotCommands.SnapshotToFile( // Path.ChangeExtension(file.CompletePath, "png"), // VisualStyleType.Wireframe2D); // PGA.PlotManager.PlotCommands.SnapShotFromPrintScreen( // Path.ChangeExtension(file.CompletePath, "jpg")); // } // catch (System.Exception ex) // { // PGA.MessengerManager.MessengerManager.AddLog(ex.Message); // } // PGA.MessengerManager.MessengerManager.AddLog("Ending Snapshot!"); } catch (System.Exception ex) { COMS.LogException(ex); } if (IsZDrawing(file.CompletePath)) { ExportZToAutoCADCurrentDWG(file.CompletePath, file.Hole); commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } else { if (!SkipSDxf) { ExportToAutoCADCurrentDWG(file.CompletePath, file.Hole); } commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } } } } } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } catch (System.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } }