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);
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
        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 void SharepointUtils_BuildCamlQuery_NoFilters_ShouldBeCreateAllItemsQuery()
 {
     //------------Setup for test--------------------------
     var sharepointUtils = new SharepointUtils();
     
     //------------Execute Test---------------------------
     var camlQuery = sharepointUtils.BuildCamlQuery(new ExecutionEnvironment(), new List<SharepointSearchTo>(), new List<ISharepointFieldTo>(),0);
     //------------Assert Results-------------------------
     Assert.AreEqual(CamlQuery.CreateAllItemsQuery().ViewXml,camlQuery.ViewXml);
 }
 public void SharepointUtils_BuildCamlQuery_ValidFilters_HasQueryWithAnd()
 {
     //------------Setup for test--------------------------
     var sharepointUtils = new SharepointUtils();
     
     //------------Execute Test---------------------------
     var camlQuery = sharepointUtils.BuildCamlQuery(new ExecutionEnvironment(), new List<SharepointSearchTo> { new SharepointSearchTo("Title", "Equal", "Bob", 1) { InternalName = "Title" }, new SharepointSearchTo("ID", "Equal", "1", 1) { InternalName = "ID" } }, new List<ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Title", Type = SharepointFieldType.Text }, new SharepointFieldTo { InternalName = "ID", Type = SharepointFieldType.Number } }, 0);
     //------------Assert Results-------------------------
     Assert.AreEqual("<View><Query><Where><And><FieldRef Name=\"Title\"></FieldRef><Value Type=\"Text\">Bob</Value>" + Environment.NewLine + "<FieldRef Name=\"ID\"></FieldRef><Value Type=\"Integer\">1</Value>" + Environment.NewLine + "</And></Where></Query></View>", camlQuery.ViewXml);
 }
 public void SharepointUtils_BuildCamlQuery_ValidFilter_In_RecSetResultCommaSeperated()
 {
     //------------Setup for test--------------------------
     var sharepointUtils = new SharepointUtils();
     var executionEnvironment = new ExecutionEnvironment();
     executionEnvironment.Assign("[[names().name]]", "bob,dora", 0);
     //------------Execute Test---------------------------
     var camlQuery = sharepointUtils.BuildCamlQuery(executionEnvironment, new List<SharepointSearchTo> { new SharepointSearchTo("Title", "In", "[[names(*).name]]", 1) { InternalName = "Title" } }, new List<ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Title", Type = SharepointFieldType.Text } }, 0);
     //------------Assert Results-------------------------
     Assert.AreEqual("<View><Query><Where><In><FieldRef Name=\"Title\"></FieldRef><Values><Value Type=\"Text\">bob</Value><Value Type=\"Text\">dora</Value></Values></In>" + Environment.NewLine + "</Where></Query></View>", camlQuery.ViewXml);
 }
Beispiel #7
0
        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);
                }
            }
        }