Пример #1
0
        public static CardboardProfile CreateNew(
            PLMPackEntities db, Group gp
            , string name, string description
            , string code, double thickness)
        {
            if (CardboardProfile.Exists(db, gp, name))
            {
                throw new ModelException(string.Format("Cardboard profile \'{0}\' already exist.", name));
            }
            CardboardProfile cp = new CardboardProfile();

            cp.Group       = gp;
            cp.Name        = name;
            cp.Description = description;
            cp.Code        = code;
            cp.Thickness   = thickness;
            db.CardboardProfiles.Add(cp);
            db.SaveChanges();
            return(cp);
        }
Пример #2
0
        private void InitializeUser(PLMPackEntities db)
        {
            if (string.IsNullOrEmpty(GroupId))
            {
                string userName = UserName;
                // create group using user name
                Group grp = Group.CreateNew(db
                                            , string.Format("{0}_grp", userName)                   // group name
                                            , string.Format("Default group of user {0}", userName) // group description
                                            , this                                                 // owner
                                            );
                // set as current group
                this.GroupId = grp.Id;
                db.SaveChanges();
                // add group of interest treeDiM
                Group grp_treeDiM = Group.GetByName(db, "treeDiM");
                if (null != grp_treeDiM)
                {
                    AddGroupOfInterest(db, grp_treeDiM);
                }
                // share user root node
                TreeNode tn = TreeNode.GetUserRootNode(db, this);
                tn.Share(db, this, Group.Everyone(db));

                if (null != grp_treeDiM)
                {
                    // copy cardboard formats from treeDiM group
                    CardboardFormat[] cardboardFormats = CardboardFormat.GetAll(db, grp_treeDiM);
                    foreach (CardboardFormat cf in cardboardFormats)
                    {
                        CardboardFormat.CreateNew(db, grp, cf.Name, cf.Description, cf.Length, cf.Width);
                    }
                    // copy cardboard profile from treeDiM group
                    CardboardProfile[] cardboardProfiles = CardboardProfile.GetAll(db, grp_treeDiM);
                    foreach (CardboardProfile cp in cardboardProfiles)
                    {
                        CardboardProfile.CreateNew(db, grp, cp.Name, cp.Description, cp.Code, cp.Thickness);
                    }
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                string user1 = "9e94b280-0cb1-455b-9eff-4412f243b71a";
                {
                    PLMPackEntities db = new PLMPackEntities();
                    // thumbnails initialize
                    Thumbnail.Initialize(db);
                    // get user by id
                    AspNetUser user = AspNetUser.GetById(db, user1);
                    user.Connect(db);
                    Console.WriteLine(string.Format("### Connected as user {0}", user.UserName));

                    // create group "treeDiM"
                    if (!Group.Exist(db, "treeDiM"))
                    {
                        Group.CreateNew(db, "treeDiM", "treeDiM", user);
                    }
                    // create group "Everyone"
                    if (!Group.Exist(db, "Everyone"))
                    {
                        Group.CreateNew(db, "Everyone", "Everyone", user);
                    }

                    // get user group
                    Group grp1 = user.CurrentGroup(db);
                    Console.WriteLine(string.Format("Current group is: {0}", grp1.GroupName));

                    // add cardboard format
                    if (!CardboardFormat.Exists(db, grp1, "Cardboard 1"))
                    {
                        CardboardFormat.CreateNew(db, grp1, "Cardboard 1", "Cardboard 1 desc.", 2200, 1600);
                    }
                    if (!CardboardFormat.Exists(db, grp1, "Cardboard 2"))
                    {
                        CardboardFormat.CreateNew(db, grp1, "Cardboard 2", "Cardboard 2 desc.", 2200, 1600);
                    }
                    CardboardFormat.PrintAll(db, grp1);

                    // add cardboard profile
                    CardboardProfile prof1 = null;
                    if (!CardboardProfile.Exists(db, grp1, "Profile 1"))
                    {
                        prof1 = CardboardProfile.CreateNew(db, grp1, "Profile 1", "", "PRO1", 1.0);
                    }
                    else
                    {
                        prof1 = CardboardProfile.GetByName(db, grp1, "Profile 1");
                    }
                    CardboardProfile prof2 = null;
                    if (!CardboardProfile.Exists(db, grp1, "Profile 2"))
                    {
                        prof2 = CardboardProfile.CreateNew(db, grp1, "Profile 2", "", "PRO2", 2.0);
                    }
                    else
                    {
                        prof2 = CardboardProfile.GetByName(db, grp1, "Profile 2");
                    }
                    CardboardProfile.PrintAll(db, grp1);

                    // add cardboard quality
                    CardboardQuality q1 = null;
                    if (!CardboardQuality.Exists(db, grp1, "Quality 1"))
                    {
                        q1 = CardboardQuality.CreateNew(db, grp1, "Quality 1", "Quality 1 based on Profile 1", prof1.Id, 0.1, 1000.0, 1000.0, 1000.0, 10.0);
                    }
                    CardboardQuality q2 = null;
                    if (!CardboardQuality.Exists(db, grp1, "Quality 2"))
                    {
                        q2 = CardboardQuality.CreateNew(db, grp1, "Quality 2", "Quality 2 based on Profile 2", prof2.Id, 0.2, 2000.0, 2000.0, 2000.0, 20.0);
                    }
                    CardboardQuality.PrintAll(db, grp1);

                    // get root tree node
                    TreeNode[] roots = TreeNode.GetRootNodes(db, user);

                    // create thumbnail
                    Thumbnail thumb = Thumbnail.DefaultFolder(db);
                    // insert new treeNode Test
                    string name        = "Test Node";
                    string description = "Test tree node";
                    if (roots[0].HasChildWithName(name))
                    {
                        Console.WriteLine(string.Format("Node {0} already has child node {1}", roots[0].Name, name));
                        List <TreeNode> childrens = new List <TreeNode>(roots[0].Childrens);
                        childrens.ForEach(tn => tn.Delete(db, user));
                    }

                    // share root node with group everyone
                    roots[0].Share(db, user);

                    // insert new node with default folder
                    TreeNode tnNew = roots[0].InsertBranch(db, grp1.Id, name, description, Thumbnail.DefaultFolder(db));
                    tnNew.Share(db, user);
                    // insert document
                    string   docName       = "TestDoc";
                    string   docDesc       = "Test document";
                    string   docType       = "PICGEOM";
                    Guid     docGuid       = Guid.NewGuid();
                    string   docExt        = "des";
                    TreeNode tnDoc         = tnNew.InsertDocument(db, grp1.Id, docName, docDesc, docType, docGuid, docExt, Thumbnail.DefaultFolder(db));
                    string   componentName = "TestComp";
                    string   componentDesc = "Test component";
                    TreeNode tnDocComp     = tnNew.InsertComponent(db, grp1.Id
                                                                   , componentName, componentDesc
                                                                   , Guid.NewGuid(), Guid.NewGuid()
                                                                   , Thumbnail.DefaultFolder(db));

                    // disconnect
                    user.Disconnect(db);
                }
                {
                    PLMPackEntities db = new PLMPackEntities();
                    // thumbnails initialize
                    Thumbnail.Initialize(db);
                    // get user by id
                    AspNetUser user = AspNetUser.GetById(db, user1);
                    // show tree
                    Tree.Print(db, user);
                }

                string user2 = "7142ebab-5a02-414d-b6ba-a676fb9f7287";
                {
                    PLMPackEntities db = new PLMPackEntities();
                    // thumbnails initialize
                    Thumbnail.Initialize(db);
                    // get user by id
                    AspNetUser user = AspNetUser.GetById(db, user2);
                    user.Connect(db);

                    Console.WriteLine(string.Format("### Connected as user {0}", user.UserName));
                    // add group of interest to current user
                    user.AddGroupOfInterest(db, Group.GetByName(db, "Anastasia_grp"));
                    // show tree
                    Tree.Print(db, user);
                    user.RemoveGroupOfInterest(db, Group.GetByName(db, "Anastasia_grp"));

                    // diconnect
                    user.Disconnect(db);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #4
0
        public Dictionary <string, double> GetMajorationSet(PLMPackEntities db, CardboardProfile cp)
        {
            if (db.MajorationSets.Count(
                    mjs => (mjs.ComponentGuid == Guid) && (mjs.CardboardProfile.GroupId == cp.GroupId)) == 0)
            {
                try
                {
                    // dict majo
                    db.MajorationSets.Add(new MajorationSet()
                    {
                        ComponentGuid      = Guid,
                        CardboardProfileId = cp.Id
                    }
                                          );
                    db.SaveChanges();
                    // build list of majo
                    var           majoSets = db.MajorationSets.Where(mjs => (mjs.ComponentGuid == this.Guid) && (mjs.CardboardProfile.GroupId == this.Document.GroupId));
                    MajorationSet mjsNearest = null; double diffMax = double.MaxValue;
                    foreach (MajorationSet mjset in majoSets)
                    {
                        double thickness = mjset.CardboardProfile.Thickness;
                        if (Math.Abs(thickness - cp.Thickness) < diffMax)
                        {
                            mjsNearest = mjset;
                            diffMax    = Math.Abs(thickness - cp.Thickness);
                        }
                    }
                    MajorationSet mjsCurrent       = MajorationSet.Single(mjs => (mjs.ComponentGuid == this.Guid) && (mjs.CardboardProfileId == cp.Id));
                    double        thicknessNearest = mjsNearest.CardboardProfile.Thickness;
                    foreach (Majoration mj in mjsNearest.Majorations)
                    {
                        db.Majorations.Add(
                            new Majoration()
                        {
                            MajorationSetId = mjsCurrent.Id,
                            Name            = mj.Name,
                            Value           = mj.Value * cp.Thickness / thicknessNearest
                        }
                            );
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            var majorationSets = db.MajorationSets.Where(mjs => (mjs.ComponentGuid == this.Guid) && (mjs.CardboardProfile.GroupId == this.Document.GroupId));

            // find nearest set
            MajorationSet nearestSet = null;

            foreach (MajorationSet majoSet in majorationSets)
            {
                if (null == nearestSet ||
                    (Math.Abs(majoSet.CardboardProfile.Thickness - cp.Thickness) < Math.Abs(nearestSet.CardboardProfile.Thickness - cp.Thickness))
                    )
                {
                    nearestSet = majoSet;
                }
            }

            // build dictionnary
            Dictionary <string, double> dictMajo = new Dictionary <string, double>();

            if (null != nearestSet)
            {
                double coef = (double)(cp.Thickness / nearestSet.CardboardProfile.Thickness);
                dictMajo.Add("th1", cp.Thickness);
                dictMajo.Add("ep1", cp.Thickness);
                foreach (Majoration maj in nearestSet.Majorations)
                {
                    double valueMaj = maj.Value * coef;
                    if (Math.Abs(coef - 1.0) > 1.0e-3)
                    {
                        MajoRounding rounding = MajoRounding.ROUDING_FIRSTDECIMALNEAREST;
                        switch (rounding)
                        {
                        case MajoRounding.ROUDING_FIRSTDECIMALNEAREST:
                            valueMaj = Math.Round(valueMaj * 10) / 10.0;
                            break;

                        case MajoRounding.ROUNDING_HALFNEAREST:
                            valueMaj = Math.Round(valueMaj * 2) / 2.0;
                            break;

                        case MajoRounding.ROUNDING_HALFTOP:
                            valueMaj = Math.Ceiling(valueMaj * 2) / 2;
                            break;

                        case MajoRounding.ROUDING_INT:
                            valueMaj = Math.Round(valueMaj);
                            break;

                        default:
                            break;     // no rounding
                        }
                    }
                    dictMajo.Add(maj.Name, valueMaj);
                }
            }
            return(dictMajo);
        }