internal bool SaveLibraryCategoryProj(LibraryCategory libCat) { string fullpath = ExpandEnvVars(libCat.ProjectPath, ""); Project proj = LoadProject(fullpath); proj.ProjectCollection.UnloadProject(proj); proj = new Project(); proj.Xml.DefaultTargets = "Build"; bool fRet = false; try { if (string.IsNullOrEmpty(fullpath)) { fullpath = Path.Combine(Environment.GetEnvironmentVariable("SPOCLIENT"), @"framework\features\" + libCat.Name + ".libcatproj"); } if (libCat.LibraryProjCache.Count > 0) { ProjectItemGroupElement big = proj.Xml.AddItemGroup(); foreach (string libRef in libCat.LibraryProjCache) { big.AddItem("LibraryCollection", libRef); } } List<string> save = libCat.LibraryProjCache; libCat.LibraryProjCache = null; ProjectPropertyGroupElement bpg = proj.Xml.AddPropertyGroup(); bpg.AddProperty(PKUI_LibCatTag, SerializeXml(libCat)); libCat.LibraryProjCache = save; proj.Save(fullpath); fRet = true; } catch( Exception e ) { System.Diagnostics.Debug.WriteLine("Error: failure saving LibCat file: " + fullpath + "\r\n", e.Message); } return fRet; }
public Library[] GetLibrariesOfType(LibraryCategory LibraryCategory, MFProject proj, MFSolution solution) { List<Library> ret = new List<Library>(); foreach (Inventory inv in m_invs) { foreach (Library lib in inv.Libraries) { if (lib.LibraryCategory != null) { if (string.IsNullOrEmpty(lib.LibraryCategory.Guid)) continue; if (0 == string.Compare(lib.LibraryCategory.Guid, LibraryCategory.Guid, true)) { ret.Add(lib); } } } } return ret.ToArray(); }
public MFComponentHash(Library lib, LibraryCategory type, MFComponent comp) { Library = lib; LibraryCategory = type; MFComponent = comp; }
// only to be called for LibraryCategories that are not dependencies of other libraries private bool ValidateLibraryCategory(LibraryCategory libc, Dictionary<string, MFComponent> selectedFeatures) { if (libc.Required) return true; if (libc.FeatureAssociations.Count > 0) { bool fOK = false; foreach (MFComponent feat in libc.FeatureAssociations) { if (selectedFeatures.ContainsKey(feat.Guid.ToLower())) { fOK = true; break; } } if (!fOK) return false; } return true; }
public Library[] GetLibrariesOfType(LibraryCategory LibraryCategory) { return GetLibrariesOfType(LibraryCategory, null, null); }
public LibraryCategoryWrapper CreateLibraryCategory(string name, string groups, LibraryLevelWrapper level) { LibraryCategory LibCat = new LibraryCategory(); LibCat.Name = name; LibCat.Groups = groups; LibCat.Level = (LibraryLevel)level; LibCat.ProjectPath = "$(SPOCLIENT)\\Framework\\Features\\" + LibCat.Name + ".libcatproj"; m_bw.SaveLibraryCategoryProj(LibCat); this.m_helper.DefaultInventory.LibraryCategories.Clear(); this.LoadDefaultLibraryCatigoriesAsync(); return BaseWrapper.Wrap<LibraryCategoryWrapper>(LibCat); }
private bool IsAssocFeatureChecked(LibraryCategory libCat, Dictionary<string, MFComponent> featureList) { bool isFeatureChecked = false; foreach (MFComponent feat in libCat.FeatureAssociations) { if (featureList.ContainsKey(feat.Guid.ToLower())) { isFeatureChecked = true; } } return isFeatureChecked; }
internal ComboBoxItem(LibraryCategory lc) { Name = lc.Name.ToUpper().Replace("_PAL", ""); _libCat = lc; }
public MFSolution() { this.m_cloneSolution = null; this.m_solRequiredLibCats = new Dictionary<string,MFComponent>(); this.m_clonedLibraryMap = new Dictionary<string, Library>(); this.descriptionField = ""; this.documentationField = ""; this.guidField = System.Guid.NewGuid().ToString("B"); this.nameField = ""; this.projectsField = new System.Collections.Generic.List<MFProject>(); this.versionField = new Version(); this.propertiesField = new System.Collections.Generic.List<MFProperty>(); this.isSolutionWizardVisibleField = true; this.authorField = ""; this.itemsField = new List<MFBuildFile>(); this.customFilterField = ""; this.m_transportType = null; this.ENDIANNESS = "le"; }
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 addLibraryCategoryToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode parent = treeViewInventory.Nodes[0].Nodes["LibraryCategories"]; LibraryCategory newLibType = new LibraryCategory(); newLibType.Guid = Guid.NewGuid().ToString("B").ToUpper(); TreeNode newNode = AddTreeElement(parent, "<New Library Type>", newLibType, true, DefaultInventory.LibraryCategories, c_defaultInventoryKey); DefaultInventory.LibraryCategories.Add(newLibType); treeViewInventory.SelectedNode = newNode; newNode.BeginEdit(); }
/// <summary> /// Get the feature association for a given library category. A feature association determines /// weather a category is associated with a feature and if the feature is selected by the user. /// </summary> /// <param name="lc"></param> /// <returns></returns> private FeatureAssociation GetFeatureAssociation(LibraryCategory lc) { // default to true if there are no assocations for this library category (so the user must choose the library) FeatureAssociation assoc = FeatureAssociation.None; foreach (MFComponent comp in lc.FeatureAssociations) { TreeNode []nodes = tv_FeatureView.Nodes.Find(comp.Guid.ToLower(), true); if (nodes.Length != 0) { if (nodes[0].Checked) { assoc = FeatureAssociation.Selected; break; } else { assoc = FeatureAssociation.NotSelected; } } else { Feature feat = m_helper.FindFeature(comp.Guid); if (feat != null) { if (m_pcdAll.Proj.ContainsFeature(comp)) { assoc = FeatureAssociation.Selected; } else { assoc = feat.Required ? FeatureAssociation.Selected : FeatureAssociation.NotSelected; } } else { assoc = FeatureAssociation.NotSelected; } } } return assoc; }
internal TemplateGenerationData(LibraryCategory lc, MFComponent cmp) { LibraryCat = lc; Comp = cmp; }
/// <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; }
internal LibraryCategory LoadLibraryCategoryProj(string libCatProjFile, string path) { Project proj; LibraryCategory libcat = null; string fullpath = ExpandEnvVars(libCatProjFile, path); try { proj = LoadProject(fullpath); foreach (ProjectPropertyGroupElement bpg in proj.Xml.PropertyGroups) { foreach (ProjectPropertyElement bp in bpg.Properties) { if (bp.Name == PKUI_LibCatTag) { libcat = (LibraryCategory)DeserializeXml(bp.Value, typeof(LibraryCategory)); libcat.ProjectPath = ConvertPathToEnv(fullpath); } } } if (libcat == null) { libcat = new LibraryCategory(); libcat.Name = Path.GetFileNameWithoutExtension(libCatProjFile); libcat.Guid = System.Guid.NewGuid().ToString("B"); libcat.ProjectPath = ConvertPathToEnv(fullpath); } else { LibraryCategory lcDb = m_helper.FindLibraryCategory(libcat.Guid); if (null == lcDb) { m_helper.DefaultInventory.LibraryCategories.Add(libcat); } else { return lcDb; } } foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups) { foreach (ProjectItemElement bi in big.Items) { libcat.LibraryProjCache.Add(bi.Include); Library lib = LoadLibraryProj(bi.Include, path); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error: loading LibCat file: " + fullpath + "\r\n", e.Message); } return libcat; }
public void CopyTo(LibraryCategory dest) { CopyHelper.CopyTo(this, dest); }
internal void CopyTemplateFiles(LibraryCategory libType, MFSolution solution, MFComponent compLibTemplate) { const string c_FastCompile = @"fastcompile.cpp"; const string c_FastCompileTag = @"FastCompileCPPFile"; string dstPath = Path.Combine(ExpandEnvVars(Path.GetDirectoryName(solution.ProjectPath), ""), "DeviceCode\\"); List<string> reloadProjs = new List<string>(); //Regex expRelPath = new Regex("([\\w\\W]*\\\\)([^\\\\]+\\\\[^\\\\]+)"); //Regex expRemoveDeviceCode = new Regex("\\\\DeviceCode\\\\", RegexOptions.IgnoreCase); //Regex expRemoveStubDir = new Regex("\\\\stub[s]?\\\\", RegexOptions.IgnoreCase); Regex expStubReplace = new Regex("(?<!Is)(stub[s]?)", RegexOptions.IgnoreCase); //string relPath = ""; foreach (ApiTemplate api in libType.Templates) { string src = ExpandEnvVars( api.FilePath, Environment.GetEnvironmentVariable("SPOCLIENT") ); // // Make relative path based on path after \DeviceCode\ if it exists, otherwise up to two directories deep // //relPath = Path.GetDirectoryName(src); //string devCode = "\\devicecode\\"; /* int idx = relPath.ToLower().IndexOf(devCode); if (idx != -1) { idx += devCode.Length; relPath = relPath.Substring(idx, relPath.Length - idx); } else { Match m = expRelPath.Match(Path.GetDirectoryName(api.FilePath)); relPath = m.Groups[1].Value.ToLower(); } */ string dst = dstPath + libType.Name + "\\" + Path.GetFileName(api.FilePath); bool isProcFile = src.ToLower().Contains("\\processor\\"); try { // ignore fast compiles if (-1 != dst.IndexOf(c_FastCompile, StringComparison.OrdinalIgnoreCase)) { continue; } //dst = expRemoveStubDir.Replace(dst, "\\"); if (isProcFile) { dst = expStubReplace.Replace(dst, solution.Processor.Name); } else { dst = expStubReplace.Replace(dst, solution.Name); } if (!Directory.Exists(Path.GetDirectoryName(dst))) { Directory.CreateDirectory(Path.GetDirectoryName(dst)); } if (File.Exists(dst)) { continue; } // // The source file may refer to "stubs" for function names or includes, we need to replace this // with the solution (or processor) name // TextWriter tw = File.CreateText(dst); TextReader tr = File.OpenText(src); try { string txt = tr.ReadToEnd(); if (isProcFile) { txt = expStubReplace.Replace(txt, solution.Processor.Name); } else { txt = expStubReplace.Replace(txt, solution.Name); } Regex exp = new Regex("<IsStub>([\\w\\W]+)</IsStub>", RegexOptions.IgnoreCase); txt = exp.Replace(txt, "<IsStub>false</IsStub>"); tw.Write(txt); } finally { tr.Close(); tw.Close(); } File.SetAttributes(dst, FileAttributes.Normal); if (0 == string.Compare(".proj", Path.GetExtension(dst), true)) { Project p = LoadProject(dst); p.Xml.DefaultTargets = "Build"; compLibTemplate.ProjectPath = ConvertPathToEnv(dst); foreach (ProjectPropertyGroupElement pg in p.Xml.PropertyGroups) { foreach (ProjectPropertyElement bp in pg.Properties) { switch (bp.Name.ToLower()) { case "directory": bp.Value = RemoveSpoClient(Path.GetDirectoryName(dst)); break; case "assemblyname": bp.Value = compLibTemplate.Name; break; case "projectpath": bp.Value = ConvertPathToEnv(dst); break; case "projectguid": bp.Value = compLibTemplate.Guid; break; case "libraryfile": bp.Value = compLibTemplate.Name + ".$(LIB_EXT)"; break; case "manifestfile": bp.Value = compLibTemplate.Name + ".$(LIB_EXT).manifest"; break; } } } foreach (ProjectItemGroupElement ig in p.Xml.ItemGroups) { ArrayList remove_list = new ArrayList(); foreach (ProjectItemElement bi in ig.Items) { if (bi.ItemType == c_FastCompileTag) { remove_list.Add(bi); continue; } //dst = expRemoveStubDir.Replace(dst, "\\"); if (-1 != src.IndexOf("\\processor\\", StringComparison.CurrentCultureIgnoreCase)) { bi.Include = expStubReplace.Replace(bi.Include, solution.Processor.Name); } else { bi.Include = expStubReplace.Replace(bi.Include, solution.Name); } } foreach (ProjectItemElement bi in remove_list) { ig.RemoveChild(bi); } } p.Save(dst); reloadProjs.Add(dst); } } catch(Exception e) { System.Diagnostics.Debug.Print(e.ToString()); System.Diagnostics.Debug.Print("Unable to copy file: " + src + " to " + dst ); } } foreach (string prj in reloadProjs) { LoadLibraryProj(prj, "", true); } }
public LibraryCategoryWrapper CloneLibraryCategory(BaseTypedWrapper<LibraryCategory> BaseLibCat, string NewName, string NewGroups, LibraryLevelWrapper NewLevel) { LibraryCategory LibCat = new LibraryCategory(); BaseLibCat.InnerObject.CopyTo(LibCat); LibCat.Name = NewName; LibCat.Groups = NewGroups; LibCat.Level = (LibraryLevel)NewLevel; LibCat.ProjectPath = "$(SPOCLIENT)\\Framework\\Features\\" + LibCat.Name + ".libcatproj"; //LibCat.Description = BaseLibCat.Description; //LibCat.Documentation = BaseLibCat.Documentation; //LibCat.FeatureAssociations = BaseLibCat.FeatureAssociations; //LibCat.Groups = NewGroups; //LibCat.IgnoreDefaultLibPath = BaseLibCat.IgnoreDefaultLibPath; //LibCat.IsTranport = BaseLibCat.IsTranport; //LibCat.Level = NewLevel; //LibCat.LibraryProjCache = BaseLibCat.LibraryProjCache; //LibCat.Name = NewName; //LibCat.ProjectPath = "$(SPOCLIENT)\\Framework\\Features\\" + LibCat.Name + ".libcatproj"; //LibCat.Required = BaseLibCat.Required; //LibCat.StubLibrary = BaseLibCat.StubLibrary; //LibCat.Templates = BaseLibCat.Templates; m_bw.SaveLibraryCategoryProj(LibCat); this.m_helper.DefaultInventory.LibraryCategories.Clear(); this.LoadDefaultLibraryCatigoriesAsync(); return BaseWrapper.Wrap<LibraryCategoryWrapper>(LibCat); }