public static void Overwrite(string zipFilePath, IProcessingCallback callback)
        {
            // check existence of zip archive
            if (!System.IO.File.Exists(zipFilePath))
            {
                throw new FileNotFoundException(string.Format("File {0} not found", zipFilePath), zipFilePath);
            }
            // extract zip archive to temp
            DBDescriptor dbDescFrom = DBDescriptor.CreateTempFromArchive(zipFilePath, callback);

            PPDataContext dbFrom   = new PPDataContext(dbDescFrom);
            TreeNode      nodeFrom = TreeNode.GetRootNodes(dbFrom)[0];

            PPDataContext dbTo   = new PPDataContext();
            TreeNode      nodeTo = TreeNode.GetRootNodes(dbTo)[0];

            // merge format table
            OverwriteCardboardFormats(dbFrom, dbTo, callback);
            // merge cardboard profiles
            OverwriteCardboardProfiles(dbFrom, dbTo, callback);
            // merge document types
            OverwriteDocumentTypes(dbFrom, dbTo, callback);

            // first clear existing documents
            ClearExistingDocumentsRecursively(dbFrom, nodeFrom, nodeTo, callback);
            // then merge
            using (PPDataContext dbTo1 = new PPDataContext())
            {
                MergeTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
            }
        }
 /// <summary>
 /// copy document types from dbFrom to dbTo
 /// </summary>
 public static void CopyDocumentTypes(PPDataContext dbFrom, PPDataContext dbTo)
 {
     foreach (DocumentType dt in dbFrom.DocumentTypes)
     {
         DocumentType.CreateNew(dbTo, dt.Name, dt.Description, dt.Application);
     }
 }
 public static void BuildListOfUsedCardboardProfiles(PPDataContext db, TreeNode nodeFrom, ref List <string> listProfileNames)
 {
     foreach (TreeNode childFrom in nodeFrom.Childrens(db))
     {
         if (childFrom.IsDocument)
         {
             Document docFrom     = childFrom.Documents(db)[0];
             string   docTypeName = docFrom.DocumentType.Name;
             if (string.Equals("Parametric component", docTypeName, StringComparison.CurrentCultureIgnoreCase))
             {
                 // get component
                 Component compFrom = docFrom.Components[0];
                 foreach (MajorationSet mjset in compFrom.MajorationSets)
                 {
                     string profileName = mjset.CardboardProfile.Name;
                     if (null == listProfileNames.Find(p => p == profileName))
                     {
                         listProfileNames.Add(profileName);
                     }
                 }
             }
         }
         else
         {
             BuildListOfUsedCardboardProfiles(db, childFrom, ref listProfileNames);
         }
     }
 }
示例#4
0
        private void CopyTreeNodeRecursively(PPDataContext db, IProcessingCallback callback)
        {
            if (null != callback)
            {
                callback.Info("Tree nodes...");
            }

            PLMPackSR.PLMPackServiceClient client = new PLMPackSR.PLMPackServiceClient();
            client.ClientCredentials.UserName.UserName = UserName;
            client.ClientCredentials.UserName.Password = Password;

            List <TreeNode> rootNodes = TreeNode.GetRootNodes(db);
            string          offset    = string.Empty;

            PLMPackSR.DCTreeNode userRootNode = client.GetUserRootNode();

            client.Close();

            foreach (TreeNode root in rootNodes)
            {
                List <TreeNode> rootChildrens = root.Childrens(db);
                foreach (TreeNode tn in rootChildrens)
                {
                    RecursiveInsert(db, tn, userRootNode, string.Empty, callback);
                }
            }
        }
 public static void MergeCardboardProfiles(PPDataContext dbFrom, PPDataContext dbTo, List <string> listCardboardProfiles, IProcessingCallback callback)
 {
     foreach (string cpName in listCardboardProfiles)
     {
         CardboardProfile cp = CardboardProfile.GetByName(dbFrom, cpName);
         if (null != cp)
         {
             if (CardboardProfile.HasByName(dbTo, cp.Name))
             {
                 if (null != callback)
                 {
                     callback.Info(string.Format("Cardboard profile {0} already exists. Skipping...", cp.Name));
                 }
             }
             else if (CardboardProfile.HasByCode(dbTo, cp.Code))
             {
                 if (null != callback)
                 {
                     callback.Info(string.Format("Cardboard profile with code {0} already exists. Skipping...", cp.Code));
                 }
             }
             else
             {
                 if (null != callback)
                 {
                     callback.Info(string.Format("Creating carboard profile {0}...", cp.Name));
                 }
                 CardboardProfile.CreateNew(dbTo, cp.Name, cp.Code, cp.Thickness);
             }
         }
     }
 }
        private void UpdateMajorationValues()
        {
            // retrieve majoration from database
            PPDataContext db = new PPDataContext();
            Dictionary <string, double> dictMajo = Pic.DAL.SQLite.Component.GetDefaultMajorations(
                db
                , _componentId
                , _profile
                // rounding to be applied while building majoration dictionary
                , Pic.DAL.SQLite.Component.IntToMajoRounding(Properties.Settings.Default.MajorationRounding)
                );

            // update nud control values
            foreach (Control ctrl in Controls)
            {
                NumericUpDown nud = ctrl as NumericUpDown;
                if (null == nud || !nud.Name.StartsWith("nud_"))
                {
                    continue;
                }
                if (dictMajo.ContainsKey(nud.Name.Substring(4)))
                {
                    decimal v = (decimal)dictMajo[nud.Name.Substring(4)];
                    if (nud.Minimum <= v && v <= nud.Maximum)
                    {
                        nud.Value = v;
                    }
                }

                nud.MouseEnter   += new EventHandler(nud_MouseEnter);
                nud.ValueChanged += new EventHandler(nud_ValueChanged);
            }
            _dirty = false;
        }
 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 bool BackupBranch(List <string> nodePath, string zipFilePath, IProcessingCallback callback)
        {
            // remove zip path if it already exists
            if (System.IO.File.Exists(zipFilePath))
            {
                System.IO.File.Delete(zipFilePath);
            }
            // build destination database path
            DBDescriptor dbDescTo = DBDescriptor.CreateTemp();

            {
                // build data contexts
                PPDataContext dbFrom = new PPDataContext();
                using (PPDataContext dbTo = new PPDataContext(dbDescTo))
                {
                    // copy format table
                    CopyCardboardFormats(dbFrom, dbTo);
                    // copy cardboard profiles
                    CopyCardboardProfiles(dbFrom, dbTo);
                    // copy document types
                    CopyDocumentTypes(dbFrom, dbTo);
                    // copy branch nodes recursively
                    TreeNode nodeFrom = TreeNode.GetNodeByPath(dbFrom, null, nodePath, 0);
                    TreeNode nodeTo   = TreeNode.GetNodeByPath(dbTo, null, nodePath, 0);;
                    CopyTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
                }
                GC.Collect();
            }
            Thread.Sleep(1000);
            // archive temp database
            dbDescTo.Archive(zipFilePath, callback);
            return(true);
        }
 /// <summary>
 /// copy cardboard formats from dbFrom to dbTo
 /// </summary>
 public static void CopyCardboardFormats(PPDataContext dbFrom, PPDataContext dbTo)
 {
     foreach (CardboardFormat cf in dbFrom.CardboardFormats)
     {
         CardboardFormat.CreateNew(dbTo, cf.Name, cf.Description, cf.Length, cf.Width);
     }
 }
 public ComponentLoaderControl()
 {
     InitializeComponent();
     if (this.DesignMode)
     {
         return;                     // exit when in design mode
     }
     try
     {
         // initialize profile combo box
         comboBoxProfile.Items.Clear();
         PPDataContext           db          = new PPDataContext();
         List <CardboardProfile> listProfile = new List <CardboardProfile>(CardboardProfile.GetAll(db));
         foreach (CardboardProfile profile in listProfile)
         {
             comboBoxProfile.Items.Add(profile);
         }
         if (comboBoxProfile.Items.Count > 0)
         {
             comboBoxProfile.SelectedIndex = 0;
         }
         // ComponentSearchMethodDB
         pluginViewCtrl.SearchMethod = new ComponentSearchMethodDB();
         // Localizer
         pluginViewCtrl.Localizer = LocalizerImpl.Instance;
     }
     catch (Exception ex)
     {
         _log.Error(string.Format("Exception: {0}", ex.ToString()));
     }
 }
 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);
         }
     }
 }
 /// <summary>
 /// copy cardboard profile from dbFrom to dbTo
 /// </summary>
 public static void CopyCardboardProfiles(PPDataContext dbFrom, PPDataContext dbTo)
 {
     foreach (CardboardProfile cp in dbFrom.CardboardProfiles)
     {
         CardboardProfile.CreateNew(dbTo, cp.Name, cp.Code, cp.Thickness);
     }
 }
示例#13
0
        public override void BuildCardboardProfileDictionary()
        {
            PPDataContext db = new PPDataContext();

            CardboardProfile[] profiles = CardboardProfile.GetAll(db);

            _dictMajoration = null;
        }
示例#14
0
        public override void SetComponent(Pic.Plugin.Component comp)
        {
            if (null == comp)
            {
                return;
            }
            _dictMajoration = null;
            PPDataContext db = new PPDataContext();

            _comp = Pic.DAL.SQLite.Component.GetByGuid(db, comp.Guid);
        }
        private void InsertChildNodes(PPDataContext db, TreeInterface treeImplementation, object parentNode, TreeNode node)
        {
            // node itself
            Object object1 = treeImplementation.InsertTreeNode(parentNode, node);
            // child nodes
            List <TreeNode> childNodes = node.Childrens(db);

            foreach (TreeNode tn in childNodes)
            {
                InsertChildNodes(db, treeImplementation, object1, tn);
            }
        }
示例#16
0
        private void ToolStripButtonPDF3D_Click(object sender, EventArgs e)
        {
            Pic.Plugin.Component comp = pluginViewCtrl.Component;
            if (!pluginViewCtrl.Visible || null == comp || !comp.IsSupportingAutomaticFolding)
            {
                return;
            }
            // get documents at the same lavel
            NodeTag nodeTag = treeView.SelectedNode.Tag as NodeTag;

            if (null == nodeTag)
            {
                return;
            }
            PPDataContext db = new PPDataContext();

            Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode);
            List <Document>         des3Docs = treeNode.GetBrothersWithExtension(db, "des3");

            if (0 == des3Docs.Count)
            {
                MessageBox.Show("Missing des3 for sample pattern files");   return;
            }
            // get default thickness
            Sharp3D.Math.Core.Vector2D refPoint = Sharp3D.Math.Core.Vector2D.Zero;
            double thickness = 0.0;

            if (!pluginViewCtrl.GetReferencePointAndThickness(ref refPoint, ref thickness))
            {
                MessageBox.Show("Failed to retrieve reference point and thickness");
                return;
            }
            // allow
            if (!System.IO.File.Exists(Pic3DExporterPath))
            {
                MessageBox.Show(string.Format("File {0} could not be found!", Pic3DExporterPath));
                return;
            }
            // show form and generate PDF 3D
            FormGeneratePDF3D form = new FormGeneratePDF3D(this)
            {
                OutputFilePath = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), treeNode.Name), "pdf"),
                thickness      = thickness,
                v = refPoint
            };

            foreach (Document d in des3Docs)
            {
                form.filePathes.Add(d.File.Path(db));
            }
            form.ShowDialog();
        }
示例#17
0
        public override void BuildCardboardProfile()
        {
            PPDataContext db = new PPDataContext();

            CardboardProfile[] profiles = CardboardProfile.GetAll(db);
            _cardboardProfiles.Clear();
            foreach (CardboardProfile dbProfile in profiles)
            {
                _cardboardProfiles.Add(dbProfile.Name, dbProfile);
            }

            _majorationList = null;
        }
示例#18
0
 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 override bool Process(PPDataContext db, TreeNode tn)
        {
            if (!tn.IsComponent)
            {
                return(true);
            }
            try
            {
                string filePath           = tn.Documents(db)[0].File.Path(db);
                Pic.Plugin.Component comp = _compLoader.LoadComponent(filePath);
                if (null != _callback && null != comp)
                {
                    _callback.Info(string.Format("Successfully loaded component {0}", tn.Name));
                }
                else
                {
                    _callback.Error(string.Format("Failed to load component {0}", tn.Name));
                }

                Pic.Plugin.ParameterStack stack = comp.BuildParameterStack(null);
                foreach (Pic.Plugin.Parameter param in stack)
                {
                    if (param.IsMajoration)
                    {
                        continue;
                    }
                    // only add parameter description
                    TryAndAddString(param.Description);
                    // ParameterMulti ?
                    if (param is Pic.Plugin.ParameterMulti paramMulti)
                    {
                        foreach (string sText in paramMulti.DisplayList)
                        {
                            TryAndAddString(sText);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (null != _callback)
                {
                    _callback.Error(ex.Message);
                }
            }
            return(true);
        }
        private void FillProfileComboBox(string selectedProfileName)
        {
            // initialize profile combo box
            comboBoxProfile.Items.Clear();
            PPDataContext db = new PPDataContext();

            CardboardProfile[] profiles = CardboardProfile.GetAll(db);
            foreach (CardboardProfile profile in profiles)
            {
                comboBoxProfile.Items.Add(profile);
                if (profile.Name == selectedProfileName)
                {
                    comboBoxProfile.SelectedItem = profile;
                }
            }
            _profile = comboBoxProfile.SelectedItem as CardboardProfile;
        }
示例#21
0
        protected override Profile[] LoadProfiles()
        {
            PPDataContext db = new PPDataContext();

            CardboardProfile[] profiles    = CardboardProfile.GetAll(db);
            List <Profile>     listProfile = new List <Profile>();

            foreach (CardboardProfile dbProfile in profiles)
            {
                listProfile.Add(new Profile(dbProfile.Name));
            }
            if (listProfile.Count > 0)
            {
                Selected = listProfile[0];
            }
            return(listProfile.ToArray());
        }
 private void listViewProfile_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     try
     {
         if (this.listViewProfile.SelectedIndices.Count > 0)
         {
             int                iSel = this.listViewProfile.SelectedIndices[0];
             PPDataContext      db   = new PPDataContext();
             CardboardProfile[] cardboardProfiles = CardboardProfile.GetAll(db);
             this.btDelete.Enabled = !cardboardProfiles[iSel].HasMajorationSets;
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
示例#23
0
 protected override Dictionary <string, double> LoadMajorationList()
 {
     if (null == Selected || null == _comp)
     {
         return(new Dictionary <string, double>());
     }
     if (null == _majorationList)
     {
         PPDataContext db = new PPDataContext();
         _majorationList = Pic.DAL.SQLite.Component.GetDefaultMajorations(
             db,
             _comp.ID,
             _cardboardProfiles[Selected.ToString()]
             // rounding to be applied while building majoration dictionary
             , Pic.DAL.SQLite.Component.IntToMajoRounding(Properties.Settings.Default.MajorationRounding)
             );
     }
     return(_majorationList);
 }
 /// <summary>
 /// restores a backup database : callback version
 /// </summary>
 public static bool Restore(string zipFilePath, IProcessingCallback callback)
 {
     try
     {
         // clear existing directories
         DBDescriptor dbDescTo = DBDescriptor.Current;
         if (!dbDescTo.Clear())
         {
             if (null != callback)
             {
                 callback.Error("Failed to clear current database!");
             }
             return(false);
         }
         // extract new database
         DBDescriptor dbDescFrom = DBDescriptor.CreateTempFromArchive(zipFilePath, callback);
         // build data contexts
         PPDataContext dbFrom = new PPDataContext(dbDescFrom);
         PPDataContext dbTo   = new PPDataContext(dbDescTo);
         // copy format table
         CopyCardboardFormats(dbFrom, dbTo);
         // copy cardboard profiles
         CopyCardboardProfiles(dbFrom, dbTo);
         // copy document types
         CopyDocumentTypes(dbFrom, dbTo);
         // copy branch nodes recursively
         TreeNode nodeFrom = TreeNode.GetRootNodes(dbFrom)[0];
         TreeNode nodeTo   = TreeNode.GetRootNodes(dbTo)[0];;
         CopyTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
         GC.Collect();
     }
     catch (Exception ex)
     {
         if (null != callback)
         {
             callback.Error(ex.Message);
         }
         _log.Error(ex.ToString());
         return(false);
     }
     return(true);
 }
示例#25
0
        public void ProcessVisitor(TreeNodeVisitor visitor)
        {
            // get data context
            PPDataContext db = new PPDataContext();

            // initialize
            visitor.Initialize(db);
            // get root node
            List <TreeNode> rootNodes = TreeNode.GetRootNodes(db);

            foreach (TreeNode tn in rootNodes)
            {
                if (!tn.ProcessVisitor(db, visitor))
                {
                    break;
                }
            }
            // finilize
            visitor.Finalize(db);
        }
 public static void MergeCardboardProfiles(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));
             }
         }
         else
         {
             if (null != callback)
             {
                 callback.Info(string.Format("Creating carboard profile {0}...", cp.Name));
             }
             CardboardProfile.CreateNew(dbTo, cp.Name, cp.Code, cp.Thickness);
         }
     }
 }
 public static void MergeCardboardFormats(PPDataContext dbFrom, PPDataContext dbTo, IProcessingCallback callback)
 {
     foreach (CardboardFormat cf in dbFrom.CardboardFormats)
     {
         if (CardboardFormat.HasByName(dbTo, cf.Name))
         {
             if (null != callback)
             {
                 callback.Info(string.Format("Cardboard format {0} already exists. Skipping...", cf.Name));
             }
         }
         else
         {
             if (null != callback)
             {
                 callback.Info(string.Format("Creating carboard format {0}...", cf.Name));
             }
             CardboardFormat.CreateNew(dbTo, cf.Name, cf.Description, cf.Length, cf.Width);
         }
     }
 }
示例#28
0
        protected override Dictionary <string, double> LoadMajorationList()
        {
            if (null == Selected || null == _comp)
            {
                return(new Dictionary <string, double>());
            }
            if (null == _dictMajoration)
            {
                PPDataContext db = new PPDataContext();

                CardboardProfile selectedProfile = CardboardProfile.GetByName(db, _selectedProfile.Name);
                _dictMajoration = Pic.DAL.SQLite.Component.GetDefaultMajorations(
                    db,
                    _comp.ID,
                    selectedProfile,
                    // rounding to be applied while building majoration dictionary
                    Pic.DAL.SQLite.Component.IntToMajoRounding(Properties.Settings.Default.MajorationRounding)
                    );
            }
            return(_dictMajoration);
        }
 public static void MergeDocumentTypes(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("Document type {0} already exists. Skipping...", dt.Name));
             }
         }
         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 bool BackupBranch(List <string> nodePath, string zipFilePath, IProcessingCallback callback)
        {
            // remove zip path if it already exists
            if (System.IO.File.Exists(zipFilePath))
            {
                System.IO.File.Delete(zipFilePath);
            }

            // instantiate data context of current database
            PPDataContext dbFrom = new PPDataContext();
            // get node from
            TreeNode nodeFrom = TreeNode.GetNodeByPath(dbFrom, null, nodePath, 0);
            // build list of profiles referred by branch components
            List <string> profileNames = new List <string>();

            BuildListOfUsedCardboardProfiles(dbFrom, nodeFrom, ref profileNames);

            // build destination database path
            DBDescriptor dbDescTo = DBDescriptor.CreateTemp();

            {
                // build data context
                using (PPDataContext dbTo = new PPDataContext(dbDescTo))
                {
                    // copy cardboard profiles
                    MergeCardboardProfiles(dbFrom, dbTo, profileNames, callback);
                    // copy document types
                    CopyDocumentTypes(dbFrom, dbTo);
                    // copy branch nodes recursively
                    TreeNode nodeTo = TreeNode.GetNodeByPath(dbTo, null, nodePath, 0);;
                    CopyTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
                }
                GC.Collect();
            }
            Thread.Sleep(1000);
            // archive temp database
            dbDescTo.Archive(zipFilePath, callback);
            return(true);
        }