コード例 #1
0
 public void UpdateConnection(Microsoft.Xrm.Sdk.IOrganizationService newService, ConnectionDetail connectionDetail, string actionName = "", object parameter = null)
 {
     if (actionName == "TargetOrganization")
     {
         targetService = newService;
         SetConnectionLabel(connectionDetail, "Target");
     }
     else
     {
         service = newService;
         SetConnectionLabel(connectionDetail, "Source");
     }
 }
コード例 #2
0
        public OrganizationService()
        {
            if (ForcedOrganization != null)
            {
                this.instance = ForcedOrganization;
                return;
            }

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var connectionString = ConnectionString.Value;

            if (connectionString.Contains("ClientSecret"))
            {
                this.instance = new OAuthOrganizationService();
            }
            else
            {
                try
                {
                    var client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
                    client.OrganizationServiceProxy.EnableProxyTypes(typeof(OrganizationService).Assembly);
                    this.instance = client;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error creating organization service: {ex.Message}");
                    Console.Write("Retrying with user/pwd approach...");
                    try
                    {
                        ClientCredentials clientCredentials = new ClientCredentials();
                        clientCredentials.UserName.UserName = connectionString.GetParameter("Username");
                        clientCredentials.UserName.Password = connectionString.GetParameter("Password");

                        var uri = new Uri($"{connectionString.GetParameter("Url")}/XRMServices/2011/Organization.svc");

                        var proxy = new OrganizationServiceProxy(uri, null, clientCredentials, null);
                        proxy.EnableProxyTypes(typeof(OrganizationService).Assembly);
                        this.instance = proxy;
                        Console.WriteLine("Success.");
                    }
                    catch (Exception ex2)
                    {
                        Console.WriteLine("Error again!");
                        Console.WriteLine(ex.Message);
                        throw ex2;
                    }
                }
            }
        }
コード例 #3
0
 public void UpdateConnection(Microsoft.Xrm.Sdk.IOrganizationService newService, ConnectionDetail connectionDetail, string actionName = "", object parameter = null)
 {
     if (actionName == "TargetOrganization")
     {
         targetService = newService;
         SetConnectionLabel(connectionDetail, "Target");
         ((OrganizationServiceProxy)((OrganizationService)targetService).InnerService).Timeout = new TimeSpan(
             0, 1, 0, 0);
     }
     else
     {
         service = newService;
         SetConnectionLabel(connectionDetail, "Source");
         ((OrganizationServiceProxy)((OrganizationService)service).InnerService).Timeout = new TimeSpan(0, 1, 0, 0);
         LoadEntities();
     }
 }
コード例 #4
0
        public DACase BuscarCaseExistente(UpdateOrCloseTaskCaseRequest request)
        {
            DACase caso = new DACase();

            try
            {
                // Cast the proxy client to the IOrganizationService interface.
                _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
                //var gestiones = FetchGestionesAbiertas(idCampania);
            }
            catch
            {
                throw;
            }

            return(caso);
        }
コード例 #5
0
ファイル: DAConexionCRM.cs プロジェクト: revenix/Claro
        public static string GetPickListText(string entityName, string attributeName, int optionSetValue, Microsoft.Xrm.Sdk.IOrganizationService service)
        {
            string AttributeName     = attributeName;
            string EntityLogicalName = entityName;
            RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
            {
                EntityFilters = EntityFilters.All,
                LogicalName   = EntityLogicalName
            };
            RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);

            Microsoft.Xrm.Sdk.Metadata.EntityMetadata            metadata         = retrieveEntityResponseObj.EntityMetadata;
            Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata;
            Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata         options          = picklistMetadata.OptionSet;
            IList <OptionMetadata> picklistOption = (from o in options.Options
                                                     where o.Value.Value == optionSetValue
                                                     select o).ToList();
            string picklistLabel = (picklistOption.First()).Label.UserLocalizedLabel.Label;

            return(picklistLabel);
        }
コード例 #6
0
 public AccountService(Microsoft.Xrm.Sdk.IOrganizationService orgService, string unsecureConfig, string secureConfig)
 {
     this.OrgService     = orgService;
     this.UnsecureConfig = unsecureConfig;
     this.SecureConfig   = secureConfig;
 }
コード例 #7
0
 public CrmRepository(SolidContextService context, Microsoft.Xrm.Sdk.IOrganizationService service)
 {
     this.context  = context;
     this._service = service;
 }
コード例 #8
0
 public AccountService(Microsoft.Xrm.Sdk.IOrganizationService orgService)
 {
     this.OrgService = orgService;
 }
コード例 #9
0
        public object Resolve(TypeCache type, Microsoft.Xrm.Sdk.IOrganizationService orgService)
        {
            try
            {
                if (services.ContainsKey(type.ObjectInstanceKey))
                {
                    return(services[type.ObjectInstanceKey]);
                }

                lock (locks)
                {
                    if (services.ContainsKey(type.ObjectInstanceKey))
                    {
                        return(services[type.ObjectInstanceKey]);
                    }

                    if (type.FromType == typeof(Guid) && type.Name != null && type.Name.ToLower() == nameof(this.pluginExecutionContext.PrimaryEntityId).ToLower())
                    {
                        return(this.pluginExecutionContext.PrimaryEntityId);
                    }

                    if (type.FromType == typeof(string) && type.Name != null && type.Name.ToLower() == nameof(this.pluginExecutionContext.PrimaryEntityName).ToLower())
                    {
                        return(this.pluginExecutionContext.PrimaryEntityName);
                    }

                    if (type.FromType == typeof(string) && type.Name != null && type.Name.ToLower() == nameof(BasePlugin.UnsecureConfig).ToLower())
                    {
                        return(this.UnsecureConfig);
                    }

                    if (type.FromType == typeof(string) && type.Name != null && type.Name.ToLower() == nameof(BasePlugin.SecureConfig).ToLower())
                    {
                        return(this.SecureConfig);
                    }

                    if (type.FromType == typeof(Microsoft.Xrm.Sdk.Query.QueryExpression))
                    {
                        if (pluginExecutionContext.InputParameters.Contains("Query"))
                        {
                            var query = pluginExecutionContext.InputParameters["Query"];
                            if (query is Microsoft.Xrm.Sdk.Query.QueryExpression qe)
                            {
                                // no cache by design - need to be resolved on all request.
                                return(qe);
                            }

                            if (query is Microsoft.Xrm.Sdk.Query.FetchExpression fe)
                            {
                                var resp = (Microsoft.Crm.Sdk.Messages.FetchXmlToQueryExpressionResponse)orgService.Execute(new Microsoft.Crm.Sdk.Messages.FetchXmlToQueryExpressionRequest
                                {
                                    FetchXml = fe.Query
                                });
                                return(resp.Query);
                            }

                            throw new Exceptions.UnresolvedQueryParameter(type.Name);
                        }
                        else
                        {
                            throw new InvalidPluginExecutionException("QueryExpression can only be requested for RetrieveMultiple requests");
                        }
                    }

                    if (type.IsTarget && !type.IsReference)
                    {
                        var entity = (Microsoft.Xrm.Sdk.Entity)pluginExecutionContext.InputParameters["Target"];
                        services[type.ObjectInstanceKey] = Extensions.Sdk.KiponSdkGeneratedExtensionMethods.ToEarlyBoundEntity(entity);
                        return(services[type.ObjectInstanceKey]);
                    }

                    if (type.IsPreimage)
                    {
                        var imgName = PluginMethod.ImageSuffixFor(1, pluginExecutionContext.Stage, pluginExecutionContext.Mode == 1);
                        var entity  = (Microsoft.Xrm.Sdk.Entity)pluginExecutionContext.PreEntityImages[imgName];
                        services[type.ObjectInstanceKey] = Extensions.Sdk.KiponSdkGeneratedExtensionMethods.ToEarlyBoundEntity(entity);
                        return(services[type.ObjectInstanceKey]);
                    }

                    if (type.IsPostimage)
                    {
                        var imgName = PluginMethod.ImageSuffixFor(2, pluginExecutionContext.Stage, pluginExecutionContext.Mode == 1);
                        var entity  = (Microsoft.Xrm.Sdk.Entity)pluginExecutionContext.PostEntityImages[$"postimage{imgName}"];
                        services[type.ObjectInstanceKey] = Extensions.Sdk.KiponSdkGeneratedExtensionMethods.ToEarlyBoundEntity(entity);
                        return(services[type.ObjectInstanceKey]);
                    }

                    if (type.IsMergedimage)
                    {
                        var merged = new Microsoft.Xrm.Sdk.Entity();

                        var target = pluginExecutionContext.InputParameters["Target"] as Microsoft.Xrm.Sdk.Entity;

                        if (target != null)
                        {
                            merged.Id          = target.Id;
                            merged.LogicalName = target.LogicalName;
                        }
                        else
                        {
                            var er = pluginExecutionContext.InputParameters["Target"] as Microsoft.Xrm.Sdk.EntityReference;
                            merged.Id          = er.Id;
                            merged.LogicalName = er.LogicalName;
                        }

                        if (pluginExecutionContext.MessageName == "Create")
                        {
                            merged = target;
                        }
                        else
                        {
                            var imgName = PluginMethod.ImageSuffixFor(1, pluginExecutionContext.Stage, pluginExecutionContext.Mode == 1);
                            var pre     = (Microsoft.Xrm.Sdk.Entity)pluginExecutionContext.PreEntityImages[imgName];

                            foreach (var attr in pre.Attributes.Keys)
                            {
                                merged[attr] = pre[attr];
                            }

                            if (target != null)
                            {
                                foreach (var attr in target.Attributes.Keys)
                                {
                                    merged[attr] = target[attr];
                                }
                            }
                        }

                        services[type.ObjectInstanceKey] = Extensions.Sdk.KiponSdkGeneratedExtensionMethods.ToEarlyBoundEntity(merged);
                        return(services[type.ObjectInstanceKey]);
                    }

                    if (type.IsReference)
                    {
                        var target = (Microsoft.Xrm.Sdk.EntityReference)pluginExecutionContext.InputParameters["Target"];
                        if (type.Constructor != null)
                        {
                            services[type.ObjectInstanceKey] = type.Constructor.Invoke(new object[] { target });
                        }
                        else
                        {
                            services[type.ObjectInstanceKey] = target;
                        }
                        return(services[type.ObjectInstanceKey]);
                    }

                    if (type.FromType == typeof(Microsoft.Xrm.Sdk.IOrganizationService))
                    {
                        return(this.GetOrganizationService(type.RequireAdminService));
                    }

                    if (type.IsQuery)
                    {
                        var uow = this.GetIUnitOfWork(type.RequireAdminService);
                        var repositoryProperty = type.RepositoryProperty;
                        var repository         = repositoryProperty.GetValue(uow, new object[0]);
                        var queryMethod        = type.QueryMethod;
                        return(queryMethod.Invoke(repository, new object[0]));
                    }

                    if (type.IsRepository)
                    {
                        var uow           = this.GetIUnitOfWork(type.RequireAdminService);
                        var queryProperty = type.RepositoryProperty;
                        return(queryProperty.GetValue(uow, new object[0]));
                    }

                    if (type.IsEntityCache)
                    {
                        var uow           = this.GetIUnitOfWork(type.RequireAdminService);
                        var cacheProperty = uow.GetType().GetProperty("Cache");
                        return(cacheProperty.GetValue(uow, new object[0]));
                    }

                    if (type.FromType == typeof(Guid))
                    {
                        if (type.Name.ToLower() == "id")
                        {
                            return(pluginExecutionContext.PrimaryEntityId);
                        }

                        if (type.Name.ToLower() == "listid")
                        {
                            return(pluginExecutionContext.InputParameters["ListId"]);
                        }

                        if (type.Name.ToLower() == "entityid")
                        {
                            return(pluginExecutionContext.InputParameters["EntityId"]);
                        }

                        throw new Exceptions.UnresolveableParameterException(type.FromType, type.Name);
                    }

                    if (type.FromType == typeof(Microsoft.Xrm.Sdk.Relationship))
                    {
                        if (pluginExecutionContext.InputParameters.Contains("Relationship"))
                        {
                            return((Microsoft.Xrm.Sdk.Relationship)pluginExecutionContext.InputParameters["Relationship"]);
                        }

                        throw new InvalidPluginExecutionException("Relationship is requested as input parameter but there is no such information in the payload");
                    }

                    return(this.CreateServiceInstance(type));
                }
            }
            catch (System.Collections.Generic.KeyNotFoundException)
            {
                var typeName = (type?.FromType?.FullName) ?? "type was null";
                var key      = type?.ObjectInstanceKey ?? "object instance key as null";
                throw new InvalidPluginExecutionException($"Unable to resolve service {typeName}, {key} or one of its dependencies.");
            }
        }