コード例 #1
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            _token = request.DataStore.GetJson("MsCrmToken")["access_token"].ToString();;
            AuthenticationHeaderValue bearer = new AuthenticationHeaderValue("Bearer", _token);

            _rc = new RestClient(request.DataStore.GetValue("ConnectorUrl"), bearer);

            _orgUrl = request.DataStore.GetValue("OrganizationUrl");
            _orgId  = request.DataStore.GetValue("OrganizationId");
            string name = request.DataStore.GetValue("ProfileName") ?? "bpst-mscrm-profile";
            string kV   = request.DataStore.GetValue("KeyVault");

            string[] entities = request.DataStore.GetValue("Entities").Split(new[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            MsCrmProfile profile = new MsCrmProfile
            {
                Entities               = new MsCrmEntity[entities.Length],
                Name                   = name,
                OrganizationId         = _orgId,
                DestinationKeyVaultUri = kV,
                DestinationPrefix      = string.Empty,
                DestinationSchemaName  = "dbo"
            };

            for (int i = 0; i < profile.Entities.Length; i++)
            {
                MsCrmEntity e = new MsCrmEntity {
                    Type = entities[i]
                };
                profile.Entities[i] = e;
            }

            List <string> invalidEntities = await RetrieveInvalidEntities(entities);

            if (invalidEntities.Count > 0)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(),
                                          new ArgumentException("The following entities are not provisioned for replication: " + string.Join(", ", invalidEntities)),
                                          "MsCrm_ErrorCreateProfile"));
            }

            try
            {
                string response = await _rc.Post(MsCrmEndpoints.URL_PROFILES, JsonConvert.SerializeObject(profile));

                MsCrmProfile createdProfile = JsonConvert.DeserializeObject <MsCrmProfile>(response);

                request.DataStore.AddToDataStore("ProfileName", createdProfile.Name, DataStoreType.Public);
                request.DataStore.AddToDataStore("ProfileId", createdProfile.Id, DataStoreType.Public);

                return(new ActionResponse(ActionStatus.Success, createdProfile.Id));
            }
            catch (Exception e)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), e, "MsCrm_ErrorCreateProfile"));
            }
        }
コード例 #2
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            _token = request.DataStore.GetJson("MsCrmToken", "access_token");;
            AuthenticationHeaderValue bearer = new AuthenticationHeaderValue("Bearer", _token);

            _rc = new RestClient(request.DataStore.GetValue("ConnectorUrl"), bearer);

            _orgUrl = request.DataStore.GetValue("OrganizationUrl");
            _orgId  = request.DataStore.GetValue("OrganizationId");
            string name = request.DataStore.GetValue("ProfileName") ?? Constants.CrmProfileName;
            string kV   = request.DataStore.GetValue("KeyVault");
            Dictionary <string, string> entities_dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(request.DataStore.GetValue("Entities"));

            List <string> entities = new List <string>();

            foreach (var e in entities_dict)
            {
                entities.Add(e.Key);
            }

            var additionalObjects = request.DataStore.GetValue("AdditionalObjects");

            if (!string.IsNullOrEmpty(additionalObjects))
            {
                string[] add = additionalObjects.SplitByCommaSpaceTabReturnArray();
                entities.AddRange(add);
            }

            MsCrmProfile profile = new MsCrmProfile
            {
                Entities               = new MsCrmEntity[entities.ToArray().Length],
                Name                   = name,
                OrganizationId         = _orgId,
                DestinationKeyVaultUri = kV,
                DestinationPrefix      = string.Empty,
                DestinationSchemaName  = "dbo"
            };

            for (int i = 0; i < profile.Entities.Length; i++)
            {
                MsCrmEntity e = new MsCrmEntity {
                    Type = entities[i]
                };
                profile.Entities[i] = e;
            }

            List <string> invalidEntities = await RetrieveInvalidEntities(entities.ToArray());

            if (invalidEntities.Count > 0)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(),
                                          new ArgumentException("The following entities are not provisioned for replication: " + string.Join(", ", invalidEntities)),
                                          "MsCrm_ErrorCreateProfile"));
            }

            try
            {
                string response = await _rc.Post(MsCrmEndpoints.URL_PROFILES, JsonConvert.SerializeObject(profile));

                MsCrmProfile createdProfile = JsonConvert.DeserializeObject <MsCrmProfile>(response);

                request.DataStore.AddToDataStore("ProfileName", createdProfile.Name, DataStoreType.Public);
                request.DataStore.AddToDataStore("ProfileId", createdProfile.Id, DataStoreType.Public);

                //Log exporter creation
                request.Logger.LogResource(request.DataStore, createdProfile.Name,
                                           DeployedResourceType.CRMExporter, CreatedBy.BPST, DateTime.UtcNow.ToString("o"), createdProfile.Id);

                return(new ActionResponse(ActionStatus.Success, createdProfile.Id));
            }
            catch (Exception e)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), e, "MsCrm_ErrorCreateProfile"));
            }
        }
コード例 #3
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            _token = request.DataStore.GetJson("MsCrmToken", "access_token");
            AuthenticationHeaderValue bearer = new AuthenticationHeaderValue("Bearer", _token);

            _rc = new RestClient(request.DataStore.GetValue("ConnectorUrl"), bearer);

            _orgUrl = request.DataStore.GetValue("OrganizationUrl");
            _orgId  = request.DataStore.GetValue("OrganizationId");
            string name = request.DataStore.GetValue("ProfileName") ?? Constants.CrmProfileName;
            string kV   = request.DataStore.GetValue("KeyVault");
            //string[] entities = request.DataStore.GetValue("Entities").Split(new[] {',', ' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
            Dictionary <string, string> entitiesDict = JsonConvert.DeserializeObject <Dictionary <string, string> >(request.DataStore.GetValue("Entities"));

            string[] entities = new string[entitiesDict.Count];
            int      iCount   = 0;

            foreach (var entity in entitiesDict)
            {
                entities[iCount++] = entity.Key;
            }


            MsCrmProfile profile = new MsCrmProfile
            {
                Entities               = new MsCrmEntity[entities.ToArray().Length],
                Name                   = name,
                OrganizationId         = _orgId,
                DestinationKeyVaultUri = kV,
                DestinationPrefix      = string.Empty,
                DestinationSchemaName  = "dbo"
            };

            for (int i = 0; i < profile.Entities.Length; i++)
            {
                MsCrmEntity e = new MsCrmEntity {
                    Type = entities[i]
                };
                profile.Entities[i] = e;
            }


            List <string> invalidEntities = await RetrieveInvalidEntities(entities);

            if (invalidEntities.Count > 0)
            {
                return(new ActionResponse(ActionStatus.Failure, null,
                                          new ArgumentException("The following entities are not provisioned for replication: " + string.Join(", ", invalidEntities)),
                                          "MsCrm_ErrorCreateProfile"));
            }

            try
            {
                await _rc.Post(MsCrmEndpoints.URL_PROFILES_VALIDATE, JsonConvert.SerializeObject(profile));

                return(new ActionResponse(ActionStatus.Success));
            }
            catch (Exception e)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), e, "MsCrm_ErrorCreateProfile"));
            }
        }