public static EntityReference GetSdkMessageFilterId(string entityName, Guid messageId, IOrganizationService service) { if (string.IsNullOrWhiteSpace(entityName)) { entityName = "none"; } if (_sdkmessages.ContainsKey(entityName + messageId.ToString())) { return(_sdkmessages[entityName + messageId.ToString()]); } var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var sdkmessagefilter = (from smf in context.CreateQuery("sdkmessagefilter") where (string)smf["primaryobjecttypecode"] == entityName.ToLower() && (Guid)smf["sdkmessageid"] == messageId select smf).FirstOrDefault(); if (entityName != "none" && sdkmessagefilter == null) { throw new Exception($"Could not find messagefilter for {entityName} on message {messageId}"); } else if (sdkmessagefilter == null) { return(null); } else { _sdkmessages.Add(entityName + messageId.ToString(), sdkmessagefilter.ToEntityReference()); return(sdkmessagefilter.ToEntityReference()); } }
public static XrmInstanceConfiguration GetWorkflowTypes(EntityReference assemblyRef, IOrganizationService service) { var assemblyId = assemblyRef.Id; var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var plugintype = (from pt in context.CreateQuery("plugintype") where (Guid)pt["pluginassemblyid"] == assemblyId select pt).ToList(); var ptdic = new Collection <XrmWorkflowTypeContainer>(); foreach (var pt in plugintype) { var workflowTypeContainer = new XrmWorkflowTypeContainer { Name = pt.GetAttributeValue <string>("typename"), Id = pt.Id, Group = pt.GetAttributeValue <string>("workflowactivitygroupname"), NameInGroup = pt.GetAttributeValue <string>("name") }; ptdic.Add(workflowTypeContainer); } return(new XrmInstanceConfiguration { WorkflowTypes = ptdic, AssemblyRef = assemblyRef }); }
public static string FoundSolution(Guid id, IOrganizationService service) { var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var sol = (from s in context.CreateQuery("solution") where s.Id == id select s).FirstOrDefault(); if (sol != null) { return((string)sol.GetAttributeValue <string>("uniquename")); } return(null); }
public static EntityReference GetAssembly(string assemblyName, IOrganizationService service) { var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var assembly = (from a in context.CreateQuery("pluginassembly") where (string)a["name"] == assemblyName select a).FirstOrDefault(); EntityReference assemblyRef = null; if (assembly != null) { assemblyRef = assembly.ToEntityReference(); } return(assemblyRef); }
public static EntityReference GetMessageId(string messageName, IOrganizationService service) { if (_messages.ContainsKey(messageName)) { return(_messages[messageName]); } var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var sdkmessage = (from sm in context.CreateQuery("sdkmessage") where (string)sm["name"] == messageName select sm).First(); _messages.Add(sdkmessage.GetAttributeValue <string>("name"), sdkmessage.ToEntityReference()); return(sdkmessage.ToEntityReference()); }
public void Should_Retrieve_Records_By_Given_Find() { // Arrange var sampleView = new SavedView() { Name = "Sample", Id = Guid.NewGuid(), FetchXML = @" <fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false""> <entity name=""contact""> <attribute name=""emailaddress1"" /> <attribute name=""lastname"" /> <attribute name=""firstname"" /> <attribute name=""address1_telephone1"" /> <attribute name=""contactid"" /> </entity> </fetch>", }; var person = new Person() { Id = Guid.NewGuid(), FirstName = "Billy", LastName = "Bob" }; var fakedContext = new XrmFakedContext(); fakedContext.Initialize(new List <Entity>() { person, sampleView, }); var service = fakedContext.GetOrganizationService(); var serviceContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); // Act var helper = new CFApiHelper(); var results = CFApiHelper.GetPeopleFromFetch( serviceContext, service, sampleView.Name); // Assert Assert.AreEqual(1, results.Count); Assert.AreEqual(results.FirstOrDefault().Id, person.Id); }
public static Guid?FoundSolution(string uniqeName, IOrganizationService service) { if (string.IsNullOrWhiteSpace(uniqeName)) { return(null); } var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var sol = (from s in context.CreateQuery("solution") where (string)s["uniquename"] == uniqeName select new { s.Id }).FirstOrDefault(); if (sol != null) { return(sol.Id); } return(null); }
public static Dictionary <string, EntityReference> GetPluginTypes(Guid assemblyId, IOrganizationService service) { var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var plugintype = (from pt in context.CreateQuery("plugintype") where ((EntityReference)pt["pluginassemblyid"]).Id == assemblyId select pt).ToList(); var ptDictionary = new Dictionary <string, EntityReference>(); foreach (var pt in plugintype) { ptDictionary.Add(pt.GetAttributeValue <string>("typename") + assemblyId.ToString(), pt.ToEntityReference()); } return(ptDictionary); }
public void Should_Throw_If_Wrong_Count_of_Finds_Found() { var fakedContext = new XrmFakedContext(); // Initialize Empty CRM fakedContext.Initialize(new List <Entity>()); var service = fakedContext.GetOrganizationService(); var serviceContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); // Act var helper = new CFApiHelper(); var exception = Assert.Throws <Exception>(() => CFApiHelper.GetPeopleFromFetch(serviceContext, service, "foo")); Assert.That(exception.Message, Is.EqualTo("Expected exactly one Advanced Find name \"foo\", but found 0")); }
public static Dictionary <string, EntityReference> GetSteps(Guid assemblyId, IOrganizationService service) { var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var steps = (from spt in context.CreateQuery("sdkmessageprocessingstep") join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals pt.Id where (Guid)pt["pluginassemblyid"] == assemblyId select spt).ToList(); var stepDictionary = new Dictionary <string, EntityReference>(); foreach (var step in steps) { stepDictionary.Add(step.GetAttributeValue <string>("name") + step.GetAttributeValue <EntityReference>("plugintypeid").Id.ToString(), step.ToEntityReference()); } return(stepDictionary); }
public static EntityReference GetPluginTypeId(Guid assemblyId, string PluginTypeName, IOrganizationService service) { if (_plugintypes.ContainsKey(PluginTypeName + assemblyId.ToString())) { return(_plugintypes[PluginTypeName + assemblyId.ToString()]); } var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var plugintype = (from pt in context.CreateQuery("plugintype") where (Guid)pt["pluginassemblyid"] == assemblyId && (string)pt["name"] == PluginTypeName select pt).First(); _plugintypes.Add(PluginTypeName + assemblyId.ToString(), plugintype.ToEntityReference()); return(plugintype.ToEntityReference()); }
public static Dictionary <string, EntityReference> GetImages(Guid assemblyId, IOrganizationService service) { var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var images = (from img in context.CreateQuery("sdkmessageprocessingstepimage") join spt in context.CreateQuery("sdkmessageprocessingstep") on(Guid) img["sdkmessageprocessingstepid"] equals spt.Id join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals pt.Id where (Guid)pt["pluginassemblyid"] == assemblyId select img).ToList(); var imagedic = new Dictionary <string, EntityReference>(); foreach (var im in images) { imagedic.Add(im.GetAttributeValue <string>("entityalias") + im.GetAttributeValue <EntityReference>("sdkmessageprocessingstepid").Id.ToString(), im.ToEntityReference()); } return(imagedic); }
public List <string> GetActions() { var result = new List <string>(); var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(_client); var actions = (from w in context.CreateQuery("workflow") where ((OptionSetValue)w["category"]).Value == 3 select new { Name = (string)w["uniquename"], }).Distinct().ToList(); foreach (var a in actions) { result.Add(a.Name); } return(result); }
public static Guid?FoundSolution(string uniqeName, IOrganizationService service, out string publisherPrefix) { publisherPrefix = null; if (string.IsNullOrWhiteSpace(uniqeName)) { return(null); } var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var sol = (from s in context.CreateQuery("solution") join p in context.CreateQuery("publisher") on(Guid) s["publisherid"] equals(Guid) p["publisherid"] where (string)s["uniquename"] == uniqeName select new { s.Id, Prefix = (string)p["customizationprefix"] }).FirstOrDefault(); if (sol != null) { publisherPrefix = sol.Prefix.ToLower(); return(sol.Id); } return(null); }
public void GenerateMessagesStruct(string filepath) { var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(_client); var sdkmessages = (from sm in context.CreateQuery("sdkmessage") where (bool)sm["isprivate"] == false select new { Name = (string)sm["name"] }).ToList(); var outpath = GetPath(filepath); using (System.IO.StreamWriter file = new System.IO.StreamWriter(outpath)) { file.WriteLine("public struct XrmMessages"); file.WriteLine("{"); foreach (var x in sdkmessages.OrderBy(x => x.Name)) { file.WriteLine($"\tpublic static readonly string {x.Name} = \"{x.Name}\";"); } file.WriteLine("}"); } }
public static XrmInstanceConfiguration GetPluginTypesHiearki(EntityReference assemblyRef, IOrganizationService service) { var assemblyId = assemblyRef.Id; var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service); var plugintype = (from pt in context.CreateQuery("plugintype") where (Guid)pt["pluginassemblyid"] == assemblyId select pt).ToList(); var steps1 = (from spt in context.CreateQuery("sdkmessageprocessingstep") join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"] where (Guid)pt["pluginassemblyid"] == assemblyId && (EntityReference)spt["sdkmessagefilterid"] == null select new { Step = spt, EntityName = string.Empty }).ToList(); var steps2 = (from spt in context.CreateQuery("sdkmessageprocessingstep") join m in context.CreateQuery("sdkmessagefilter") on(Guid) spt["sdkmessagefilterid"] equals(Guid) m["sdkmessagefilterid"] join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"] where (Guid)pt["pluginassemblyid"] == assemblyId select new { Step = spt, EntityName = m.GetAttributeValue <string>("primaryobjecttypecode") }).ToList(); var steps = steps1.Union(steps2).ToList(); var images = (from img in context.CreateQuery("sdkmessageprocessingstepimage") join spt in context.CreateQuery("sdkmessageprocessingstep") on(Guid) img["sdkmessageprocessingstepid"] equals(Guid) spt["sdkmessageprocessingstepid"] join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"] where (Guid)pt["pluginassemblyid"] == assemblyId select img).ToList(); var secureConfigs = (from spt in context.CreateQuery("sdkmessageprocessingstep") join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"] join sc in context.CreateQuery("sdkmessageprocessingstepsecureconfig") on(Guid) spt["sdkmessageprocessingstepsecureconfigid"] equals(Guid) sc["sdkmessageprocessingstepsecureconfigid"] where (Guid)pt["pluginassemblyid"] == assemblyId select new { Step = new { Id = (Guid)spt["sdkmessageprocessingstepid"], SecureConfig = (string)sc["secureconfig"], SecureConfigId = (Guid)sc["sdkmessageprocessingstepsecureconfigid"] } }).ToList(); var ptdic = new Collection <XrmPluginTypeContainer>(); foreach (var pt in plugintype) { var pluginTypeContainer = new XrmPluginTypeContainer { Name = pt.GetAttributeValue <string>("typename"), Id = pt.Id, Steps = new Collection <XrmStepContainer>() }; var pluginsteps = steps.Where(x => x.Step.GetAttributeValue <EntityReference>("plugintypeid").Id == pt.Id).ToList(); foreach (var step in pluginsteps) { var secureConfig = secureConfigs.Where(x => x.Step.Id == step.Step.Id).FirstOrDefault(); var stepContainer = new XrmStepContainer { Name = step.Step.GetAttributeValue <string>("name"), Id = step.Step.Id, Images = new Collection <XrmImageContainer>(), XrmPluginTypeName = pt.GetAttributeValue <string>("name"), Entity = step.EntityName, Message = step.Step.GetAttributeValue <EntityReference>("sdkmessageid").Name, FilteringAttributes = step.Step.GetAttributeValue <string>("filteringattributes"), Rank = step.Step.GetAttributeValue <int?>("rank").Value, Mode = step.Step.GetAttributeValue <OptionSetValue>("mode").Value, Stage = step.Step.GetAttributeValue <OptionSetValue>("stage").Value, UnsecureConfig = step.Step.GetAttributeValue <string>("configuration"), SecureConfig = secureConfig != null ? secureConfig.Step.SecureConfig : null, SecureConfigId = secureConfig != null ? (Guid?)secureConfig.Step.SecureConfigId : null }; var stepimages = images.Where(x => x.GetAttributeValue <EntityReference>("sdkmessageprocessingstepid").Id == step.Step.Id).ToList(); foreach (var image in stepimages) { var imageContainer = new XrmImageContainer { Id = image.Id, Name = image.GetAttributeValue <string>("name"), Type = image.GetAttributeValue <OptionSetValue>("imagetype").Value, Attributes = image.GetAttributeValue <string>("attributes"), XrmPluginTypeName = pt.GetAttributeValue <string>("name"), XrmStepContainerName = step.Step.GetAttributeValue <string>("name"), }; stepContainer.Images.Add(imageContainer); } pluginTypeContainer.Steps.Add(stepContainer); } ptdic.Add(pluginTypeContainer); } return(new XrmInstanceConfiguration { PluginTypes = ptdic, AssemblyRef = assemblyRef }); }