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 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);
             }
         }
     }
 }
예제 #3
0
        public DCCardboardProfile GetCardboardProfileByName(string name)
        {
            PLMPackEntities  db   = new PLMPackEntities();
            AspNetUser       user = AspNetUser.GetByUserName(db, UserName);
            CardboardProfile cp   = CardboardProfile.GetByName(db, user.CurrentGroup(db), name);

            return(new DCCardboardProfile()
            {
                ID = cp.Id,
                Name = cp.Name,
                Description = cp.Description,
                Code = cp.Code,
                Thickness = cp.Thickness
            });
        }
예제 #4
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 MergeTreeNodesRecursively(PPDataContext dbFrom, PPDataContext dbTo, 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;

                    if (nodeTo.HasChild(dbTo, childFrom.Name))
                    {
                        if (null != callback)
                        {
                            callback.Info(string.Format("Document {0} already exists...", childFrom.Name));
                        }
                    }
                    else
                    {
                        if (string.Equals("Parametric component", docTypeName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (null != callback)
                            {
                                callback.Info(string.Format("Parametric component {0} already exists...", childFrom.Name));
                            }
                            // insert as component
                            Component compFrom = docFrom.Components[0];
                            Component compTo   = Component.GetByGuid(dbTo, compFrom.Guid);
                            if (null == compTo)
                            {
                                if (null != callback)
                                {
                                    callback.Info(string.Format("Inserting component {0}...", childFrom.Name));
                                }
                                compTo = nodeTo.InsertComponent(dbTo, docFrom.File.Path(dbFrom), compFrom.Guid, childFrom.Name, childFrom.Description, thumbnailPath);

                                // parameter default values
                                Dictionary <string, double> dictNameValues = compFrom.GetParamDefaultValues();
                                if (dictNameValues.Count > 0)
                                {
                                    if (null != callback)
                                    {
                                        string sParameters = string.Empty;
                                        foreach (string defParamName in dictNameValues.Keys)
                                        {
                                            StringBuilder sb = new StringBuilder();
                                            sb.Append(defParamName);
                                            sb.Append("=");
                                            sb.Append(dictNameValues[defParamName]);
                                            sb.Append(", ");
                                            sParameters += sb.ToString();
                                        }
                                        sParameters.Trim();
                                        sParameters.Trim(',');
                                        callback.Info(string.Format("Default parameter values : {0}", sParameters));
                                    }
                                    compTo.InsertNewParamDefaultValues(dbTo, dictNameValues);
                                }
                                // majorations
                                foreach (MajorationSet mjset in compFrom.MajorationSets)
                                {
                                    // retrieve profile
                                    string           profileName = mjset.CardboardProfile.Name;
                                    CardboardProfile profileTo   = CardboardProfile.GetByName(dbTo, profileName);
                                    if (null == profileTo)
                                    {
                                        if (null != callback)
                                        {
                                            callback.Error(string.Format("Failed to retrieve profile {0}", mjset.CardboardProfile.Name));
                                        }
                                        continue;
                                    }
                                    // get majorations
                                    Dictionary <string, double> majorations = new Dictionary <string, double>();
                                    string sMajo = string.Format("prof = {0} -> ", profileName);
                                    foreach (Majoration mj in mjset.Majorations)
                                    {
                                        majorations.Add(mj.Name, mj.Value);
                                        sMajo += string.Format("{0}={1}, ", mj.Name, mj.Value);
                                    }
                                    // insert
                                    if (null != callback)
                                    {
                                        callback.Info(sMajo);
                                    }
                                    compTo.InsertNewMajorationSet(dbTo, profileTo.Name, majorations);
                                }
                            }
                            else
                            {
                                if (null != callback)
                                {
                                    callback.Info(string.Format("Component with GUID {0} already exists...", compFrom.Guid));
                                }
                            }
                        }
                        else
                        {
                            if (null != callback)
                            {
                                callback.Info(string.Format("Inserting document {0}...", childFrom.Name));
                            }
                            // insert as document
                            nodeTo.InsertDocument(dbTo, docFrom.File.Path(dbFrom), childFrom.Name, childFrom.Description, docTypeName, thumbnailPath);
                        }
                    }
                }
                else
                {
                    TreeNode childTo = null;
                    if (nodeTo.HasChild(dbTo, childFrom.Name))
                    {
                        if (null != callback)
                        {
                            callback.Info(string.Format("Branch {0} already exists.Skipping...", childFrom.Name));
                        }
                        childTo = nodeTo.GetChild(dbTo, childFrom.Name);
                    }
                    else
                    {
                        if (null != callback)
                        {
                            callback.Info(string.Format("Inserting branch {0}...", childFrom.Name));
                        }
                        childTo = nodeTo.CreateChild(dbTo, childFrom.Name, childFrom.Description, thumbnailPath);
                    }
                    MergeTreeNodesRecursively(dbFrom, dbTo, 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());
            }
        }