public static void OverwriteDocumentTypes(PPDataContext dbFrom, PPDataContext dbTo, IProcessingCallback callback) { foreach (DocumentType dt in dbFrom.DocumentTypes) { if (DocumentType.HasByName(dbTo, dt.Name)) { if (null != callback) { callback.Info(string.Format("Updating document type {0} already exists...", dt.Name)); } DocumentType docType = DocumentType.GetByName(dbTo, dt.Name); docType.Description = dt.Description; docType.Application = dt.Application; dbTo.SubmitChanges(); } else { if (null != callback) { callback.Info(string.Format("Creating document type {0}...", dt.Name)); } DocumentType.CreateNew(dbTo, dt.Name, dt.Description, dt.Application); } } }
public static void OverwriteCardboardProfiles(PPDataContext dbFrom, PPDataContext dbTo, IProcessingCallback callback) { foreach (CardboardProfile cp in dbFrom.CardboardProfiles) { if (CardboardProfile.HasByName(dbTo, cp.Name)) { if (null != callback) { callback.Info(string.Format("Cardboard profile {0} already exists. Skipping...", cp.Name)); } CardboardProfile cardboardProf = CardboardProfile.GetByName(dbTo, cp.Name); cardboardProf.Code = cp.Code; cardboardProf.Thickness = cp.Thickness; dbTo.SubmitChanges(); } else { if (null != callback) { callback.Info(string.Format("Creating carboard profile {0}...", cp.Name)); } CardboardProfile.CreateNew(dbTo, cp.Name, cp.Code, cp.Thickness); } } }
public void OnToolStripEditComponentCode(object sender, EventArgs e) { try { if (!(treeView.SelectedNode.Tag is NodeTag nodeTag)) { return; } PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); if (null == treeNode) { return; } Document doc = treeNode.Documents(db)[0]; if (null == doc) { return; } Pic.DAL.SQLite.Component comp = doc.Components[0]; if (null == comp) { return; } // output Guid / path Guid outputGuid = Guid.NewGuid(); string outputPath = Pic.DAL.SQLite.File.GuidToPath(db, outputGuid, "dll"); // form plugin editor FormPluginEditor editorForm = new FormPluginEditor(); editorForm.PluginPath = doc.File.Path(db); editorForm.OutputPath = outputPath; if (DialogResult.OK == editorForm.ShowDialog()) { _log.Info("Component successfully modified!"); doc.File.Guid = outputGuid; db.SubmitChanges(); // clear component cache in plugin viewer ComponentLoader.ClearCache(); // update pluginviewer pluginViewCtrl.PluginPath = outputPath; } } catch (Exception ex) { _log.Error(ex.ToString()); } }
public static void ClearExistingDocumentsRecursively(PPDataContext dbFrom, TreeNode nodeFrom, TreeNode nodeTo, IProcessingCallback callback) { if (null != callback && !nodeFrom.IsDocument) { callback.Info(string.Format("Processing branch {0}", nodeFrom.Name)); } // get thumbnail path of node to insert string thumbnailPath = nodeFrom.Thumbnail.File.Path(dbFrom); // handle childrens foreach (TreeNode childFrom in nodeFrom.Childrens(dbFrom)) { // get thumbnail of node to insert thumbnailPath = childFrom.Thumbnail.File.Path(dbFrom); if (childFrom.IsDocument) { Document docFrom = childFrom.Documents(dbFrom)[0]; string docTypeName = docFrom.DocumentType.Name; // delete existing document // will be using new data context each time a tree node is deleted // in order to avoid exceptions claiming that there is a foreign key violation using (PPDataContext dbTo0 = new PPDataContext()) { if (nodeTo.HasChild(dbTo0, childFrom.Name)) { string documentName = childFrom.Name; TreeNode childTo = nodeTo.GetChild(dbTo0, documentName); if (null != childTo && childTo.IsDocument) { try { if (null != callback) { callback.Info(string.Format("Deleting tree node {0} ...", childTo.Name)); } childTo.Delete(dbTo0, true, callback); dbTo0.SubmitChanges(); } catch (Exception ex) { callback.Error(string.Format("Deleting document {0} failed with exception {1}", documentName, ex.Message)); } } } } } else // childFrom.IsDocument { using (PPDataContext dbTo2 = new PPDataContext()) { TreeNode childTo = null; if (nodeTo.HasChild(dbTo2, childFrom.Name)) { if (null != callback) { callback.Info(string.Format("Branch {0} already exists.Skipping...", childFrom.Name)); } childTo = nodeTo.GetChild(dbTo2, childFrom.Name); ClearExistingDocumentsRecursively(dbFrom, childFrom, childTo, callback); } } } } }
static void Main(string[] args) { // set up a simple configuration that logs on the console. XmlConfigurator.Configure(); bool deleteAll = true; try { // ================================ CardboardFormat try { PPDataContext db = new PPDataContext(); CardboardFormat cbf1 = CardboardFormat.CreateNew(db, "F1", "Format 1", 1000.0f, 1000.0f); _log.Info(string.Format("Created new cardboard format with Id = {0}", cbf1.ID)); CardboardFormat cbf2 = CardboardFormat.CreateNew(db, "F2", "Format 2", 2000.0f, 2000.0f); _log.Info(string.Format("Created new cardboard format with Id = {0}", cbf2.ID)); CardboardFormat cbf3 = CardboardFormat.CreateNew(db, "F3", "Format 3", 3000.0f, 3000.0f); _log.Info(string.Format("Created new cardboard format with Id = {0}", cbf3.ID)); foreach (CardboardFormat cbf in CardboardFormat.GetAll(db)) { _log.Info(cbf.ToString()); } } catch (System.Exception ex) { _log.Error(ex.Message); } // ================================ // ================================ CardboardProfile // get list of existing cardboards try { PPDataContext db = new PPDataContext(); IEnumerable <CardboardProfile> profiles = from cp in db.CardboardProfiles select cp; foreach (CardboardProfile cbp in profiles) { _log.Info(cbp.ToString()); } db.Dispose(); } catch (System.Exception ex) { _log.Error(ex.Message); } // add first CardboardProfile ->expected to throw exception if already exists try { PPDataContext db = new PPDataContext(); CardboardProfile cbprofile1 = CardboardProfile.CreateNew(db, "Profile1", "P1", 0.1f); _log.Info(string.Format("created cardboard profile with Id = {0}", cbprofile1.ID)); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // add second CardboardProfile try { PPDataContext db = new PPDataContext(); CardboardProfile cbprofile2 = CardboardProfile.CreateNew(db, "Profile2", "P2", 0.2f); _log.Info(string.Format("created cardboard profile with Id = {0}", cbprofile2.ID)); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // delete CardboardProfile { PPDataContext db = new PPDataContext(); CardboardProfile profile = db.CardboardProfiles.Single <CardboardProfile>(cp => cp.Code == "P2"); db.CardboardProfiles.DeleteOnSubmit(profile); db.SubmitChanges(); } // ================================ // ================================ DocumentType // add new DocumentType try { PPDataContext db = new PPDataContext(); DocumentType docType = DocumentType.CreateNew(db, "Parametric component", "Parametric component to be used in PicParam", "PicParam"); _log.Info(string.Format("created document type with Id = {0}", docType.ID)); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // ================================ // ================================ TreeNode // create new rootNodes string imageFilePath = string.Empty; try { PPDataContext db = new PPDataContext(); TreeNode rootNode1 = TreeNode.CreateNew(db, "Parametric components", "Parametric component to be used in PicParam", imageFilePath); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } try { PPDataContext db = new PPDataContext(); TreeNode rootNode2 = TreeNode.CreateNew(db, "Drawing files", "Either PicGEOM or Autocad dxf files", imageFilePath); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // create new child treenode try { PPDataContext db = new PPDataContext(); TreeNode parentNode = TreeNode.GetRootNodes(db)[0]; TreeNode childNode1 = parentNode.CreateChild(db, "Node1", "Node1", imageFilePath); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } Guid guidComponent = Guid.Empty; // ================================ // ================================ Component // create new child node + component try { PPDataContext db = new PPDataContext(); TreeNode parentNode = TreeNode.GetRootNodes(db)[0]; TreeNode childNode1 = parentNode.Childrens(db)[0]; TreeNode childNode2 = null; try { childNode2 = childNode1.CreateChild(db, "Node2", "Node2", imageFilePath); _log.Info(string.Format("successfully created Node with ID = {0}", childNode2.ID)); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } if (null == childNode2) { childNode2 = childNode1.Childrens(db)[0]; } // insert component string filePath = @"K:\Codesion\PicSharp\Pic.Plugin.SimpleRectangle\bin\Release\Pic.Plugin.SimpleRectangle.dll"; Component component = childNode2.InsertComponent(db, filePath, Guid.NewGuid(), "Rounded rectangle", "Rounded rectangle", ""); guidComponent = component.Guid; // set majorations Dictionary <string, double> majorations = new Dictionary <string, double>(); majorations.Add("m1", 1.0); majorations.Add("m2", 2.0); component.InsertNewMajorationSet(db, "Profile1", majorations); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // ================================ // ================================ Document // create documents try { PPDataContext db = new PPDataContext(); TreeNode parentNode = TreeNode.GetRootNodes(db)[0]; string filePath = @"K:\SVN Projects\PicSharp\Pic.Plugin.SimpleRectangle\bin\Release\Pic.Plugin.SimpleRectangle.dll"; parentNode.InsertDocument(db, filePath, "Rounded rectangle", "Rounded Rectangle", "Parametric component", ""); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // ================================ // ================================ TreeBuilder // show document tree TreeBuilder builder = new TreeBuilder(); TreeConsole treeConsole = new TreeConsole(); builder.BuildTree(treeConsole); // ================================ // ================================ try { // retrieve component PPDataContext db = new PPDataContext(); Component component = Component.GetByGuid(db, guidComponent); if (null == component) { throw new ExceptionDAL(string.Format("No component with Guid = {0}", guidComponent)); } CardboardProfile profile3 = CardboardProfile.GetByName(db, "P3"); if (null == profile3) { profile3 = CardboardProfile.CreateNew(db, "P3", "P3", 3.0f); } Dictionary <string, double> defaultMajorations = Component.GetDefaultMajorations(db, component.ID, profile3, Component.MajoRounding.ROUDING_FIRSTDECIMALNEAREST); component.InsertNewMajorationSet(db, profile3.Name, defaultMajorations); defaultMajorations["m1"] = 100.0; defaultMajorations["m2"] = 100.0; component.UpdateMajorationSet(db, profile3, defaultMajorations); db.Dispose(); } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (Exception ex) { _log.Error(ex.Message); } // ================================ // ================================ TreeBuilder // show document tree builder.BuildTree(treeConsole); // ================================ // ================================ Delete components / documents try { if (deleteAll) { PPDataContext db = new PPDataContext(); Component.DeleteAll(db); _log.Info("Successfully deleted Components..."); Document.DeleteAll(db); _log.Info("Successfully deleted Documents..."); DocumentType.DeleteAll(db); _log.Info("Successfully deleted DocumentTypes..."); TreeNode.DeleteAll(db); _log.Info("Successfully deleted TreeNodes..."); CardboardProfile.DeleteAll(db); _log.Info("Successfully deleted CardboardProfile..."); CardboardFormat.DeleteAll(db); _log.Info("Successfully deleted Cardboard formats..."); db.Dispose(); } } catch (ExceptionDAL ex) { _log.Debug(ex.Message); } catch (System.Exception ex) { _log.Error(ex.Message); } // ================================ // ================================ TreeBuilder // show document tree builder.BuildTree(treeConsole); // ================================ } catch (System.Exception ex) { _log.Error(ex.ToString()); } }