private void wpChooseFeatures_ShowFromNext(object sender, EventArgs e) { //Populate feature selection menu with features from the Inventory.xml if (!m_worker.IsBusy) { if (tv_FeatureView.Nodes.Count == 0) { Wiz.NextEnabled = false; Wiz.BackEnabled = false; cbProjectSelect_Feature.Enabled = false; this.UseWaitCursor = true; rtb_FeatureDescription.Text = Properties.Resources.LoadingFeatures; m_worker.RunWorkerAsync(BackgroundWorkerType.LoadFeatures); } else { cbProjectSelect_Feature.Items.Clear(); foreach (MFProject proj in m_solution.Projects) { if (proj.IsClrProject && proj.Guid != m_allProjectsGuid) { ProjectComboData pcd = new ProjectComboData(proj.Name, proj); cbProjectSelect_Feature.Items.Add(pcd); } } cbProjectSelect_Feature.SelectedItem = cbProjectSelect_Feature.Items[0]; } } }
private void tv_LibraryView_AfterCheck(object sender, TreeViewEventArgs e) { MFComponent ctn = e.Node.Tag as MFComponent; ProjectComboData pcd = cbProjectSelect_Library.SelectedItem as ProjectComboData; if (ctn != null && ctn.ComponentType == MFComponentType.Library) { if (e.Node.Parent != null && e.Node.Checked) { foreach (TreeNode sib in e.Node.Parent.Nodes) { if (sib != e.Node) { MFComponent ctnSib = sib.Tag as MFComponent; if (sib.Checked && string.IsNullOrEmpty(ctnSib.Conditional)) { sib.Checked = false; } } } } ApplyToAllProjects(pcd, ctn, e.Node.Checked); if (e.Node.Checked && e.Node.Parent != null) { e.Node.Parent.Checked = true; } } // // Checking the root node will cause all "Generate Template" nodes to be checked. // if (e.Node.Parent == null) { foreach (TreeNode child in e.Node.Nodes) { foreach (TreeNode sib in child.Nodes) { MFComponent ctnSib = sib.Tag as MFComponent; if (ctnSib.Name == c_GenerateTemplateString) { if (sib.Checked != e.Node.Checked) { sib.Checked = e.Node.Checked; ctn = sib.Tag as MFComponent; ApplyToAllProjects(pcd, ctn, e.Node.Checked); } } } } } }
private void cbLibraryCond_SelectedIndexCommitted(object sender, EventArgs e) { if (tv_LibraryView.SelectedNode == null) { return; } string cond = cbLibraryCond.Text; if (cbLibraryCond.SelectedIndex != -1) { cond = ConvertConditionIndexToString((ConditionIndex)cbLibraryCond.SelectedIndex); } MFComponent tnd = tv_LibraryView.SelectedNode.Tag as MFComponent; if (tnd != null) { tnd.Conditional = cond; if (cbProjectSelect_Library.SelectedItem == m_pcdAll) { foreach (ProjectComboData pcd in cbProjectSelect_Library.Items) { if (pcd == m_pcdAll) { continue; } int idx = pcd.Proj.Libraries.IndexOf(tnd); if (idx >= 0) { pcd.Proj.Libraries[idx].Conditional = cond; } } } else { ProjectComboData pcd = cbProjectSelect_Library.SelectedItem as ProjectComboData; if (pcd != null) { int idx = pcd.Proj.Libraries.IndexOf(tnd); if (idx >= 0) { pcd.Proj.Libraries[idx].Conditional = cond; } } } } }
private void LoadProjectFeatureData() { cbProjectSelect_Feature.Items.Clear(); cbProjectSelect_Feature.ValueMember = "DisplayName"; foreach (MFProject proj in m_solution.Projects) { if (proj.IsClrProject && proj.Guid != m_allProjectsGuid) { ProjectComboData pcd = new ProjectComboData(proj.Name, proj); cbProjectSelect_Feature.Items.Add(pcd); } } cbProjectSelect_Feature.Invalidate(); }
private void UpdateProjectDependencies(ProjectComboData pcd, List <LibraryCategory> unresolvedItems, List <LibraryCategory> removedItems) { bool fReanalyze = true; int retries = 20; List <TreeNode> nodeList = new List <TreeNode>(); Dictionary <string, MFComponent> resolveMap = new Dictionary <string, MFComponent>(); while (fReanalyze && retries-- > 0) { unresolvedItems.Clear(); removedItems.Clear(); //LoadProjectLibraryData(pcd, m_pcdAll, true); pcd.Proj.AnalyzeLibraries(m_helper, m_solution, unresolvedItems, removedItems); fReanalyze = (removedItems.Count > 0); foreach (LibraryCategory lc in unresolvedItems) { if (!resolveMap.ContainsKey(lc.Guid)) { AddGenerateTemplateNode(pcd, lc); Library sel = AutoSelectLibrary(pcd, lc); if (sel != null) { fReanalyze = true; MFComponent cmpNew = new MFComponent(MFComponentType.Library, sel.Name, sel.Guid, sel.ProjectPath); resolveMap[lc.Guid] = cmpNew; ApplyToProject(pcd, cmpNew, true, unresolvedItems, removedItems); } } else { ApplyToProject(pcd, resolveMap[lc.Guid], true, unresolvedItems, removedItems); } } } }
private void cbProjectSelect_SelectedIndexChanged(object sender, EventArgs e) { ProjectComboData pcd = cbProjectSelect_Feature.SelectedItem as ProjectComboData; if (pcd == null) { return; } TreeNode root = tv_FeatureView.Nodes[0]; pcd.Proj.AnalyzeFeatures(m_helper); UpdateFeatureSelections(pcd); root.Expand(); //expand tree to display all nodes tv_FeatureView.Sort(); tv_FeatureView.SelectedNode = root; }
private void UpdateFeatureSelections(ProjectComboData pcd) { TreeNode root = tv_FeatureView.Nodes[0]; Dictionary <string, MFComponent> featList = new Dictionary <string, MFComponent>(); foreach (MFComponent cmp in pcd.Proj.Features) { featList[cmp.Guid.ToLower()] = cmp; } Dictionary <TreeNode, bool> nodesToUpdate = new Dictionary <TreeNode, bool>(); foreach (TreeNode tn in root.Nodes) { if (tn != null) { MFComponent c = tn.Tag as MFComponent; if (featList.ContainsKey(c.Guid.ToLower())) { if (!tn.Checked) { nodesToUpdate[tn] = true; } } else { if (tn.Checked) { nodesToUpdate[tn] = false; } } } } System.Threading.Interlocked.Increment(ref m_CheckRefCount); foreach (TreeNode tn in nodesToUpdate.Keys) { tn.Checked = nodesToUpdate[tn]; } System.Threading.Interlocked.Decrement(ref m_CheckRefCount); }
/// <summary> /// Apply user "check/uncheck" to all project nodes if "All Projects" is selected, otherwise /// just to the selected project. /// </summary> /// <param name="pcdAll"></param> /// <param name="compGuid"></param> /// <param name="fAdd"></param> private void ApplyToAllProjects(ProjectComboData pcd, MFComponent comp, bool fCheck) { ApplyToProject(pcd, comp, fCheck, null, null); if (pcd == m_pcdAll) { foreach (ProjectComboData pcd2 in cbProjectSelect_Library.Items) { if (pcd2 != pcd) { // change the component to a bootloader component if it exists if (pcd2.Proj.IsBootloaderProject()) { Library lib = m_helper.FindLibrary(comp); if (lib != null && lib.HasLibraryCategory) { LibraryCategory lc = m_helper.FindLibraryCategory(lib.LibraryCategory.Guid); if (lc != null) { foreach (Library li in m_helper.GetLibrariesOfType(lc)) { if (li.IsBootloaderLibrary()) { comp = new MFComponent(MFComponentType.Library, li.Name, li.Guid, li.ProjectPath, comp.Conditional); break; } } } } } ApplyToProject(pcd2, comp, fCheck, null, null); } } } else if (pcd.Name.ToLower() == "tinyclr") { ApplyToProject(m_pcdAll, comp, fCheck, null, null); } }
/// <summary> /// Adds a "Generate Template" node to the library category node if supported /// </summary> /// <param name="pcd"></param> /// <param name="lc"></param> private Library AddGenerateTemplateNode(ProjectComboData pcd, LibraryCategory lc) { // There are no CLR or Support libraries that can be overriden if (lc.Level != LibraryLevel.CLR && (lc.Templates.Count > 0)) { Library lib = null; string key = lc.Guid.ToLower(); // Since each project may have its own set of libraries (and generate template nodes) // we need to synchronize the component guids for like categories if (m_lcGuidToGenGuid.ContainsKey(key)) { lib = m_lcGuidToGenGuid[key]; } else { lib = new Library(); lib.Name = c_GenerateTemplateString; lib.Level = lc.Level; lib.Description = "Generates template code in your solution's DeviceCode directory for the given Library Category." + "The project will be generated in Solutions\\" + m_solution.Name + "\\DeviceCode\\" + lc.Name; lib.LibraryCategory = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath); m_lcGuidToGenGuid[key] = lib; } lib.ProjectPath = m_spoClientPath + "\\Solutions\\" + m_solution.Name + "\\DeviceCode\\" + lc.Name + "\\dotnetmf.proj"; // add the library to the inventory if (null == m_helper.FindLibrary(lib.Guid)) { m_helper.AddLibraryToInventory(lib, false, m_inv); } return(lib); } return(null); }
private Library AutoSelectLibrary(ProjectComboData pcd, LibraryCategory lc) { Library defaultLib = null; Library stubLib = null; Library bootLoaderLib = null; Library generateLib = null; Library clrLib = null; bool fTooManyLibs = false; MFProject proj = pcd.Proj; FeatureAssociation fa = GetFeatureAssociation(lc); foreach (Library lib in m_helper.GetLibrariesOfType(lc)) { if (proj.ValidateLibrary(lib, m_solution, m_solutionProc, m_helper)) { if (m_pcdAll.Proj.Libraries.Contains(new MFComponent(MFComponentType.Library, lib.Name, lib.Guid))) { clrLib = lib; } if (lib.IsStub) { stubLib = lib; } else if (lib.IsBootloaderLibrary()) { bootLoaderLib = lib; } else if (lib.Name == c_GenerateTemplateString) { generateLib = lib; } else if (defaultLib == null) { defaultLib = lib; } else if (fa != FeatureAssociation.NotSelected) { // there are now too many libraries for us to choose from // so we can not auto-select unless this is a cloned solution // in which case we will look for common libraries. fTooManyLibs = true; } } } // if the solution is cloned then lets try to choose common libraries where possible if (m_solution.m_cloneSolution != null) { MFProject cloneProj = null; // for "all projects" choose the TinyCLR project bool fAllProj = (0 == string.Compare(proj.Name, Properties.Resources.AllProjects, true)); // match libraries from the given project foreach (MFProject prj in m_solution.m_cloneSolution.Projects) { if (fAllProj) { if (prj.IsClrProject) { cloneProj = prj; break; } } else if (0 == string.Compare(prj.Name, proj.Name, true)) { cloneProj = prj; break; } } // Only match libraries from common projects if (cloneProj != null) { // search the cloned solution for the common library category foreach (MFComponent cloneLib in cloneProj.Libraries) { Library cl = m_helper.FindLibrary(cloneLib); if (cl == null && m_solution.m_clonedLibraryMap.ContainsKey(cloneLib.Guid.ToUpper())) { cl = m_solution.m_clonedLibraryMap[cloneLib.Guid.ToUpper()]; } if (cl != null) { if (cl.HasLibraryCategory && (0 == string.Compare(lc.Guid, cl.LibraryCategory.Guid, true))) { // if the library is a solution dependent library, then choose to generate it (which will // at a later stage copy the code from the clone solution). if (cl.ProjectPath.ToLower().Contains("\\solutions\\" + m_solution.m_cloneSolution.Name.ToLower() + "\\")) { if (generateLib == null) { // it is possible that we haven't created the "Generate Template" library yet. generateLib = AddGenerateTemplateNode(pcd, lc); } if (fa == FeatureAssociation.Selected || fa == FeatureAssociation.None) { return(generateLib); } else { defaultLib = generateLib; } } /// /// if the associated feature is not selected than use the cloned projects selection /// as the default /// else if (fa != FeatureAssociation.Selected) { defaultLib = cl; } /// /// If the feature is selected use the cloned projects selection if it is not a stub /// else if (!cl.IsStub) { return(cl); } break; } } } } } switch (fa) { case FeatureAssociation.Selected: if (proj.IsBootloaderProject()) { if (bootLoaderLib != null) { return(bootLoaderLib); } else if (lc.IsTransport && m_solution.m_transportType.Equals(lc)) { if (!fTooManyLibs) { return(defaultLib); } } else if (stubLib != null) { return(stubLib); } else if (!fTooManyLibs && defaultLib != null && (generateLib == null || !string.IsNullOrEmpty(defaultLib.CustomFilter) || !string.IsNullOrEmpty(defaultLib.ProcessorSpecific.Guid))) { return(defaultLib); } } else { if (!fTooManyLibs && defaultLib != null) { return(defaultLib); } else if (clrLib != null) { return(clrLib); } } break; case FeatureAssociation.NotSelected: if (!lc.IsTransport || !m_solution.m_transportType.Equals(lc)) { return(stubLib); } break; case FeatureAssociation.None: // if we don't have a stub library then we should be able to select the appropriate library // automatically if (proj.IsBootloaderProject()) { if (bootLoaderLib != null) { return(bootLoaderLib); } else if (stubLib != null) { return(stubLib); } else if (!fTooManyLibs) { return(defaultLib); } } else if (!fTooManyLibs && defaultLib != null && ((stubLib == null && generateLib == null) || !string.IsNullOrEmpty(defaultLib.CustomFilter) || !string.IsNullOrEmpty(defaultLib.ProcessorSpecific.Guid))) { return(defaultLib); } else if (clrLib != null) { return(clrLib); } break; } return(null); }
private void ApplyToProject(ProjectComboData pcd, MFComponent comp, bool fCheck, List <LibraryCategory> unresolvedItems, List <LibraryCategory> removedItems) { bool fActiveProj = (cbProjectSelect_Library.SelectedItem == pcd); bool fContainsLib = pcd.Proj.Libraries.Contains(comp); if (fCheck) { if (fContainsLib && pcd != m_pcdAll) { return; } pcd.Proj.Libraries.Add(comp); } else { if (!fContainsLib && pcd != m_pcdAll) { return; } pcd.Proj.RemoveLibrary(comp); } if (unresolvedItems == null || removedItems == null) { unresolvedItems = new List <LibraryCategory>(); removedItems = new List <LibraryCategory>(); pcd.Proj.AnalyzeLibraries(m_helper, m_solution, unresolvedItems, removedItems); } if (fActiveProj && tv_LibraryView.Nodes.Count > 0) { if (fCheck) { foreach (LibraryCategory lc in unresolvedItems) { if (tv_LibraryView.Nodes.Find(lc.Guid.ToLower(), true).Length == 0) { AddGenerateTemplateNode(pcd, lc); Library sel = AutoSelectLibrary(pcd, lc); TreeNode lcNode = tv_LibraryView.Nodes[0].Nodes.Add(lc.Guid.ToLower(), lc.Name); lcNode.Tag = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath); foreach (Library lib in m_helper.GetLibrariesOfType(lc, pcd.Proj, m_solution)) { if (pcd.Proj.ValidateLibrary(lib, m_solution, m_solutionProc, m_helper)) { TreeNode tnLib = lcNode.Nodes.Add(lib.Guid.ToLower(), lib.Name); tnLib.Tag = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, lib.ProjectPath); if (sel == lib) { tnLib.Checked = true; } } } lcNode.Expand(); } } } else { foreach (LibraryCategory lc in removedItems) { TreeNode[] nds = tv_LibraryView.Nodes.Find(lc.Guid.ToLower(), true); if (nds.Length > 0) { nds[0].Remove(); } } } } }
/// <summary> /// Only call this method from initialization, it will repopulate all project library nodes and /// undo any user selections of libraries. /// </summary> private void LoadAllProjectLibraryData() { cbProjectSelect_Library.Items.Clear(); cbProjectSelect_Library.ValueMember = "DisplayName"; m_pcdAll = new ProjectComboData(m_solution.Projects[0].Name, m_solution.Projects[0]); m_pcdAll.Proj.Features.Clear(); m_pcdAll.Proj.Libraries.Clear(); m_pcdAll.Proj.LibraryCategories.Clear(); m_pcdAll.Proj.IsClrProject = true; cbProjectSelect_Library.Items.Add(m_pcdAll); ProjectComboData pcdDef = null; foreach (MFProject proj in m_solution.Projects) { if (proj.Guid == m_allProjectsGuid) { continue; } ProjectComboData pcd = new ProjectComboData(proj.Name, proj); // always have the clr 2nd after "All Projects" if (0 == string.Compare(proj.Name, "tinyclr", true)) { cbProjectSelect_Library.Items.Insert(1, pcd); pcdDef = pcd; } else { if (pcdDef == null) { pcdDef = pcd; } cbProjectSelect_Library.Items.Add(pcd); } } if (pcdDef != null) { m_pcdAll.Proj.Features.AddRange(pcdDef.Proj.Features); m_pcdAll.Proj.Libraries.AddRange(pcdDef.Proj.Libraries); m_pcdAll.Proj.LibraryCategories.AddRange(pcdDef.Proj.LibraryCategories); m_pcdAll.Proj.m_cloneProj = pcdDef.Proj.m_cloneProj; } ProjectComboData pcdSelect = null; foreach (ProjectComboData pcd in cbProjectSelect_Library.Items) { List <LibraryCategory> unresolvedItems = new List <LibraryCategory>(); List <LibraryCategory> removedItems = new List <LibraryCategory>(); UpdateProjectDependencies(pcd, unresolvedItems, removedItems); if (unresolvedItems.Count > 0 && (pcdSelect == null || pcd == pcdDef)) { pcdSelect = pcd; } } if (pcdSelect != null && pcdSelect != pcdDef) { cbProjectSelect_Library.SelectedItem = pcdSelect; } }
private Library AutoSelectLibrary(ProjectComboData pcd, LibraryCategory lc) { Library defaultLib = null; Library stubLib = null; Library bootLoaderLib = null; Library generateLib = null; Library clrLib = null; bool fTooManyLibs = false; MFProject proj = pcd.Proj; FeatureAssociation fa = GetFeatureAssociation(lc); foreach (Library lib in m_helper.GetLibrariesOfType(lc)) { if (proj.ValidateLibrary(lib, m_solution, m_solutionProc, m_helper)) { if (m_pcdAll.Proj.Libraries.Contains(new MFComponent(MFComponentType.Library, lib.Name, lib.Guid))) clrLib = lib; if (lib.IsStub) stubLib = lib; else if (lib.IsBootloaderLibrary()) bootLoaderLib = lib; else if (lib.Name == c_GenerateTemplateString) generateLib = lib; else if (defaultLib == null) { defaultLib = lib; } else if (fa != FeatureAssociation.NotSelected) { // there are now too many libraries for us to choose from // so we can not auto-select unless this is a cloned solution // in which case we will look for common libraries. fTooManyLibs = true; } } } // if the solution is cloned then lets try to choose common libraries where possible if (m_solution.m_cloneSolution != null) { MFProject cloneProj = null; // for "all projects" choose the TinyCLR project bool fAllProj = (0 == string.Compare(proj.Name, Properties.Resources.AllProjects, true)); // match libraries from the given project foreach(MFProject prj in m_solution.m_cloneSolution.Projects) { if (fAllProj) { if (prj.IsClrProject) { cloneProj = prj; break; } } else if(0 == string.Compare(prj.Name, proj.Name , true)) { cloneProj = prj; break; } } // Only match libraries from common projects if (cloneProj != null) { // search the cloned solution for the common library category foreach (MFComponent cloneLib in cloneProj.Libraries) { Library cl = m_helper.FindLibrary(cloneLib); if (cl == null && m_solution.m_clonedLibraryMap.ContainsKey(cloneLib.Guid.ToUpper())) { cl = m_solution.m_clonedLibraryMap[cloneLib.Guid.ToUpper()]; } if (cl != null) { if (cl.HasLibraryCategory && (0 == string.Compare(lc.Guid, cl.LibraryCategory.Guid, true))) { // if the library is a solution dependent library, then choose to generate it (which will // at a later stage copy the code from the clone solution). if (cl.ProjectPath.ToLower().Contains("\\solutions\\" + m_solution.m_cloneSolution.Name.ToLower() + "\\")) { if (generateLib == null) { // it is possible that we haven't created the "Generate Template" library yet. generateLib = AddGenerateTemplateNode(pcd, lc); } if (fa == FeatureAssociation.Selected || fa == FeatureAssociation.None) { return generateLib; } else { defaultLib = generateLib; } } /// /// if the associated feature is not selected than use the cloned projects selection /// as the default /// else if (fa != FeatureAssociation.Selected) { defaultLib = cl; } /// /// If the feature is selected use the cloned projects selection if it is not a stub /// else if(!cl.IsStub) { return cl; } break; } } } } } switch (fa) { case FeatureAssociation.Selected: if (proj.IsBootloaderProject()) { if (bootLoaderLib != null) { return bootLoaderLib; } else if (lc.IsTransport && m_solution.m_transportType.Equals(lc)) { if (!fTooManyLibs) { return defaultLib; } } else if (stubLib != null) { return stubLib; } else if (!fTooManyLibs && defaultLib != null && (generateLib == null || !string.IsNullOrEmpty(defaultLib.CustomFilter) || !string.IsNullOrEmpty(defaultLib.ProcessorSpecific.Guid))) { return defaultLib; } } else { if (!fTooManyLibs && defaultLib != null) { return defaultLib; } else if (clrLib != null) { return clrLib; } } break; case FeatureAssociation.NotSelected: if (!lc.IsTransport || !m_solution.m_transportType.Equals(lc)) { return stubLib; } break; case FeatureAssociation.None: // if we don't have a stub library then we should be able to select the appropriate library // automatically if (proj.IsBootloaderProject()) { if (bootLoaderLib != null) { return bootLoaderLib; } else if (stubLib != null) { return stubLib; } else if (!fTooManyLibs) { return defaultLib; } } else if (!fTooManyLibs && defaultLib != null && ((stubLib == null && generateLib == null) || !string.IsNullOrEmpty(defaultLib.CustomFilter) || !string.IsNullOrEmpty(defaultLib.ProcessorSpecific.Guid))) { return defaultLib; } else if (clrLib != null) { return clrLib; } break; } return null; }
private void UpdateFeatureSelections(ProjectComboData pcd) { TreeNode root = tv_FeatureView.Nodes[0]; Dictionary<string, MFComponent> featList = new Dictionary<string, MFComponent>(); foreach (MFComponent cmp in pcd.Proj.Features) { featList[cmp.Guid.ToLower()] = cmp; } Dictionary<TreeNode,bool> nodesToUpdate = new Dictionary<TreeNode, bool>(); foreach (TreeNode tn in root.Nodes) { if (tn != null) { MFComponent c = tn.Tag as MFComponent; if (featList.ContainsKey(c.Guid.ToLower())) { if (!tn.Checked) { nodesToUpdate[tn] = true; } } else { if (tn.Checked) { nodesToUpdate[tn] = false; } } } } System.Threading.Interlocked.Increment(ref m_CheckRefCount); foreach (TreeNode tn in nodesToUpdate.Keys) { tn.Checked = nodesToUpdate[tn]; } System.Threading.Interlocked.Decrement(ref m_CheckRefCount); }
/// <summary> /// Apply user "check/uncheck" to all project nodes if "All Projects" is selected, otherwise /// just to the selected project. /// </summary> /// <param name="pcdAll"></param> /// <param name="compGuid"></param> /// <param name="fAdd"></param> private void ApplyToAllProjects(ProjectComboData pcd, MFComponent comp, bool fCheck) { ApplyToProject(pcd, comp, fCheck, null, null); if (pcd == m_pcdAll) { foreach (ProjectComboData pcd2 in cbProjectSelect_Library.Items) { if (pcd2 != pcd) { // change the component to a bootloader component if it exists if (pcd2.Proj.IsBootloaderProject()) { Library lib = m_helper.FindLibrary(comp); if (lib != null && lib.HasLibraryCategory) { LibraryCategory lc = m_helper.FindLibraryCategory(lib.LibraryCategory.Guid); if (lc != null) { foreach (Library li in m_helper.GetLibrariesOfType(lc)) { if (li.IsBootloaderLibrary()) { comp = new MFComponent(MFComponentType.Library, li.Name, li.Guid, li.ProjectPath, comp.Conditional); break; } } } } } ApplyToProject(pcd2, comp, fCheck, null, null); } } } else if(pcd.Name.ToLower() == "tinyclr") { ApplyToProject(m_pcdAll, comp, fCheck, null, null); } }
private void ShowLibraryCategories(bool showAll, bool noFilter) { ProjectComboData pcd = null; if (cbProjectSelect_Library.SelectedItem == null) { if (cbProjectSelect_Library.Items.Count > 0) { pcd = cbProjectSelect_Library.Items[0] as ProjectComboData; } } else { pcd = cbProjectSelect_Library.SelectedItem as ProjectComboData; } if (pcd == null || pcd.Proj == null) { return; } tv_LibraryView.Nodes.Clear(); TreeNode root = new TreeNode(Properties.Resources.LibraryCategories); List <LibraryCategory> unresolvedItems = new List <LibraryCategory>(); List <LibraryCategory> removedItems = new List <LibraryCategory>(); UpdateProjectDependencies(pcd, unresolvedItems, removedItems); if (showAll) { foreach (MFComponent lcCmp in pcd.Proj.LibraryCategories) { LibraryCategory lc = m_helper.FindLibraryCategory(lcCmp.Guid); if (!unresolvedItems.Contains(lc)) { unresolvedItems.Add(lc); } } } /// /// Show all generated code /// foreach (MFComponent lCmp in pcd.Proj.Libraries) { if (lCmp.Name == c_GenerateTemplateString) { Library lib = m_helper.FindLibrary(lCmp); if (lib != null && lib.HasLibraryCategory) { unresolvedItems.Add(m_helper.FindLibraryCategory(lib.LibraryCategory.Guid)); } } } Dictionary <string, TreeNode> libLookup = new Dictionary <string, TreeNode>(); foreach (LibraryCategory lc in removedItems) { TreeNode [] nds = root.Nodes.Find(lc.Guid.ToLower(), false); if (nds.Length > 0) { nds[0].Remove(); } } foreach (LibraryCategory lc in unresolvedItems) { TreeNode lcNode = new TreeNode(lc.Name); lcNode.Name = lc.Guid.ToLower(); lcNode.Tag = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath); root.Nodes.Add(lcNode); AddGenerateTemplateNode(pcd, lc); foreach (Library lib in m_helper.GetLibrariesOfType(lc, pcd.Proj, m_solution)) { if (pcd.Proj.ValidateLibrary(lib, m_solution, m_solutionProc, m_helper)) { TreeNode tnLib = lcNode.Nodes.Add(lib.Guid.ToLower(), lib.Name); tnLib.Tag = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, lib.ProjectPath); libLookup[lib.Guid.ToLower()] = tnLib; } } } foreach (MFComponent cmp in pcd.Proj.Libraries) { if (libLookup.ContainsKey(cmp.Guid.ToLower())) { libLookup[cmp.Guid.ToLower()].Checked = true; (libLookup[cmp.Guid.ToLower()].Tag as MFComponent).Conditional = cmp.Conditional; } } if (root.Nodes.Count == 0) { root.Nodes.Add(Properties.Resources.NoUnresolvedLibCats); } tv_LibraryView.Nodes.Add(root); tv_LibraryView.Sort(); root.ExpandAll(); tv_LibraryView.SelectedNode = root; }
private void UpdateProjectDependencies(ProjectComboData pcd, List<LibraryCategory> unresolvedItems, List<LibraryCategory> removedItems) { bool fReanalyze = true; int retries = 20; List<TreeNode> nodeList = new List<TreeNode>(); Dictionary<string, MFComponent> resolveMap = new Dictionary<string, MFComponent>(); while (fReanalyze && retries-- > 0) { unresolvedItems.Clear(); removedItems.Clear(); //LoadProjectLibraryData(pcd, m_pcdAll, true); pcd.Proj.AnalyzeLibraries(m_helper, m_solution, unresolvedItems, removedItems); fReanalyze = (removedItems.Count > 0); foreach (LibraryCategory lc in unresolvedItems) { if (!resolveMap.ContainsKey(lc.Guid)) { AddGenerateTemplateNode(pcd, lc); Library sel = AutoSelectLibrary(pcd, lc); if (sel != null) { fReanalyze = true; MFComponent cmpNew = new MFComponent(MFComponentType.Library, sel.Name, sel.Guid, sel.ProjectPath); resolveMap[lc.Guid] = cmpNew; ApplyToProject(pcd, cmpNew, true, unresolvedItems, removedItems); } } else { ApplyToProject(pcd, resolveMap[lc.Guid], true, unresolvedItems, removedItems); } } } }
private void tv_FeatureView_AfterCheck(object sender, TreeViewEventArgs e) { ProjectComboData pcd = cbProjectSelect_Feature.SelectedItem as ProjectComboData; MFComponent feat = e.Node.Tag as MFComponent; TreeNode root = tv_FeatureView.Nodes[0]; if (feat != null) { List <TreeNode> updateNodes = new List <TreeNode>(); if (e.Node == root) { foreach (TreeNode tn in root.Nodes) { updateNodes.Add(tn); } } else { updateNodes.Add(e.Node); } foreach (TreeNode tn in updateNodes) { if (tn.Checked != e.Node.Checked || tn == e.Node) { if (tn.Checked != e.Node.Checked) { tn.Checked = e.Node.Checked; } if (pcd != null) { if (e.Node.Checked) { pcd.Proj.Features.Add(new MFComponent(MFComponentType.Feature, feat.Name, feat.Guid, feat.ProjectPath)); } else { Feature f = m_helper.FindFeature(feat.Guid); Dictionary <string, MFComponent> dependants = f.GetDependants(m_helper); dependants[feat.Guid.ToLower()] = feat; List <MFComponent> remFeatures = new List <MFComponent>(); foreach (MFComponent fCmp in pcd.Proj.Features) { if (dependants.ContainsKey(fCmp.Guid.ToLower())) { remFeatures.Add(fCmp); } } foreach (MFComponent cmpFeat in remFeatures) { pcd.Proj.Features.Remove(cmpFeat); } } } } } if (m_CheckRefCount == 0) { pcd.Proj.AnalyzeFeatures(m_helper); System.Threading.Interlocked.Increment(ref m_CheckRefCount); UpdateFeatureSelections(pcd); System.Threading.Interlocked.Decrement(ref m_CheckRefCount); } return; } }
/// <summary> /// Only call this method from initialization, it will repopulate all project library nodes and /// undo any user selections of libraries. /// </summary> private void LoadAllProjectLibraryData() { cbProjectSelect_Library.Items.Clear(); cbProjectSelect_Library.ValueMember = "DisplayName"; m_pcdAll = new ProjectComboData(m_solution.Projects[0].Name, m_solution.Projects[0]); m_pcdAll.Proj.Features.Clear(); m_pcdAll.Proj.Libraries.Clear(); m_pcdAll.Proj.LibraryCategories.Clear(); m_pcdAll.Proj.IsClrProject = true; cbProjectSelect_Library.Items.Add(m_pcdAll); ProjectComboData pcdDef = null; foreach (MFProject proj in m_solution.Projects) { if (proj.Guid == m_allProjectsGuid) continue; ProjectComboData pcd = new ProjectComboData(proj.Name, proj); // always have the clr 2nd after "All Projects" if (0 == string.Compare(proj.Name, "tinyclr", true)) { cbProjectSelect_Library.Items.Insert(1, pcd); pcdDef = pcd; } else { if (pcdDef == null) pcdDef = pcd; cbProjectSelect_Library.Items.Add(pcd); } } if (pcdDef != null) { m_pcdAll.Proj.Features.AddRange(pcdDef.Proj.Features); m_pcdAll.Proj.Libraries.AddRange(pcdDef.Proj.Libraries); m_pcdAll.Proj.LibraryCategories.AddRange(pcdDef.Proj.LibraryCategories); m_pcdAll.Proj.m_cloneProj = pcdDef.Proj.m_cloneProj; } ProjectComboData pcdSelect = null; foreach (ProjectComboData pcd in cbProjectSelect_Library.Items) { List<LibraryCategory> unresolvedItems = new List<LibraryCategory>(); List<LibraryCategory> removedItems = new List<LibraryCategory>(); UpdateProjectDependencies(pcd, unresolvedItems, removedItems); if (unresolvedItems.Count > 0 && (pcdSelect == null || pcd == pcdDef)) { pcdSelect = pcd; } } if (pcdSelect != null && pcdSelect != pcdDef) { cbProjectSelect_Library.SelectedItem = pcdSelect; } }
/// <summary> /// Adds a "Generate Template" node to the library category node if supported /// </summary> /// <param name="pcd"></param> /// <param name="lc"></param> private Library AddGenerateTemplateNode(ProjectComboData pcd, LibraryCategory lc) { // There are no CLR or Support libraries that can be overriden if (lc.Level != LibraryLevel.CLR && (lc.Templates.Count > 0)) { Library lib = null; string key = lc.Guid.ToLower(); // Since each project may have its own set of libraries (and generate template nodes) // we need to synchronize the component guids for like categories if (m_lcGuidToGenGuid.ContainsKey(key)) { lib = m_lcGuidToGenGuid[key]; } else { lib = new Library(); lib.Name = c_GenerateTemplateString; lib.Level = lc.Level; lib.Description = "Generates template code in your solution's DeviceCode directory for the given Library Category." + "The project will be generated in Solutions\\" + m_solution.Name + "\\DeviceCode\\" + lc.Name; lib.LibraryCategory = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath); m_lcGuidToGenGuid[key] = lib; } lib.ProjectPath = m_spoClientPath + "\\Solutions\\" + m_solution.Name + "\\DeviceCode\\" + lc.Name + "\\dotnetmf.proj"; // add the library to the inventory if (null == m_helper.FindLibrary(lib.Guid)) { m_helper.AddLibraryToInventory(lib, false, m_inv); } return lib; } return null; }
private void ApplyToProject(ProjectComboData pcd, MFComponent comp, bool fCheck, List<LibraryCategory> unresolvedItems, List<LibraryCategory>removedItems) { bool fActiveProj = (cbProjectSelect_Library.SelectedItem == pcd); bool fContainsLib = pcd.Proj.Libraries.Contains(comp); if (fCheck) { if (fContainsLib && pcd != m_pcdAll) return; pcd.Proj.Libraries.Add(comp); } else { if (!fContainsLib && pcd != m_pcdAll) return; pcd.Proj.RemoveLibrary(comp); } if (unresolvedItems == null || removedItems == null) { unresolvedItems = new List<LibraryCategory>(); removedItems = new List<LibraryCategory>(); pcd.Proj.AnalyzeLibraries(m_helper, m_solution, unresolvedItems, removedItems); } if (fActiveProj && tv_LibraryView.Nodes.Count > 0) { if (fCheck) { foreach (LibraryCategory lc in unresolvedItems) { if (tv_LibraryView.Nodes.Find(lc.Guid.ToLower(), true).Length == 0) { AddGenerateTemplateNode(pcd, lc); Library sel = AutoSelectLibrary(pcd, lc); TreeNode lcNode = tv_LibraryView.Nodes[0].Nodes.Add(lc.Guid.ToLower(), lc.Name); lcNode.Tag = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath); foreach (Library lib in m_helper.GetLibrariesOfType(lc, pcd.Proj, m_solution)) { if (pcd.Proj.ValidateLibrary(lib, m_solution, m_solutionProc, m_helper)) { TreeNode tnLib = lcNode.Nodes.Add(lib.Guid.ToLower(), lib.Name); tnLib.Tag = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, lib.ProjectPath); if (sel == lib) { tnLib.Checked = true; } } } lcNode.Expand(); } } } else { foreach (LibraryCategory lc in removedItems) { TreeNode[] nds = tv_LibraryView.Nodes.Find(lc.Guid.ToLower(), true); if (nds.Length > 0) { nds[0].Remove(); } } } } }