#pragma warning disable S1541 // Methods and properties should not be too complex #pragma warning disable S3776 // Cognitive Complexity of methods should not be too high void AddInputDebug(IExecutionEnvironment env, int update) #pragma warning restore S3776 // Cognitive Complexity of methods should not be too high #pragma warning restore S1541 // Methods and properties should not be too complex { var validItems = SharepointUtils.GetValidReadListItems(ReadListItems).ToList(); foreach (var varDebug in validItems) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", _indexCounter.ToString(CultureInfo.InvariantCulture)), debugItem); var variableName = varDebug.VariableName; if (!string.IsNullOrEmpty(variableName)) { AddDebugItem(new DebugItemStaticDataParams(varDebug.FieldName, "Field Name"), debugItem); AddDebugItem(new DebugEvalResult(variableName, "Variable", env, update), debugItem); } _indexCounter++; _debugInputs.Add(debugItem); } if (FilterCriteria != null && FilterCriteria.Any()) { var requireAllCriteriaToMatch = RequireAllCriteriaToMatch ? "Yes" : "No"; foreach (var varDebug in FilterCriteria) { if (string.IsNullOrEmpty(varDebug.FieldName)) { return; } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", _indexCounter.ToString(CultureInfo.InvariantCulture)), debugItem); var fieldName = varDebug.FieldName; if (!string.IsNullOrEmpty(fieldName)) { AddDebugItem(new DebugEvalResult(fieldName, "Field Name", env, update), debugItem); } var searchType = varDebug.SearchType; if (!string.IsNullOrEmpty(searchType)) { AddDebugItem(new DebugEvalResult(searchType, "Search Type", env, update), debugItem); } var valueToMatch = varDebug.ValueToMatch; if (!string.IsNullOrEmpty(valueToMatch)) { AddDebugItem(new DebugEvalResult(valueToMatch, "Value", env, update), debugItem); } AddDebugItem(new DebugEvalResult(requireAllCriteriaToMatch, "Require All Criteria To Match", env, update), debugItem); _indexCounter++; _debugInputs.Add(debugItem); } } }
public void SharepointUtils_GetValidReadListItems_NullList_EmptyList() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var validList = sharepointUtils.GetValidReadListItems(null); //------------Assert Results------------------------- Assert.IsNotNull(validList); Assert.AreEqual(0,validList.Count()); }
public void SharepointUtils_GetValidReadListItems_WhereVariableNameEmpty_ListWithoutItem() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var validList = sharepointUtils.GetValidReadListItems(new List<SharepointReadListTo> { new SharepointReadListTo("Bob", "Title", "Title", ""), new SharepointReadListTo("", "Title", "Title", "") }); //------------Assert Results------------------------- Assert.IsNotNull(validList); var tos = validList as IList<SharepointReadListTo> ?? validList.ToList(); Assert.AreEqual(1,tos.Count()); Assert.AreEqual("Bob",tos[0].VariableName); }
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); } } }
void AddInputDebug(IExecutionEnvironment env, int update) { var validItems = SharepointUtils.GetValidReadListItems(ReadListItems).ToList(); foreach (var varDebug in validItems) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", _indexCounter.ToString(CultureInfo.InvariantCulture)), debugItem); var variableName = varDebug.VariableName; if (!string.IsNullOrEmpty(variableName)) { AddDebugItem(new DebugItemStaticDataParams(varDebug.FieldName, "Field Name"), debugItem); AddDebugItem(new DebugEvalResult(variableName, "Variable", env, update), debugItem); } _indexCounter++; _debugInputs.Add(debugItem); } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); _indexCounter = 1; var allErrors = new ErrorResultTO(); try { var sharepointReadListTos = SharepointUtils.GetValidReadListItems(ReadListItems).ToList(); if (sharepointReadListTos.Any()) { TryExecute(dataObject, update, sharepointReadListTos); } } catch (Exception e) { Dev2Logger.Error("SharepointCreateListItemActivity", e, GlobalConstants.WarewolfError); allErrors.AddError(e.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { dataObject.Environment.Assign(Result, "Failed", update); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); DisplayAndWriteError(dataObject, DisplayName, allErrors); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); _indexCounter = 1; ErrorResultTO allErrors = new ErrorResultTO(); try { var sharepointReadListTos = _sharepointUtils.GetValidReadListItems(ReadListItems).ToList(); if (sharepointReadListTos.Any()) { var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId); Dictionary <string, IWarewolfIterator> 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); List 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); } } } catch (Exception e) { Dev2Logger.Error("SharepointUpdateListItemActivity", e); allErrors.AddError(e.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { dataObject.Environment.Assign(Result, "Failed", update); DisplayAndWriteError("SharepointUpdateListItemActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); _indexCounter = 1; ErrorResultTO allErrors = new ErrorResultTO(); try { var sharepointReadListTos = _sharepointUtils.GetValidReadListItems(ReadListItems).ToList(); if (sharepointReadListTos.Any()) { var sharepointSource = ResourceCatalog.Instance.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId); if (sharepointSource == null) { var contents = ResourceCatalog.Instance.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); List list = ctx.Web.Lists.GetByTitle(SharepointList); var listItems = list.GetItems(camlQuery); ctx.Load(listItems); ctx.ExecuteQuery(); var index = 1; foreach (var listItem in listItems) { foreach (var sharepointReadListTo in sharepointReadListTos) { var variableName = sharepointReadListTo.VariableName; var fieldToName = sharepointReadListTo.FieldName; var fieldName = fields.FirstOrDefault(field => field.Name == fieldToName); if (fieldName != null) { var listItemValue = ""; try { var sharepointValue = listItem[fieldName.InternalName]; if (sharepointValue != null) { var sharepointVal = GetSharepointValue(sharepointValue); listItemValue = sharepointVal.ToString(); } } catch (Exception e) { Dev2Logger.Log.Error(e); //Ignore sharepoint exception on retrieval not all fields can be retrieved. } var correctedVariable = variableName; if (DataListUtil.IsValueRecordset(variableName) && DataListUtil.IsStarIndex(variableName)) { correctedVariable = DataListUtil.ReplaceStarWithFixedIndex(variableName, index); } env.AssignWithFrame(new AssignValue(correctedVariable, listItemValue), update); } } index++; } } env.CommitAssign(); AddOutputDebug(dataObject, env, update); } } catch (Exception e) { Dev2Logger.Log.Error("SharepointReadListActivity", e); allErrors.AddError(e.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("SharepointReadListActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); _indexCounter = 1; ErrorResultTO allErrors = new ErrorResultTO(); try { var sharepointReadListTos = _sharepointUtils.GetValidReadListItems(ReadListItems).ToList(); if (sharepointReadListTos.Any()) { var sharepointSource = ResourceCatalog.Instance.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId); Dictionary <string, IWarewolfIterator> listOfIterators = new Dictionary <string, IWarewolfIterator>(); if (sharepointSource == null) { var contents = ResourceCatalog.Instance.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(); } } env.Assign(Result, "Success", update); AddOutputDebug(dataObject, env, update); } } catch (Exception e) { Dev2Logger.Log.Error("SharepointReadListActivity", e); allErrors.AddError(e.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { dataObject.Environment.Assign(Result, "Failed", update); DisplayAndWriteError("SharepointReadListActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }