예제 #1
0
        public void SearchAttributesInsideAttributesOFElectricConnectorType(string searchName, AttributeType attribute, ClassOfListsFromReferencefile item
                                                                            , ExternalInterfaceType electricConnectorType)
        {
            foreach (var nestedAttribute in attribute.Attribute)
            {
                if (nestedAttribute.Name == searchName)
                {
                    var eachattribute = nestedAttribute.Attribute.Append(item.Name.ToString());
                    eachattribute.Value             = item.Value;
                    eachattribute.DefaultValue      = item.Default;
                    eachattribute.Unit              = item.Unit;
                    eachattribute.AttributeDataType = item.DataType;
                    eachattribute.Description       = item.Description;
                    eachattribute.Copyright         = item.CopyRight;

                    eachattribute.ID = item.ID;
                    foreach (var val in item.RefSemanticList.Elements)
                    {
                        var refsem = eachattribute.RefSemantic.Append();
                        refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                    }


                    electricConnectorType.RefBaseClassPath = item.RefBaseClassPath;
                }

                if (nestedAttribute.Attribute.Exists)
                {
                    SearchAttributesInsideAttributesOFElectricConnectorType(searchName, nestedAttribute, item, electricConnectorType);
                }
            }
        }
예제 #2
0
        public void CkeckForNestedAttributesOfElectricalConnectorPins(int i, AttributeType attributeType, ExternalInterfaceType externalInterface,
                                                                      ExternalInterfaceType classType)
        {
            List <List <ClassOfListsFromReferencefile> > attributelist = new List <List <ClassOfListsFromReferencefile> >();

            if (attributeType.Attribute.Exists)
            {
                foreach (var attributeinattribute in attributeType.Attribute)
                {
                    StoreEachAttributeValueInListOfElectricalConnectorPins(i, attributelist, attributeinattribute, attributeType, externalInterface, classType);
                    CkeckForNestedAttributesOfElectricalConnectorPins(i, attributeinattribute, externalInterface, classType);
                }
            }
            if (!attributeType.Attribute.Exists)
            {
                List <List <ClassOfListsFromReferencefile> > list    = new List <List <ClassOfListsFromReferencefile> >();
                List <ClassOfListsFromReferencefile>         sublist = new List <ClassOfListsFromReferencefile>();


                list.Add(sublist);
                if (DictioanryofElectricalConnectorPinType.ContainsKey("(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                                       + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"))
                {
                    DictioanryofElectricalConnectorPinType["(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                           + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"].AddRange(list);
                }
                else
                {
                    DictioanryofElectricalConnectorPinType.Add("(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                               + "{" + "Class:" + "  " + externalInterface.BaseClass + "}", list);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Creates the Structur to reference a picture and set the correct value <paramref name="pic"/>.
        /// If the structur is already there, it will only update the value.
        /// </summary>
        /// <param name="pic">the absolut path to the picture</param>
        /// <param name="pictype">Picturetyp like 'DevicePicture' or 'DeviceIcon'</param>
        /// <param name="externalname">The name of the externalElement</param>
        /// <param name="systemUnitClass">the systemUnitClass to insert the structure into</param>
        /// <returns></returns>
        public Uri createPictureRef(string pic, string pictype, string externalname, SystemUnitClassType systemUnitClass)
        {
            // create the package paths
            FileInfo pictureInfo = new FileInfo(pic);
            Uri      picturePath = new Uri(pictureInfo.Name, UriKind.Relative);
            Uri      picturePart = PackUriHelper.CreatePartUri(picturePath);

            // Create the InternalElement which refers to the picture
            InternalElementType pictureIE = null;

            foreach (var internalElement in systemUnitClass.InternalElement)
            {
                if (internalElement.Name.Equals(pictype))
                {
                    pictureIE = internalElement;
                    break;
                }
            }
            if (pictureIE == null)
            {
                pictureIE = systemUnitClass.InternalElement.Append(pictype);
            }

            // create the externalelement
            ExternalInterfaceType pictureEI = null;

            foreach (var externalinterface in pictureIE.ExternalInterface)
            {
                if (externalinterface.Name.Equals(externalname))
                {
                    pictureEI = externalinterface;
                    break;
                }
            }
            if (pictureEI == null)
            {
                pictureEI = pictureIE.ExternalInterface.Append(externalname);
            }

            pictureEI.RefBaseClassPath = AutomationMLInterfaceClassLib.ExternalDataConnector;

            // create the refURI Attribute with the value of the path

            AttributeType pictureAtt = null;

            if (pictureEI.Attribute.GetCAEXAttribute("refURI") == null)
            {
                pictureAtt = pictureEI.Attribute.Append("refURI");
            }
            pictureAtt.AttributeDataType = "xs:anyURI";
            pictureAtt.Value             = picturePart.ToString();


            return(picturePart);
        }
예제 #4
0
        /// <summary>
        /// Takes the url of the picture and setup in the value attribute of the corresponding internal element <paramref name="pic"/>.
        /// </summary>
        /// <param name="url">the absolut path to the picture or document in the internet</param>
        /// <param name="urltype">Picturetyp like 'DevicePicture' or 'DeviceIcon' and document type like "Short guide" or "Bill of materials" etc</param>
        /// <param name="externalname">The name of the externalElement</param>
        /// <param name="systemUnitClass">the systemUnitClass to insert the structure into</param>
        /// <returns></returns>
        public void interneturl(string url, string urltype, string externalname, SystemUnitClassType systemUnitClass)
        {
            // Create the InternalElement which refers to the picture
            InternalElementType urlIE = null;

            foreach (var internalElement in systemUnitClass.InternalElement)
            {
                if (internalElement.Name.Equals(urltype))
                {
                    urlIE = internalElement;
                    break;
                }
            }
            if (urlIE == null)
            {
                urlIE = systemUnitClass.InternalElement.Append(urltype);
            }

            // create the externalelement
            ExternalInterfaceType urlEI = null;

            foreach (var externalinterface in urlIE.ExternalInterface)
            {
                if (externalinterface.Name.Equals(externalname))
                {
                    urlEI = externalinterface;
                    break;
                }
            }
            if (urlEI == null)
            {
                urlEI = urlIE.ExternalInterface.Append(externalname);
            }

            urlEI.RefBaseClassPath = AutomationMLInterfaceClassLib.ExternalDataConnector;

            // create the refURI Attribute with the value of the path

            AttributeType urlAtt = null;

            if (urlEI.Attribute.GetCAEXAttribute("refURI") == null)
            {
                urlAtt = urlEI.Attribute.Append("refURI");
            }
            urlAtt.AttributeDataType = "xs:anyURI";
            urlAtt.Value             = url.ToString();
        }
        /// <summary>
        /// Creates the aml object relation between the provided partners if they are not aready linked
        /// </summary>
        /// <param name="aPartner">a partner.</param>
        /// <param name="bPartner">The b partner.</param>
        /// <returns></returns>
        internal static bool CreateAMLObjectRelationIfUnrelated(ExternalInterfaceType aPartner, ExternalInterfaceType bPartner)
        {
            // we don't want to link interfaces of the same aml object
            if (aPartner.AssociatedObject.Equals(bPartner.AssociatedObject))
            {
                return(false);
            }

            // we don`t want to create more than one link from an already linked object
            if (aPartner.InternalLinksToInterface().Count() > 0)
            {
                return(false);
            }

            // we don`t want to create more than one link from an already linked object
            if (bPartner.InternalLinksToInterface().Count() > 0)
            {
                return(false);
            }

            return(InternalLinkType.New_InternalLink(aPartner, bPartner, "AmlRelation").Exists);
        }
예제 #6
0
        public void CheckForAttributesOfExternalIterface(int i, ExternalInterfaceType externalInterface)
        {
            List <List <ClassOfListsFromReferencefile> > attributelist = new List <List <ClassOfListsFromReferencefile> >();

            if (externalInterface.Attribute.Exists)
            {
                foreach (var attribute in externalInterface.Attribute)
                {
                    StoreEachAttributeValueInListOfExternalIterface(i, attributelist, attribute, externalInterface);
                    CkeckForNestedAttributesOfExternalIterface(i, attribute, externalInterface);
                }
            }
            if (!externalInterface.Attribute.Exists)
            {
                List <List <ClassOfListsFromReferencefile> > list    = new List <List <ClassOfListsFromReferencefile> >();
                List <ClassOfListsFromReferencefile>         sublist = new List <ClassOfListsFromReferencefile>();

                list.Add(sublist);
                try
                {
                    if (DictionaryofElectricalConnectorType.ContainsKey("(" + i + ")" + externalInterface.Name.ToString() + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"))
                    {
                        DictionaryofElectricalConnectorType["(" + i + ")" + externalInterface.Name.ToString()
                                                            + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"].AddRange(list);
                    }
                    else
                    {
                        DictionaryofElectricalConnectorType.Add("(" + i + ")" + externalInterface.Name.ToString()
                                                                + "{" + "Class:" + "  " + externalInterface.BaseClass + "}", list);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Create the AMLX File with the correct AML File and optional pictures
        /// </summary>
        /// <param name="device">The device which will be created</param>
        /// <param name="isEdit">true if an amlx file get update, false if a new file will be created</param>
        /// <returns></returns>
        public string CreateDevice(MWDevice device, bool isEdit)
        {
            CAEXDocument          document = null;
            AutomationMLContainer amlx     = null;

            // Init final .amlx Filepath
            //first of all create a folder on "Vendor Name"
            string vendorCompanyName         = device.vendorName;
            string vendorCompanyNameFilePath = "";



            string fileName = device.fileName;

            string amlFilePath = System.IO.Path.Combine(device.filepath, fileName + ".amlx");


            FileInfo file = new FileInfo(amlFilePath);



            // Create directory if it's not existing
            file.Directory.Create();


            // Init CAEX Document
            if (isEdit)
            {
                // Load the amlx file
                amlx = new AutomationMLContainer(amlFilePath, FileMode.Open);

                IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root);

                // We expect the aml to only have one root part
                if (rootParts.First() != null)
                {
                    PackagePart part = rootParts.First();

                    // load the aml file as an CAEX document
                    document = CAEXDocument.LoadFromStream(part.GetStream());
                }
                else
                {
                    // the amlx contains no aml file
                    document = CAEXDocument.New_CAEXDocument();
                }
            }
            else
            {
                // create a new CAEX document
                document = CAEXDocument.New_CAEXDocument();
                try
                { amlx = new AutomationMLContainer(amlFilePath, FileMode.Create); } catch (Exception) {}
            }



            // Init the default Libs
            AutomationMLBaseRoleClassLibType.RoleClassLib(document);
            AutomationMLInterfaceClassLibType.InterfaceClassLib(document);

            var structureRoleFamilyType = AutomationMLBaseRoleClassLibType.RoleClassLib(document).Structure;


            SystemUnitFamilyType systemUnitClass = null;

            // Create the SystemUnitClass for our device
            if (!isEdit)
            {
                systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName);


                device.listWithURIConvertedToString = new List <AttachablesDataGridViewParameters>();
                foreach (AttachablesDataGridViewParameters eachparameter in device.dataGridAttachablesParametrsList)
                {
                    if (eachparameter.FilePath.Contains("https://") || eachparameter.FilePath.Contains("http://") || eachparameter.FilePath.Contains("www") || eachparameter.FilePath.Contains("WWW"))
                    {
                        interneturl(eachparameter.FilePath, eachparameter.ElementName.ToString(), "ExternalDataConnector", systemUnitClass);
                    }
                    else
                    {
                        Boolean myBool;
                        Boolean.TryParse(eachparameter.AddToFile, out myBool);

                        if (myBool == true)
                        {
                        }

                        Uri eachUri = null;
                        AttachablesDataGridViewParameters par = new AttachablesDataGridViewParameters();
                        eachUri         = createPictureRef(eachparameter.FilePath, eachparameter.ElementName.ToString(), "ExternalDataConnector", systemUnitClass);
                        par.ElementName = eachUri.ToString();
                        par.FilePath    = eachparameter.FilePath;

                        device.listWithURIConvertedToString.Add(par);
                    }
                }
                foreach (var pair in device.DictionaryForRoleClassofComponent)
                {
                    SupportedRoleClassType supportedRoleClass = null;


                    Match  numberfromElectricalConnectorType = Regex.Match(pair.Key.ToString(), @"\((\d+)\)");
                    string initialnumberbetweenparanthesisofElectricalConnectorType = numberfromElectricalConnectorType.Groups[1].Value;
                    // string stringinparanthesis = Regex.Match(pair.Key.ToString(), @"\{(\d+)\}").Groups[1].Value;

                    string supportedRoleClassFromDictionary = Regex.Replace(pair.Key.ToString(), @"\(.+?\)", "");
                    supportedRoleClassFromDictionary = Regex.Replace(supportedRoleClassFromDictionary, @"\{.+?\}", "");



                    var SRC = systemUnitClass.SupportedRoleClass.Append();



                    var attributesOfSystemUnitClass = systemUnitClass.Attribute;

                    foreach (var valueList in pair.Value)
                    {
                        foreach (var item in valueList)
                        {
                            if (item.AttributePath.Contains("/") || item.AttributePath.Contains("."))
                            {
                                int          count               = 2;
                                int          counter             = 0;
                                Stack <char> stack               = new Stack <char>();
                                string       searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length);

                                foreach (var character in searchAttributeName.Reverse())
                                {
                                    if (!char.IsLetterOrDigit(character))
                                    {
                                        counter++;
                                        if (counter == count)
                                        {
                                            break;
                                        }
                                    }
                                    if (char.IsLetterOrDigit(character))
                                    {
                                        stack.Push(character);
                                    }
                                }

                                string finalAttributeName = new string(stack.ToArray());

                                foreach (var attribute in systemUnitClass.Attribute)
                                {
                                    if (attribute.Name == finalAttributeName)
                                    {
                                        var eachattribute = attribute.Attribute.Append(item.Name.ToString());
                                        eachattribute.Value             = item.Value;
                                        eachattribute.DefaultValue      = item.Default;
                                        eachattribute.Unit              = item.Unit;
                                        eachattribute.AttributeDataType = item.DataType;
                                        eachattribute.Description       = item.Description;
                                        eachattribute.Copyright         = item.CopyRight;

                                        eachattribute.ID = item.ID;

                                        foreach (var val in item.RefSemanticList.Elements)
                                        {
                                            var refsem = eachattribute.RefSemantic.Append();
                                            refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                                        }



                                        SRC.RefRoleClassPath = item.SupportesRoleClassType;
                                    }
                                    if (attribute.Attribute.Exists)
                                    {
                                        SearchForAttributesInsideAttributesofAutomationComponent(finalAttributeName, attribute, item, SRC);
                                    }
                                }
                            }
                            else
                            {
                                var eachattribute = attributesOfSystemUnitClass.Append(item.Name.ToString());
                                eachattribute.Value             = item.Value;
                                eachattribute.DefaultValue      = item.Default;
                                eachattribute.Unit              = item.Unit;
                                eachattribute.AttributeDataType = item.DataType;
                                eachattribute.Description       = item.Description;
                                eachattribute.Copyright         = item.CopyRight;

                                eachattribute.ID = item.ID;


                                foreach (var val in item.RefSemanticList.Elements)
                                {
                                    var refsem = eachattribute.RefSemantic.Append();
                                    refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                                }


                                SRC.RefRoleClassPath = item.SupportesRoleClassType;
                            }
                        }
                    }


                    foreach (var pairofList in device.DictionaryForExternalInterfacesUnderRoleClassofComponent)
                    {
                        Match  numberfromElectricalConnectorPins = Regex.Match(pairofList.Key.ToString(), @"\((\d+)\)");
                        string initialnumberbetweenparanthesisElectricalConnectorPins = numberfromElectricalConnectorPins.Groups[1].Value;

                        string electricalConnectorPinName = Regex.Replace(pairofList.Key.ToString(), @"\(.*?\)", "");
                        electricalConnectorPinName = Regex.Replace(electricalConnectorPinName, @"\{.*?\}", "");
                        electricalConnectorPinName = electricalConnectorPinName.Replace(supportedRoleClassFromDictionary, "");



                        /*if (initialnumberbetweenparanthesisofElectricalConnectorType == initialnumberbetweenparanthesisElectricalConnectorPins)
                         * {
                         *  supportedRoleClass.RoleReference = pairofList.Key.ToString();
                         *
                         *  systemUnitClass.SupportedRoleClass.Append(supportedRoleClass);
                         *  systemUnitClass.BaseClass.Name = supportedRoleClassFromDictionary;
                         *
                         *  var attributesOfSystemUnitClassattributes = systemUnitClass.Attribute;
                         *
                         *  foreach (var valueList in pairofList.Value)
                         *  {
                         *      foreach (var item in valueList)
                         *      {
                         *          var eachattribute = attributesOfSystemUnitClassattributes.Append(item.Name.ToString());
                         *          eachattribute.Value = item.Value;
                         *          eachattribute.DefaultValue = item.Default;
                         *          eachattribute.Unit = item.Unit;
                         *          //eachattribute.AttributeDataType =
                         *          eachattribute.Description = item.Description;
                         *          eachattribute.Copyright = item.CopyRight;
                         *
                         *          eachattribute.ID = item.ID;
                         *
                         *
                         *
                         *         // systemUnitClass.BaseClass.Name   = item.RefBaseClassPath;
                         *      }
                         *  }
                         * }*/
                    }
                }
            }
            else
            {
                // check if our format is given in the amlx file if not: create it
                bool foundSysClassLib = false;
                foreach (var sysclasslib in document.CAEXFile.SystemUnitClassLib)
                {
                    if (sysclasslib.Name.Equals("ComponentSystemUnitClassLib"))
                    {
                        bool foundSysClass = false;
                        foreach (var sysclass in sysclasslib.SystemUnitClass)
                        {
                            if (sysclass.Name.Equals(device.deviceName))
                            {
                                foundSysClass   = true;
                                systemUnitClass = sysclass;
                                break;
                            }
                        }
                        if (!foundSysClass)
                        {
                            systemUnitClass = sysclasslib.SystemUnitClass.Append(device.deviceName);
                        }
                        foundSysClassLib = true;
                    }
                }
                if (!foundSysClassLib)
                {
                    systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName);
                }
            }



            // Create the internalElement Electrical Interfaces

            if (device.vendorName != null)
            {
                InternalElementType  electricalInterface = null;
                RoleRequirementsType roleRequirements    = null;
                foreach (var internalElement in systemUnitClass.InternalElement)
                {
                    if (internalElement.Name.Equals("ElectricalInterfaces"))
                    {
                        electricalInterface = internalElement;
                        roleRequirements    = electricalInterface.RoleRequirements.Append();
                        roleRequirements.RefBaseRoleClassPath = structureRoleFamilyType.CAEXPath();
                        break;
                    }
                }
                if (electricalInterface == null)
                {
                    electricalInterface = systemUnitClass.InternalElement.Append("ElectricalInterfaces");
                }
                roleRequirements = electricalInterface.RoleRequirements.Append();

                roleRequirements.RefBaseRoleClassPath = structureRoleFamilyType.CAEXPath();

                foreach (var pair in device.DictionaryForInterfaceClassesInElectricalInterfaces)
                {
                    InternalElementType   internalElementofElectricalConnectorType = null;
                    ExternalInterfaceType electricalConnectorType = null;

                    ExternalInterfaceType electricalConnectorPins = null;

                    Match  numberfromElectricalConnectorType = Regex.Match(pair.Key.ToString(), @"\((\d+)\)");
                    string initialnumberbetweenparanthesisofElectricalConnectorType = numberfromElectricalConnectorType.Groups[1].Value;


                    string electricalConnectorTypeName = Regex.Replace(pair.Key.ToString(), @"\(.+?\)", "");
                    electricalConnectorTypeName = Regex.Replace(electricalConnectorTypeName, @"\{.+?\}", "");

                    internalElementofElectricalConnectorType = electricalInterface.InternalElement.Append(electricalConnectorTypeName);

                    electricalConnectorType = internalElementofElectricalConnectorType.ExternalInterface.Append(electricalConnectorTypeName);

                    var attributesOfConnectorType = electricalConnectorType.Attribute;

                    foreach (var valueList in pair.Value)
                    {
                        foreach (var item in valueList)
                        {
                            if (item.AttributePath.Contains("/") || item.AttributePath.Contains("."))
                            {
                                int          count               = 2;
                                int          counter             = 0;
                                Stack <char> stack               = new Stack <char>();
                                string       searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length);

                                foreach (var character in searchAttributeName.Reverse())
                                {
                                    if (!char.IsLetterOrDigit(character))
                                    {
                                        counter++;
                                        if (counter == count)
                                        {
                                            break;
                                        }
                                    }
                                    if (char.IsLetterOrDigit(character))
                                    {
                                        stack.Push(character);
                                    }
                                }

                                string finalAttributeName = new string(stack.ToArray());

                                foreach (var attribute in electricalConnectorType.Attribute)
                                {
                                    if (attribute.Name == finalAttributeName)
                                    {
                                        var eachattribute = attribute.Attribute.Append(item.Name.ToString());
                                        eachattribute.Value             = item.Value;
                                        eachattribute.DefaultValue      = item.Default;
                                        eachattribute.Unit              = item.Unit;
                                        eachattribute.AttributeDataType = item.DataType;
                                        eachattribute.Description       = item.Description;
                                        eachattribute.Copyright         = item.CopyRight;

                                        eachattribute.ID = item.ID;

                                        foreach (var val in item.RefSemanticList.Elements)
                                        {
                                            var refsem = eachattribute.RefSemantic.Append();
                                            refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                                        }

                                        electricalConnectorType.RefBaseClassPath = item.RefBaseClassPath;
                                    }
                                    if (attribute.Attribute.Exists)
                                    {
                                        SearchAttributesInsideAttributesOFElectricConnectorType(finalAttributeName, attribute, item, electricalConnectorType);
                                    }
                                }
                            }
                            else
                            {
                                var eachattribute = attributesOfConnectorType.Append(item.Name.ToString());
                                eachattribute.Value             = item.Value;
                                eachattribute.DefaultValue      = item.Default;
                                eachattribute.Unit              = item.Unit;
                                eachattribute.AttributeDataType = item.DataType;
                                eachattribute.Description       = item.Description;
                                eachattribute.Copyright         = item.CopyRight;

                                eachattribute.ID = item.ID;

                                foreach (var val in item.RefSemanticList.Elements)
                                {
                                    var refsem = eachattribute.RefSemantic.Append();
                                    refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                                }

                                electricalConnectorType.RefBaseClassPath = item.RefBaseClassPath;
                            }
                        }
                    }


                    foreach (var pairofList in device.DictionaryForExternalInterfacesUnderInterfaceClassInElectricalInterfaces)
                    {
                        Match  numberfromElectricalConnectorPins = Regex.Match(pairofList.Key.ToString(), @"\((\d+)\)");
                        string initialnumberbetweenparanthesisElectricalConnectorPins = numberfromElectricalConnectorPins.Groups[1].Value;

                        string electricalConnectorPinName = Regex.Replace(pairofList.Key.ToString(), @"\(.*?\)", "");
                        electricalConnectorPinName = Regex.Replace(electricalConnectorPinName, @"\{.*?\}", "");
                        electricalConnectorPinName = electricalConnectorPinName.Replace(electricalConnectorTypeName, "");



                        if (initialnumberbetweenparanthesisofElectricalConnectorType == initialnumberbetweenparanthesisElectricalConnectorPins)
                        {
                            electricalConnectorPins = electricalConnectorType.ExternalInterface.Append(electricalConnectorPinName);

                            var attributesOfConnectorPins = electricalConnectorPins.Attribute;

                            foreach (var valueList in pairofList.Value)
                            {
                                foreach (var item in valueList)
                                {
                                    if (item.AttributePath.Contains("/") || item.AttributePath.Contains("."))
                                    {
                                        int          count               = 2;
                                        int          counter             = 0;
                                        Stack <char> stack               = new Stack <char>();
                                        string       searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length);

                                        foreach (var character in searchAttributeName.Reverse())
                                        {
                                            if (!char.IsLetterOrDigit(character))
                                            {
                                                counter++;
                                                if (counter == count)
                                                {
                                                    break;
                                                }
                                            }
                                            if (char.IsLetterOrDigit(character))
                                            {
                                                stack.Push(character);
                                            }
                                        }

                                        string finalAttributeName = new string(stack.ToArray());

                                        foreach (var attribute in electricalConnectorPins.Attribute)
                                        {
                                            if (attribute.Name == finalAttributeName)
                                            {
                                                var eachattribute = attribute.Attribute.Append(item.Name.ToString());
                                                eachattribute.Value             = item.Value;
                                                eachattribute.DefaultValue      = item.Default;
                                                eachattribute.Unit              = item.Unit;
                                                eachattribute.AttributeDataType = item.DataType;
                                                eachattribute.Description       = item.Description;
                                                eachattribute.Copyright         = item.CopyRight;

                                                eachattribute.ID = item.ID;

                                                foreach (var val in item.RefSemanticList.Elements)
                                                {
                                                    var refsem = eachattribute.RefSemantic.Append();
                                                    refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                                                }

                                                electricalConnectorPins.RefBaseClassPath = item.RefBaseClassPath;
                                            }
                                            if (attribute.Attribute.Exists)
                                            {
                                                SearchAttributesInsideAttributesOFElectricConnectorType(finalAttributeName, attribute, item, electricalConnectorPins);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var eachattribute = attributesOfConnectorPins.Append(item.Name.ToString());
                                        eachattribute.Value             = item.Value;
                                        eachattribute.DefaultValue      = item.Default;
                                        eachattribute.Unit              = item.Unit;
                                        eachattribute.AttributeDataType = item.DataType;
                                        eachattribute.Description       = item.Description;
                                        eachattribute.Copyright         = item.CopyRight;

                                        eachattribute.ID = item.ID;

                                        foreach (var val in item.RefSemanticList.Elements)
                                        {
                                            var refsem = eachattribute.RefSemantic.Append();
                                            refsem.CorrespondingAttributePath = val.FirstAttribute.Value;
                                        }

                                        electricalConnectorPins.RefBaseClassPath = item.RefBaseClassPath;
                                    }
                                }
                            }
                        }
                    }
                }
            }



            // create the PackageUri for the root aml file
            Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + fileName + "-root.aml", UriKind.Relative));


            // tcreate the aml file as a temporary file
            string path = Path.GetTempFileName();

            document.SaveToFile(path, true);

            if (isEdit)
            {
                // delete the old aml file
                amlx.Package.DeletePart(partUri);

                // delete all files in the amlx package.
                // Directory.Delete(Path.GetFullPath(amlx.ContainerFilename), true);
            }

            // write the new aml file into the package
            PackagePart root = amlx.AddRoot(path, partUri);


            if (!isEdit)
            {
                foreach (AttachablesDataGridViewParameters listWithUri in device.listWithURIConvertedToString)
                {
                    if (listWithUri.ElementName != null)
                    {
                        Uri newuri = null;
                        newuri = new Uri(listWithUri.ElementName, UriKind.Relative);
                        amlx.AddAnyContent(root, listWithUri.FilePath.ToString(), newuri);
                    }
                }
            }
            DirectoryInfo directory = new DirectoryInfo(Path.GetDirectoryName(amlFilePath));

            foreach (FileInfo fileInfos in directory.GetFiles())
            {
                if (fileInfos.Extension != ".amlx")
                {
                    fileInfos.Delete();
                }
            }


            amlx.Save();
            amlx.Close();
            if (isEdit)
            {
                return("Sucessfully updated device!\nFilepath " + amlFilePath);
            }
            else
            {
                return("Device description file created!\nFilepath " + amlFilePath);
            }
        }
예제 #8
0
        public void StoreEachAttributeValueInListOfElectricalConnectorPins(int i, List <List <ClassOfListsFromReferencefile> > list,
                                                                           AttributeType AttributeInAttribute, AttributeType attributeType, ExternalInterfaceType externalInterface, ExternalInterfaceType classType)
        {
            list = new List <List <ClassOfListsFromReferencefile> >();
            List <ClassOfListsFromReferencefile> sublist = new List <ClassOfListsFromReferencefile>();

            ClassOfListsFromReferencefile attributeparameters = new ClassOfListsFromReferencefile();

            // In the following parameters on right hand side "attributeType" has been changed to "AttributeInAttribute" this has been repeated to all
            // methods of name "StoreEachAttributeValuesInList" with four parameters.
            attributeparameters.Name            = AttributeInAttribute.Name;
            attributeparameters.Value           = AttributeInAttribute.Value;
            attributeparameters.Default         = AttributeInAttribute.DefaultValue;
            attributeparameters.Unit            = AttributeInAttribute.Unit;
            attributeparameters.DataType        = AttributeInAttribute.AttributeDataType;
            attributeparameters.Description     = AttributeInAttribute.Description;
            attributeparameters.CopyRight       = AttributeInAttribute.Copyright;
            attributeparameters.AttributePath   = AttributeInAttribute.AttributePath;
            attributeparameters.RefSemanticList = AttributeInAttribute.RefSemantic;
            //attributeparameters.ReferencedClassName = externalInterface.BaseClass.ToString();
            attributeparameters.RefBaseClassPath = externalInterface.RefBaseClassPath;
            attributeparameters.ID = externalInterface.ID;


            sublist.Add(attributeparameters);
            list.Add(sublist);
            if (DictioanryofElectricalConnectorPinType.ContainsKey("(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                                   + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"))
            {
                DictioanryofElectricalConnectorPinType["(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                       + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"].AddRange(list);
            }
            else
            {
                DictioanryofElectricalConnectorPinType.Add("(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                           + "{" + "Class:" + "  " + externalInterface.BaseClass + "}", list);
            }
        }
예제 #9
0
        public void StoreEachAttributeValueInListOfElectricalConnectorPins(int i, List <List <ClassOfListsFromReferencefile> > list,
                                                                           AttributeType attributeType, ExternalInterfaceType externalInterface, ExternalInterfaceType classType)
        {
            list = new List <List <ClassOfListsFromReferencefile> >();
            List <ClassOfListsFromReferencefile> sublist             = new List <ClassOfListsFromReferencefile>();
            ClassOfListsFromReferencefile        attributeparameters = new ClassOfListsFromReferencefile();

            attributeparameters.Name            = attributeType.Name;
            attributeparameters.Value           = attributeType.Value;
            attributeparameters.Default         = attributeType.DefaultValue;
            attributeparameters.Unit            = attributeType.Unit;
            attributeparameters.DataType        = attributeType.AttributeDataType;
            attributeparameters.Description     = attributeType.Description;
            attributeparameters.CopyRight       = attributeType.Copyright;
            attributeparameters.AttributePath   = attributeType.AttributePath;
            attributeparameters.RefSemanticList = attributeType.RefSemantic;
            // attributeparameters.ReferencedClassName = externalInterface.BaseClass.ToString();
            attributeparameters.RefBaseClassPath = externalInterface.RefBaseClassPath;
            attributeparameters.ID = externalInterface.ID;

            sublist.Add(attributeparameters);
            list.Add(sublist);
            try
            {
                if (DictioanryofElectricalConnectorPinType.ContainsKey("(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                                       + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"))
                {
                    DictioanryofElectricalConnectorPinType["(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                           + "{" + "Class:" + "  " + externalInterface.BaseClass + "}"].AddRange(list);
                }
                else
                {
                    DictioanryofElectricalConnectorPinType.Add("(" + i + ")" + classType.Name.ToString() + "{" + "Class:" + "  " + classType.BaseClass + "}" + externalInterface.Name.ToString()
                                                               + "{" + "Class:" + "  " + externalInterface.BaseClass + "}", list);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public ExternalGeometryConnectorViewModel(ExternalInterfaceType model, IAmlProvider provider) : base(model, provider)
 {
 }
 public InterfaceViewModel(ExternalInterfaceType model, IAmlProvider provider)
     : base(provider)
 {
     _interface = model;
     Initialize();
 }
 public InterfaceViewModel(IAmlProvider provider)
     : base(provider)
 {
     _interface = provider.CaexDocument.Create <ExternalInterfaceType>();
 }
예제 #13
0
 public ExternalDataConnectorViewModel(ExternalInterfaceType model, IAmlProvider provider)
     : base(model, provider)
 {
     _interface = model;
     Initialize();
 }
예제 #14
0
 public ExternalDataConnectorViewModel(IAmlProvider provider)
     : base(provider)
 {
     _interface = provider.CaexDocument.Create <ExternalInterfaceType>();
     Initialize();
 }