Example #1
0
        private void ExcludeDataTypesFromProfile(PredefinedClasses cimPredefined)
        {
            if ((cimPredefined != null) && (profile != null) && (profile.ClassCount > 0))
            {
                ClassCategory packageCorePE = profile.FindProfileElementByUri("#Package_Core") as ClassCategory;
                if (packageCorePE != null)
                {
                    foreach (string dataTypeName in cimPredefined.PedifinedClassesList)
                    {
                        ProfileElement dataTypePE = profile.ProfileMap[ProfileElementTypes.Class].Find(x => string.Compare(x.Name, dataTypeName) == 0);
                        if (dataTypePE != null)
                        {
                            //// remove dataTypePE from package Core
                            packageCorePE.MembersOfClassCategory.Remove(dataTypePE);
                            //// remove dataTypePE from profile
                            profile.ProfileMap[ProfileElementTypes.Class].Remove(dataTypePE);
                        }
                    }

                    //// remove enums UnitSymbol and UnitMultiplier
                    ProfileElement unitSymbolPE      = profile.FindProfileElementByUri("#UnitSymbol");
                    ProfileElement unitMultiplierlPE = profile.FindProfileElementByUri("#UnitMultiplier");
                    //// remove from package Core
                    packageCorePE.MembersOfClassCategory.Remove(unitSymbolPE);
                    packageCorePE.MembersOfClassCategory.Remove(unitMultiplierlPE);
                    //// remove from profile
                    profile.ProfileMap[ProfileElementTypes.Class].Remove(unitSymbolPE);
                    profile.ProfileMap[ProfileElementTypes.Class].Remove(unitMultiplierlPE);
                }
            }
        }
        public ActionResult DeleteConfirmed(string id)
        {
            ClassCategory classCategory = db.ClassCategories.Find(id);

            db.ClassCategories.Remove(classCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 private static void TestcaseParseClassDefinition(string code,
                                                  bool isSuccess,
                                                  Modifier?mod                      = null,
                                                  ClassCategory category            = default(ClassCategory),
                                                  TypeInfo type                     = null,
                                                  IEnumerable <TypeInfo> inheriteds = null)
 {
     TestcaseParseClassAll(code, 0, isSuccess, 1, mod, category, type, inheriteds);
 }
 public ActionResult Edit([Bind(Include = "CategoryID,Name")] ClassCategory classCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(classCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(classCategory));
 }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inputVariable"></param>
 /// <param name="inputVariableValue"></param>
 /// <param name="c"></param>
 /// <param name="plot"></param>
 public void AssociateWithCategory(PatternClassificationInput inputVariable, int inputVariableValue,
                                   ClassCategory c, bool plot)
 {
     // associate input value with cateogiry, for the specified variable
     MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".InputNodeClassifiers(" + inputVariable.ClassifierMatlabIndex + ").createAssociation(" + inputVariableValue + ", " + c.MatlabIndex + ");");
     // plot
     if (plot)
     {
         MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".InputNodeClassifiers(" + inputVariable.ClassifierMatlabIndex + ").plotLikelihoods();");
     }
 }
        public ActionResult Create([Bind(Include = "CategoryID,Name")] ClassCategory classCategory)
        {
            if (ModelState.IsValid)
            {
                db.ClassCategories.Add(classCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(classCategory));
        }
Example #7
0
        private void InjectReflectedData(ClassShape newShape)
        {
            Random rnd = new Random();

            Type type = sampleTypes[rnd.Next(0, sampleTypes.Length)];


            MethodInfo[]   meths = type.GetMethods();
            PropertyInfo[] props = type.GetProperties();

            ObservableCollection <ClassMember> methods = new ObservableCollection <ClassMember>();

            for (int i = 0; i < meths.Length && i < 10; i++)
            {
                methods.Add(new ClassMember(meths[i].Name, "PublicMethod"));
            }


            ClassCategory methodSection = new ClassCategory("Methods", methods);

            ObservableCollection <ClassMember> properties = new ObservableCollection <ClassMember>();

            for (int i = 0; i < props.Length && i < 10; i++)
            {
                properties.Add(new ClassMember(props[i].Name, "PublicProperty"));
            }
            ;
            ClassCategory propertySection = new ClassCategory("Properties", properties);

            ObservableCollection <ClassCategory> categories = new ObservableCollection <ClassCategory>();

            categories.Add(propertySection);
            categories.Add(methodSection);

            newShape.Title = type.Name;
            if (type.IsPublic)
            {
                newShape.SubTitle += "public ";
            }
            //if (type.IsSealed)
            //    newShape.SubTitle += "sealed ";
            if (type.IsAbstract)
            {
                newShape.SubTitle += "abstract ";
            }
            if (type.IsInterface)
            {
                newShape.SubTitle += "interface ";
            }

            newShape.SubTitle += "class";

            newShape.TreeData = categories;
        }
Example #8
0
 /// <summary>
 /// Associate current values with a particular category.
 /// </summary>
 public void AssociateWithCategory(int[] inputValues, ClassCategory c, bool plot)
 {
     MatlabInterface.ArrayToMatlabVector(inputValues, "evaluateTheseValues", true);
     // MatlabInterface.Execute request
     MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".associateValuesWithCategory(evaluateTheseValues, " + c.MatlabIndex + ");");
     // show us the result - comment out of not needed
     if (plot)
     {
         MatlabInterface.Execute(ClassifierUniqueId + ".plotAllLikelihoods();");
     }
 }
Example #9
0
        void AddNewCategory(object sender, EventArgs e)
        {
            var bt   = (Button)sender;
            var tbox = (TextBox)bt.Tag;
            var cat  = new ClassCategory()
            {
                Name = tbox.Text
            };

            _selectedBCM.ClassificationCategories.Add(cat);
        }
Example #10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="modifier">Modifier</param>
 /// <param name="category">Class category</param>
 /// <param name="package">Package name or namespace</param>
 /// <param name="type">Class type</param>
 /// <param name="inheritedClasses">Inherited classes and interfaces</param>
 /// <exception cref="ArgumentNullException">If <paramref name="type"/> is null.</exception>
 public ClassInfo(Modifier modifier, ClassCategory category, string package, TypeInfo type, IEnumerable <TypeInfo> inheritedClasses)
 {
     this.Modifier         = modifier;
     this.Category         = category;
     this.Package          = package;
     this.Type             = type ?? throw new ArgumentNullException();
     this.InheritedClasses = new ReadOnlyCollection <TypeInfo>(
         new List <TypeInfo>(inheritedClasses ?? Enumerable.Empty <TypeInfo>()));
     this.InnerClasses = new List <ClassInfo>();
     this.Methods      = new List <MethodInfo>();
     this.Fields       = new List <FieldInfo>();
 }
 /// <summary>
 /// Associate current values with a particular category.
 /// </summary>
 public void AssociateWithCategory(ClassCategory c, bool plot)
 {
     // create array of values in MATLAB
     CreateArrayOfPresentValues(true, "evaluateTheseValues");
     // execute request
     Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".associateValuesWithCategory(evaluateTheseValues, " + c.MatlabIndex + ");");
     // show us the result - comment out of not needed
     if (plot)
     {
         Execute(ClassifierUniqueId + "plotAllLikelihoods();");
     }
 }
Example #12
0
 /// <summary>
 /// On user selecting/deselecting listviewitem in Classification Categories listview
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listOfCategories_itemsSelectedOrDeselected(object sender, EventArgs e)
 {
     if (listClassCategories.SelectedItems.Count > 0)
     {
         _selectedClassCategory = (ClassCategory)listClassCategories.SelectedItems[0].Tag;
         OnNewClassCategorySelected();
     }
     else
     {
         _selectedClassCategory = null;
         OnSelectedClassCategoryCleared();
     }
 }
        // GET: ClassCategories/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClassCategory classCategory = db.ClassCategories.Find(id);

            if (classCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(classCategory));
        }
Example #14
0
        public void TestMethod1()
        {
            /* For Creation of "TestCategory" Category, it can be only done once. It needs to be changed
             * for next test because Category name is uniquely saved. */

            ClassCategory gotoClassCategory = new ClassCategory();

            gotoClassCategory.userid123   = 1;
            gotoClassCategory.category123 = "TestCategory";
            string resultant = gotoClassCategory.insertcategory();
            string Needed    = "success";

            Assert.AreEqual(Needed, resultant);
        }
Example #15
0
        /// <summary>
        /// Associate current values with a particular category.
        /// </summary>
        public void AssociateWithCategory(ClassCategory c, bool plot)
        {
            if (c == null)
            {
                throw new ApplicationException("No Category Selected.");
            }

            // create array of values in MATLAB
            CreateArrayOfPresentValues(true, "evaluateTheseValues");
            // MatlabInterface.Execute request
            MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".associateValuesWithCategory(evaluateTheseValues, " + c.MatlabIndex + ");");
            // show us the result - comment out of not needed
            if (plot)
            {
                MatlabInterface.Execute(ClassifierUniqueId + ".plotAllLikelihoods();");
            }
        }
        public void CreatePackage(Profile profile, string key)
        {
            List <NameValuePair> packageProps = predefinedPackages[key];
            ClassCategory        package      = new ClassCategory();

            foreach (NameValuePair prop in packageProps)
            {
                if (prop.Name.Equals("URI"))
                {
                    package.URI = prop.Value;
                }
                else if (prop.Name.Equals("BelongsToCategory"))
                {
                    package.BelongsToCategory = prop.Value;
                }
                else if (prop.Name.Equals("Comment"))
                {
                    package.Comment = prop.Value;
                }
                else if (prop.Name.Equals("Label"))
                {
                    package.Label = prop.Value;
                }
                else if (prop.Name.Equals("Type"))
                {
                    package.Type = prop.Value;
                }
            }

            List <ProfileElement> elems = profile.ProfileMap[ProfileElementTypes.ClassCategory];

            if (elems == null)
            {
                elems = new List <ProfileElement>();
            }

            if (elems.Count > 0 && !elems.Contains(package))
            {
                elems.Add(package);
                profile.ProfileMap.Remove(ProfileElementTypes.ClassCategory);
                profile.ProfileMap.Add(ProfileElementTypes.ClassCategory, elems);
            }

            package.BelongsToCategoryAsObject = (ClassCategory)profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(package.BelongsToCategory, StringManipulationManager.SeparatorSharp));
            ((ClassCategory)profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(package.BelongsToCategory, StringManipulationManager.SeparatorSharp))).AddToMembersOfClassCategory(package);
        }
        public static bool Save(DayCarePL.ClassCategoryProperties objClassCategory)
        {
            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clClassCategory, "Save", "Execute Save Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();
            bool result           = false;
            DayCareDataContext db = new DayCareDataContext();
            ClassCategory      DBClassCategory = null;

            try
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clClassCategory, "Save", "Debug Save Method", DayCarePL.Common.GUID_DEFAULT);
                if (objClassCategory.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    DBClassCategory    = new ClassCategory();
                    DBClassCategory.Id = System.Guid.NewGuid();
                }
                else
                {
                    DBClassCategory = db.ClassCategories.SingleOrDefault(C => C.Id.Equals(objClassCategory.Id));
                }
                DBClassCategory.LastModifiedById     = objClassCategory.LastModifiedById;
                DBClassCategory.LastModifiedDatetime = DateTime.Now;
                DBClassCategory.SchoolId             = objClassCategory.SchoolId;
                DBClassCategory.Name                 = objClassCategory.Name;
                DBClassCategory.Active               = objClassCategory.Active;
                DBClassCategory.Comments             = objClassCategory.Comments;
                DBClassCategory.LastModifiedById     = objClassCategory.LastModifiedById;
                DBClassCategory.LastModifiedDatetime = DateTime.Now;
                if (objClassCategory.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    db.ClassCategories.InsertOnSubmit(DBClassCategory);
                }
                db.SubmitChanges();
                result = true;
            }
            catch (Exception ex)
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clClassCategory, "Save", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT);
                result = false;
            }
            return(result);
        }
Example #18
0
    public void IntialzeTheNewData()
    {
        for (int i = 0; i < 5; i++)
        {
            _playerData.TotalCorrectAnswers = 0;
            LevelClass obj = new LevelClass();
            obj.levelNum = i;

            obj.Active = "false";
            _playerData.LevelsData.Add(obj);

            for (int j = 0; j < 7; j++)
            {
                ClassCategory newobj = new ClassCategory();
                newobj.categotyName   = (j + 1).ToString();
                newobj.CorrectAnswers = 0;
                _playerData.LevelsData [i].categories.Add(newobj);
            }
        }
    }
Example #19
0
        /// <summary>
        /// Gets a text describing class category from <see cref="ClassCategory"/>.
        /// </summary>
        /// <param name="category">Class category to be converted into a text</param>
        /// <returns>Text describing class category</returns>
        private static string ClassCategoryText(ClassCategory category)
        {
            switch (category)
            {
            case ClassCategory.Class:
                return("class");

            case ClassCategory.Interface:
                return("interface");

            case ClassCategory.Enum:
                return("enum");

            case ClassCategory.Struct:
                return("class");                        // "struct" is not supported in UML.

            default:
                throw new NotImplementedException();
            }
        }
Example #20
0
        /// <summary>
        /// 3. Draw Single Classified Assembly Classes Collapsing Header
        /// </summary>
        void DrawCategoryHeader(
            ClassCategory category,
            string label,
            string title,
            string tooltip = "")
        {
            ImGui.Text(title);
            if (ImGui.IsItemHovered())
            {
                ImGui.SetTooltip(tooltip);
            }

            foreach (var name2type in category)
            {
                PadLeft("  ", () =>
                {
                    if (ImGui.CollapsingHeader(name2type.Key + "##Header" + label))
                    {
                        DrawClassTable(name2type.Value, "##tabel" + label);
                    }
                });
            }
        }
        private static void TestcaseParseClassAll(string code,
                                                  int startPos,
                                                  bool isSuccess,
                                                  int?expectedReadLines                = null,
                                                  Modifier?mod                         = null,
                                                  ClassCategory category               = default(ClassCategory),
                                                  TypeInfo type                        = null,
                                                  IEnumerable <TypeInfo> inheriteds    = null,
                                                  IEnumerable <FieldInfo> fields       = null,
                                                  IEnumerable <MethodInfo> methods     = null,
                                                  IEnumerable <string> innerClassNames = null,
                                                  Modifier defaultAL                   = Modifier.None)
        {
            var reader = ReaderFromCode(code);

            Enumerable.Range(0, startPos).ToList().ForEach(_ => reader.TryRead(out var _));

            new ClassParser("test-namespace", defaultAL).TryParse(reader, out var info).Is(isSuccess);

            if (isSuccess)
            {
                info.Modifier.Is(mod.Value);
                info.Category.Is(category);
                info.Type.Is(type);
                info.InheritedClasses.IsCollection(inheriteds ?? Enumerable.Empty <TypeInfo>());
                info.Fields.IsCollection(fields ?? Enumerable.Empty <FieldInfo>());
                info.Methods.IsCollection(methods ?? Enumerable.Empty <MethodInfo>());
                info.InnerClasses.Select(ic => ic.Name).IsCollection(innerClassNames ?? Enumerable.Empty <string>());

                reader.Position.Is(startPos + expectedReadLines.Value);
            }
            else
            {
                reader.Position.Is(startPos);
            }
        }
Example #22
0
        /// <summary>
        /// Method creates CodeCompileUnit that represents class
        /// </summary>
        /// <param name="package">ProfileElement element that represents the package</param>
        /// <param name="entity">ProfileElement element that represents class</param>
        /// <returns>CodeCompileUnit unit representing class</returns>
        private CodeCompileUnit CreateClass(Profile profile, ProfileElement package, Class entity)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            string         fullNS = package.Name;
            ProfileElement temp   = package;

            /*while(temp.BelongsToCategoryAsObject != null)
             * {
             *  temp = temp.BelongsToCategoryAsObject;
             *  fullNS = temp.Name + "." + fullNS;
             * }
             * fullNS = defaultNS + "." + fullNS;
             * CodeNamespace nameSpace = new CodeNamespace(fullNS);*/
            CodeNamespace nameSpace = new CodeNamespace(defaultNS);

            unit.Namespaces.Add(nameSpace);

            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            //class
            CodeTypeDeclaration file = new CodeTypeDeclaration();

            file.IsClass        = true;
            file.Name           = entity.Name;
            file.TypeAttributes = TypeAttributes.Public;
            file.Attributes     = MemberAttributes.Public;

            //parent class... adding namespace also
            if (entity.SubClassOfAsObject != null)
            {
                file.BaseTypes.Add(new CodeTypeReference(entity.SubClassOfAsObject.Name));

                //string parentNS = "";
                ProfileElement tempParent = entity.SubClassOfAsObject;
                nameSpace.Imports.Add(new CodeNamespaceImport(defaultNS));
            }
            else
            {
                //if class doesn't have a parent,
                //it should extend IDClass as the root of hierarhy - for rdf:ID

                //add namespace
                //add parent
                file.BaseTypes.Add(new CodeTypeReference("IDClass"));
                nameSpace.Imports.Add(new CodeNamespaceImport(defaultNS));
            }


            if (!string.IsNullOrEmpty(entity.Comment))
            {
                file.Comments.Add(new CodeCommentStatement(entity.Comment, true));
            }
            //dataType - local variable just as a little help
            string dataType = "";

            List <Property> fields = new List <Property>();

            if (entity.MyProperties != null)
            {
                fields = entity.MyProperties.Cast <Property>().ToList();
            }
            if (fields != null)
            {
                foreach (Property field in fields)
                {
                    CodeMemberField att = null;
                    //class field
                    //if(field.TypeAsEnumValue == ProfileElementTypes.Property)
                    //{
                    dataType = field.DataType;

                    //if data type is null... it is probably a reference
                    if (field.IsPropertyDataTypeSimple)
                    {
                        //SIMPLE VALUE
                        dataType = field.DataTypeAsSimple.ToString();

                        //multiplicity
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString1) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString2) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrOneString))
                        {
                            //create field
                            string fieldName = "cim_" + field.Name;

                            att = new CodeMemberField((String.Compare(dataType, "system.string", true) == 0)?(dataType):(dataType + "?"), fieldName);
                            //CodeMemberField att = new CodeMemberField(dataType, fieldName);


                            att.Attributes = MemberAttributes.Private;
                            if (!string.IsNullOrEmpty(field.Comment))
                            {
                                att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                            }
                            file.Members.Add(att);


                            //property for the field
                            ////this property is different because it has to remove "?"
                            CreatePropertyForField(file, dataType, att, true, true);
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                        //when multiplicity is more then 1 we have to add List
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityOneOrMoreString) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrMoreString))
                        {
                            //import list namespace
                            nameSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));

                            string fieldName = "cim_" + field.Name;

                            att                = new CodeMemberField(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(dataType) }), fieldName);
                            att.Attributes     = MemberAttributes.Private;
                            att.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(dataType) }));
                            if (!string.IsNullOrEmpty(field.Comment))
                            {
                                att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                            }
                            file.Members.Add(att);

                            CreatePropertyForField(file, att, true, true);
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                    }
                    else
                    {
                        /*
                         * if range as object is empty, we should look for dataType, coz that is where
                         * data regarding that can be found...
                         * range itself is actually set
                         *
                         */


                        //REFERENCE - not a simple value
                        string         typeName = "";
                        ProfileElement temp1    = null;
                        //in case when both are null - u have to set at least one...
                        //if not say its an error
                        if (field.RangeAsObject == null && field.DataTypeAsComplexObject == null)
                        {
                            if (!string.IsNullOrEmpty(field.Range))
                            {
                                //find what element is it and place it in RangeAsObject
                                temp1 = profile.FindProfileElementByUri(field.Range);
                                if (temp1 != null)
                                {
                                    field.RangeAsObject = temp1;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            //if range was nonexistent and we still need temp
                            if (temp1 == null)
                            {
                                if (!string.IsNullOrEmpty(field.DataType))
                                {
                                    temp1 = profile.FindProfileElementByUri(field.DataType);
                                    if (temp1 != null)
                                    {
                                        field.DataTypeAsComplexObject = temp1;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        if (field.RangeAsObject != null)
                        {
                            if (ExtractSimpleNameFromResourceURI(field.RangeAsObject.Type).Equals("Class"))
                            {
                                Class  cl   = (Class)field.RangeAsObject;
                                string pack = cl.BelongsToCategoryAsObject != null ? cl.BelongsToCategoryAsObject.Name : "global";
                                typeName = cl.Name;
                                temp1    = cl;
                            }
                            if (ExtractSimpleNameFromResourceURI(field.RangeAsObject.Type).Equals("ClassCategory"))
                            {
                                ClassCategory cl   = (ClassCategory)field.RangeAsObject;
                                string        pack = cl.BelongsToCategoryAsObject != null ? cl.BelongsToCategoryAsObject.Name : "global";
                                typeName = cl.Name;
                                temp1    = cl;
                            }
                        }
                        if (field.DataTypeAsComplexObject != null)
                        {
                            if (ExtractSimpleNameFromResourceURI(field.DataTypeAsComplexObject.Type).Equals("Class"))
                            {
                                Class  cl   = (Class)field.DataTypeAsComplexObject;
                                string pack = cl.BelongsToCategoryAsObject != null ? cl.BelongsToCategoryAsObject.Name : "global";
                                typeName = cl.Name;
                                temp1    = cl;
                            }
                        }
                        if (temp1 == null)
                        {
                            OnMessage("\r\nERROR - missing reference, or invalid URI on property:" + field.UniqueName + "in class:" + entity.UniqueName);
                            OnMessage("\r\nProcess canceled!");
                        }

                        /*
                         * Type tp = typeof(Class);
                         * if (ExtractSimpleNameFromResourceURI(temp1.Type).Equals("ClassCategory"))
                         * {
                         *  tp = typeof(ClassCategory);
                         * }
                         * PropertyInfo prop = tp.GetProperty("BelongsToCategoryAsObject");
                         * Object ob = temp1;
                         * while (prop.GetValue(ob, null) != null)
                         * {
                         *  ob = prop.GetValue(ob, null);
                         *  if (ob as Class != null)
                         *  {
                         *      tp = typeof(Class);
                         *  }
                         *  else if (ob as ClassCategory != null)
                         *  {
                         *      tp = typeof(ClassCategory);
                         *  }
                         *  prop = tp.GetProperty("BelongsToCategoryAsObject");
                         *
                         *  if(((ProfileElement)ob).Name != null)
                         *  {
                         *      ns = ((ProfileElement)ob).Name + (string.IsNullOrEmpty(ns) ? ns : ("." + ns));
                         *  }
                         * }
                         *
                         * if(string.IsNullOrEmpty(ns))
                         * {
                         *  OnMessage("\r\nWARNING: Missing namespace declaration! This might make your code flawed and prevent compiling!");
                         *  OnMessage("\r\nWarning Info: Type referenced: " + temp1.UniqueName + "\r\n              From field: " + entity.UniqueName + "." + field.Label);
                         *  OnMessage("\r\nProcess will continue...");
                         * }
                         * else
                         * {
                         *  ns = defaultNS + "." + ns;
                         * }
                         */
                        //multiplicity check
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrOneString) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString1) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString2))
                        {
                            //creating field
                            string fieldName = "cim_" + field.Name;


                            Class type = null;
                            if (field.DataTypeAsComplexObject != null)
                            {
                                type = (Class)field.DataTypeAsComplexObject;
                            }
                            if (field.RangeAsObject != null)
                            {
                                type = (Class)field.RangeAsObject;
                            }
                            if (type != null && type.IsEnumeration)
                            {
                                att            = new CodeMemberField(typeName + "?", fieldName);
                                att.Attributes = MemberAttributes.Private;

                                if (!string.IsNullOrEmpty(field.Comment))
                                {
                                    att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                                }

                                file.Members.Add(att);
                                //property for the field
                                CreatePropertyForEnumField(file, att, typeName, true, true);
                            }
                            else
                            {
                                att            = new CodeMemberField(typeName, fieldName);
                                att.Attributes = MemberAttributes.Private;

                                if (!string.IsNullOrEmpty(field.Comment))
                                {
                                    att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                                }

                                file.Members.Add(att);
                                //property for the field
                                CreatePropertyForField(file, att, true, true);
                            }
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                        //when multiplicity is more then 1 we have to add List
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityOneOrMoreString) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrMoreString))
                        {
                            //import List namespace
                            nameSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));


                            string fieldName = "cim_" + field.Name;

                            att                = new CodeMemberField(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(typeName) }), fieldName);
                            att.Attributes     = MemberAttributes.Private;
                            att.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(typeName) }));

                            if (!string.IsNullOrEmpty(field.Comment))
                            {
                                att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                            }
                            file.Members.Add(att);

                            CreatePropertyForField(file, att, true, true);
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                        //}
                    }
                }
            }

            nameSpace.Types.Add(file);
            return(unit);
        }
Example #23
0
 public void AutoCluster(ClassSubCategory name2type)
 {
     main       = ClassCluster.MainClass(name2type);
     auto       = ClassCluster.ClassCategory(name2type);
     namespaces = ClassCluster.NamespaceClasses(name2type);
 }
Example #24
0
        private void ProcessProfile()
        {
            if (profile.ProfileMap != null)
            {
                List <ProfileElement> moveFromUnknownToEnumElement = new List <ProfileElement>();
                foreach (ProfileElementTypes type in profile.ProfileMap.Keys)
                {
                    switch (type)
                    {
                    case ProfileElementTypes.ClassCategory:
                    {
                        List <ClassCategory> list = profile.ProfileMap[type].Cast <ClassCategory>().ToList();
                        foreach (ClassCategory element in list)
                        {
                            //// search for classes of class categories
                            if ((belongingMap != null) && (belongingMap.ContainsKey(element.URI)))
                            {
                                Stack <ProfileElement> stack = belongingMap[element.URI];
                                ProfileElement         classInPackage;
                                while (stack.Count > 0)
                                {
                                    classInPackage = stack.Pop();
                                    if (ExtractSimpleNameFromResourceURI(classInPackage.Type).Equals("Class"))
                                    {
                                        Class cl = (Class)classInPackage;
                                        element.AddToMembersOfClassCategory(cl);
                                        cl.BelongsToCategoryAsObject = element;
                                    }
                                    else
                                    {
                                        ClassCategory cl = (ClassCategory)classInPackage;
                                        element.AddToMembersOfClassCategory(cl);
                                        cl.BelongsToCategoryAsObject = element;
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case ProfileElementTypes.Class:
                    {
                        List <Class> list = profile.ProfileMap[type].Cast <Class>().ToList();
                        foreach (Class element in list)
                        {
                            if (element.SubClassOf != null)
                            {
                                Class uppclass = (Class)profile.FindProfileElementByUri(element.SubClassOf);
                                element.SubClassOfAsObject = uppclass;

                                if (uppclass != null)
                                {
                                    uppclass.AddToMySubclasses(element);
                                }
                            }

                            //// search for attributes of class and classCategory of class
                            if ((belongingMap != null) && (belongingMap.ContainsKey(element.URI)))
                            {
                                Stack <ProfileElement> stack = belongingMap[element.URI];
                                Property property;
                                while (stack.Count > 0)
                                {
                                    property = (Property)stack.Pop();
                                    element.AddToMyProperties(property);
                                    property.DomainAsObject = element;
                                }
                            }
                        }
                        break;
                    }

                    case ProfileElementTypes.Property:
                    {
                        List <Property> list = profile.ProfileMap[type].Cast <Property>().ToList();
                        foreach (Property element in list)
                        {
                            if (!element.IsPropertyDataTypeSimple)
                            {
                                element.DataTypeAsComplexObject = profile.FindProfileElementByUri(element.DataType);
                            }
                            if (!string.IsNullOrEmpty(element.Range))
                            {
                                element.RangeAsObject = profile.FindProfileElementByUri(element.Range);
                            }
                            //if (!string.IsNullOrEmpty(element.Name) && (Char.IsUpper(element.Name[0]))
                            //    && (!element.HasStereotype(ProfileElementStereotype.StereotypeByReference)))
                            //{
                            //    element.IsExpectedToContainLocalClass = true;
                            //    if (element.RangeAsObject != null)
                            //    {
                            //        element.RangeAsObject.IsExpectedAsLocal = true;
                            //    }
                            //}
                        }
                        break;
                    }

                    case ProfileElementTypes.Unknown:
                    {
                        List <EnumMember> list = profile.ProfileMap[type].Cast <EnumMember>().ToList();
                        foreach (EnumMember element in list)
                        {
                            Class enumElement = (Class)profile.FindProfileElementByUri(element.Type);
                            if (enumElement != null)
                            {
                                element.EnumerationObject = enumElement;
                                enumElement.AddToMyEnumerationMembers(element);
                                moveFromUnknownToEnumElement.Add(element);
                            }
                        }
                        break;
                    }
                    }
                }
                if (moveFromUnknownToEnumElement.Count > 0)
                {
                    List <ProfileElement> unknownsList            = null;
                    List <ProfileElement> enumerationElementsList = null;
                    profile.ProfileMap.TryGetValue(ProfileElementTypes.Unknown, out unknownsList);
                    profile.ProfileMap.TryGetValue(ProfileElementTypes.EnumerationElement, out enumerationElementsList);
                    if (unknownsList != null)
                    {
                        if (enumerationElementsList == null)
                        {
                            enumerationElementsList = new List <ProfileElement>();
                        }

                        foreach (ProfileElement movingEl in moveFromUnknownToEnumElement)
                        {
                            unknownsList.Remove(movingEl);
                            enumerationElementsList.Add(movingEl);
                        }

                        profile.ProfileMap.Remove(ProfileElementTypes.Unknown);
                        if (unknownsList.Count > 0)
                        {
                            profile.ProfileMap.Add(ProfileElementTypes.Unknown, unknownsList);
                        }

                        profile.ProfileMap.Remove(ProfileElementTypes.EnumerationElement);
                        if (enumerationElementsList.Count > 0)
                        {
                            enumerationElementsList.Sort(CIMComparer.ProfileElementComparer);
                            profile.ProfileMap.Add(ProfileElementTypes.EnumerationElement, enumerationElementsList);
                        }
                    }
                }
            }
        }
Example #25
0
        public void EndElement(string localName, string qName)
        {
            if (!abort)
            {
                if (qName.Equals(rdfProfileElement) || qName.Equals(cimsClassCategoryElement) ||
                    qName.Equals(rdfsClassElement) || qName.Equals(rdfPropertyElement))                        //end of element
                {
                    //novo
                    if (prop != null)
                    {
                        string type;
                        prop.TryGetValue(rdfType, out type);

                        if (ExtractSimpleNameFromResourceURI(type) == "ClassCategory")
                        {
                            ClassCategory cs = new ClassCategory();
                            foreach (KeyValuePair <string, string> pp in prop)
                            {
                                string str = pp.Value;
                                if ((pp.Key.Equals(cimsBelongsToCategory)) && (str != null))
                                {
                                    cs.BelongsToCategory = str;
                                    AddBelongingInformation(cs, cs.BelongsToCategory);
                                }
                                else if ((pp.Key.Equals(rdfsComment)) && (str != null))
                                {
                                    cs.Comment = str;
                                }
                                else if ((pp.Key.Equals(rdfsLabel)) && (str != null))
                                {
                                    cs.Label = str;
                                }
                                else if ((pp.Key.Equals(rdfType)) && (str != null))
                                {
                                    cs.Type = str;
                                }
                                else if ((pp.Key.Equals(rdfProfileElement)) && (str != null))
                                {
                                    cs.URI = str;
                                }
                                else if ((pp.Key.Equals(cimsMultiplicity)) && (str != null))
                                {
                                    cs.MultiplicityAsString = ExtractSimpleNameFromResourceURI(str);
                                }
                            }
                            AddProfileElement(ProfileElementTypes.ClassCategory, cs);
                        }
                        else if (ExtractSimpleNameFromResourceURI(type) == "Class")
                        {
                            Class cs = new Class();
                            foreach (KeyValuePair <string, string> pp in prop)
                            {
                                string str = pp.Value;
                                if ((pp.Key.Equals(cimsBelongsToCategory)) && (str != null))
                                {
                                    cs.BelongsToCategory = str;
                                    AddBelongingInformation(cs, cs.BelongsToCategory);
                                }
                                else if ((pp.Key.Equals(rdfsComment)) && (str != null))
                                {
                                    cs.Comment = str;
                                }
                                else if ((pp.Key.Equals(rdfsLabel)) && (str != null))
                                {
                                    cs.Label = str;
                                }
                                else if ((pp.Key.Equals(cimsMultiplicity)) && (str != null))
                                {
                                    cs.MultiplicityAsString = ExtractSimpleNameFromResourceURI(str);
                                }
                                else if ((pp.Key.Contains(cimsStereotype)) && (str != null))
                                {
                                    cs.AddStereotype(str);
                                }
                                else if ((pp.Key.Contains(rdfsSubClassOf)) && (str != null))
                                {
                                    cs.SubClassOf = str;
                                }
                                else if ((pp.Key.Equals(rdfType)) && (str != null))
                                {
                                    cs.Type = str;
                                }
                                else if ((pp.Key.Equals(rdfProfileElement)) && (str != null))
                                {
                                    cs.URI = str;
                                }
                            }
                            AddProfileElement(ProfileElementTypes.Class, cs);
                        }
                        else if (ExtractSimpleNameFromResourceURI(type) == "Property")
                        {
                            Property pr = new Property();
                            foreach (KeyValuePair <string, string> pp in prop)
                            {
                                string str = pp.Value;
                                if ((pp.Key.Equals(cimsDataType)) && (str != null))
                                {
                                    pr.DataType = str;
                                }
                                else if ((pp.Key.Equals(cimsMultiplicity)) && (str != null))
                                {
                                    pr.MultiplicityAsString = str;
                                }
                                else if ((pp.Key.Equals(rdfProfileElement)) && (str != null))
                                {
                                    pr.URI = str;
                                }
                                else if ((pp.Key.Equals(rdfType)) && (str != null))
                                {
                                    pr.Type = str;
                                }
                                else if ((pp.Key.Equals(rdfsDomain)) && (str != null))
                                {
                                    pr.Domain = str;
                                    AddBelongingInformation(pr, pr.Domain);
                                }
                                else if ((pp.Key.Contains(cimsStereotype)) && (str != null))
                                {
                                    pr.AddStereotype(str);
                                }
                                else if ((pp.Key.Contains(rdfsComment)) && (str != null))
                                {
                                    pr.Comment = str;
                                }
                                else if ((pp.Key.Equals(rdfsLabel)) && (str != null))
                                {
                                    pr.Label = str;
                                }
                                else if ((pp.Key.Equals(rdfsRange)) && (str != null))
                                {
                                    pr.Range = str;
                                }
                            }
                            AddProfileElement(ProfileElementTypes.Property, pr);
                        }
                        else
                        {
                            EnumMember en = new EnumMember();
                            foreach (KeyValuePair <string, string> pp in prop)
                            {
                                string str = pp.Value;
                                if ((pp.Key.Equals(rdfsComment)) && (str != null))
                                {
                                    en.Comment = str;
                                }
                                else if ((pp.Key.Equals(rdfsLabel)) && (str != null))
                                {
                                    en.Label = str;
                                }
                                else if ((pp.Key.Equals(rdfType)) && (str != null))
                                {
                                    en.Type = str;
                                }
                                else if ((pp.Key.Equals(rdfProfileElement)) && (str != null))
                                {
                                    en.URI = str;
                                }
                                else if ((pp.Key.Equals(cimsMultiplicity)) && (str != null))
                                {
                                    en.MultiplicityAsString = ExtractSimpleNameFromResourceURI(str);
                                }
                            }
                            AddProfileElement(ProfileElementTypes.Unknown, en);
                        }
                        prop.Clear();
                    }
                }

                else if (qName.Equals(rdfsLabel))                //// end of label subelement
                {
                    content = content.Trim();
                    if (!string.IsNullOrEmpty(content))
                    {
                        //novo
                        string ls;
                        prop.TryGetValue(qName, out ls);
                        if (ls == null)
                        {
                            ls = (string)content.Clone();
                            prop.Add(qName, ls);
                        }
                        content = string.Empty;
                    }
                }
                else if (qName.Equals(rdfsComment))                //// end of comment subelement
                {
                    content = content.Trim();
                    if (!string.IsNullOrEmpty(content))
                    {
                        //novo
                        string ls;
                        prop.TryGetValue(qName, out ls);
                        if (ls == null)
                        {
                            ls = (string)content.Clone();
                            prop.Add(qName, ls);
                        }
                        content = string.Empty;
                    }
                }
                else if (qName.Equals(cimsIsAggregate))                //// end of isAggregate subelement
                {
                    content = content.Trim();
                    if (!string.IsNullOrEmpty(content))
                    {
                        bool paresedValue;

                        //novo
                        string ls;
                        prop.TryGetValue(qName, out ls);
                        if (ls == null)
                        {
                            if (bool.TryParse((string)content.Clone(), out paresedValue))
                            {
                                ls = paresedValue.ToString();
                            }
                            prop.Add(qName, ls);
                        }
                        content = string.Empty;
                    }
                }
            }
        }
Example #26
0
        /// <summary>
        /// Method creates CodeCompileUnit that represents class
        /// </summary>
        /// <param name="package">ProfileElement element that represents the package</param>
        /// <param name="entity">ProfileElement element that represents class</param>
        /// <returns>CodeCompileUnit unit representing class</returns>
        private CodeCompileUnit CreateClass(Profile profile, ProfileElement package, Class entity)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            string         fullNS    = package.Name;
            ProfileElement temp      = package;
            CodeNamespace  nameSpace = new CodeNamespace(defaultNS);

            unit.Namespaces.Add(nameSpace);

            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            //class
            CodeTypeDeclaration file = new CodeTypeDeclaration();

            file.IsClass        = true;
            file.Name           = entity.Name;
            file.TypeAttributes = TypeAttributes.Public;
            file.Attributes     = MemberAttributes.Public;

            //parent class... adding namespace also
            if (entity.SubClassOfAsObject != null)
            {
                file.BaseTypes.Add(new CodeTypeReference(entity.SubClassOfAsObject.Name));

                ProfileElement tempParent = entity.SubClassOfAsObject;
                nameSpace.Imports.Add(new CodeNamespaceImport(defaultNS));
            }
            else
            {
                //if class doesn't have a parent,
                //it should extend IDClass as the root of hierarhy - for rdf:ID

                file.BaseTypes.Add(new CodeTypeReference("IDClass"));
                nameSpace.Imports.Add(new CodeNamespaceImport(defaultNS));
            }


            if (!string.IsNullOrEmpty(entity.Comment))
            {
                file.Comments.Add(new CodeCommentStatement(entity.Comment, true));
            }

            string dataType = "";

            List <Property> fields = new List <Property>();

            if (entity.MyProperties != null)
            {
                fields = entity.MyProperties.Cast <Property>().ToList();
            }

            if (fields != null)
            {
                foreach (Property field in fields)
                {
                    CodeMemberField att = null;

                    dataType = field.DataType;

                    //if data type is null... it is probably a reference
                    if (field.IsPropertyDataTypeSimple)
                    {
                        //SIMPLE VALUE
                        dataType = field.DataTypeAsSimple.ToString();

                        //multiplicity
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString1) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString2) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrOneString))
                        {
                            //create field
                            string fieldName = "cim_" + field.Name;

                            att = new CodeMemberField((String.Compare(dataType, "system.string", true) == 0)?(dataType):(dataType + "?"), fieldName);

                            att.Attributes = MemberAttributes.Private;
                            if (!string.IsNullOrEmpty(field.Comment))
                            {
                                att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                            }
                            file.Members.Add(att);

                            //property for the field
                            CreatePropertyForField(file, dataType, att, true, true);
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                        //when multiplicity is more then 1 we have to add List
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityOneOrMoreString) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrMoreString))
                        {
                            //import list namespace
                            nameSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));

                            string fieldName = "cim_" + field.Name;

                            att                = new CodeMemberField(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(dataType) }), fieldName);
                            att.Attributes     = MemberAttributes.Private;
                            att.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(dataType) }));
                            if (!string.IsNullOrEmpty(field.Comment))
                            {
                                att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                            }
                            file.Members.Add(att);

                            CreatePropertyForField(file, att, true, true);
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                    }
                    else
                    {
                        /*
                         * if range as object is empty, we should look for dataType, coz that is where
                         * data regarding that can be found...
                         * range itself is actually set
                         *
                         */

                        //REFERENCE - not a simple value
                        string         typeName = "";
                        ProfileElement temp1    = null;
                        //in case when both are null - u have to set at least one...
                        //if not say its an error
                        if (field.RangeAsObject == null && field.DataTypeAsComplexObject == null)
                        {
                            if (!string.IsNullOrEmpty(field.Range))
                            {
                                //find what element is it and place it in RangeAsObject
                                temp1 = profile.FindProfileElementByUri(field.Range);
                                if (temp1 != null)
                                {
                                    field.RangeAsObject = temp1;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            //if range was nonexistent and we still need temp
                            if (temp1 == null)
                            {
                                if (!string.IsNullOrEmpty(field.DataType))
                                {
                                    temp1 = profile.FindProfileElementByUri(field.DataType);
                                    if (temp1 != null)
                                    {
                                        field.DataTypeAsComplexObject = temp1;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        if (field.RangeAsObject != null)
                        {
                            if (ExtractSimpleNameFromResourceURI(field.RangeAsObject.Type).Equals("Class"))
                            {
                                Class  cl   = (Class)field.RangeAsObject;
                                string pack = cl.BelongsToCategoryAsObject != null ? cl.BelongsToCategoryAsObject.Name : "global";
                                typeName = cl.Name;
                                temp1    = cl;
                            }
                            if (ExtractSimpleNameFromResourceURI(field.RangeAsObject.Type).Equals("ClassCategory"))
                            {
                                ClassCategory cl   = (ClassCategory)field.RangeAsObject;
                                string        pack = cl.BelongsToCategoryAsObject != null ? cl.BelongsToCategoryAsObject.Name : "global";
                                typeName = cl.Name;
                                temp1    = cl;
                            }
                        }
                        if (field.DataTypeAsComplexObject != null)
                        {
                            if (ExtractSimpleNameFromResourceURI(field.DataTypeAsComplexObject.Type).Equals("Class"))
                            {
                                Class  cl   = (Class)field.DataTypeAsComplexObject;
                                string pack = cl.BelongsToCategoryAsObject != null ? cl.BelongsToCategoryAsObject.Name : "global";
                                typeName = cl.Name;
                                temp1    = cl;
                            }
                        }
                        if (temp1 == null)
                        {
                            OnMessage("\r\nERROR - missing reference, or invalid URI on property:" + field.UniqueName + "in class:" + entity.UniqueName);
                            OnMessage("\r\nProcess canceled!");
                        }

                        //multiplicity check
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrOneString) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString1) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString2))
                        {
                            //creating field
                            string fieldName = "cim_" + field.Name;

                            Class type = null;
                            if (field.DataTypeAsComplexObject != null)
                            {
                                type = (Class)field.DataTypeAsComplexObject;
                            }
                            if (field.RangeAsObject != null)
                            {
                                type = (Class)field.RangeAsObject;
                            }
                            if (type != null && type.IsEnumeration)
                            {
                                att            = new CodeMemberField(typeName + "?", fieldName);
                                att.Attributes = MemberAttributes.Private;

                                if (!string.IsNullOrEmpty(field.Comment))
                                {
                                    att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                                }

                                file.Members.Add(att);

                                //property for the field
                                CreatePropertyForEnumField(file, att, typeName, true, true);
                            }
                            else
                            {
                                att            = new CodeMemberField(typeName, fieldName);
                                att.Attributes = MemberAttributes.Private;

                                if (!string.IsNullOrEmpty(field.Comment))
                                {
                                    att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                                }

                                file.Members.Add(att);

                                //property for the field
                                CreatePropertyForField(file, att, true, true);
                            }
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                        //when multiplicity is more then 1 we have to add List
                        if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityOneOrMoreString) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityZeroOrMoreString))
                        {
                            //import List namespace
                            nameSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));


                            string fieldName = "cim_" + field.Name;

                            att                = new CodeMemberField(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(typeName) }), fieldName);
                            att.Attributes     = MemberAttributes.Private;
                            att.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(typeName) }));

                            if (!string.IsNullOrEmpty(field.Comment))
                            {
                                att.Comments.Add(new CodeCommentStatement(field.Comment, true));
                            }
                            file.Members.Add(att);

                            CreatePropertyForField(file, att, true, true);
                            CreateIsMandatoryFieldAndProperty(file, att, field);
                            CreateFieldPrefix(file, att, field);
                        }
                    }
                }
            }

            nameSpace.Types.Add(file);
            return(unit);
        }
Example #27
0
        private void ExcludeDataTypesFromProfile(PredefinedClasses cimPredefined)
        {
            if ((cimPredefined != null) && (profile != null) && (profile.ClassCount > 0))
            {
                ClassCategory packageCorePE = profile.FindProfileElementByUri("#Package_Core") as ClassCategory;
                if (packageCorePE != null)
                {
                    foreach (string dataTypeName in cimPredefined.PedifinedClassesList)
                    {
                        ProfileElement dataTypePE = profile.ProfileMap[ProfileElementTypes.Class].Find(x => string.Compare(x.Name, dataTypeName) == 0);
                        if (dataTypePE != null)
                        {
                            //// remove dataTypePE from package Core
                            packageCorePE.MembersOfClassCategory.Remove(dataTypePE);
                            //// remove dataTypePE from profile
                            profile.ProfileMap[ProfileElementTypes.Class].Remove(dataTypePE);
                        }
                    }

                    //// remove enums UnitSymbol and UnitMultiplier if not used in classes
                    ProfileElement unitSymbolPE         = profile.FindProfileElementByUri("#UnitSymbol");
                    ProfileElement unitMultiplierlPE    = profile.FindProfileElementByUri("#UnitMultiplier");
                    bool           removeUnitSymbol     = !profile.GetAllProfileElementsOfType(ProfileElementTypes.Property).Cast <Property>().Any(p => string.Equals(p.Range, "#UnitSymbol"));
                    bool           removeUnitMultiplier = !profile.GetAllProfileElementsOfType(ProfileElementTypes.Property).Cast <Property>().Any(p => string.Equals(p.Range, "#UnitMultiplier"));
                    if (removeUnitSymbol)
                    {
                        //// remove from package Core
                        packageCorePE.MembersOfClassCategory.Remove(unitSymbolPE);
                        //// remove from profile
                        profile.ProfileMap[ProfileElementTypes.Class].Remove(unitSymbolPE);
                        unitSymbolPE = null;
                    }
                    if (removeUnitMultiplier)
                    {
                        //// remove from package Core
                        packageCorePE.MembersOfClassCategory.Remove(unitMultiplierlPE);
                        //// remove from profile
                        profile.ProfileMap[ProfileElementTypes.Class].Remove(unitMultiplierlPE);
                        unitMultiplierlPE = null;
                    }

                    //// remove Domain package or just remove all members not used elsewhere
                    ClassCategory packageDomainPE = profile.FindProfileElementByUri("#Package_Domain") as ClassCategory;
                    if (packageDomainPE != null)
                    {
                        if (packageDomainPE.CountMembersOfClassCategory > 0)
                        {
                            packageDomainPE.MembersOfClassCategory.Clear();
                            if (unitSymbolPE != null)
                            {
                                packageDomainPE.AddToMembersOfClassCategory(unitSymbolPE);
                            }
                            if (unitMultiplierlPE != null)
                            {
                                packageDomainPE.AddToMembersOfClassCategory(unitMultiplierlPE);
                            }
                        }
                        if ((unitSymbolPE == null) && (unitMultiplierlPE == null))
                        {
                            profile.ProfileMap[ProfileElementTypes.ClassCategory].Remove(packageDomainPE);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Converts <see cref="ClassCategory"/> into a string.
 /// </summary>
 /// <param name="category"></param>
 /// <returns>String of <see cref="ClassCategory"/></returns>
 public static string ToCategoryString(this ClassCategory category)
 {
     return(StringMap.TryGetValue(category, out var value)
                         ? value
                         : throw new NotImplementedException());
 }