private void TraverseComponentAssembly(CyPhy.ComponentAssembly componentasm)
        {
            foreach (CyPhy.ComponentRef cref in componentasm.Children.ComponentRefCollection)
            {
                throw new Exception("Model not fully elaborated, contains ComponentRef [" + cref.Path + "]");
            }

            foreach (CyPhy.ComponentAssembly cainst in componentasm.Children.ComponentAssemblyCollection)
            {
                TraverseComponentAssembly(cainst);
            }

            foreach (CyPhy.Component cint in componentasm.Children.ComponentCollection)
            {
                foreach (CyPhy.ManufacturingModel manModel in cint.Children.ManufacturingModelCollection)
                {
                    string manfilename;
                    if (! manModel.TryGetResourcePath(out manfilename) ||
                           String.IsNullOrWhiteSpace(manfilename))
                    {
                        GMEConsole.Warning.Write("ManufacturingModel's FileLocation does not have a valid file name [" + manModel.Path + "]");
                        continue;
                    }

                    string avmid = cint.Attributes.AVMID;
                    string ComponentPath = cint.GetDirectoryPath();
                    string RandnewMfgFileName;
                    
                    {
                        string MfgDir = Path.Combine(this.OutputDirectory, "ManufacturingModels"); 
                        if (!Directory.Exists(MfgDir))
                            Directory.CreateDirectory(MfgDir);

                        string MfgComponentFileLocation;
                        char[] charsToTrim1 = { '{', '}' };
                        string newMfgFileNameGUID = cint.Attributes.ID + ".xml";
                        string newMfgFileNameAVMID = cint.Attributes.AVMID.Trim(charsToTrim1) + ".xml";
                        RandnewMfgFileName = System.IO.Path.GetRandomFileName() + ".xml";                // RB META-3152
                        //MfgComponentFileLocation = Path.Combine(MfgDir, newMfgFileNameGUID); // manfilename); 
                        MfgComponentFileLocation = Path.Combine(MfgDir, RandnewMfgFileName); // manfilename);   // RB META-3152
                        string resource_path;
                        manModel.TryGetResourcePath(out resource_path, ComponentLibraryManager.PathConvention.ABSOLUTE);
                        File.Copy(resource_path, MfgComponentFileLocation, true);
                    }

                    // for xml data
                    ComponentManufacturingData mfdata = new ComponentManufacturingData();
                    mfdata.AVMID = cint.Attributes.AVMID;
                    mfdata.RevID = cint.Attributes.Revision;
                    mfdata.VerID = cint.Attributes.Version;
                    mfdata.GUID = cint.Attributes.InstanceGUID;
                    mfdata.Name = cint.Name;
                    mfdata.Location = Path.Combine(this.ProjectRootDirectory, ComponentPath, manfilename);         // form path
                    mfdata.NewLocation = Path.Combine(this.OutputDirectory, "ManufacturingModels");

                    foreach (CyPhy.ManufacturingModelParameter param in manModel.Children.ManufacturingModelParameterCollection)
                    {
                        int srcCount = param.AllSrcConnections.Count();
                        if (srcCount > 1)
                            throw new Exception("ManufacturingModelParameter is connected to >1 value flow targets [" + param.Path + "]");

                        if (String.IsNullOrEmpty(param.Attributes.Value))
                        {
                            if (String.IsNullOrEmpty(param.Attributes.DefaultValue))
                                continue;
                            else
                                mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.DefaultValue);
                        }
                        else
                            mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.Value);
                    }

                    this.ComponentManufacturingDataList.Add(mfdata);

                    // for manifest data
                    char[] charsToTrim = { '{', '}' };
                    var componentmanifestdata = new DesignManufactureManifest.ComponentManufactureManifestData(
                                                                                        cint.Attributes.InstanceGUID, 
                                                                                        cint.Attributes.ID.ToString(), 
                                                                                        mfdata.NewLocation);
                    string fileName = cint.Attributes.ID + ".xml";
                    componentmanifestdata.ManufacturingModel = "ManufacturingModels/" + RandnewMfgFileName;       // RB META-3152
                    //componentmanifestdata.ManufacturingModel = "ManufacturingModels/" + fileName;
                    this.ManufacturingManifestData.ComponentManufactureList.Add(componentmanifestdata);


                }               

            }
        }
Beispiel #2
0
        private void TraverseComponentAssembly(CyPhy.ComponentAssembly componentasm)
        {
            foreach (CyPhy.ComponentRef cref in componentasm.Children.ComponentRefCollection)
            {
                throw new Exception("Model not fully elaborated, contains ComponentRef [" + cref.Path + "]");
            }

            foreach (CyPhy.ComponentAssembly cainst in componentasm.Children.ComponentAssemblyCollection)
            {
                TraverseComponentAssembly(cainst);
            }

            foreach (CyPhy.Component cint in componentasm.Children.ComponentCollection)
            {
                foreach (CyPhy.ManufacturingModel manModel in cint.Children.ManufacturingModelCollection)
                {
                    string manfilename;
                    if (!manModel.TryGetResourcePath(out manfilename) ||
                        String.IsNullOrWhiteSpace(manfilename))
                    {
                        GMEConsole.Warning.Write("ManufacturingModel's FileLocation does not have a valid file name [" + manModel.Path + "]");
                        continue;
                    }

                    string avmid         = cint.Attributes.AVMID;
                    string ComponentPath = cint.GetDirectoryPath();
                    string RandnewMfgFileName;

                    {
                        string MfgDir = Path.Combine(this.OutputDirectory, "ManufacturingModels");
                        if (!Directory.Exists(MfgDir))
                        {
                            Directory.CreateDirectory(MfgDir);
                        }

                        string MfgComponentFileLocation;
                        char[] charsToTrim1        = { '{', '}' };
                        string newMfgFileNameGUID  = cint.Attributes.ID + ".xml";
                        string newMfgFileNameAVMID = cint.Attributes.AVMID.Trim(charsToTrim1) + ".xml";
                        RandnewMfgFileName = System.IO.Path.GetRandomFileName() + ".xml";    // RB META-3152
                        //MfgComponentFileLocation = Path.Combine(MfgDir, newMfgFileNameGUID); // manfilename);
                        MfgComponentFileLocation = Path.Combine(MfgDir, RandnewMfgFileName); // manfilename);   // RB META-3152
                        string resource_path;
                        manModel.TryGetResourcePath(out resource_path, ComponentLibraryManager.PathConvention.ABSOLUTE);
                        File.Copy(resource_path, MfgComponentFileLocation, true);
                    }

                    // for xml data
                    ComponentManufacturingData mfdata = new ComponentManufacturingData();
                    mfdata.AVMID       = cint.Attributes.AVMID;
                    mfdata.RevID       = cint.Attributes.Revision;
                    mfdata.VerID       = cint.Attributes.Version;
                    mfdata.GUID        = cint.Attributes.InstanceGUID;
                    mfdata.Name        = cint.Name;
                    mfdata.Location    = Path.Combine(this.ProjectRootDirectory, ComponentPath, manfilename);      // form path
                    mfdata.NewLocation = Path.Combine(this.OutputDirectory, "ManufacturingModels");

                    foreach (CyPhy.ManufacturingModelParameter param in manModel.Children.ManufacturingModelParameterCollection)
                    {
                        int srcCount = param.AllSrcConnections.Count();
                        if (srcCount > 1)
                        {
                            throw new Exception("ManufacturingModelParameter is connected to >1 value flow targets [" + param.Path + "]");
                        }

                        if (String.IsNullOrEmpty(param.Attributes.Value))
                        {
                            if (String.IsNullOrEmpty(param.Attributes.DefaultValue))
                            {
                                continue;
                            }
                            else
                            {
                                mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.DefaultValue);
                            }
                        }
                        else
                        {
                            mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.Value);
                        }
                    }

                    this.ComponentManufacturingDataList.Add(mfdata);

                    // for manifest data
                    char[] charsToTrim           = { '{', '}' };
                    var    componentmanifestdata = new DesignManufactureManifest.ComponentManufactureManifestData(
                        cint.Attributes.InstanceGUID,
                        cint.Attributes.ID.ToString(),
                        mfdata.NewLocation);
                    string fileName = cint.Attributes.ID + ".xml";
                    componentmanifestdata.ManufacturingModel = "ManufacturingModels/" + RandnewMfgFileName;       // RB META-3152
                    //componentmanifestdata.ManufacturingModel = "ManufacturingModels/" + fileName;
                    this.ManufacturingManifestData.ComponentManufactureList.Add(componentmanifestdata);
                }
            }
        }