예제 #1
0
        private bool IsOkForRegisterDataProvider(List <DataProviderEvent> dataProviderEvents)
        {
            var count = dataProviderEvents.Count(x => x.Message == "Retrieve");

            if (count != 0 && count != 1)
            {
                throw new Exception($"{LOG} multiple message VirtualTablePlugin.Retrieve found");
            }
            count = dataProviderEvents.Count(x => x.Message == "RetrieveMultiple");
            if (count != 0 && count != 1)
            {
                throw new Exception($"{LOG} multiple message VirtualTablePlugin.RetrieveMultiple found");
            }
            if (XrmHelper.IsVirtualTableSupportCRUD(crmServiceClient))
            {
                count = dataProviderEvents.Count(x => x.Message == "Create");
                if (count != 0 && count != 1)
                {
                    throw new Exception($"{LOG} multiple message VirtualTablePlugin.Create found");
                }
                count = dataProviderEvents.Count(x => x.Message == "Update");
                if (count != 0 && count != 1)
                {
                    throw new Exception($"{LOG} multiple message VirtualTablePlugin.Update found");
                }
                count = dataProviderEvents.Count(x => x.Message == "Delete");
                if (count != 0 && count != 1)
                {
                    throw new Exception($"{LOG} multiple message VirtualTablePlugin.Delete found");
                }
            }
            return(true);
        }
예제 #2
0
        private void RegisterDataProvider(List <DataProviderEvent> dataProviderEvents, string dataProviderName)
        {
            var entity = new Entity("entitydataprovider");

            entity.Attributes.Add("name", dataProviderName);
            entity.Attributes.Add("datasourcelogicalname", $"{DataSourceName.ToLower()}");
            entity.Attributes.Add("solutionid", SolutionId);

            var retrieve = dataProviderEvents.Where(x => x.Message == "Retrieve").FirstOrDefault();

            if (retrieve == null)
            {
                entity.Attributes.Add("retrieveplugin", new Guid("{c1919979-0021-4f11-a587-a8f904bdfdf9}"));
            }
            else
            {
                entity.Attributes.Add("retrieveplugin", retrieve.PluginTypeId);
            }

            var retrievemultiple = dataProviderEvents.Where(x => x.Message == "RetrieveMultiple").FirstOrDefault();

            if (retrievemultiple == null)
            {
                entity.Attributes.Add("retrievemultipleplugin", new Guid("{c1919979-0021-4f11-a587-a8f904bdfdf9}"));
            }
            else
            {
                entity.Attributes.Add("retrievemultipleplugin", retrievemultiple.PluginTypeId);
            }
            if (XrmHelper.IsVirtualTableSupportCRUD(crmServiceClient))
            {
                var create = dataProviderEvents.Where(x => x.Message == "Create").FirstOrDefault();
                if (create == null)
                {
                    entity.Attributes.Add("createplugin", new Guid("{c1919979-0021-4f11-a587-a8f904bdfdf9}"));
                }
                else
                {
                    entity.Attributes.Add("createplugin", create.PluginTypeId);
                }

                var update = dataProviderEvents.Where(x => x.Message == "Update").FirstOrDefault();
                if (update == null)
                {
                    entity.Attributes.Add("updateplugin", new Guid("{c1919979-0021-4f11-a587-a8f904bdfdf9}"));
                }
                else
                {
                    entity.Attributes.Add("updateplugin", update.PluginTypeId);
                }

                var delete = dataProviderEvents.Where(x => x.Message == "Delete").FirstOrDefault();
                if (delete == null)
                {
                    entity.Attributes.Add("deleteplugin", new Guid("{c1919979-0021-4f11-a587-a8f904bdfdf9}"));
                }
                else
                {
                    entity.Attributes.Add("deleteplugin", delete.PluginTypeId);
                }
            }

            var entityDataProvider = GetEntityDataProviderId(dataProviderName);

            if (entityDataProvider == null)
            {
                var request = new CreateRequest();
                if (request.Parameters == null)
                {
                    request.Parameters = new ParameterCollection();
                }
                request.Target = entity;
                request.Parameters.Add("SuppressDuplicateDetection", true);
                request.Parameters.Add("SolutionUniqueName", json.solution);
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorRed, " Registering", CliLog.ColorGreen, " Data Provider: ", CliLog.ColorCyan, $"{dataProviderName}");
                crmServiceClient.Execute(request);
            }
            else
            {
                var entitydataproviderid   = entityDataProvider.GetAttributeValue <Guid?>("entitydataproviderid");
                var retrieveplugin         = entityDataProvider.GetAttributeValue <Guid?>("retrieveplugin");
                var retrievemultipleplugin = entityDataProvider.GetAttributeValue <Guid?>("retrievemultipleplugin");
                var createplugin           = entityDataProvider.GetAttributeValue <Guid?>("createplugin");
                var deleteplugin           = entityDataProvider.GetAttributeValue <Guid?>("deleteplugin");
                var updateplugin           = entityDataProvider.GetAttributeValue <Guid?>("updateplugin");
                if (retrievemultipleplugin != entity.GetAttributeValue <Guid>("retrievemultipleplugin") ||
                    retrieveplugin != entity.GetAttributeValue <Guid>("retrieveplugin") ||
                    createplugin != entity.GetAttributeValue <Guid>("createplugin") ||
                    deleteplugin != entity.GetAttributeValue <Guid>("deleteplugin") ||
                    updateplugin != entity.GetAttributeValue <Guid>("updateplugin")
                    )
                {
                    entity.Attributes.Add("entitydataproviderid", entitydataproviderid.Value);
                    var request = new UpdateRequest
                    {
                        Target = entity
                    };
                    CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorRed, " Updating", CliLog.ColorGreen, " Data Provider: ", CliLog.ColorCyan, $"{dataProviderName}");
                    crmServiceClient.Execute(request);
                }
            }
        }