public DataHelper(IOrganizationService service, string entitiesString, string solutionsString, bool fetchFromAssemblies) { this.service = service; this.SolutionNames = solutionsString.Split(',').Select(x => x.Trim()).ToArray(); this.EntityLogicalNames = new HashSet <string>(); // Add entites from assemblies if (fetchFromAssemblies) { this.EntityLogicalNames = GetLogicalNames(AssemblyGetter.GetAssembliesInBuildPath()); } // Add default entities var defaultEntities = new string[] { "businessunit", "systemuser", "transactioncurrency", "role", "systemuserroles", "teamroles", "activitypointer" }; foreach (var logicalName in defaultEntities) { this.EntityLogicalNames.Add(logicalName); } // Add specified entities if (!String.IsNullOrWhiteSpace(entitiesString)) { foreach (var logicalName in entitiesString.Split(',')) { this.EntityLogicalNames.Add(logicalName.Trim()); } } }
private static Assembly ResolveXrmAssemblies(object sender, ResolveEventArgs args) { if (listOfAssemblies.Contains(args.Name)) { return(null); } try { listOfAssemblies.Add(args.Name); return(AssemblyGetter.GetAssemblyFromName(args.Name)); } finally { listOfAssemblies.Remove(args.Name); } }
public DataHelper(IOrganizationService service, string entitiesString, string solutionsString) { this.service = service; this.EntityLogicalNames = GetLogicalNames(AssemblyGetter.GetAssembliesInBuildPath()); var defaultEntities = new string[] { "businessunit", "systemuser", "transactioncurrency", "role", "systemuserroles", "teamroles" }; foreach (var logicalName in defaultEntities) { this.EntityLogicalNames.Add(logicalName); } if (!String.IsNullOrWhiteSpace(entitiesString)) { foreach (var logicalName in entitiesString.Split(',')) { this.EntityLogicalNames.Add(logicalName.Trim()); } } this.SolutionNames = solutionsString.Split(',').Select(x => x.Trim()).ToArray(); }
static void GenerateMetadata() { var auth = new AuthHelper( ParsedArgs[Arguments.Url], ParsedArgs[Arguments.RedirectUrl], ParsedArgs[Arguments.ClientId] ); Console.WriteLine("Generation of metadata files started"); var generator = new DataHelper(auth.Authenticate(), ParsedArgs[Arguments.Entities], ParsedArgs[Arguments.Solutions], ParsedArgs.GetAsType <bool>(Arguments.fetchFromAssemblies)); var outputLocation = ParsedArgs[Arguments.OutDir] ?? Directory.GetCurrentDirectory(); var skeleton = generator.GetMetadata(AssemblyGetter.GetProjectPath()); var serializer = new DataContractSerializer(typeof(MetadataSkeleton)); var workflowSerializer = new DataContractSerializer(typeof(Entity)); var securitySerializer = new DataContractSerializer(typeof(SecurityRole)); var workflowsLocation = Path.Combine(outputLocation, "Workflows"); var securityLocation = Path.Combine(outputLocation, "SecurityRoles"); Console.WriteLine("Deleting old files"); Directory.CreateDirectory(workflowsLocation); foreach (var file in Directory.EnumerateFiles(workflowsLocation, "*.xml")) { File.Delete(Path.Combine(workflowsLocation, file)); } Directory.CreateDirectory(securityLocation); foreach (var file in Directory.EnumerateFiles(securityLocation, "*.xml")) { File.Delete(Path.Combine(securityLocation, file)); } Console.WriteLine("Writing files"); Directory.CreateDirectory(outputLocation); using (var stream = new FileStream(outputLocation + "/Metadata.xml", FileMode.Create)) { serializer.WriteObject(stream, skeleton); } foreach (var workflow in generator.GetWorkflows()) { var safeName = ToSafeName(workflow.GetAttributeValue <string>("name")); using (var stream = new FileStream($"{workflowsLocation}/{safeName}.xml", FileMode.Create)) { workflowSerializer.WriteObject(stream, workflow); } } var securityRoles = generator.GetSecurityRoles(skeleton.RootBusinessUnit.Id); foreach (var securityRole in securityRoles) { var safeName = ToSafeName(securityRole.Value.Name); using (var stream = new FileStream($"{securityLocation}/{safeName}.xml", FileMode.Create)) { securitySerializer.WriteObject(stream, securityRole.Value); } } // Write to TypeDeclarations file var typedefFile = Path.Combine(outputLocation, "TypeDeclarations.cs"); using (var file = new StreamWriter(typedefFile, false)) { file.WriteLine("using System;"); file.WriteLine(""); file.WriteLine("namespace DG.Tools.XrmMockup {"); file.WriteLine("\tpublic struct SecurityRoles {"); foreach (var securityRole in securityRoles.OrderBy(x => x.Value.Name)) { file.WriteLine($"\t\tpublic static Guid {ToSafeName(securityRole.Value.Name)} = new Guid(\"{securityRole.Key}\");"); } file.WriteLine("\t}"); file.WriteLine("}"); } }