Exemplo n.º 1
0
        public ResultData Run(StepStartData data)
        {
            // You will have to run another step before this one or provide a license for the Aspose library.
            // Step to run before this one: RecognizeBarcodesFromWordDoc.

            string barCodeText = data[INPUT_BAR_CODE_TEXT] as string;

            if (string.IsNullOrEmpty(barCodeText))
            {
                throw new BusinessRuleException("You cannot generate a bar code without any barcode text.");
            }

            BarcodeGenerator generator = new BarcodeGenerator(GetEncodeTypeFromName(BarcodeEncodingType), barCodeText);

            generator.Parameters.Barcode.XDimension.Millimeters = 1f;
            FileData fdResult = null;

            using (MemoryStream ms = new MemoryStream())
            {
                // Save the image to your system and set its image format to Jpeg
                generator.Save(ms, BarCodeImageFormat.Jpeg);
                fdResult = new FileData("BarCode.jpg", ms.ToArray());
            }

            return(new ResultData(PATH_DONE, new DataPair[] { new DataPair(RESULT_DATA_FILE, fdResult) }));
        }
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var folderId   = (string)data.Data[FILE_OR_FOLDER_ID];
            var permission = (GoogleDrivePermission)data.Data[PERMISSION];

            return(GoogleDriveUtility.SetResourcePermissions(connection, folderId, permission));
        }
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var fileId   = (string)data.Data[FILE_ID];
            var filePath = (string)data.Data[LOCAL_FILE_PATH];

            return(GoogleDriveUtility.DownloadFile(connection, fileId, filePath));
        }
        public ResultData Run(StepStartData data)
        {
            try
            {
                Connection            connection = CreateConnection(data);
                GoogleDriveBaseResult res        = ExecuteStep(connection, data);

                if (res.IsSucceed)
                {
                    var outputData    = OutcomeScenarios[RESULT_OUTCOME_INDEX].OutputData;
                    var exitPointName = OutcomeScenarios[RESULT_OUTCOME_INDEX].ExitPointName;

                    if (outputData != null && outputData.Length > 0)
                    {
                        return(new ResultData(exitPointName, new DataPair[] { new DataPair(outputData[0].Name, res.DataObj) }));
                    }
                    else
                    {
                        return(new ResultData(exitPointName));
                    }
                }
                else
                {
                    return(new ResultData(ERROR_OUTCOME, new DataPair[] { new DataPair(ERROR_OUTCOME_DATA_NAME, res.ErrorInfo) }));
                }
            }
            catch (Exception ex)
            {
                GoogleDriveErrorInfo ErrInfo = new GoogleDriveErrorInfo()
                {
                    ErrorMessage = ex.ToString(), HttpErrorCode = null
                };
                return(new ResultData(ERROR_OUTCOME, new DataPair[] { new DataPair(ERROR_OUTCOME_DATA_NAME, ErrInfo) }));
            }
        }
        public ResultData Run(StepStartData data)
        {
            try
            {
                IOrganizationService serviceProxy = GetServiceProxy();

                EntityCollection entityCollection = serviceProxy.RetrieveMultiple(new QueryExpression()
                {
                    EntityName = CRMEntity.CRMEntityName,
                    ColumnSet  = new ColumnSet(true)
                });
                Type type = GetMSCRMType();

                ArrayList entities = new ArrayList();
                foreach (var entity in entityCollection.Entities)
                {
                    var obj = CreateObjectFromAttributes(type, entity.Attributes);
                    entities.Add(obj);
                }
                Array value = Array.CreateInstance(type, entities.Count);
                entities.CopyTo(value);
                return(new ResultData(PATH_SUCCESS, new DataPair[] { new DataPair(string.Format("{0} Entities", CRMEntity.CRMEntityDisplayName), value) }));
            }
            catch (Exception ex)
            {
                return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", ex.Message) }));
            }
        }
        public ResultData Run(StepStartData data)

        {

            string query = (string)data.Data["Query"];

            string host = (string)data.Data["Host"];

            string account = (string)data.Data["Account"];

            string username = (string)data.Data["Username"];

            string password = (string)data.Data["Password"];

            string database = (string)data.Data["Database"];

            string schema = (string)data.Data["Schema"];

            string warehouse = (string)data.Data["Warehouse"];

            string role = (string)data.Data["Role"];

            var result = new DecisionsSnowflake.QueryRtnJson().QuerySnowFlake(query, host, account, username, password, database, schema, warehouse, role);

            return new ResultData("Done", new DataPair[] { new DataPair("Result", result) });

        }
        public ResultData Run(StepStartData data)
        {
            try
            {
                if (data.Data.ContainsKey(ENTITY_ID))
                {
                    string entityId = data.Data[ENTITY_ID] as string;

                    IOrganizationService serviceProxy = GetServiceProxy();

                    Entity entity = serviceProxy.Retrieve(CRMEntity.CRMEntityName, new Guid(entityId), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

                    if (entity != null)
                    {
                        Type type = GetMSCRMType();

                        var obj = CreateObjectFromAttributes(type, entity.Attributes);

                        return(new ResultData(PATH_SUCCESS, new DataPair[] { new DataPair(string.Format("{0} Entity", CRMEntity.CRMEntityDisplayName), obj) }));
                    }
                    else
                    {
                        return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", "No entity with that ID could be found.") }));
                    }
                }
                else
                {
                    return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", "Entity Id cannot be null.") }));
                }
            }
            catch (Exception ex)
            {
                return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", ex.Message) }));
            }
        }
Exemplo n.º 8
0
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var parentFolderId = (string)data.Data[PARENT_FOLDER_ID];
            var newFolderName  = (string)data.Data[NEW_FOLDER_NAME];

            return(GoogleDriveUtility.CreateFolder(connection, newFolderName, parentFolderId));
        }
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var folderId      = (string)data.Data[PARENT_FOLDER_ID];
            var localFilePath = (string)data.Data[LOCAL_FILE_PATH];
            var fileName      = System.IO.Path.GetFileName(localFilePath);

            return(GoogleDriveUtility.UploadFile(connection, localFilePath, fileName, folderId));
        }
        public ResultData Run(StepStartData data)
        {
            object value = data.Data[VALUE_INPUT];

            OPCTag tag;
            string serverUrl;

            if (chooseTagAtRuntime)
            {
                string tagPath = data.Data[TAG_INPUT] as string;
                serverUrl = data.Data[SERVER_URL_INPUT] as string;
                if (string.IsNullOrEmpty(tagPath))
                {
                    throw new Exception("No tag specified");
                }
                if (string.IsNullOrEmpty(serverUrl))
                {
                    throw new Exception("No server URL specified");
                }
                tag = EntityCache <OPCTag> .GetCache().AllEntities.FirstOrDefault(x => x.Path == tagPath && x.ServerUrl == serverUrl);

                if (tag == null)
                {
                    throw new Exception($"No tag found at '{tagPath}' on server '{serverUrl}'");
                }
            }
            else
            {
                tag = EntityCache <OPCTag> .GetCache().GetById(tagId);

                if (tag == null)
                {
                    throw new Exception($"Tag '{tagId}' not found");
                }
                serverUrl = tag.ServerUrl;
            }

            BaseTagValue tagValue = TagValueUtils.GetTagWithValue(TypeUtilities.FindTypeByFullName(tag.TypeName), value);

            tagValue.Path = tag.Path;

            OPCServerFolderBehaviorData folderExt = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == serverUrl);

            Folder folder = folderExt?.GetEntity() as Folder;

            if (folder == null)
            {
                throw new Exception($"No server folder configured for URL '{serverUrl}'.");
            }

            OPCEngine.SetTagValues(serverUrl, folderExt.AgentId, new BaseTagValue[] { tagValue });

            return(new ResultData(PATH_DONE, new KeyValuePair <string, object>[] { }));
        }
        public void Start(StepStartData data)
        {
            // Get the Flow Tracking ID and Step Tracking ID
            string flowTrackingId = data.FlowTrackingID;
            string stepTrackingId = data.StepTrackingID;

            ORM <ExternalInvocationEntity> externalInvocationEntityOrm = new ORM <ExternalInvocationEntity>();
            ExternalInvocationEntity       externalInvocationEntity    = new ExternalInvocationEntity
            {
                Status         = "Running",
                FlowTrackingId = flowTrackingId,
                StepTrackingId = stepTrackingId
            };

            externalInvocationEntityOrm.Store(externalInvocationEntity);

            Log.Warn($"External Invocation Entity ID: {externalInvocationEntity.GetPrimaryKeyValue()}");
        }
        private Connection CreateConnection(StepStartData data)
        {
            var credentinal = (GoogleDriveCredential)data.Data[CREDENTINAL_DATA];

            if (credentinal != null)
            {
                switch (credentinal.CredentinalType)
                {
                case GoogleDriveCredentialType.ServiceAccount:
                    return(Connection.Create(credentinal.ServiceAccount));

                case GoogleDriveCredentialType.Token:
                    var token = FindToken(credentinal.Token);
                    return(Connection.Create(token.TokenData, token.ConsumerKey, token.ConsumerSecret));
                }
            }

            throw new BusinessRuleException($"Step needs {CREDENTINAL_DATA}");
        }
        public ResultData Run(StepStartData data)
        {
            List <SCORunbookInstanceParameter> rbInputParams = new List <SCORunbookInstanceParameter>();

            foreach (DataDescription inData in InputData)
            {
                rbInputParams.Add(new SCORunbookInstanceParameter {
                    Name = inData.Name, Value = data.Data[inData.Name] as string
                });
            }

            Guid JobId = SCOrchestratorSteps.StartRunbookWithParameters(Guid.Parse(selectedRunbook), rbInputParams.ToArray());

            Dictionary <string, object> resultData = new Dictionary <string, object>();

            resultData.Add("Job Id", JobId);

            return(new ResultData("Done", resultData));
        }
Exemplo n.º 14
0
        public ResultData Run(StepStartData data)
        {
            Dictionary <string, object> resultData = new Dictionary <string, object>();

            var value = (int)data.Data[INPUT_VALUE];

            if (value % 2 == 0)
            {
                //even
                resultData.Add(OUTPUT_VALUE, value);
                return(new ResultData(OUTCOME_EVEN, resultData));
            }
            else
            {
                //Number is odd")

                resultData.Add(OUTPUT_VALUE, value);
                return(new ResultData(OUTCOME_ODD, resultData));
            }
            throw new NotImplementedException();
        }
Exemplo n.º 15
0
        //Run the step and build the output data
        public ResultData Run(StepStartData data)
        {
            double[] regressionResults;
            double[] xData = data[INPUT_X_DATA] as double[];
            double[] yData = data[INPUT_Y_DATA] as double[];

            //Check what Regression Type was selected in the Step Properties
            if (AppliedRegressionType.Equals(RegressionTypes.Simple.ToString()))
            {
                //Call a private method to perform an operation
                regressionResults = PerformSimpleRegression(xData, yData);

                //Build the result data
                return(new ResultData(PATH_DONE, new DataPair[] {
                    new DataPair(RESULT_ITEM_ONE, regressionResults[0]),
                    new DataPair(RESULT_ITEM_TWO, regressionResults[1])
                }));
            }
            else if (AppliedRegressionType.Equals(RegressionTypes.Polynomial.ToString()))
            {
                //Call a private method to perform an operation
                regressionResults = PerformPolynomialRegression(xData, yData);

                //Build the result data
                return(new ResultData(PATH_DONE, new DataPair[] {
                    new DataPair(RESULT_ITEM_ONE, regressionResults[0]),
                    new DataPair(RESULT_ITEM_TWO, regressionResults[1])
                }));
            }
            else
            {
                return(new ResultData(PATH_DONE, new DataPair[] {
                    new DataPair(RESULT_ITEM_ONE, 0),
                    new DataPair(RESULT_ITEM_TWO, 0)
                }));
            }
        }
        public ResultData Run(StepStartData data)
        {
            try
            {
                if (data.Data.ContainsKey(ENTITY_ID))
                {
                    string entityId = data.Data[ENTITY_ID] as string;

                    IOrganizationService serviceProxy = GetServiceProxy();

                    serviceProxy.Delete(CRMEntity.CRMEntityName, new Guid(entityId));

                    return(new ResultData(PATH_SUCCESS));
                }
                else
                {
                    return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", "Entity Id cannot be null.") }));
                }
            }
            catch (Exception ex)
            {
                return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", ex.Message) }));
            }
        }
        public ResultData Run(StepStartData data)
        {
            try
            {
                var accessToken = FindAccessToken(Token);
                GraphServiceClient connection = AuthenticationHelper.GetAuthenticatedClient(accessToken);
                OneDriveBaseResult res        = ExecuteStep(connection, data);

                if (res.IsSucceed)
                {
                    var outputData    = OutcomeScenarios[RESULT_OUTCOME_INDEX].OutputData;
                    var exitPointName = OutcomeScenarios[RESULT_OUTCOME_INDEX].ExitPointName;

                    if (outputData != null && outputData.Length > 0)
                    {
                        return(new ResultData(exitPointName, new DataPair[] { new DataPair(outputData[0].Name, res.DataObj) }));
                    }
                    else
                    {
                        return(new ResultData(exitPointName));
                    }
                }
                else
                {
                    return(new ResultData(ERROR_OUTCOME, new DataPair[] { new DataPair(ERROR_OUTCOME_DATA_NAME, res.ErrorInfo) }));
                }
            }
            catch (Exception ex)
            {
                OneDriveErrorInfo ErrInfo = new OneDriveErrorInfo()
                {
                    ErrorMessage = ex.ToString(), HttpErrorCode = null
                };
                return(new ResultData(ERROR_OUTCOME, new DataPair[] { new DataPair(ERROR_OUTCOME_DATA_NAME, ErrInfo) }));
            }
        }
Exemplo n.º 18
0
        public ResultData Run(StepStartData data)
        {
            try
            {
                if (data.Data.ContainsKey(ENTITY_ID))
                {
                    string entityId = data.Data[ENTITY_ID] as string;

                    IOrganizationService serviceProxy = GetServiceProxy();

                    Entity entity = new Entity(CRMEntity.CRMEntityName);

                    entity.Id = new Guid(entityId);

                    if (data.Data.ContainsKey(CRMEntity.CRMEntityDisplayName))
                    {
                        Type type = GetMSCRMType();

                        object obj = data.Data[CRMEntity.CRMEntityDisplayName];

                        Dictionary <string, object> objDict = (Dictionary <string, object>)type.GetProperty("Fields").GetValue(obj);

                        Type objType = obj.GetType();

                        CRMEntity.LogCrmEntityFields("UpdateStep");

                        foreach (var field in CRMEntity.CRMEntityFields)
                        {
                            if (field.IsValidForUpdate == true)
                            {
                                object fieldValue;

                                if (!objDict.TryGetValue(field.FieldName, out fieldValue))
                                {
                                    // If this field doesn't exist on the update obj, skip it.
                                    log.Debug($"Field '{field.FieldName}' is not being updated (no new value supplied).");
                                    continue;
                                }

                                if (TreatEmptyStringAsNull)
                                {
                                    string fieldValueStr = fieldValue as string;
                                    if (fieldValueStr != null && fieldValueStr.Length == 0)
                                    {
                                        log.Debug($"Empty string '{field.FieldName}' is being treated as null.");
                                        fieldValue = null;
                                    }
                                }

                                if (fieldValue == null)
                                {
                                    // If this option is set, don't add null values.
                                    if (!TreatNullAsIgnore)
                                    {
                                        entity[field.FieldName] = null;
                                    }
                                    if (TreatNullAsIgnore)
                                    {
                                        log.Debug($"Null field '{field.FieldName}' is being ignored.");
                                    }
                                    else
                                    {
                                        log.Debug($"Null field '{field.FieldName}' updated normally.");
                                    }
                                }
                                else
                                {
                                    if (field.AttributeType == AttributeTypeCode.Money.ToString())
                                    {
                                        decimal decimalValue = (decimal)fieldValue;
                                        entity[field.FieldName] = new Money(decimalValue);
                                        log.Debug($"Field '{field.FieldName}[Money/decimal]' updated normally.");
                                    }
                                    else if (field.AttributeType == AttributeTypeCode.Picklist.ToString())
                                    {
                                        int?optionValue = field.CRMOptionSet.FirstOrDefault(t => t.OptionName == fieldValue.ToString())?.OptionValue;
                                        if (optionValue != null)
                                        {
                                            entity[field.FieldName] = new OptionSetValue(optionValue.GetValueOrDefault());
                                            log.Debug($"Field '{field.FieldName}[OptionSet]' updated normally.");
                                        }
                                        else
                                        {
                                            log.Debug($"Value '{fieldValue.ToString()}' not found in optionset, checking enum type directly.");
                                            string enumTypeName = $"{CRMEntity.GetFullTypeName()}_{field.FieldName}";
                                            Type   enumType     = TypeUtilities.FindTypeByFullName(enumTypeName);
                                            if (enumType != null)
                                            {
                                                bool enumFound = false;
                                                try
                                                {
                                                    if (Enum.IsDefined(enumType, fieldValue))
                                                    {
                                                        // Enum.Parse should return an object with the string representation instead of int:
                                                        object enumObj = Enum.Parse(enumType, fieldValue.ToString(), true);
                                                        enumFound = true;
                                                        // Then, find the Description of the enum, because this is what will actually match the dropdown list.
                                                        FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
                                                        DescriptionAttribute[] attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
                                                        string enumDisplayName            = null;
                                                        if (attributes.Length > 0)
                                                        {
                                                            enumDisplayName = attributes[0].Description;
                                                        }
                                                        optionValue = field.CRMOptionSet.FirstOrDefault(t => t.OptionName == enumDisplayName)?.OptionValue;
                                                        if (optionValue != null)
                                                        {
                                                            entity[field.FieldName] = new OptionSetValue(optionValue.GetValueOrDefault());
                                                            log.Debug($"Field '{field.FieldName}[OptionSet]' updated normally.");
                                                        }
                                                        else
                                                        {
                                                            log.Debug($"Field '{field.FieldName}[OptionSet]' not updated: null OptionValue, or no option found matching name '{enumDisplayName}'.");
                                                        }
                                                    }
                                                }
                                                catch
                                                {
                                                    // Enum not found...
                                                }
                                                finally
                                                {
                                                    if (!enumFound && log.IsDebugEnabled)
                                                    {
                                                        log.Debug($"Field '{field.FieldName}' not updated: optionset value '{fieldValue.ToString()}' not found in optionset "
                                                                  + $"({string.Join(", ", field.CRMOptionSet.Select(x => x.OptionName))})"
                                                                  + $" or in enum type '{enumTypeName}'.");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (log.IsDebugEnabled)
                                                {
                                                    log.Debug($"Field '{field.FieldName}' not updated: optionset value '{fieldValue.ToString()}' not found in optionset "
                                                              + $"({string.Join(", ", field.CRMOptionSet.Select(x => x.OptionName))})"
                                                              + " and enum type was not found.");
                                                }
                                            }
                                        }
                                    }
                                    else if (field.AttributeType == AttributeTypeCode.Customer.ToString() || field.AttributeType == AttributeTypeCode.Lookup.ToString())
                                    {
                                        CRM2011LookUpTypeField lookUpFieldValue = fieldValue as CRM2011LookUpTypeField;
                                        if (lookUpFieldValue != null && string.IsNullOrEmpty(lookUpFieldValue.LookUpEntityName) == false && string.IsNullOrEmpty(lookUpFieldValue.Id) == false)
                                        {
                                            entity[field.FieldName] = new EntityReference(lookUpFieldValue.LookUpEntityName, new Guid(lookUpFieldValue.Id));
                                            log.Debug($"Field '{field.FieldName}[Lookup]' updated normally.");
                                        }
                                        else
                                        {
                                            log.Debug($"Field '{field.FieldName}' not updated: lookup field value not found.");
                                        }
                                    }
                                    else
                                    {
                                        entity[field.FieldName] = fieldValue;
                                        log.Debug($"Field '{field.FieldName}' updated normally.");
                                    }
                                }
                            }
                            else
                            {
                                log.Debug($"Skipping field '{field.FieldName}', not valid for update.");
                            }
                        }
                    }
                    serviceProxy.Update(entity);
                    return(new ResultData(PATH_SUCCESS));
                }
                else
                {
                    return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", "Entity Id cannot be null.") }));
                }
            }
            catch (Exception ex)
            {
                return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", ex.Message) }));
            }
        }
Exemplo n.º 19
0
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var FolderId = (string)data.Data[PARENT_FOLDER_ID];

            return(GoogleDriveUtility.GetFolders(connection, FolderId)); //StepsCore.GetFolderList(credentinal, FolderId);
        }
 protected abstract GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data);
Exemplo n.º 21
0
        protected override OneDriveBaseResult ExecuteStep(GraphServiceClient connection, StepStartData data)
        {
            var fileId        = (string)data.Data[FILE_ID];
            var localFilePath = (string)data.Data[LOCAL_FILE_PATH];

            return(OneDriveUtility.DownloadFile(connection, fileId, localFilePath));
        }
 protected abstract OneDriveBaseResult ExecuteStep(GraphServiceClient connection, StepStartData data);
Exemplo n.º 23
0
        protected override OneDriveBaseResult ExecuteStep(GraphServiceClient connection, StepStartData data)
        {
            var folderId = (string)data.Data[FILE_OR_FOLDER_ID];

            return(OneDriveUtility.GetResourcePermissions(connection, folderId));
        }
Exemplo n.º 24
0
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var FolderId = (string)data.Data[PARENT_FOLDER_ID];

            return(GoogleDriveUtility.GetFiles(connection, FolderId));
        }
        protected override OneDriveBaseResult ExecuteStep(GraphServiceClient connection, StepStartData data)
        {
            var FolderId = (string)data.Data[PARENT_FOLDER_ID];

            return(OneDriveUtility.GetFiles(connection, FolderId));
        }
        protected override OneDriveBaseResult ExecuteStep(GraphServiceClient connection, StepStartData data)
        {
            var folderId = (string)data.Data[FILE_OR_FOLDER_ID];
            OneDriveShareType  shareType  = (OneDriveShareType)data.Data[TYPE_OF_LINK];
            OneDriveShareScope shareScope = (OneDriveShareScope)data.Data[SCOPE_OF_LINK];

            return(OneDriveUtility.CreateShareLink(connection, folderId, shareType, shareScope));
        }
Exemplo n.º 27
0
        public ResultData Run(StepStartData data)
        {
            try
            {
                IOrganizationService serviceProxy = GetServiceProxy();

                Entity entity = new Entity(CRMEntity.CRMEntityName);

                if (data.Data.ContainsKey(CRMEntity.CRMEntityDisplayName))
                {
                    Type type = GetMSCRMType();

                    object obj = data.Data[CRMEntity.CRMEntityDisplayName];

                    Dictionary <string, object> objDict = (Dictionary <string, object>)type.GetProperty("Fields").GetValue(obj);

                    foreach (var field in CRMEntity.CRMEntityFields)
                    {
                        if (field.IsValidForUpdate == true)
                        {
                            if (field.IsRequired && !objDict.ContainsKey(field.FieldName))
                            {
                                // Required fields must be present. If not, try to give a useful error message by listing all of the missing fields:
                                IEnumerable <string> missingFields = CRMEntity.CRMEntityFields
                                                                     .Where(f => f.IsValidForUpdate == true && f.IsRequired && !objDict.ContainsKey(f.FieldName))
                                                                     .Select(f => f.FieldName);
                                string allMissing = string.Join(", ", missingFields);
                                return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] {
                                    new KeyValuePair <string, object>("Error Message", string.Format("The following required fields are missing: {0}.", allMissing))
                                }));
                            }

                            object fieldValue;

                            if (!objDict.TryGetValue(field.FieldName, out fieldValue))
                            {
                                // If this field doesn't exist on the update obj, skip it.
                                continue;
                            }

                            if (fieldValue == null)
                            {
                                entity[field.FieldName] = null;
                            }
                            else
                            {
                                if (field.AttributeType == AttributeTypeCode.Money.ToString())
                                {
                                    decimal decimalValue = (decimal)fieldValue;
                                    entity[field.FieldName] = new Money(decimalValue);
                                }
                                else if (field.AttributeType == AttributeTypeCode.Picklist.ToString())
                                {
                                    int?optionValue = field.CRMOptionSet.FirstOrDefault(t => t.OptionName == fieldValue.ToString())?.OptionValue;
                                    if (optionValue != null)
                                    {
                                        entity[field.FieldName] = new OptionSetValue(optionValue.GetValueOrDefault());
                                    }
                                }
                                else if (field.AttributeType == AttributeTypeCode.Customer.ToString() || field.AttributeType == AttributeTypeCode.Lookup.ToString())
                                {
                                    CRM2011LookUpTypeField lookUpFieldValue = fieldValue as CRM2011LookUpTypeField;
                                    if (lookUpFieldValue != null && string.IsNullOrEmpty(lookUpFieldValue.LookUpEntityName) == false && string.IsNullOrEmpty(lookUpFieldValue.Id) == false)
                                    {
                                        entity[field.FieldName] = new EntityReference(lookUpFieldValue.LookUpEntityName, new Guid(lookUpFieldValue.Id));
                                    }
                                }
                                else
                                {
                                    entity[field.FieldName] = fieldValue;
                                }
                            }
                        }
                    }
                }

                Guid guid = serviceProxy.Create(entity);
                return(new ResultData(PATH_SUCCESS, new DataPair[] { new DataPair(string.Format("Added {0} Id", CRMEntity.CRMEntityDisplayName), guid.ToString()) }));
            }
            catch (Exception ex)
            {
                return(new ResultData(PATH_ERROR, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Error Message", ex.Message) }));
            }
        }
Exemplo n.º 28
0
        protected override GoogleDriveBaseResult ExecuteStep(Connection connection, StepStartData data)
        {
            var fileOrFolderId = (string)data.Data[FILE_OR_FOLDER_ID];

            return(GoogleDriveUtility.DoesResourceExist(connection, fileOrFolderId));
        }
        protected override OneDriveBaseResult ExecuteStep(GraphServiceClient connection, StepStartData data)
        {
            var fileOrFolderId = (string)data.Data[FILE_OR_FOLDER_ID];

            return(OneDriveUtility.DoesResourceExist(connection, fileOrFolderId));
        }
        public ResultData Run(StepStartData data)
        {
            IDocusignCreds creds;

            if (data.Data.ContainsKey(INPUT_CREDS) && data.Data[INPUT_CREDS] != null)
            {
                creds = data.Data[INPUT_CREDS] as IDocusignCreds;
            }
            else
            {
                creds = DSServiceClientFactory.DsSettings;
            }

            var dsClient = DSServiceClientFactory.GetDsClient(creds);

            var document   = (FileData[])data.Data[INPUT_DOCUMENT];
            var recipients = (RecipientTabMapping[])data.Data[INPUT_RECIPIENTS];
            var subject    = (string)data.Data[INPUT_SUBJECT];
            var emailBlurb = (string)data.Data[INPUT_EMAILBLURB];

            Dictionary <string, object> resultData = new Dictionary <string, object>();

            try
            {
                using (var scope = new System.ServiceModel.OperationContextScope(dsClient.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = DSServiceClientFactory.GetAuthHeaderRequestProperty(creds);

                    var dsRecipients   = new List <Recipient>();
                    var tabs           = new List <Tab>();
                    var recipientsList = recipients.ToList();

                    List <Document> documents = new List <Document>();
                    foreach (FileData doc in document)
                    {
                        documents.Add(new Document
                        {
                            PDFBytes = doc.Contents,
                            ID       = new Guid().ToString(),
                            Name     = doc.FileName
                        });
                    }

                    //each recipient has a list of tabs; this is represented by the RecipientTabMapping type
                    var recipientIndex = 1; //RecipientID must be a non-negative integer; using the index of each Recipient in the list for simplicity
                    foreach (var rtm in recipientsList)
                    {
                        dsRecipients.Add(new Recipient
                        {
                            Email                 = rtm.EmailAddress,
                            UserName              = rtm.EmailAddress,
                            Type                  = RecipientTypeCode.Signer,
                            RoutingOrder          = (ushort)rtm.RoutingOrder,
                            RoutingOrderSpecified = rtm.RoutingOrder > 0,
                            ID         = recipientIndex.ToString(),
                            SignerName = rtm.SignerNameField
                        });

                        //add a Tab to the list for each of the RTM's simplified tab objects, setting the RecipientID and DocumentID to match current recipient and document
                        //first do absolutely positioned tabs (normal Tab)
                        if (rtm.AbsolutePositionTabs != null)
                        {
                            foreach (var apt in rtm.AbsolutePositionTabs)
                            {
                                tabs.Add(new Tab
                                {
                                    PageNumber  = apt.PageNumber.ToString(),
                                    XPosition   = apt.XPosition.ToString(),
                                    YPosition   = apt.YPosition.ToString(),
                                    Type        = apt.TabType,
                                    RecipientID = recipientIndex.ToString(),
                                    Name        = apt.TabType == TabTypeCode.SignHere ? rtm.SignerNameField : rtm.UserNameField,
                                    DocumentID  = "1"
                                });
                            }
                        }
                        ;
                        //then do AnchorTabs
                        if (rtm.AnchorStringTabs != null)
                        {
                            foreach (var ast in rtm.AnchorStringTabs)
                            {
                                tabs.Add(new Tab
                                {
                                    PageNumber    = ast.PageNumber.ToString(),
                                    AnchorTabItem = new AnchorTab {
                                        AnchorTabString = ast.AnchorTabString, XOffset = ast.XOffset, YOffset = ast.YOffset
                                    },
                                    Type        = ast.TabType,
                                    RecipientID = recipientIndex.ToString(),
                                    DocumentID  = "1"
                                });
                            }
                        }
                        ;
                        recipientIndex++;
                    }
                    ;

                    //construct the envelope and send; return EnvelopeID
                    var envelopeID = dsClient.CreateAndSendEnvelope(new Envelope
                    {
                        Subject    = subject,
                        EmailBlurb = emailBlurb,
                        Recipients = dsRecipients.ToArray <Recipient>(),
                        AccountId  = creds.AccountId,
                        Documents  = documents.ToArray(),
                        Tabs       = tabs.ToArray()
                    }).EnvelopeID;


                    resultData.Add(OUTPUT_ENVELOPEID, envelopeID);
                    return(new ResultData(OUTCOME_SENT, resultData));
                }
            }
            catch (Exception ex)
            {
                resultData.Add(OUTPUT_ERRORMESSAGE, ex.Message);
                return(new ResultData(OUTCOME_ERROR, resultData));
            }
        }