示例#1
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            RestClient rc = ScribeUtility.Initialize(request.DataStore.GetValue("ScribeUsername"), request.DataStore.GetValue("ScribePassword"));

            string apiToken = request.DataStore.GetValue("ScribeApiToken");
            string orgId    = request.DataStore.GetValue("ScribeOrganizationId");

            await ScribeUtility.InstallConnector(rc, orgId, CONNECTOR_ID);

            ScribeConnection connection = new ScribeConnection
            {
                ConnectorId = CONNECTOR_ID,
                Color       = "#FFEA69A6",
                Name        = ScribeUtility.BPST_SOURCE_NAME,
                Properties  = new List <ScribeKeyValue>()
            };

            string username = request.DataStore.GetValue("D365Username");

            // Set authentication
            ScribeKeyValue kvp = new ScribeKeyValue {
                Key = "DeploymentType", Value = ScribeUtility.AesEncrypt(apiToken, "Online")
            };                                                                                                                        // OnPremise

            connection.Properties.Add(kvp);
            kvp = new ScribeKeyValue {
                Key = "Url", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("ConnectorUrl"))
            };
            connection.Properties.Add(kvp);
            // Set CRM user name
            kvp = new ScribeKeyValue {
                Key = "UserId", Value = ScribeUtility.AesEncrypt(apiToken, username.Split('\\').Last())
            };
            connection.Properties.Add(kvp);
            kvp = new ScribeKeyValue {
                Key = "Domain", Value = ScribeUtility.AesEncrypt(apiToken, username.Split('\\').First())
            };
            connection.Properties.Add(kvp);
            // Set CRM user password
            kvp = new ScribeKeyValue {
                Key = "Password", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("D365Password"))
            };
            connection.Properties.Add(kvp);
            // Set CRM pick list
            kvp = new ScribeKeyValue {
                Key = "DisplayPickListNames", Value = ScribeUtility.AesEncrypt(apiToken, "true")
            };
            connection.Properties.Add(kvp);
            // Set organization name
            kvp = new ScribeKeyValue {
                Key = "Organization", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("OrganizationName"))
            };
            connection.Properties.Add(kvp);

            await rc.Post(string.Format(CultureInfo.InvariantCulture, URL_CONNECTIONS, orgId), JsonConvert.SerializeObject(connection, Formatting.Indented));

            return(new ActionResponse(ActionStatus.Success, JsonUtility.GetEmptyJObject()));
        }
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            RestClient rc = ScribeUtility.Initialize(request.DataStore.GetValue("ScribeUsername"), request.DataStore.GetValue("ScribePassword"));

            string apiToken = request.DataStore.GetValue("ScribeApiToken");
            string orgId    = request.DataStore.GetValue("ScribeOrganizationId");

            await ScribeUtility.InstallConnector(rc, orgId, CONNECTOR_ID);

            ScribeConnection connection = new ScribeConnection
            {
                ConnectorId = CONNECTOR_ID,
                Color       = "#FFEA69A6",
                Name        = ScribeUtility.BPST_SOURCE_NAME,
                Properties  = new List <ScribeKeyValue>()
            };

            // Set discovery URL
            ScribeKeyValue kvp = new ScribeKeyValue {
                Key = "Url", Value = ScribeUtility.AesEncrypt(apiToken, $"https://{request.DataStore.GetValue("SalesforceUrl")}/services/Soap/u/33.0")
            };

            connection.Properties.Add(kvp);
            // Set CRM user name
            kvp = new ScribeKeyValue {
                Key = "UserId", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("SalesforceUser"))
            };
            connection.Properties.Add(kvp);
            // Set CRM user password
            kvp = new ScribeKeyValue {
                Key = "Password", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("SalesforcePassword"))
            };
            connection.Properties.Add(kvp);
            // Set bulk APIs
            kvp = new ScribeKeyValue {
                Key = "UseBulkApiRS", Value = ScribeUtility.AesEncrypt(apiToken, "true")
            };
            connection.Properties.Add(kvp);
            // Set metadata refresh
            kvp = new ScribeKeyValue {
                Key = "RefeshMetaDataUponReconnect", Value = ScribeUtility.AesEncrypt(apiToken, "true")
            };
            connection.Properties.Add(kvp);
            // Set organization name
            kvp = new ScribeKeyValue {
                Key = "SecurityToken", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("SalesforceToken"))
            };
            connection.Properties.Add(kvp);

            await rc.Post(string.Format(ScribeUtility.URL_CONNECTIONS, orgId), JsonUtility.Serialize(connection));

            return(new ActionResponse(ActionStatus.Success));
        }
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            RestClient rc = ScribeUtility.Initialize(request.DataStore.GetValue("ScribeUsername"), request.DataStore.GetValue("ScribePassword"));

            string apiToken = request.DataStore.GetValue("ScribeApiToken");
            string orgId    = request.DataStore.GetValue("ScribeOrganizationId");

            await ScribeUtility.InstallConnector(rc, orgId, CONNECTOR_ID);

            ScribeConnection connection = new ScribeConnection
            {
                ConnectorId = CONNECTOR_ID,
                Color       = "#FFEA69A6",
                Name        = ScribeUtility.BPST_TARGET_NAME,
                Properties  = new List <ScribeKeyValue>()
            };

            // Set authentication
            ScribeKeyValue kvp = new ScribeKeyValue
            {
                Key   = "WindowsAuthentication",
                Value = request.DataStore.GetJson("SqlCredentials", "AuthType").EqualsIgnoreCase("Windows") ? ScribeUtility.AesEncrypt(apiToken, "true") : ScribeUtility.AesEncrypt(apiToken, "false")
            };

            connection.Properties.Add(kvp);
            // Set server name
            kvp = new ScribeKeyValue {
                Key = "Server", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("Server"))
            };
            connection.Properties.Add(kvp);
            // Set database
            kvp = new ScribeKeyValue {
                Key = "Database", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("Database"))
            };
            connection.Properties.Add(kvp);
            // Set user name
            kvp = new ScribeKeyValue {
                Key = "UserName", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("Username"))
            };
            connection.Properties.Add(kvp);
            // Set password
            kvp = new ScribeKeyValue {
                Key = "Password", Value = ScribeUtility.AesEncrypt(apiToken, request.DataStore.GetValue("Password"))
            };
            connection.Properties.Add(kvp);

            await rc.Post(string.Format(ScribeUtility.URL_CONNECTIONS, orgId), JsonUtility.Serialize(connection), null);

            return(new ActionResponse(ActionStatus.Success));
        }