private void lvClasses_SelectedIndexChanged(object sender, EventArgs e) { this.lsbDetails.Items.Clear(); if (currentAssembly == null) return; if (lvClasses.SelectedItems.Count == 0) return; Type type = currentAssembly.GetType(lvClasses.SelectedItems[0].Text); Generator g = new Generator(); txtSchema.Text = g.Generate(type); ResourceBaseAttribute resourceAttr = type.GetCustomAttribute<SDK.Attributes.ResourceBaseAttribute>(); resourceAttr = type.GetCustomAttribute(typeof(ResourceBaseAttribute), false) as ResourceBaseAttribute; if (resourceAttr == null) return; this.lsbDetails.Items.Add("apsVersion: " + resourceAttr.ApsVersion); this.lsbDetails.Items.Add("id: " + resourceAttr.Id); if(resourceAttr.Implements != null) this.lsbDetails.Items.Add("implements: " + String.Join(",", resourceAttr.Implements)); List<PropertyInfo> p = new List<PropertyInfo>(); List<PropertyInfo> l = new List<PropertyInfo>(); List<PropertyInfo> s = new List<PropertyInfo>(); foreach(PropertyInfo property in type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)) { if (property.GetCustomAttribute<SDK.Attributes.LinkAttribute>() != null) l.Add(property); else if (property.GetCustomAttribute<SDK.Attributes.StructureAttribute>() != null) s.Add(property); else p.Add(property); } FillListItems(p, ">P>"); FillListItems(l, ">L>"); FillListItems(s, ">S>"); }
public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) { pcbOutput = 0; try { DTE dte = GetDTE(); var activeItem = dte.ActiveDocument.Name; ProjectItem projectItem = dte.Solution.FindProjectItem(wszInputFilePath); var solution = dte.Solution; var solutionProjects = dte.ActiveSolutionProjects as Array; if (solutionProjects == null || solutionProjects.Length == 0) return VSConstants.S_FALSE; var activeProject = solutionProjects.GetValue(0) as Project; Generator g = new Generator(); string result = ""; var data = Encoding.Default.GetBytes(result); var ptr = Marshal.AllocCoTaskMem(data.Length); Marshal.Copy(data, 0, ptr, data.Length); pcbOutput = (uint)data.Length; rgbOutputFileContents[0] = ptr; } catch (Exception e) { throw new COMException(string.Format("{0}: {1}\n{2}", e.GetType().Name, e.Message, e.StackTrace)); } return VSConstants.S_OK; // force an error message }
private void bttGenerate_Click(object sender, EventArgs e) { Schema s = new Schema(); s.ApsVersion = "2.0"; s.Name = "Addon"; s.Id = "http://www.parallels.com/Office365/Addon/1.0"; s.Implements = new string[] { "http://aps-standard.org/types/core/resource/1.0" }; s.Access = new Access(); s.Access.Admin = true; s.Properties = new Dictionary<string, VSPlugin.Property>(); s.Properties.Add("adminName", new VSPlugin.Property() { Type = "string", Description = "description", Required = false, Readonly = true, Final = true, Encrypted = true, Unit = "gb", Default = "string", Format = "date-time", Pattern = "^[a-zA-Z][0-9a-zA-Z_\\-]*", Title = "title", Headline = true, MinLength = 3, MaxLength = 20, MinItems = 2, MaxItems = 30, UniqueItems = true, EnumValues = new List<string>(), EnumTitles = new List<string>(), Access = new Access() }); s.Properties["adminName"].EnumTitles.Add("enumtitle1"); s.Properties["adminName"].EnumTitles.Add("enumtitle2"); s.Properties["adminName"].EnumValues.Add("enumvalue1"); s.Properties["adminName"].EnumValues.Add("enumvalue2"); s.Properties["adminName"].Access.Admin = true; s.Properties.Add("simpleString", new VSPlugin.Property() { Type = "string", Required = true }); s.Properties.Add("admin_password", new VSPlugin.Property() { Type = "string", Encrypted = true, Required = true }); s.Properties.Add("array", new VSPlugin.Property() { Type = "array", Items = new ArraySchema() { Type = "string" }, Encrypted = true, Required = true }); s.Operations = new Dictionary<string, Operation>(); s.Operations.Add("verify", new Operation() { Verb = "POST", Path = "/verify", Static = false, Access = new Access(), Parameters = new Dictionary<string, Parameters>(), ErrorResponse = new ErrorResponse(), }); s.Operations["verify"].Access.Admin = true; s.Operations["verify"].Parameters.Add("arguments", new Parameters() { Kind = "body", Type = "object", Required = false }); s.Operations["verify"].ErrorResponse.Type = "object"; s.Operations["verify"].ErrorResponse.Properties = new ErrorProperty(); s.Operations["verify"].ErrorResponse.Properties.Code = "long"; s.Operations["verify"].ErrorResponse.Properties.Message = "string"; s.Structures = new Dictionary<string, Structure>(); s.Structures.Add("Person", new Structure() { Type = "object", Properties = new Dictionary<string, StructureProperty>() }); s.Structures["Person"].Properties.Add("firstName", new StructureProperty() { Type = "string", Required = true }); s.Structures["Person"].Properties.Add("lastName", new StructureProperty() { Type = "string", }); s.Structures["Person"].Properties.Add("books", new StructureProperty() { Type = "array", Items = new ArraySchema() { Type = "string" } }); s.Relations = new Dictionary<string, Relation>(); s.Relations.Add("offers", new Relation() { Type = "http://examples.apsdemo.org/vpscloud/offers/1.0", Collection = true, Requirement = "requiremente" }); s.Relations.Add("contexts", new Relation() { Type = "http://examples.apsdemo.org/vpscloud/contexts/1.0", Collection = true, Required = true }); APSSchemaGenerator a = new APSSchemaGenerator(); txtGenerated.Text = a.ConvertClass(s); Generator g = new Generator(); }