private void GetSource(ResourceCatalog catalog)
 {
     Source = catalog.GetResource <TSource>(GlobalConstants.ServerWorkspaceID, Service.Source.ResourceID) ??
              catalog.GetResource <TSource>(GlobalConstants.ServerWorkspaceID, Service.Source.ResourceName);
     if (Source == null)
     {
         ErrorResult.AddError(string.Format("Error retrieving DBSource for resource ID:{0} and Name:{1}",
                                            Service.Source.ResourceID, Service.Source.ResourceName));
     }
 }
 private bool GetService(ResourceCatalog catalog)
 {
     Service = catalog.GetResource <TService>(GlobalConstants.ServerWorkspaceID, DataObj.ResourceID) ??
               catalog.GetResource <TService>(GlobalConstants.ServerWorkspaceID, DataObj.ServiceName);
     if (Service == null)
     {
         ErrorResult.AddError(string.Format(ErrorResource.ErrorLoadingResource, DataObj.ResourceID));
         return(false);
     }
     return(true);
 }
 protected virtual bool GetService(ResourceCatalog catalog)
 {
     Service = catalog.GetResource <TService>(GlobalConstants.ServerWorkspaceID, DataObj.ResourceID) ??
               catalog.GetResource <TService>(GlobalConstants.ServerWorkspaceID, DataObj.ServiceName);
     if (Service == null)
     {
         ErrorResult.AddError(string.Format("Error loading resource with ID:{0}", DataObj.ResourceID));
         return(false);
     }
     return(true);
 }
示例#4
0
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            tmpErrors = new ErrorResultTO();
            IEnumerable <NameValue> head = null;

            if (Headers != null)
            {
                head = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(a.Value, update))));
            }
            var query = "";

            if (QueryString != null)
            {
                query = ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(QueryString, update));
            }
            var putData = "";

            if (PutData != null)
            {
                putData = ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(PutData, update));
            }

            var url = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
            var webRequestResult = PerformWebRequest(head, query, url, putData);

            ResponseManager = new ResponseManager {
                OutputDescription = OutputDescription, Outputs = Outputs, IsObject = IsObject, ObjectName = ObjectName
            };
            ResponseManager.PushResponseIntoEnvironment(webRequestResult, update, dataObject);
        }
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO errors, int update)
        {
            errors = new ErrorResultTO();
            if (Headers == null)
            {
                errors.AddError(ErrorResource.HeadersAreNull);
                return;
            }
            if (QueryString == null)
            {
                errors.AddError(ErrorResource.QueryIsNull);
                return;
            }
            var head  = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(a.Value, update))));
            var query = ExecutionEnvironment.WarewolfEvalResultToString(dataObject.Environment.Eval(QueryString, update));


            var url = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugEvalResult(query, "URL", dataObject.Environment, update));
                AddDebugInputItem(new DebugEvalResult(url.Address, "Query String", dataObject.Environment, update));
            }
            var webRequestResult = PerformWebRequest(head, query, url);

            ResponseManager = new ResponseManager {
                OutputDescription = OutputDescription, Outputs = Outputs, IsObject = IsObject, ObjectName = ObjectName
            };
            ResponseManager.PushResponseIntoEnvironment(webRequestResult, update, dataObject);
        }
        private void ExecuteConcreteAction(IDSFDataObject dataObject, int update)
        {
            var sharepointReadListTos = SharepointUtils.GetValidReadListItems(ReadListItems).ToList();

            if (sharepointReadListTos.Any())
            {
                var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId);
                if (sharepointSource == null)
                {
                    var contents = ResourceCatalog.GetResourceContents(dataObject.WorkspaceID, SharepointServerResourceId);
                    sharepointSource = new SharepointSource(contents.ToXElement());
                }
                var env = dataObject.Environment;
                if (dataObject.IsDebugMode())
                {
                    AddInputDebug(env, update);
                }
                var sharepointHelper = sharepointSource.CreateSharepointHelper();
                var fields           = sharepointHelper.LoadFieldsForList(SharepointList, false);
                using (var ctx = sharepointHelper.GetContext())
                {
                    var camlQuery = SharepointUtils.BuildCamlQuery(env, FilterCriteria, fields, update);
                    var list      = ctx.Web.Lists.GetByTitle(SharepointList);
                    var listItems = list.GetItems(camlQuery);
                    ctx.Load(listItems);
                    ctx.ExecuteQuery();
                    AddItemList(update, sharepointReadListTos, env, fields, listItems);
                }
                env.CommitAssign();
                AddOutputDebug(dataObject, env, update);
            }
        }
示例#7
0
        protected void ExecuteService(int update, out ErrorResultTO errors, IPluginAction method, IDSFDataObject dataObject)
        {
            errors = new ErrorResultTO();
            var itrs = new List <IWarewolfIterator>(5);
            IWarewolfListIterator itrCollection = new WarewolfListIterator();
            var source           = ResourceCatalog.GetResource <ComPluginSource>(dataObject.WorkspaceID, SourceId);
            var methodParameters = Inputs?.Select(a => new MethodParameter {
                EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value, TypeName = a.TypeName
            }).ToList() ?? new List <MethodParameter>();

            BuildParameterIterators(update, methodParameters.ToList(), itrCollection, itrs, dataObject);
            var args = new ComPluginInvokeArgs
            {
                ClsId        = source.ClsId,
                Is32Bit      = source.Is32Bit,
                Method       = method.Method,
                AssemblyName = Namespace?.AssemblyName,
                Parameters   = methodParameters
            };

            try
            {
                TryExecute(update, dataObject, itrs, itrCollection, methodParameters, args);
            }
            catch (Exception e)
            {
                errors.AddError(e.Message);
            }
        }
示例#8
0
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            tmpErrors = new ErrorResultTO();
            var webRequestResult = string.Empty;

            try
            {
                var(head, query, putData) = ConfigureHttp(dataObject, update);

                var url = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
                webRequestResult = PerformWebRequest(head, query, url, putData, IsPutDataBase64);
            }
            catch (Exception ex)
            {
                tmpErrors.AddError(ex.Message);
            }
            finally
            {
                tmpErrors.MergeErrors(_errorsTo);

                var bytes    = webRequestResult.Base64StringToByteArray();
                var response = bytes.ReadToString();

                ResponseManager = new ResponseManager
                {
                    OutputDescription = OutputDescription,
                    Outputs           = Outputs,
                    IsObject          = IsObject,
                    ObjectName        = ObjectName
                };

                ResponseManager.PushResponseIntoEnvironment(response, update, dataObject);
            }
        }
示例#9
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            try
            {
                RedisSource = ResourceCatalog.GetResource <RedisSource>(GlobalConstants.ServerWorkspaceID, SourceId);
                if (RedisSource == null || RedisSource.ResourceType != enSourceType.RedisSource.ToString())
                {
                    _messages.Add(ErrorResource.RedisSourceHasBeenRemoved);
                    return(_messages);
                }
                _redisCache = new RedisCacheImpl(RedisSource.HostName, Convert.ToInt32(RedisSource.Port), RedisSource.Password);
                if (CounterType == "Increment")
                {
                    _result = _redisCache.Increment(Key, StepSize);

                    Dev2Logger.Debug($"Cache {Key} Incremented {StepSize}: {_result}", GlobalConstants.WarewolfDebug);
                }
                else
                {
                    _result = _redisCache.Decrement(Key, StepSize);
                    Dev2Logger.Debug($"Cache {Key} Decremented {StepSize}: {_result}", GlobalConstants.WarewolfDebug);
                }
                return(new List <string> {
                    _result.ToString()
                });
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(nameof(RedisCounterActivity), ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.GetAllMessages());
            }
        }
示例#10
0
        public override List <DebugItem> GetDebugInputs(IExecutionEnvironment env, int update)
        {
            if (env == null)
            {
                return(new List <DebugItem>());
            }
            base.GetDebugInputs(env, update);

            var head         = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(a.Value, update)))).Where(a => !(String.IsNullOrEmpty(a.Name) && String.IsNullOrEmpty(a.Value)));
            var query        = ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(QueryString, update));
            var url          = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
            var headerString = string.Join(" ", head.Select(a => a.Name + " : " + a.Value));

            var debugItem = new DebugItem();

            AddDebugItem(new DebugItemStaticDataParams("", "URL"), debugItem);
            AddDebugItem(new DebugEvalResult(url.Address, "", env, update), debugItem);
            _debugInputs.Add(debugItem);
            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", "Query String"), debugItem);
            AddDebugItem(new DebugEvalResult(query, "", env, update), debugItem);
            _debugInputs.Add(debugItem);
            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", "Headers"), debugItem);
            AddDebugItem(new DebugEvalResult(headerString, "", env, update), debugItem);
            _debugInputs.Add(debugItem);

            return(_debugInputs);
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var errorResultTo           = new ErrorResultTO();
            var allErrors               = new ErrorResultTO();
            var addExceptionToErrorList = true;

            InitializeDebug(dataObject);
            try
            {
                var parametersIteratorCollection = BuildParametersIteratorCollection(dataObject.Environment, out IWarewolfIterator batchItr, out IWarewolfIterator timeoutItr, update);

                var currentOptions  = BuildSqlBulkCopyOptions();
                var runtimeDatabase = ResourceCatalog.GetResource <DbSource>(dataObject.WorkspaceID, Database.ResourceID);

                Common.Utilities.PerformActionInsideImpersonatedContext(Common.Utilities.OrginalExecutingUser, () =>
                {
                    if (!allErrors.HasErrors())
                    {
                        if (runtimeDatabase.ServerType == enSourceType.MySqlDatabase)
                        {
                            DoInsertForMySql(runtimeDatabase, currentOptions, parametersIteratorCollection, batchItr, timeoutItr, dataObject, errorResultTo, allErrors, ref addExceptionToErrorList, update);
                        }
                        else
                        {
                            DoInsertForSqlServer(runtimeDatabase, currentOptions, dataObject, allErrors, batchItr, parametersIteratorCollection, timeoutItr, ref errorResultTo, ref addExceptionToErrorList, update);
                        }
                    }
                });
                allErrors.MergeErrors(errorResultTo);
            }
            catch (Exception e)
            {
                if (addExceptionToErrorList)
                {
                    allErrors.AddError(e.Message);
                }
                Dev2Logger.Error(this, e, GlobalConstants.WarewolfError);
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfSqlBulkInsertActivity", allErrors);
                    dataObject.Environment.Assign(Result, null, update);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("Failure", Result, "", "="));
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
示例#12
0
        public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            try
            {
                Dev2Logger.Info("Find Dependencies", GlobalConstants.WarewolfInfo);
                var result = new ExecuteMessage {
                    HasError = false
                };

                string resourceId        = null;
                string dependsOnMeString = null;
                var    dependsOnMe       = false;
                values.TryGetValue("ResourceId", out StringBuilder tmp);
                if (tmp != null)
                {
                    resourceId = tmp.ToString();
                }
                values.TryGetValue("GetDependsOnMe", out tmp);
                if (tmp != null)
                {
                    dependsOnMeString = tmp.ToString();
                }
                if (string.IsNullOrEmpty(resourceId))
                {
                    throw new InvalidDataContractException(ErrorResource.ResourceIdIsNull);
                }
                if (!Guid.TryParse(resourceId, out Guid resId))
                {
                    throw new InvalidDataContractException(ErrorResource.ResourceIdNotAGUID);
                }
                var resource = ResourceCatalog.GetResource(theWorkspace.ID, resId);
                if (!string.IsNullOrEmpty(dependsOnMeString) && !bool.TryParse(dependsOnMeString, out dependsOnMe))
                {
                    dependsOnMe = false;
                }


                if (dependsOnMe)
                {
                    result.Message.Append($"<graph title=\"Local Dependants Graph: {resourceId}\">");
                    result.Message.Append(FindWhatDependsOnMe(theWorkspace.ID, resource.ResourceID, new List <Guid>()));
                    result.Message.Append("</graph>");
                }
                else
                {
                    result.Message.Append($"<graph title=\"Dependency Graph Of {resourceId}\">");
                    result.Message.Append(FindDependenciesRecursive(resource.ResourceID, theWorkspace.ID, new List <Guid>()));
                    result.Message.Append("</graph>");
                }

                var serializer = new Dev2JsonSerializer();
                return(serializer.SerializeToBuilder(result));
            }
            catch (Exception e)
            {
                Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                throw;
            }
        }
示例#13
0
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            _dataObject = dataObject;
            tmpErrors   = new ErrorResultTO();
            var webRequestResult = string.Empty;

            try
            {
                var(head, query, postData, conditions) = GetEnvironmentInputVariables(_dataObject.Environment, update);

                var source              = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
                var isManualChecked     = Convert.ToBoolean(Settings?.FirstOrDefault(s => s.Name == nameof(IsManualChecked))?.Value);
                var isFormDataChecked   = Convert.ToBoolean(Settings?.FirstOrDefault(s => s.Name == nameof(IsFormDataChecked))?.Value);
                var isUrlEncodedChecked = Convert.ToBoolean(Settings?.FirstOrDefault(s => s.Name == nameof(IsUrlEncodedChecked))?.Value);

                if (isManualChecked || isFormDataChecked || isUrlEncodedChecked)
                {
                    var webPostOptions = new WebPostOptions
                    {
                        Head                = head,
                        Headers             = head?.Select(h => h.Name + ":" + h.Value)?.ToArray() ?? new string[0],
                        Method              = WebRequestMethod.Post,
                        Parameters          = conditions,
                        Query               = query,
                        Source              = source,
                        PostData            = postData,
                        Settings            = Settings,
                        IsManualChecked     = isManualChecked,
                        IsFormDataChecked   = isFormDataChecked,
                        IsUrlEncodedChecked = isUrlEncodedChecked
                    };

                    webRequestResult = PerformWebPostRequest(webPostOptions);
                }
            }
            catch (Exception ex)
            {
                tmpErrors.AddError(ex.Message);
            }
            finally
            {
                tmpErrors.MergeErrors(_errorsTo);

                var bytes    = webRequestResult.Base64StringToByteArray();
                var response = bytes.ReadToString();

                ResponseManager = new ResponseManager
                {
                    OutputDescription = OutputDescription,
                    Outputs           = Outputs,
                    IsObject          = IsObject,
                    ObjectName        = ObjectName
                };
                response = Scrubber.Scrub(response);
                ResponseManager.PushResponseIntoEnvironment(response, update, dataObject);
            }
        }
示例#14
0
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            tmpErrors = new ErrorResultTO();
            var webRequestResult = string.Empty;

            try
            {
                if (Headers == null)
                {
                    tmpErrors.AddError(ErrorResource.HeadersAreNull);
                    return;
                }

                if (QueryString == null)
                {
                    tmpErrors.AddError(ErrorResource.QueryIsNull);
                    return;
                }

                var(head, query, _) = ConfigureHttp(dataObject, update);

                var url = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugEvalResult(query, "URL", dataObject.Environment, update));
                    AddDebugInputItem(new DebugEvalResult(url.Address, "Query String", dataObject.Environment, update));
                }

                webRequestResult = PerformWebRequest(head, query, url);
            }
            catch (Exception ex)
            {
                tmpErrors.AddError(ex.Message);
            }
            finally
            {
                tmpErrors.MergeErrors(_errorsTo);

                ResponseManager = new ResponseManager
                {
                    OutputDescription = OutputDescription,
                    Outputs           = Outputs,
                    IsObject          = IsObject,
                    ObjectName        = ObjectName
                };
            }

            if (IsResponseBase64)
            {
                ResponseManager.PushResponseIntoEnvironment(webRequestResult, update, dataObject);
                return;
            }

            webRequestResult = Scrubber.Scrub(webRequestResult);
            ResponseManager.PushResponseIntoEnvironment(webRequestResult, update, dataObject);
        }
示例#15
0
        protected void ExecuteService(int update, out ErrorResultTO errors, IPluginAction method, IDSFDataObject dataObject)
        {
            errors = new ErrorResultTO();
            var itrs = new List <IWarewolfIterator>(5);
            IWarewolfListIterator itrCollection = new WarewolfListIterator();
            var source           = ResourceCatalog.GetResource <ComPluginSource>(dataObject.WorkspaceID, SourceId);
            var methodParameters = Inputs?.Select(a => new MethodParameter {
                EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value, TypeName = a.TypeName
            }).ToList() ?? new List <MethodParameter>();

            BuildParameterIterators(update, methodParameters.ToList(), itrCollection, itrs, dataObject);
            var args = new ComPluginInvokeArgs
            {
                ClsId        = source.ClsId,
                Is32Bit      = source.Is32Bit,
                Method       = method.Method,
                AssemblyName = Namespace?.AssemblyName,
                Parameters   = methodParameters
            };

            try
            {
                if (Inputs == null || Inputs.Count == 0)
                {
                    PerfromExecution(update, dataObject, args);
                }
                else
                {
                    while (itrCollection.HasMoreData())
                    {
                        int pos = 0;
                        foreach (var itr in itrs)
                        {
                            string injectVal = itrCollection.FetchNextValue(itr);
                            var    param     = methodParameters.ToList()[pos];


                            param.Value = param.EmptyToNull &&
                                          (injectVal == null ||
                                           string.Compare(injectVal, string.Empty,
                                                          StringComparison.InvariantCultureIgnoreCase) == 0)
                                ? null
                                : injectVal;

                            pos++;
                        }
                        PerfromExecution(update, dataObject, args);
                    }
                }
            }
            catch (Exception e)
            {
                errors.AddError(e.Message);
            }
        }
示例#16
0
        public override List <DebugItem> GetDebugInputs(IExecutionEnvironment env, int update)
        {
            if (env == null)
            {
                return(_debugInputs);
            }

            base.GetDebugInputs(env, update);

            IEnumerable <INameValue> head = null;

            if (Headers != null)
            {
                head = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(a.Value, update)))).Where(a => !(String.IsNullOrEmpty(a.Name) && String.IsNullOrEmpty(a.Value)));
            }

            var url          = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
            var headerString = string.Empty;

            if (head != null)
            {
                headerString = string.Join(" ", head.Select(a => a.Name + " : " + a.Value));
            }

            var debugItem = new DebugItem();

            AddDebugItem(new DebugItemStaticDataParams("", "URL"), debugItem);
            AddDebugItem(new DebugEvalResult(url.Address, "", env, update), debugItem);
            _debugInputs.Add(debugItem);
            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", "Query String"), debugItem);
            AddDebugItem(new DebugEvalResult(QueryString, "", env, update), debugItem);
            _debugInputs.Add(debugItem);
            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", "Post Data"), debugItem);
            AddDebugItem(new DebugEvalResult(PostData, "", env, update), debugItem);
            _debugInputs.Add(debugItem);

            if (IsPostDataBase64)
            {
                debugItem = new DebugItem();
                AddDebugItem(new DebugItemStaticDataParams("", nameof(IsPostDataBase64)), debugItem);
                AddDebugItem(new DebugEvalResult(IsPostDataBase64.ToString(), "", env, update), debugItem);
                _debugInputs.Add(debugItem);
            }

            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", nameof(Headers)), debugItem);
            AddDebugItem(new DebugEvalResult(headerString, "", env, update), debugItem);
            _debugInputs.Add(debugItem);

            return(_debugInputs);
        }
        private void TryExecute(IDSFDataObject dataObject, int update, List <SharepointReadListTo> sharepointReadListTos)
        {
            var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId);
            var listOfIterators  = new Dictionary <string, IWarewolfIterator>();

            if (sharepointSource == null)
            {
                var contents = ResourceCatalog.GetResourceContents(dataObject.WorkspaceID, SharepointServerResourceId);
                sharepointSource = new SharepointSource(contents.ToXElement());
            }
            var env = dataObject.Environment;

            if (dataObject.IsDebugMode())
            {
                AddInputDebug(env, update);
            }
            var sharepointHelper = sharepointSource.CreateSharepointHelper();
            var fields           = sharepointHelper.LoadFieldsForList(SharepointList, true);

            using (var ctx = sharepointHelper.GetContext())
            {
                var list         = sharepointHelper.LoadFieldsForList(SharepointList, ctx, true);
                var iteratorList = new WarewolfListIterator();
                foreach (var sharepointReadListTo in sharepointReadListTos)
                {
                    var warewolfIterator = new WarewolfIterator(env.Eval(sharepointReadListTo.VariableName, update));
                    iteratorList.AddVariableToIterateOn(warewolfIterator);
                    listOfIterators.Add(sharepointReadListTo.FieldName, warewolfIterator);
                }
                while (iteratorList.HasMoreData())
                {
                    var itemCreateInfo = new ListItemCreationInformation();
                    var listItem       = list.AddItem(itemCreateInfo);
                    foreach (var warewolfIterator in listOfIterators)
                    {
                        var sharepointFieldTo = fields.FirstOrDefault(to => to.Name == warewolfIterator.Key);
                        if (sharepointFieldTo != null)
                        {
                            object value = warewolfIterator.Value.GetNextValue();
                            value = SharepointUtils.CastWarewolfValueToCorrectType(value, sharepointFieldTo.Type);
                            listItem[sharepointFieldTo.InternalName] = value;
                        }
                    }
                    listItem.Update();
                    ctx.ExecuteQuery();
                }
            }
            if (!string.IsNullOrEmpty(Result))
            {
                env.Assign(Result, "Success", update);
                AddOutputDebug(dataObject, env, update);
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            _dataObject = dataObject;

            var allErrors       = new ErrorResultTO();
            var indexToUpsertTo = 0;

            InitializeDebug(dataObject);
            try
            {
                IExchange runtimeSource = ResourceCatalog.GetResource <ExchangeSource>(dataObject.WorkspaceID, SavedSource.ResourceID);

                if (runtimeSource == null)
                {
                    dataObject.Environment.Errors.Add(ErrorResource.InvalidEmailSource);
                    return;
                }

                indexToUpsertTo = TryExecute(dataObject, update, allErrors, indexToUpsertTo, runtimeSource);
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFEmail", e, GlobalConstants.WarewolfError);
                allErrors.AddError(e.Message);
            }

            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    foreach (var err in allErrors.FetchErrors())
                    {
                        dataObject.Environment.Errors.Add(err);
                    }

                    UpsertResult(indexToUpsertTo, dataObject.Environment, null, update);
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }

                    DisplayAndWriteError(dataObject, DisplayName, allErrors);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
        private void ExecuteConcreteAction(IDSFDataObject dataObject, int update)
        {
            var sharepointReadListTos = SharepointUtils.GetValidReadListItems(ReadListItems).ToList();

            if (sharepointReadListTos.Any())
            {
                var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId);
                var listOfIterators  = new Dictionary <string, IWarewolfIterator>();
                if (sharepointSource == null)
                {
                    var contents = ResourceCatalog.GetResourceContents(dataObject.WorkspaceID, SharepointServerResourceId);
                    sharepointSource = new SharepointSource(contents.ToXElement());
                }
                var env = dataObject.Environment;
                if (dataObject.IsDebugMode())
                {
                    AddInputDebug(env, update);
                }
                var sharepointHelper = sharepointSource.CreateSharepointHelper();
                var fields           = sharepointHelper.LoadFieldsForList(SharepointList, true);
                using (var ctx = sharepointHelper.GetContext())
                {
                    var camlQuery = _sharepointUtils.BuildCamlQuery(env, FilterCriteria, fields, update, RequireAllCriteriaToMatch);
                    var list      = ctx.Web.Lists.GetByTitle(SharepointList);
                    var listItems = list.GetItems(camlQuery);
                    ctx.Load(listItems);
                    ctx.ExecuteQuery();
                    var iteratorList = new WarewolfListIterator();
                    foreach (var sharepointReadListTo in sharepointReadListTos)
                    {
                        var warewolfIterator = new WarewolfIterator(env.Eval(sharepointReadListTo.VariableName, update));
                        iteratorList.AddVariableToIterateOn(warewolfIterator);
                        listOfIterators.Add(sharepointReadListTo.InternalName, warewolfIterator);
                    }
                    foreach (var listItem in listItems)
                    {
                        foreach (var warewolfIterator in listOfIterators)
                        {
                            listItem[warewolfIterator.Key] = warewolfIterator.Value.GetNextValue();
                        }
                        listItem.Update();
                        ctx.ExecuteQuery();
                    }
                }
                if (!string.IsNullOrEmpty(Result))
                {
                    env.Assign(Result, "Success", update);
                    AddOutputDebug(dataObject, env, update);
                }
            }
        }
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            try
            {
                RabbitMQSource = ResourceCatalog.GetResource <RabbitMQSource>(GlobalConstants.ServerWorkspaceID, RabbitMQSourceResourceId);
                if (RabbitMQSource == null)
                {
                    return(new List <string> {
                        ErrorResource.RabbitSourceHasBeenDeleted
                    });
                }

                if (!evaluatedValues.TryGetValue("QueueName", out string queueName) ||
                    !evaluatedValues.TryGetValue("Message", out string message))
                {
                    return(new List <string> {
                        ErrorResource.RabbitQueueNameAndMessageRequired
                    });
                }

                ConnectionFactory.HostName    = RabbitMQSource.HostName;
                ConnectionFactory.Port        = RabbitMQSource.Port;
                ConnectionFactory.UserName    = RabbitMQSource.UserName;
                ConnectionFactory.Password    = RabbitMQSource.Password;
                ConnectionFactory.VirtualHost = RabbitMQSource.VirtualHost;

                using (Connection = ConnectionFactory.CreateConnection())
                {
                    using (Channel = Connection.CreateModel())
                    {
                        Channel.ExchangeDeclare(queueName, ExchangeType.Direct, IsDurable, IsAutoDelete, null);
                        Channel.QueueDeclare(queueName, IsDurable, IsExclusive, IsAutoDelete, null);
                        Channel.QueueBind(queueName, queueName, "", new Dictionary <string, object>());

                        var basicProperties = Channel.CreateBasicProperties();
                        basicProperties.Persistent = true;
                        Channel.BasicPublish(queueName, "", basicProperties, Encoding.UTF8.GetBytes(message));
                    }
                }
                Dev2Logger.Debug($"Message published to queue {queueName}", GlobalConstants.WarewolfDebug);
                return(new List <string> {
                    "Success"
                });
            }
            catch (Exception ex)
            {
                Dev2Logger.Error("PublishRabbitMQActivity", ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.GetAllMessages());
            }
        }
示例#21
0
        public override List <DebugItem> GetDebugInputs(IExecutionEnvironment env, int update)
        {
            if (env == null)
            {
                return(_debugInputs);
            }

            base.GetDebugInputs(env, update);

            var(head, parameters, _, conditions) = GetEnvironmentInputVariables(env, update);

            var url          = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
            var headerString = string.Empty;

            if (head != null)
            {
                headerString = string.Join(" ", head.Select(a => a.Name + " : " + a.Value));
            }

            var debugItem = new DebugItem();

            AddDebugItem(new DebugItemStaticDataParams("", "URL"), debugItem);
            AddDebugItem(new DebugEvalResult(url.Address, "", env, update), debugItem);
            _debugInputs.Add(debugItem);
            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", "Query String"), debugItem);
            AddDebugItem(new DebugEvalResult(QueryString, "", env, update), debugItem);
            _debugInputs.Add(debugItem);

            debugItem = new DebugItem();
            AddDebugItem(new DebugItemStaticDataParams("", nameof(Headers)), debugItem);
            AddDebugItem(new DebugEvalResult(headerString, "", env, update), debugItem);
            _debugInputs.Add(debugItem);

            if (IsManualChecked)
            {
                debugItem = new DebugItem();
                AddDebugItem(new DebugItemStaticDataParams("", "Post Data"), debugItem);
                AddDebugItem(new DebugEvalResult(PostData, "", env, update), debugItem);
                _debugInputs.Add(debugItem);
            }

            if (IsFormDataChecked || IsUrlEncodedChecked)
            {
                AddDebugFormDataInputs(conditions);
            }

            return(_debugInputs);
        }
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            _messages = new List <string>();
            try
            {
                RabbitSource =
                    ResourceCatalog.GetResource <RabbitMQSource>(GlobalConstants.ServerWorkspaceID,
                                                                 RabbitMQSourceResourceId);
                if (RabbitSource == null || RabbitSource.ResourceType != enSourceType.RabbitMQSource.ToString())
                {
                    _messages.Add(ErrorResource.RabbitSourceHasBeenDeleted);
                    return(_messages);
                }

                if (!evaluatedValues.TryGetValue("QueueName", out var queueName))
                {
                    _messages.Add(ErrorResource.RabbitQueueNameRequired);
                    return(_messages);
                }

                if (!evaluatedValues.TryGetValue("Prefetch", out var prefetch))
                {
                    prefetch = string.Empty;
                }

                ConnectionFactory.HostName    = RabbitSource.HostName;
                ConnectionFactory.Port        = RabbitSource.Port;
                ConnectionFactory.UserName    = RabbitSource.UserName;
                ConnectionFactory.Password    = RabbitSource.Password;
                ConnectionFactory.VirtualHost = RabbitSource.VirtualHost;

                using (Connection = ConnectionFactory.CreateConnection())
                {
                    using (Channel = Connection.CreateModel())
                    {
                        PerformExecutionOnChannel(queueName, prefetch);
                    }
                }

                return(new List <string> {
                    _result
                });
            }
            catch (Exception ex)
            {
                Dev2Logger.Error("ConsumeRabbitMQActivity", ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.GetAllMessages());
            }
        }
        protected void ExecuteService(int update, out ErrorResultTO errors, IWcfAction method, IDSFDataObject dataObject, IOutputFormatter formater)
        {
            errors = new ErrorResultTO();
            Source = ResourceCatalog.GetResource <WcfSource>(dataObject.WorkspaceID, SourceId);
            var itrs = new List <IWarewolfIterator>(5);
            IWarewolfListIterator itrCollection = new WarewolfListIterator();
            var methodParameters = Inputs.Select(a => new MethodParameter {
                EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value, TypeName = a.TypeName
            }).ToList();

            BuildParameterIterators(update, methodParameters.ToList(), itrCollection, itrs, dataObject);
            try
            {
                while (itrCollection.HasMoreData())
                {
                    var pos = 0;
                    foreach (var itr in itrs)
                    {
                        var injectVal = itrCollection.FetchNextValue(itr);
                        var param     = methodParameters.ToList()[pos];


                        param.Value = param.EmptyToNull &&
                                      (injectVal == null ||
                                       string.Compare(injectVal, string.Empty,
                                                      StringComparison.InvariantCultureIgnoreCase) == 0)
                            ? null
                            : injectVal;

                        pos++;
                    }

                    var result = Source.ExecuteMethod(method);

                    if (result != null)
                    {
                        ResponseManager = new ResponseManager {
                            OutputDescription = OutputDescription, Outputs = Outputs, IsObject = IsObject, ObjectName = ObjectName
                        };
                        ResponseManager.PushResponseIntoEnvironment(result.ToString(), update, dataObject);
                    }
                }
            }
            catch (Exception e)
            {
                errors.AddError(e.Message);
            }
        }
示例#24
0
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            tmpErrors = new ErrorResultTO();

            var(head, query, postData) = ConfigureHttp(dataObject, update);

            var url = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);
            var webRequestResult = PerformWebPostRequest(head, query, url, postData);

            tmpErrors.MergeErrors(_errorsTo);

            ResponseManager = new ResponseManager {
                OutputDescription = OutputDescription, Outputs = Outputs, IsObject = IsObject, ObjectName = ObjectName
            };
            ResponseManager.PushResponseIntoEnvironment(webRequestResult, update, dataObject);
        }
示例#25
0
        protected override IList <OutputTO> TryExecuteConcreteAction(IDSFDataObject context, out ErrorResultTO error, int update)
        {
            _debugInputs = new List <DebugItem>();
            error        = new ErrorResultTO();
            IList <OutputTO> outputs = new List <OutputTO>();
            var colItr = new WarewolfListIterator();

            var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(context.WorkspaceID, SharepointServerResourceId);

            if (sharepointSource == null)
            {
                sharepointSource           = SharepointSource;
                SharepointServerResourceId = sharepointSource.ResourceID;
            }

            ValidateRequest();

            var serverInputFromItr = new WarewolfIterator(context.Environment.Eval(ServerInputPathFrom, update));

            colItr.AddVariableToIterateOn(serverInputFromItr);

            var serverInputFromTo = new WarewolfIterator(context.Environment.Eval(ServerInputPathTo, update));

            colItr.AddVariableToIterateOn(serverInputFromTo);

            if (context.IsDebugMode())
            {
                AddDebugInputItem(ServerInputPathFrom, "ServerInput Path From", context.Environment, update);
                AddDebugInputItem(ServerInputPathTo, "ServerInput Path To", context.Environment, update);
            }

            while (colItr.HasMoreData())
            {
                try
                {
                    ExecuteConcreteAction(outputs, colItr, sharepointSource, serverInputFromItr, serverInputFromTo);
                }
                catch (Exception e)
                {
                    outputs.Add(DataListFactory.CreateOutputTO(null));
                    error.AddError(e.Message);
                    break;
                }
            }

            return(outputs);
        }
示例#26
0
        public Guid GetResourceID(Dictionary <string, StringBuilder> requestArgs)
        {
            _existingResource = false;
            requestArgs.TryGetValue("ResourceDefinition", out StringBuilder resourceDefinition);
            if (resourceDefinition != null && resourceDefinition.Length != 0)
            {
                var xml      = resourceDefinition.ToXElement();
                var resource = new Resource(xml);

                var res = ResourceCatalog.GetResource(GlobalConstants.ServerWorkspaceID, resource.ResourceID);
                if (res != null)
                {
                    _existingResource = true;
                    return(res.ResourceID);
                }
            }
            return(Guid.Empty);
        }
示例#27
0
        public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            try
            {
                if (values == null)
                {
                    throw new InvalidDataContractException(ErrorResource.NoParameter);
                }
                string selectedSourceId = null;
                values.TryGetValue("SelectedSourceId", out StringBuilder tmp);
                if (tmp != null)
                {
                    selectedSourceId = tmp.ToString();
                }

                if (string.IsNullOrEmpty(selectedSourceId))
                {
                    throw new ArgumentNullException("SelectedSourceId");
                }
                Dev2Logger.Info("Find Options. " + selectedSourceId, GlobalConstants.WarewolfInfo);

                var source = ResourceCatalog.GetResource(theWorkspace.ID, Guid.Parse(selectedSourceId));
                var result = new List <IOption>();
                if (source.ResourceType == enSourceType.RabbitMQSource.ToString())
                {
                    var options = OptionConvertor.Convert(new RabbitMqOptions());
                    result.AddRange(options);
                }

                if (result != null)
                {
                    var serializer = new Dev2JsonSerializer();
                    return(serializer.SerializeToBuilder(result));
                }

                return(new StringBuilder());
            }
            catch (Exception err)
            {
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
                throw;
            }
        }
示例#28
0
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            _dataObject = dataObject;
            tmpErrors   = new ErrorResultTO();
            var webRequestResult = string.Empty;

            try
            {
                var(head, query, postData, conditions) = GetEnvironmentInputVariables(_dataObject.Environment, update);

                var source = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId);

                if (IsFormDataChecked)
                {
                    webRequestResult = PerformFormDataWebPostRequest(source, WebRequestMethod.Post, query, head, conditions);
                }
                else if (IsManualChecked)
                {
                    webRequestResult = PerformManualWebPostRequest(head, query, source, postData);
                }
            }
            catch (Exception ex)
            {
                tmpErrors.AddError(ex.Message);
            }
            finally
            {
                tmpErrors.MergeErrors(_errorsTo);

                var bytes    = webRequestResult.Base64StringToByteArray();
                var response = bytes.ReadToString();

                ResponseManager = new ResponseManager
                {
                    OutputDescription = OutputDescription,
                    Outputs           = Outputs,
                    IsObject          = IsObject,
                    ObjectName        = ObjectName
                };
                response = Scrubber.Scrub(response);
                ResponseManager.PushResponseIntoEnvironment(response, update, dataObject);
            }
        }
        PluginInvokeArgs BuidlPluginInvokeArgs(int update, IPluginConstructor constructor, INamespaceItem namespaceItem, IDSFDataObject dataObject)
        {
            var pluginSource = ResourceCatalog.GetResource <PluginSource>(GlobalConstants.ServerWorkspaceID, SourceId);

            return(new PluginInvokeArgs
            {
                AssemblyLocation = pluginSource.AssemblyLocation,
                AssemblyName = Namespace.AssemblyName,
                Fullname = namespaceItem.FullName,
                PluginConstructor = constructor,
                MethodsToRun = MethodsToRun?.Select(action =>
                {
                    if (action != null)
                    {
                        return new Dev2MethodInfo
                        {
                            Method = action.Method,
                            ID = action.ID,
                            Parameters = action.Inputs?.Select(p => new MethodParameter
                            {
                                Name = p.Name,
                                Value = GetEvaluatedResult(dataObject, p.Value, p.EmptyIsNull, update),
                                TypeName = p.TypeName,
                                EmptyToNull = p.EmptyIsNull,
                                IsRequired = p.RequiredField
                            } as IMethodParameter).ToList() ?? new List <IMethodParameter>(),
                            IsObject = action.IsObject,
                            MethodResult = action.MethodResult,
                            OutputVariable = action.OutputVariable,
                            IsVoid = action.IsVoid
                        } as IDev2MethodInfo;
                    }
                    return new Dev2MethodInfo();
                }).Where(info => !string.IsNullOrEmpty(info.Method)).ToList() ?? new List <IDev2MethodInfo>()
            });
        }
示例#30
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            var allErrors = new ErrorResultTO();

            try
            {
                var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId);
                if (sharepointSource == null)
                {
                    var contents = ResourceCatalog.GetResourceContents(dataObject.WorkspaceID, SharepointServerResourceId);
                    sharepointSource = new SharepointSource(contents.ToXElement());
                }
                var env = dataObject.Environment;
                if (dataObject.IsDebugMode())
                {
                    AddInputDebug(env, update);
                }
                ListItemCollection listItems;
                var sharepointHelper = sharepointSource.CreateSharepointHelper();
                var fields           = sharepointHelper.LoadFieldsForList(SharepointList, true);
                using (var ctx = sharepointHelper.GetContext())
                {
                    var camlQuery = _sharepointUtils.BuildCamlQuery(env, FilterCriteria, fields, update, RequireAllCriteriaToMatch);
                    var list      = sharepointHelper.LoadFieldsForList(SharepointList, ctx, false);
                    listItems = list.GetItems(camlQuery);
                    ctx.Load(listItems);
                    ctx.ExecuteQuery();
                }
                using (var ctx = sharepointHelper.GetContext())
                {
                    var list = ctx.Web.Lists.GetByTitle(SharepointList);
                    foreach (var item in listItems)
                    {
                        list.GetItemById(item.Id).DeleteObject();
                    }
                    list.Update();
                    ctx.ExecuteQuery();
                }
                var successfulDeleteCount = listItems.Count();
                if (!string.IsNullOrWhiteSpace(DeleteCount))
                {
                    dataObject.Environment.Assign(DeleteCount, successfulDeleteCount.ToString(), update);
                    env.CommitAssign();
                    AddOutputDebug(dataObject, update);
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Error("SharepointDeleteListItemActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("SharepointDeleteListItemActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }