internal Feature LoadFeatureProj(string featureProjFile, string path)
        {
            Project proj;
            string fullpath = ExpandEnvVars(featureProjFile, path);
            Feature feat = null;

            try
            {
                feat = m_helper.FindFeatureByProject(fullpath);

                if (feat != null) return feat;

                feat = new Feature();

                if (!File.Exists(fullpath))
                {
                    // TODO: add logging support
                    return null;
                }

                proj = LoadProject(fullpath);

                path = Path.GetDirectoryName(fullpath);
                feat.ProjectPath = ConvertPathToEnv(featureProjFile);

                Dictionary<string, string> tbl = new Dictionary<string, string>();
                tbl["FeatureName"] = "Name";
                tbl["Filter"] = "Filter";

                LoadStringProps(proj, feat, tbl);

                if (string.IsNullOrEmpty(feat.Guid)) feat.Guid = System.Guid.NewGuid().ToString("B");


                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        switch (bi.ItemType)
                        {
                            case "RequiredManagedProjects":
                                {
                                    MFAssembly asm = LoadAssemblyProj(bi.Include, path);

                                    if (asm != null)
                                    {
                                        MFComponent asmRef = new MFComponent(MFComponentType.MFAssembly);

                                        asmRef.Name = asm.Name;
                                        asmRef.Guid = asm.Guid;
                                        asmRef.ProjectPath = asm.ProjectPath;
                                        asmRef.Conditional = cond;

                                        feat.Assemblies.Add(asmRef);
                                    }
                                }
                                break;
                            case "RequiredProjects":
                                string test = Path.GetExtension(bi.Include).ToUpper();

                                switch (test)
                                {
                                    case ".FEATUREPROJ":
                                        System.Diagnostics.Debug.Assert(false, "Use ProjectImportElement for featureproj files");
                                        break;
                                    case ".LIBCATPROJ":
                                        System.Diagnostics.Debug.Assert(false, "Use ProjectImportElement for libcatproj files");
                                        break;
                                    case ".PROJ":
                                        Library lib = LoadLibraryProj(bi.Include, path);
                                        if (lib != null)
                                        {
                                            feat.ComponentDependencies.Add(new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, bi.Include, cond));
                                        }
                                        else
                                        {
                                            //TODO: ERROR LOGGING
                                        }
                                        break;
                                }
                                break;
                            // ignore
                            case "MMP_DAT_CreateDatabase":
                            case "InteropFeature":
                                break;
                            default:
                                Console.WriteLine("Warning: Unknown ProjectItemElement " + bi.ItemType);
                                break;

                        }
                    }

                }

                // featureproj and libcatproj files are imported
                foreach (ProjectImportElement imp in proj.Xml.Imports)
                {
                    switch (Path.GetExtension(imp.Project).ToUpper())
                    {
                        case ".FEATUREPROJ":
                            Feature f2 = LoadFeatureProj(imp.Project, path);
                            feat.FeatureDependencies.Add(new MFComponent(MFComponentType.Feature, f2.Name, f2.Guid, imp.Project, imp.Condition));
                            break;
                        case ".LIBCATPROJ":
                            LibraryCategory libcat = LoadLibraryCategoryProj(imp.Project, path);
                            feat.ComponentDependencies.Add(new MFComponent(MFComponentType.LibraryCategory, libcat.Name, libcat.Guid, libcat.ProjectPath));
                            break;
                    }
                }

                Feature dbFeat = null;

                if (!string.IsNullOrEmpty(feat.Guid)) dbFeat = m_helper.FindFeature(feat.Guid);

                if (dbFeat == null) dbFeat = m_helper.FindFeatureByName(feat.Name);

                if (null == dbFeat)
                {
                    m_helper.DefaultInventory.Features.Add(feat);
                }
                else
                {
                    feat = dbFeat;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading feature file: " + fullpath + "\r\n", e.Message);
                feat = null;
            }

            return feat;
        }
        internal void SaveFeatureProj(Feature feature)
        {
            if (!string.IsNullOrEmpty(feature.ProjectPath))
            {
                try
                {
                    Project proj;
                    
                    string path = ExpandEnvVars(feature.ProjectPath, "");

                    if (File.Exists(path))
                    {
                        proj = LoadProject(path);
                    }
                    else
                    {
                        proj = new Project();
                        proj.FullPath = path;
                    }

                    UpdatePropertyGroups(proj, feature,
                        new string[]{
                            "FeatureName",
                            "Filter",
                            "Description",
                            "Guid",
                            "Groups",
                            "Documentation",
                            "IsSolutionWizardVisible"
                        },
                            new string[]{
                            "Name",
                        });

                    // TODO: Save imports (libcatproj and featureproj files)

                    proj.Save(proj.FullPath);
                }
                catch(Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Error: failure saving feature file " + feature.ProjectPath + "\r\n" + e.Message);
                }
            }
        }
        private void addFeatureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode parent = treeViewInventory.Nodes[0].Nodes["Features"];
            Feature newFeat = new Feature();

            newFeat.Guid = Guid.NewGuid().ToString("B").ToUpper();

            TreeNode newNode = AddTreeElement(parent, "<New Feature>", newFeat, true, DefaultInventory.Features, c_defaultInventoryKey);

            DefaultInventory.Features.Add(newFeat);

            treeViewInventory.SelectedNode = newNode;
            newNode.BeginEdit();
        }
 public void CopyTo(Feature dest)
 {
     CopyHelper.CopyTo(this, dest);
 }
Ejemplo n.º 5
0
 public void SaveFeatureProj(Feature feat)
 {
     m_bw.SaveFeatureProj(feat);
     this.m_helper.DefaultInventory.Features.Clear();
     this.LoadDefaultFeaturesAsync();
 }