private void ComponentBuilderForm_Load(object sender, EventArgs e)
        {
            treeViewInventory.Nodes[0].Expand();

            m_fileToInventory[c_defaultInventoryKey] = new Inventory();

            m_bw = new MsBuildWrapper(DefaultInventory);

            if (m_colorIndex >= c_TextColors.Count) m_colorIndex--; // same color as last opened.
            m_fileToColorTable[c_defaultInventoryKey] = c_TextColors[m_colorIndex++];

            m_spoClient = Environment.GetEnvironmentVariable("SPOCLIENT");
        }
        public MsBuildWrapper(Inventory inv)
        {
            //Engine.GlobalEngine.BinPath = Path.GetDirectoryName(Environment.GetEnvironmentVariable("MSBUILD_EXE"));
            List<Inventory> list = new List<Inventory>();
            list.Add(inv);

            Init(list);
        }
        public void AddLibraryToInventory(Library library, bool isManifest, Inventory inv)
        {
            if (isManifest)
            {
                // only add manifests if we don't have the project loaded
                if (m_guidToObjectHash.ContainsKey(library.Guid.ToLower()))
                {
                    return;
                }
            }

            string path = MsBuildWrapper.ExpandEnvVars(library.ProjectPath, "").ToLower();
            if (m_projToObjectHash.ContainsKey(path))
            {
                return;

                //Console.WriteLine("Warning: project path alread in inventory: " + library.ProjectPath);
            }
            m_projToObjectHash[path] = library;

            string libFile = Path.GetFileNameWithoutExtension(library.LibraryFile);
            if (!string.IsNullOrEmpty(libFile))
            {
                libFile = libFile.ToLower();

                if (m_fileToObjectHash.ContainsKey(libFile))
                {
                    if (!isManifest)
                    {
                        m_fileToObjectHash[libFile] = library;
                    }
                }
                else
                {
                    m_fileToObjectHash[libFile] = library;
                }
            }
            string guid = library.Guid;

            if (string.IsNullOrEmpty(guid))
            {
                if (!isManifest)
                {
                    Console.WriteLine("WARNING: project without guid found: " + library.ProjectPath);
                }
                library.Guid = Guid.NewGuid().ToString("B");
                guid = library.Guid;
            }
            guid = guid.ToLower();

            if (m_guidToObjectHash.ContainsKey(guid))
            {
                Console.WriteLine("Warning: GUID alread in inventory: " + guid);
            }
            m_guidToObjectHash[guid] = library;

            inv.Libraries.Add(library);
        }
 public void CopyTo(Inventory dest)
 {
     CopyHelper.CopyTo(this, dest);
 }
        public SolutionWizardForm()
        {
            InitializeComponent();

            m_inv = new Inventory();
            m_helper = new InventoryHelper(m_inv);
            m_bw = new MsBuildWrapper(m_inv);
            m_spoClientPath = "";
            m_worker = new BackgroundWorker();
            m_worker.DoWork += new DoWorkEventHandler(m_worker_DoWork);
            m_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_worker_RunWorkerCompleted);
        }
        private void allToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List<string> removeKeys = new List<string>();
            foreach (string file in m_fileToInventory.Keys)
            {
                if (file != c_defaultInventoryKey)
                {
                    removeKeys.Add(file);
                }
            }

            m_fileToInventory[c_defaultInventoryKey] = new Inventory();
            m_bw = new MsBuildWrapper(DefaultInventory);
            foreach (string file in removeKeys)
            {
                RemoveFileMenus(file);
                RemoveInventory(file);
            }
            RefreshTree();           
        }
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
            sfd.OverwritePrompt = true;

            if (DialogResult.OK == sfd.ShowDialog(this))
            {
                if (!SaveFile(sfd.FileName, DefaultInventory))
                {
                    MessageBox.Show(this, "Error: Unable to save to " + sfd.FileName, "Save File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    m_fileToInventory[sfd.FileName.ToLower()] = DefaultInventory;
                    DefaultInventory = new Inventory();
                    AddFileMenus(sfd.FileName);
                }
            }

        }
        private bool SaveFile(string filePath, Inventory inv)
        {
            try
            {
                SaveGridView();

                ComponentObjectModel.InventoryHelper helper = new ComponentObjectModel.InventoryHelper(inv);

                helper.ValidateData();

                XmlWriterSettings set = new XmlWriterSettings();
                set.Indent = true;
                set.NewLineChars = "\r\n";

                XmlWriter xw = XmlWriter.Create(filePath, set);

                XmlSerializer xser = new XmlSerializer(typeof(Inventory));

                xser.Serialize(xw, inv);

                xw.Close();
            }
            catch
            {
                return false;
            }

            return true;
        }
        private Inventory CollapseInventory(string filePath, params Inventory[] invParams)
        {
            Inventory allInv = new Inventory();
            List<Inventory> invList;

            SaveGridView();

            if(invParams == null || invParams.Length == 0)
            {
                invList = new List<Inventory>();

                foreach (Inventory inv in m_fileToInventory.Values)
                {
                    invList.Add(inv);
                }
            }
            else
            {
                invList = new List<Inventory>(invParams);
            }

            foreach (Inventory inv in invList)
            {
                allInv.Solutions.AddRange(inv.Solutions);
                allInv.Features.AddRange(inv.Features);
                allInv.Libraries.AddRange(inv.Libraries);
                allInv.Processors.AddRange(inv.Processors);
                allInv.BuildTools.AddRange(inv.BuildTools);
                allInv.BuildParameters.AddRange(inv.BuildParameters);
                allInv.LibraryCategories.AddRange(inv.LibraryCategories);
                allInv.Assemblies.AddRange(inv.Assemblies);
            }

            // now lets update the tree with the new file assignment
            List<string> removeKeys = new List<string>();

            foreach (string key in m_fileToInventory.Keys)
            {
                if (string.Compare(key, filePath, true) != 0 &&
                    invList.Contains(m_fileToInventory[key] as Inventory))
                {
                    removeKeys.Add(key);
                }
            }
            foreach (string key in removeKeys)
            {
                if (key == c_defaultInventoryKey)
                {
                    m_fileToInventory[key] = new Inventory();
                }
                else
                {
                    RemoveFileMenus(key);
                    RemoveInventory(key);
                }
            }

            m_fileToInventory[filePath.ToLower()] = allInv;

            RefreshTree();

            return allInv;
        }
        private void LoadInventory(Inventory inv, string fileName)
        {
            TreeNode tnc = treeViewInventory.Nodes[0].Nodes["Solutions"];
            foreach (MFSolution p in inv.Solutions)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.Solutions, fileName);
            }
            tnc = treeViewInventory.Nodes[0].Nodes["Features"];
            foreach (Feature p in inv.Features)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.Features, fileName);
            }
            tnc = treeViewInventory.Nodes[0].Nodes["Libraries"];
            foreach (Library p in inv.Libraries)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.Libraries, fileName);
            }
            tnc = treeViewInventory.Nodes[0].Nodes["BuildTools"];
            foreach (BuildTool p in inv.BuildTools)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.BuildTools, fileName);
            }
            tnc = treeViewInventory.Nodes[0].Nodes["Processors"];
            foreach (Processor p in inv.Processors)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.Processors, fileName);
            }
            tnc = treeViewInventory.Nodes[0].Nodes["BuildParameters"];
            string name = fileName == c_defaultInventoryKey ? "Default" : Path.GetFileNameWithoutExtension(fileName);
            AddTreeElement(tnc, name, inv.BuildParameters, false, inv, fileName);

            tnc = treeViewInventory.Nodes[0].Nodes["LibraryCategories"];
            foreach (LibraryCategory p in inv.LibraryCategories)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.LibraryCategories, fileName);
            }
            tnc = treeViewInventory.Nodes[0].Nodes["Assemblies"];
            foreach (MFAssembly p in inv.Assemblies)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.Assemblies, fileName);
            }

            /*
            tnc = treeViewInventory.Nodes[0].Nodes["BSPs"];
            foreach (BSP p in inv.BSPs)
            {
                AddTreeElement(tnc, p.Name, p, false, inv.BSPs, fileName);
            }
            */

            treeViewInventory.Sort();
        }