private void AddAllFiles(IList <OutputTO> outputs, SharepointSource sharepointSource, string path, string recsetName, string fieldName) { var files = GetSharePointFiles(sharepointSource, path); var indexToUpsertTo = 1; foreach (var file in files) { var fullRecsetName = DataListUtil.CreateRecordsetDisplayValue(recsetName, fieldName, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); outputs.Add(DataListFactory.CreateOutputTO(DataListUtil.AddBracketsToValueIfNotExist(fullRecsetName), file)); indexToUpsertTo++; } }
protected override void Save(IEnvironmentModel environmentModel, dynamic jsonObj) { // ReSharper disable once MaximumChainedReferences string resName = jsonObj.resourceName; string resCat = HelperUtils.SanitizePath((string)jsonObj.resourcePath, resName); var sharepointSource = new SharepointSource { Server = Server, UserName = _userName, Password = _password, AuthenticationType = _authenticationType, ResourceName = resName, ResourcePath = resCat, IsNewResource = true, ResourceID = Guid.NewGuid() }; var source = sharepointSource.ToStringBuilder(); environmentModel.ResourceRepository.SaveResource(environmentModel, source, GlobalConstants.ServerWorkspaceID); environmentModel.ResourceRepository.ReloadResource(sharepointSource.ResourceID, ResourceType.Source, ResourceModelEqualityComparer.Current, true); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (ServerInputPath != null ? ServerInputPath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (LocalInputPath != null ? LocalInputPath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Overwrite.GetHashCode(); hashCode = (hashCode * 397) ^ (SharepointSource != null ? SharepointSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ SharepointServerResourceId.GetHashCode(); return(hashCode); } }
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); } } }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ IsFilesSelected.GetHashCode(); hashCode = (hashCode * 397) ^ IsFoldersSelected.GetHashCode(); hashCode = (hashCode * 397) ^ IsFilesAndFoldersSelected.GetHashCode(); hashCode = (hashCode * 397) ^ (ServerInputPath != null ? ServerInputPath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SharepointSource != null ? SharepointSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ SharepointServerResourceId.GetHashCode(); return(hashCode); } }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (ServerInputPathFrom != null ? ServerInputPathFrom.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ServerInputPathTo != null ? ServerInputPathTo.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DisplayName != null ? DisplayName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Overwrite.GetHashCode(); hashCode = (hashCode * 397) ^ (SharepointSource != null ? SharepointSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ SharepointServerResourceId.GetHashCode(); return(hashCode); } }
void SetSelectedSharepointServer(SharepointSource sharepointServerSource) { var selectSharepointSource = sharepointServerSource ?? SharepointServers.FirstOrDefault(d => d.ResourceID == SharepointServerResourceId); if (selectSharepointSource == null) { if (SharepointServers.FirstOrDefault(d => d.Equals(SelectSharepointSource)) == null) { SharepointServers.Insert(0, SelectSharepointSource); } selectSharepointSource = SelectSharepointSource; } SelectedSharepointServer = selectSharepointSource; }
public void SharepointListDesignerViewModelBase_SetSelectedSharepointServer_SetToServer_ShouldLoadLists() { //------------Setup for test-------------------------- var mockEnvironmentModel = new Mock <IServer>(); var mockResourceRepo = new Mock <IResourceRepository>(); var sharepointSource = new SharepointSource { ResourceName = "SharepointServer1", ResourceID = Guid.NewGuid() }; var sharepointSources = new List <SharepointSource> { sharepointSource }; mockResourceRepo.Setup(repository => repository.FindSourcesByType <SharepointSource>(It.IsAny <IServer>(), enSourceType.SharepointServerSource)).Returns(sharepointSources); var sharepointListTo = new SharepointListTo { FullName = "Share List", Fields = new List <ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Field 1", IsEditable = false, Name = "Name 1", IsRequired = false, Type = SharepointFieldType.Text } } }; var sharepointListTos = new List <SharepointListTo> { sharepointListTo }; mockResourceRepo.Setup(repository => repository.GetSharepointLists(It.IsAny <SharepointSource>())).Returns(sharepointListTos); mockEnvironmentModel.Setup(model => model.ResourceRepository).Returns(mockResourceRepo.Object); var sharepointListDesignerViewModelBase = CreateSharepointListDesignerViewModel(mockEnvironmentModel); //------------Execute Test--------------------------- sharepointListDesignerViewModelBase.SelectedSharepointServer = sharepointSource; //------------Assert Results------------------------- Assert.IsNotNull(sharepointListDesignerViewModelBase.SelectedSharepointServer); Assert.IsNotNull(sharepointListDesignerViewModelBase.Lists); Assert.AreEqual(2, sharepointListDesignerViewModelBase.Lists.Count); Assert.AreEqual(sharepointListDesignerViewModelBase.GetSelectAList, sharepointListDesignerViewModelBase.Lists[0]); Assert.AreEqual(sharepointListTo, sharepointListDesignerViewModelBase.Lists[1]); }
public void TestResourceXamlNullEmpty() { //arrange var expectedServerName = "someServerName"; var expectedUserName = "******"; var expectedPassword = "******"; var expectedAuthenticationType = AuthenticationType.User; var expectedValueMock = new Mock <IContextualResourceModel>(); var source = new SharepointSource() { Server = expectedServerName, UserName = expectedUserName, Password = expectedPassword, AuthenticationType = expectedAuthenticationType }; var xaml = new StringBuilder(source.ToXml().ToString()); expectedValueMock.SetupGet(it => it.WorkflowXaml).Returns(new StringBuilder()); var resourceId = Guid.NewGuid(); expectedValueMock.SetupGet(it => it.ID).Returns(resourceId); var resourceRepositoryMock = new Mock <IResourceRepository>(); resourceRepositoryMock.Setup( it => it.FetchResourceDefinition(_environmentMock.Object, It.IsAny <Guid>(), resourceId, false)) .Returns(new ExecuteMessage() { Message = xaml, HasError = false }); _environmentMock.SetupGet(it => it.ResourceRepository).Returns(resourceRepositoryMock.Object); _changedProperties.Clear(); //act _target.Resource = expectedValueMock.Object; var actualValue = _target.Resource; //assert Assert.AreSame(expectedValueMock.Object, actualValue); Assert.AreEqual(expectedServerName, _target.ServerName); Assert.AreEqual(expectedUserName, _target.UserName); Assert.AreEqual(expectedPassword, _target.Password); Assert.AreEqual(expectedAuthenticationType, _target.AuthenticationType); }
public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace) { var msg = new ExecuteMessage(); var serializer = new Dev2JsonSerializer(); try { Dev2Logger.Info("Save Sharepoint Source", GlobalConstants.WarewolfInfo); values.TryGetValue("SharepointServer", out StringBuilder resourceDefinition); var src = serializer.Deserialize <SharePointServiceSourceDefinition>(resourceDefinition); if (src.Path.EndsWith("\\")) { src.Path = src.Path.Substring(0, src.Path.LastIndexOf("\\", StringComparison.Ordinal)); } var res = new SharepointSource { AuthenticationType = src.AuthenticationType, Server = src.Server, Password = src.Password, UserName = src.UserName, ResourceID = src.Id, ResourceName = src.Name, IsSharepointOnline = src.IsSharepointOnline, }; ResourceCatalog.Instance.SaveResource(GlobalConstants.ServerWorkspaceID, res, src.Path); msg.HasError = false; } catch (Exception err) { msg.HasError = true; msg.Message = new StringBuilder(err.Message); Dev2Logger.Error(err, GlobalConstants.WarewolfError); } return(serializer.SerializeToBuilder(msg)); }
void AddBlankIndexDebugOutputs(IList <OutputTO> outputs, SharepointSource sharepointSource, string path) { if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Blank) { if (IsFoldersSelected) { var folders = GetSharePointFolders(sharepointSource, path); foreach (var folder in folders) { outputs.Add(DataListFactory.CreateOutputTO(Result, folder)); } } if (IsFilesSelected) { var files = GetSharePointFiles(sharepointSource, path); foreach (var file in files) { outputs.Add(DataListFactory.CreateOutputTO(Result, file)); } } if (IsFilesAndFoldersSelected) { var folderAndPathList = new List <string>(); folderAndPathList.AddRange(GetSharePointFiles(sharepointSource, path)); folderAndPathList.AddRange(GetSharePointFolders(sharepointSource, path)); foreach (var fileAndfolder in folderAndPathList) { outputs.Add(DataListFactory.CreateOutputTO(Result, fileAndfolder)); } } } }
public void SharepointListDesignerViewModelBase_SetSelectedList_SetToList_ShouldLoadFields() { //------------Setup for test-------------------------- var mockEnvironmentModel = new Mock <IServer>(); var mockResourceRepo = new Mock <IResourceRepository>(); var sharepointSource = new SharepointSource { ResourceName = "SharepointServer1", ResourceID = Guid.NewGuid() }; var sharepointSources = new List <SharepointSource> { sharepointSource }; mockResourceRepo.Setup(repository => repository.FindSourcesByType <SharepointSource>(It.IsAny <IServer>(), enSourceType.SharepointServerSource)).Returns(sharepointSources); var sharepointFieldTos = new List <ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Field 1", IsEditable = false, Name = "Name 1", IsRequired = false, Type = SharepointFieldType.Text }, new SharepointFieldTo { InternalName = "fMyField", IsEditable = false, Name = "fMyField 1", IsRequired = false, Type = SharepointFieldType.Text }, new SharepointFieldTo { InternalName = "1 Field Name", IsEditable = false, Name = "1 Field Name", IsRequired = false, Type = SharepointFieldType.Text }, new SharepointFieldTo { InternalName = "_Field", IsEditable = false, Name = "_Field Name", IsRequired = false, Type = SharepointFieldType.Text }, new SharepointFieldTo { InternalName = "_Field_", IsEditable = false, Name = "Field_Name_1", IsRequired = false, Type = SharepointFieldType.Text } }; var sharepointListTo = new SharepointListTo { FullName = "Share List", Fields = sharepointFieldTos }; var sharepointListTos = new List <SharepointListTo> { sharepointListTo }; mockResourceRepo.Setup(repository => repository.GetSharepointLists(It.IsAny <SharepointSource>())).Returns(sharepointListTos); mockResourceRepo.Setup(repository => repository.GetSharepointListFields(It.IsAny <ISharepointSource>(), It.IsAny <SharepointListTo>(), false)).Returns(sharepointFieldTos); mockEnvironmentModel.Setup(model => model.ResourceRepository).Returns(mockResourceRepo.Object); var sharepointListDesignerViewModelBase = CreateSharepointListDesignerViewModel(mockEnvironmentModel); sharepointListDesignerViewModelBase.SelectedSharepointServer = sharepointSource; //------------Assert Preconditions------------------- Assert.IsNotNull(sharepointListDesignerViewModelBase.SelectedSharepointServer); Assert.IsNotNull(sharepointListDesignerViewModelBase.Lists); Assert.AreEqual(2, sharepointListDesignerViewModelBase.Lists.Count); //------------Execute Test--------------------------- sharepointListDesignerViewModelBase.SelectedList = sharepointListTo; //------------Assert Results------------------------- Assert.IsNotNull(sharepointListDesignerViewModelBase.SelectedList); Assert.IsNotNull(sharepointListDesignerViewModelBase.ListItems); Assert.AreEqual(5, sharepointListDesignerViewModelBase.ListItems.Count); Assert.AreEqual("Name 1", sharepointListDesignerViewModelBase.ListItems[0].FieldName); Assert.AreEqual("Field 1", sharepointListDesignerViewModelBase.ListItems[0].InternalName); Assert.AreEqual(SharepointFieldType.Text.ToString(), sharepointListDesignerViewModelBase.ListItems[0].Type); Assert.IsFalse(sharepointListDesignerViewModelBase.ListItems[0].IsRequired); Assert.AreEqual("[[ShareList(*).Name1]]", sharepointListDesignerViewModelBase.ListItems[0].VariableName); Assert.AreEqual("[[ShareList(*).MyField1]]", sharepointListDesignerViewModelBase.ListItems[1].VariableName); Assert.AreEqual("[[ShareList(*).x0031_FieldName]]", sharepointListDesignerViewModelBase.ListItems[2].VariableName); Assert.AreEqual("[[ShareList(*).FieldName]]", sharepointListDesignerViewModelBase.ListItems[3].VariableName); Assert.AreEqual("[[ShareList(*).Fiele_1]]", sharepointListDesignerViewModelBase.ListItems[4].VariableName); }
public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace) { if (values == null) { throw new InvalidDataContractException(ErrorResource.NoParameter); } string serializedSource = null; string listName = null; string editableOnly = null; values.TryGetValue("SharepointServer", out StringBuilder tmp); if (tmp != null) { serializedSource = tmp.ToString(); } values.TryGetValue("ListName", out tmp); if (tmp != null) { listName = tmp.ToString(); } values.TryGetValue("OnlyEditable", out tmp); if (tmp != null) { editableOnly = tmp.ToString(); } var serializer = new Dev2JsonSerializer(); if (string.IsNullOrEmpty(serializedSource)) { var res = new ExecuteMessage(); res.HasError = true; res.SetMessage(ErrorResource.NoSharepointServerSet); Dev2Logger.Debug(ErrorResource.NoSharepointServerSet, GlobalConstants.WarewolfDebug); return(serializer.SerializeToBuilder(res)); } if (string.IsNullOrEmpty(listName)) { var res = new ExecuteMessage(); res.HasError = true; res.SetMessage(ErrorResource.NoSharepointListNameSet); Dev2Logger.Debug(ErrorResource.NoSharepointListNameSet, GlobalConstants.WarewolfDebug); return(serializer.SerializeToBuilder(res)); } var editableFieldsOnly = false; if (!string.IsNullOrEmpty(editableOnly)) { editableFieldsOnly = serializer.Deserialize <bool>(editableOnly); } try { listName = serializer.Deserialize <string>(listName); var sharepointSource = serializer.Deserialize <SharepointSource>(serializedSource); var source = ResourceCatalog.Instance.GetResource <SharepointSource>(theWorkspace.ID, sharepointSource.ResourceID); if (source == null) { var contents = ResourceCatalog.Instance.GetResourceContents(theWorkspace.ID, sharepointSource.ResourceID); source = new SharepointSource(contents.ToXElement()); } var fields = source.LoadFieldsForList(listName, editableFieldsOnly); return(serializer.SerializeToBuilder(fields)); } catch (Exception ex) { Dev2Logger.Error(ex, GlobalConstants.WarewolfError); var res = new DbColumnList(ex); return(serializer.SerializeToBuilder(res)); } }
private void ExecuteConcreteAction(IList <OutputTO> outputs, WarewolfListIterator colItr, SharepointSource sharepointSource, WarewolfIterator serverInputFromItr, WarewolfIterator serverInputFromTo) { var serverPath = colItr.FetchNextValue(serverInputFromItr); var localPath = colItr.FetchNextValue(serverInputFromTo); if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) != enRecordsetIndexType.Numeric) { if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { var recsetName = DataListUtil.ExtractRecordsetNameFromValue(Result); var fieldName = DataListUtil.ExtractFieldNameFromValue(Result); var newPath = MoveFile(sharepointSource, serverPath, localPath); var indexToUpsertTo = 1; foreach (var file in newPath) { var fullRecsetName = DataListUtil.CreateRecordsetDisplayValue(recsetName, fieldName, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); outputs.Add(DataListFactory.CreateOutputTO(DataListUtil.AddBracketsToValueIfNotExist(fullRecsetName), file)); indexToUpsertTo++; } } else { AddBlankIndexDebugOutputs(outputs, sharepointSource, serverPath, localPath); } } else { var newPath = MoveFile(sharepointSource, serverPath, localPath); var xmlList = string.Join(",", newPath.Select(c => c)); outputs.Add(DataListFactory.CreateOutputTO(Result)); outputs.Last().OutputStrings.Add(xmlList); } }
List <SharepointListTo> GetSharepointLists(SharepointSource sharepointSource) { var sharepointLists = _server.ResourceRepository.GetSharepointLists(sharepointSource); return(sharepointLists ?? new List <SharepointListTo>()); }
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); } } }
private void ExecuteConcreteAction(IList <OutputTO> outputs, WarewolfListIterator colItr, SharepointSource sharepointSource, WarewolfIterator inputItr) { var path = colItr.FetchNextValue(inputItr); if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) != enRecordsetIndexType.Numeric) { if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { var recsetName = DataListUtil.ExtractRecordsetNameFromValue(Result); var fieldName = DataListUtil.ExtractFieldNameFromValue(Result); if (IsFoldersSelected) { AddAllFolders(outputs, sharepointSource, path, recsetName, fieldName); } if (IsFilesSelected) { AddAllFiles(outputs, sharepointSource, path, recsetName, fieldName); } if (IsFilesAndFoldersSelected) { AddAllFilesAndFolders(outputs, sharepointSource, path, recsetName, fieldName); } } else { AddBlankIndexDebugOutputs(outputs, sharepointSource, path); } } else { if (IsFoldersSelected) { var folders = GetSharePointFolders(sharepointSource, path); var xmlList = string.Join(",", folders.Select(c => c)); outputs.Add(DataListFactory.CreateOutputTO(Result)); outputs.Last().OutputStrings.Add(xmlList); } if (IsFilesSelected) { var files = GetSharePointFiles(sharepointSource, path); var xmlList = string.Join(",", files.Select(c => c)); outputs.Add(DataListFactory.CreateOutputTO(Result)); outputs.Last().OutputStrings.Add(xmlList); } if (IsFilesAndFoldersSelected) { var folderAndPathList = new List <string>(); folderAndPathList.AddRange(GetSharePointFiles(sharepointSource, path)); folderAndPathList.AddRange(GetSharePointFolders(sharepointSource, path)); var xmlList = string.Join(",", folderAndPathList.Select(c => c)); outputs.Add(DataListFactory.CreateOutputTO(Result)); outputs.Last().OutputStrings.Add(xmlList); } } }
/// <summary> /// Executes the service /// </summary> /// <param name="values">The values.</param> /// <param name="theWorkspace">The workspace.</param> /// <returns></returns> public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace) { Dev2JsonSerializer serializer = new Dev2JsonSerializer(); if (values == null) { throw new InvalidDataContractException("No parameter values provided."); } string serializedSource = null; StringBuilder tmp; values.TryGetValue("SharepointServer", out tmp); if (tmp != null) { serializedSource = tmp.ToString(); } if (string.IsNullOrEmpty(serializedSource)) { ExecuteMessage message = new ExecuteMessage(); message.HasError = true; message.SetMessage("No sharepoint server set."); Dev2Logger.Log.Debug("No sharepoint server set."); return(serializer.SerializeToBuilder(message)); } SharepointSource source; SharepointSource runtimeSource = null; try { source = serializer.Deserialize <SharepointSource>(serializedSource); if (source.ResourceID != Guid.Empty) { runtimeSource = ResourceCatalog.Instance.GetResource <SharepointSource>(theWorkspace.ID, source.ResourceID); if (runtimeSource == null) { var contents = ResourceCatalog.Instance.GetResourceContents(theWorkspace.ID, source.ResourceID); runtimeSource = new SharepointSource(contents.ToXElement()); } } } catch (Exception e) { Dev2Logger.Log.Error(e); var res = new DbTableList("Invalid JSON data for sharepoint server parameter. Exception: {0}", e.Message); return(serializer.SerializeToBuilder(res)); } if (runtimeSource == null) { var res = new DbTableList("Invalid sharepoint server source"); Dev2Logger.Log.Debug("Invalid sharepoint server source"); return(serializer.SerializeToBuilder(res)); } if (string.IsNullOrEmpty(runtimeSource.Server)) { var res = new DbTableList("Invalid sharepoint server sent {0}.", serializedSource); Dev2Logger.Log.Debug(String.Format("Invalid sharepoint server sent {0}.", serializedSource)); return(serializer.SerializeToBuilder(res)); } try { Dev2Logger.Log.Info("Get Sharepoint Server Lists. " + source.Server); List <SharepointListTo> lists = runtimeSource.LoadLists(); return(serializer.SerializeToBuilder(lists)); } catch (Exception ex) { var tables = new DbTableList(ex); return(serializer.SerializeToBuilder(tables)); } }
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); } } }
public void SharepointListDesignerViewModelBase_RemoveFilterItem_ShouldRemoveFromCollection() { //------------Setup for test-------------------------- var mockEnvironmentModel = new Mock <IServer>(); var mockResourceRepo = new Mock <IResourceRepository>(); var sharepointSource = new SharepointSource { ResourceName = "SharepointServer1", ResourceID = Guid.NewGuid() }; var sharepointSources = new List <SharepointSource> { sharepointSource }; mockResourceRepo.Setup(repository => repository.FindSourcesByType <SharepointSource>(It.IsAny <IServer>(), enSourceType.SharepointServerSource)).Returns(sharepointSources); var sharepointFieldTos = new List <ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Field 1", IsEditable = false, Name = "Name 1", IsRequired = false, Type = SharepointFieldType.Text } }; var sharepointListTo = new SharepointListTo { FullName = "Share List", Fields = sharepointFieldTos }; var sharepointListTos = new List <SharepointListTo> { sharepointListTo }; mockResourceRepo.Setup(repository => repository.GetSharepointLists(It.IsAny <SharepointSource>())).Returns(sharepointListTos); mockResourceRepo.Setup(repository => repository.GetSharepointListFields(It.IsAny <ISharepointSource>(), It.IsAny <SharepointListTo>(), false)).Returns(sharepointFieldTos); mockEnvironmentModel.Setup(model => model.ResourceRepository).Returns(mockResourceRepo.Object); var sharepointReadListTos = new List <SharepointReadListTo> { new SharepointReadListTo("[[ShareList(*).Name1]]", "Name 1", "Field 1", SharepointFieldType.Text.ToString()) }; var modelItem = CreatePopulatedModelItem(sharepointSource.ResourceID, sharepointReadListTos, "Share List"); var sharepointListDesignerViewModelBase = new TestSharepointListDesignerViewModelBase(modelItem, new SynchronousAsyncWorker(), mockEnvironmentModel.Object, new Mock <IEventAggregator>().Object, false); //------------Assert Precondtion--------------------- Assert.IsNotNull(sharepointListDesignerViewModelBase.SelectedSharepointServer); Assert.IsNotNull(sharepointListDesignerViewModelBase.Lists); Assert.AreEqual(1, sharepointListDesignerViewModelBase.Lists.Count); Assert.IsNotNull(sharepointListDesignerViewModelBase.SelectedList); Assert.IsNotNull(sharepointListDesignerViewModelBase.ListItems); Assert.AreEqual(1, sharepointListDesignerViewModelBase.ListItems.Count); Assert.AreEqual("Name 1", sharepointListDesignerViewModelBase.ListItems[0].FieldName); Assert.AreEqual("Field 1", sharepointListDesignerViewModelBase.ListItems[0].InternalName); Assert.AreEqual(SharepointFieldType.Text.ToString(), sharepointListDesignerViewModelBase.ListItems[0].Type); Assert.IsFalse(sharepointListDesignerViewModelBase.ListItems[0].IsRequired); Assert.AreEqual("[[ShareList(*).Name1]]", sharepointListDesignerViewModelBase.ListItems[0].VariableName); Assert.AreEqual(2, sharepointListDesignerViewModelBase.ModelItemCollection.Count); //------------Execute Test--------------------------- sharepointListDesignerViewModelBase.RemoveAt(1); //------------Assert Results------------------------- Assert.AreEqual(1, sharepointListDesignerViewModelBase.ModelItemCollection.Count); }
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); } } }
public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace) { var serializer = new Dev2JsonSerializer(); if (values == null) { throw new InvalidDataContractException(ErrorResource.NoParameter); } string serializedSource = null; values.TryGetValue("SharepointServer", out StringBuilder tmp); if (tmp != null) { serializedSource = tmp.ToString(); } if (string.IsNullOrEmpty(serializedSource)) { var message = new ExecuteMessage(); message.HasError = true; message.SetMessage(ErrorResource.NoSharepointServerSet); Dev2Logger.Debug(ErrorResource.NoSharepointServerSet, GlobalConstants.WarewolfDebug); return(serializer.SerializeToBuilder(message)); } SharepointSource source; SharepointSource runtimeSource = null; try { source = serializer.Deserialize <SharepointSource>(serializedSource); if (source.ResourceID != Guid.Empty) { runtimeSource = ResourceCatalog.Instance.GetResource <SharepointSource>(theWorkspace.ID, source.ResourceID); if (runtimeSource == null) { var contents = ResourceCatalog.Instance.GetResourceContents(theWorkspace.ID, source.ResourceID); runtimeSource = new SharepointSource(contents.ToXElement()); } } } catch (Exception e) { Dev2Logger.Error(e, GlobalConstants.WarewolfError); var res = new DbTableList("Invalid JSON data for sharepoint server parameter. Exception: {0}", e.Message); return(serializer.SerializeToBuilder(res)); } if (runtimeSource == null) { var res = new DbTableList(ErrorResource.InvalidSharepointServerSource); Dev2Logger.Debug(ErrorResource.InvalidSharepointServerSource, GlobalConstants.WarewolfDebug); return(serializer.SerializeToBuilder(res)); } if (string.IsNullOrEmpty(runtimeSource.Server)) { var res = new DbTableList(ErrorResource.InvalidSharepointServerSent, serializedSource); Dev2Logger.Debug(string.Format(ErrorResource.InvalidSharepointServerSent, serializedSource), GlobalConstants.WarewolfDebug); return(serializer.SerializeToBuilder(res)); } try { Dev2Logger.Info("Get Sharepoint Server Lists. " + source.Server, GlobalConstants.WarewolfDebug); var lists = runtimeSource.LoadLists(); return(serializer.SerializeToBuilder(lists)); } catch (Exception ex) { var tables = new DbTableList(ex); return(serializer.SerializeToBuilder(tables)); } }
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); } } }
List <SharepointListTo> GetSharepointLists(SharepointSource dbSource) { var tables = _environmentModel.ResourceRepository.GetSharepointLists(dbSource); return(tables ?? new List <SharepointListTo>()); }