private void AddGetItemByIdMethod(ServiceObject so) { Method mGetItemById = Helper.CreateMethod(Constants.Methods.GetItemById, "Retrieve metadata for one item by it's ID", MethodType.Read); if (base.IsDynamicSiteURL) { Helper.AddSiteURLParameter(mGetItemById); } foreach (Property prop in so.Properties) { if (string.Compare(prop.Name, Constants.SOProperties.ID, true) == 0) { mGetItemById.InputProperties.Add(prop); mGetItemById.Validation.RequiredProperties.Add(prop); } if (!prop.IsInternal() && !prop.IsFile()) { mGetItemById.ReturnProperties.Add(prop); } if (so.IsDocumentLibrary() && prop.IsFileName()) { mGetItemById.ReturnProperties.Add(prop); } if (prop.IsLinkToItem()) { mGetItemById.ReturnProperties.Add(prop); } } so.Methods.Add(mGetItemById); }
private void AddGetItemsMethod(ServiceObject so) { Method mGetItems = Helper.CreateMethod(Constants.Methods.GetItems, "Retrieve items list", MethodType.List); if (base.IsDynamicSiteURL) { Helper.AddSiteURLParameter(mGetItems); } foreach (Property prop in so.Properties) { if (!prop.IsInternal() && !prop.IsFile()) { mGetItems.InputProperties.Add(prop); mGetItems.ReturnProperties.Add(prop); } if (so.IsSPFolderEnabled() && (prop.IsFolderName() || prop.IsRecursivelyName())) { mGetItems.InputProperties.Add(prop); } if ((so.IsDocumentLibrary() && prop.IsFileName()) || prop.IsLinkToItem()) { mGetItems.ReturnProperties.Add(prop); } } so.Methods.Add(mGetItems); }
private void AddServiceObjectMethods(ServiceObject so) { //add methods AddGetItemByIdMethod(so); AddUpdateItemByIdMethod(so); AddBreakItemInheritanceByIdMethod(so); AddResetItemInheritanceByIdMethod(so); AddAddItemPermissionByIdMethod(so); AddRemoveItemPermissionByIdMethod(so); AddGetItemPermissionByIdMethod(so); AddGetItemsMethod(so); if (!so.IsDocumentLibrary()) { AddCreateItemMethod(so); AddDeleteItemByIdMethod(so); AddGetItemByTitleMethod(so); } else { AddGetItemByNameMethod(so); AddCreateDocumentMethod(so); AddDeleteDocumentByIdMethod(so); AddGetDocumentByIdMethod(so); AddGetDocumentsMethod(so); AddRenameDocumentByIdMethod(so); AddCopyDocumentByNameMethod(so); AddMoveDocumentByNameMethod(so); AddCheckInDocumentByNameMethod(so); AddCheckInDocumentByIdMethod(so); AddCheckOutDocumentByIdMethod(so); AddCheckOutDocumentByNameMethod(so); if (so.IsDocumentSetLibrary()) { AddCreateDocumentSetByNameMethod(so); AddUpdateDocumentSetByNameMethod(so); AddGetDocSetMethod(so); AddGetDocumentSetsMethod(so); AddRenameDocumentSetMethod(so); AddDeleteDocumentSetMethod(so); } } if (so.IsSPFolderEnabled()) { AddCreateFolderMethod(so); AddDeleteFolderMethod(so); AddRenameFolderMethod(so); AddBreakFolderInheritanceByNameMethod(so); AddResetFolderInheritanceByNameMethod(so); AddAddFolderPermissionByNameMethod(so); AddRemoveFolderPermissionByNameMethod(so); AddGetFolderPermissionByIdMethod(so); AddMoveFolderMethod(so); } }
private void ExecuteGetItems() { ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0]; serviceObject.Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; string listTitle = serviceObject.GetListTitle(); GetDynamicListTitle(ref listTitle); string siteURL = GetSiteURL(); string folderName = base.GetStringProperty(Constants.SOProperties.FolderName); bool recursive = base.GetBoolProperty(Constants.SOProperties.Recursively); string listtype = serviceObject.MetaData.GetServiceElement <string>(Constants.InternalProperties.ListBaseType).ToString(); Properties searchProperties = Helpers.SPHelper.GetSearchFields(serviceObject.Properties); using (ClientContext context = InitializeContext(siteURL)) { Web spWeb = context.Web; List list = spWeb.Lists.GetByTitle(listTitle); context.Load(list); context.Load(list, l => l.Fields, l => l.DefaultDisplayFormUrl); context.Load(list.RootFolder); context.ExecuteQuery(); IEnumerable <ListItem> source = FilterListItems(context, spWeb, list, searchProperties, folderName, recursive, "BeginsWith"); foreach (ListItem listItem in source) { DataRow dataRow = results.NewRow(); foreach (Property prop in serviceObject.Properties) { if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile()) { Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem); } if (prop.IsFileName() && serviceObject.IsDocumentLibrary()) { var fileName = (string)listItem.FieldValues[Constants.SharePointProperties.FileLeafRef].ToString(); dataRow[prop.Name] = fileName; } if (prop.IsLinkToItem()) { string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id); dataRow[prop.Name] = strurl; } } results.Rows.Add(dataRow); } } }
private void AddGetListMethod(ServiceObject so) { Method mLists = Helper.CreateMethod(Constants.Methods.ListAllItems, "Retrieve item lists", MethodType.List); if (base.IsDynamicSiteURL) { Helper.AddSiteURLParameter(mLists); } foreach (Property prop in so.Properties) { if (!prop.IsInternal() && !prop.IsFile()) { mLists.InputProperties.Add(prop); mLists.ReturnProperties.Add(prop); } if (prop.IsFile()) { mLists.ReturnProperties.Add(prop); } if (string.Compare(prop.Name, Constants.SOProperties.FolderName, true) == 0) { mLists.InputProperties.Add(prop); } if (string.Compare(prop.Name, Constants.SOProperties.Recursively, true) == 0) { mLists.InputProperties.Add(prop); } if (so.IsDocumentLibrary() && prop.IsFileName()) { mLists.ReturnProperties.Add(prop); } } so.Methods.Add(mLists); }
private void AddInputServiceObjectPropertie(ServiceObject so) { //add recursively property Property recursivelyNameProperty = NewProperty(Constants.SOProperties.Recursively, Constants.SOProperties.Recursively_DisplayName, true, SoType.YesNo, "Recursively do this operation"); so.Properties.Add(recursivelyNameProperty); //add folder name property Property folderNameProperty = NewProperty(Constants.SOProperties.FolderName, Constants.SOProperties.FolderName_DisplayName, true, SoType.Text, "The foldername to apply this operation to"); so.Properties.Add(folderNameProperty); //add linkToItem property Property linkToItemProperty = NewProperty(Constants.SOProperties.LinkToItem, Constants.SOProperties.LinkToItem_DisplayName, true, SoType.Text, "Link To Item"); so.Properties.Add(linkToItemProperty); //add userLogins property Property userLoginsProperty = NewProperty(Constants.SOProperties.UserLogins, Constants.SOProperties.UserLogins_DisplayName, true, SoType.Text, "User logins separated by semicolon"); so.Properties.Add(userLoginsProperty); //add groupLogins property Property groupLoginsProperty = NewProperty(Constants.SOProperties.GroupLogins, Constants.SOProperties.GroupLogins_DisplayName, true, SoType.Text, "Group logins separated by semicolon"); so.Properties.Add(groupLoginsProperty); //add permission property Property permissionProperty = NewProperty(Constants.SOProperties.Permission, Constants.SOProperties.Permission_DisplayName, true, SoType.Text, "Role Definition Name"); so.Properties.Add(permissionProperty); //add userOrGroup property Property userOrGroupProperty = NewProperty(Constants.SOProperties.UserOrGroup, Constants.SOProperties.UserOrGroup_DisplayName, true, SoType.Text, "User or group login"); so.Properties.Add(userOrGroupProperty); //add DestinationURL property Property destinationURLProperty = NewProperty(Constants.SOProperties.DestinationURL, Constants.SOProperties.DestinationURL_DisplayName, true, SoType.Text, "The destination URL"); so.Properties.Add(destinationURLProperty); //add DestinationLibrary property Property destinationLibraryProperty = NewProperty(Constants.SOProperties.DestinationLibrary, Constants.SOProperties.DestinationLibrary_DisplayName, true, SoType.Text, "The system name of the list"); so.Properties.Add(destinationLibraryProperty); //add DestinationListLibrary property Property destinationListLibraryProperty = NewProperty(Constants.SOProperties.DestinationListLibrary, Constants.SOProperties.DestinationListLibrary_DisplayName, true, SoType.Text, "The system name of the list/library"); so.Properties.Add(destinationListLibraryProperty); //add DestinationFolder property Property destinationFolderProperty = NewProperty(Constants.SOProperties.DestinationFolder, Constants.SOProperties.DestinationFolder_DisplayName, true, SoType.Text, "The foldername to apply this operation to"); so.Properties.Add(destinationFolderProperty); if (so.IsDocumentLibrary()) { //add overwriteExistingDocument property Property overwriteExistingDocument = NewProperty(Constants.SOProperties.OverwriteExistingDocument, Constants.SOProperties.OverwriteExistingDocument_DisplayName, true, SoType.YesNo, "Overwrite Existing Document"); so.Properties.Add(overwriteExistingDocument); //add newFileName property Property newFileNameProperty = NewProperty(Constants.SOProperties.NewFileName, Constants.SOProperties.NewFileName_DisplayName, true, SoType.Text, "New File Name"); so.Properties.Add(newFileNameProperty); //properties used in Check In Functionality Property checkInComments = NewProperty(Constants.SOProperties.CheckInComment, Constants.SOProperties.CheckInComment_DisplayName, true, SoType.Memo, "Check In Comments"); so.Properties.Add(checkInComments); Property retainCheckout = NewProperty(Constants.SOProperties.RetainCheckOut, Constants.SOProperties.RetainCheckOut_DisplayName, true, SoType.YesNo, "Retain Checkout"); so.Properties.Add(retainCheckout); Property useCheckedInVersion = NewProperty(Constants.SOProperties.UseCheckedInVersion, Constants.SOProperties.UseCheckedInVersion_DisplayName, true, SoType.YesNo, "Used Checked In version"); so.Properties.Add(useCheckedInVersion); //property use in CheckOut functionality Property useCheckedOutVersion = NewProperty(Constants.SOProperties.UseCheckedOutVersion, Constants.SOProperties.UseCheckedOutVersion_DisplayName, true, SoType.YesNo, "Used Checked Out version"); so.Properties.Add(useCheckedOutVersion); if (so.IsDocumentSetLibrary()) { //property use in CheckOut functionality Property docSetName = NewProperty(Constants.SOProperties.DocSetName, Constants.SOProperties.DocSetName_DisplayName, true, SoType.Text, "Document Set Name"); so.Properties.Add(docSetName); Property docSetNewName = NewProperty(Constants.SOProperties.DocSetNewName, Constants.SOProperties.DocSetNewName_DisplayName, true, SoType.Text, "New Document Set Name"); so.Properties.Add(docSetNewName); } } }
private void AddGetItemByNameMethod(ServiceObject so) { Method mGetItemByName = Helper.CreateMethod(Constants.Methods.GetItemByName, "Retrieve metadata for one item by it's document name", MethodType.List); if (base.IsDynamicSiteURL) { Helper.AddSiteURLParameter(mGetItemByName); } foreach (Property prop in so.Properties) { if (string.Compare(prop.Name, Constants.SOProperties.FileName, true) == 0) { mGetItemByName.InputProperties.Add(prop); mGetItemByName.Validation.RequiredProperties.Add(prop); } if (so.IsSPFolderEnabled() == true && ( prop.IsFolderName() || prop.IsRecursivelyName())) { mGetItemByName.InputProperties.Add(prop); } if ((!prop.IsInternal() && !prop.IsFile()) || prop.IsLinkToItem() || (so.IsDocumentLibrary() && prop.IsFileName())) { mGetItemByName.ReturnProperties.Add(prop); } } so.Methods.Add(mGetItemByName); }
private void CreateListItem() { ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0]; serviceObject.Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; string listTitle = serviceObject.GetListTitle(); string siteURL = GetSiteURL(); DataRow dataRow = results.NewRow(); using (ClientContext context = InitializeContext(siteURL)) { Web spWeb = context.Web; List list = spWeb.Lists.GetByTitle(listTitle); FieldCollection fieldColl = list.Fields; context.Load(list, d => d.RootFolder.Name); context.Load(fieldColl); context.ExecuteQuery(); ListItem newItem = null; //get folder path string folderPath = string.Empty; if (serviceObject.Properties[Constants.SOProperties.FolderName].Value != null) { folderPath = serviceObject.Properties[Constants.SOProperties.FolderName].Value.ToString(); } if (!serviceObject.IsDocumentLibrary()) { ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); itemCreateInfo.FolderUrl = string.Empty; if (!string.IsNullOrEmpty(folderPath)) { itemCreateInfo.FolderUrl = string.Format("{0}/lists/{1}/{2}", siteURL, list.Title, folderPath.Trim('/')); } newItem = list.AddItem(itemCreateInfo); } else { FileCreationInformation fileCreateInfo = new FileCreationInformation(); //TODO: XmlDocument would load everything into memory. XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(serviceObject.Properties[Constants.InternalProperties.FileLeafRef].Value.ToString()); foreach (XmlNode xn in xmlDocument) { XmlNode name = xn.SelectSingleNode("name"); XmlNode content = xn.SelectSingleNode("content"); if (name != null) { if (string.IsNullOrEmpty(folderPath)) { fileCreateInfo.Url = string.Concat(GetSiteURL(), "/", list.RootFolder.Name, "/", name.InnerText); } else { fileCreateInfo.Url = string.Concat(GetSiteURL(), "/", list.RootFolder.Name, "/", folderPath, "/", name.InnerText); } } if (content != null) { // byte[] fileContent = Convert.FromBase64String(content.InnerText); //fileCreateInfo.Content = fileContent; fileCreateInfo.ContentStream = new System.IO.MemoryStream(Convert.FromBase64String(content.InnerText)); } } fileCreateInfo.Overwrite = true; File newFile = null; if (string.IsNullOrEmpty(folderPath)) { newFile = list.RootFolder.Files.Add(fileCreateInfo); } else { Folder currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.Name, folderPath.Trim('/'))); context.Load(currentFolder); context.ExecuteQuery(); newFile = currentFolder.Files.Add(fileCreateInfo); } context.Load(newFile); context.ExecuteQuery(); newItem = newFile.ListItemAllFields; context.Load(newItem); context.ExecuteQuery(); } foreach (Property prop in serviceObject.Properties) { if (prop.Value != null && !prop.IsFile() && string.Compare(prop.Name, Constants.SOProperties.FolderName, true) != 0) { Helpers.SPHelper.AssignFieldValue(newItem, prop); } } newItem.Update(); context.ExecuteQuery(); dataRow[Constants.SOProperties.ID] = newItem.Id; results.Rows.Add(dataRow); } }
//SPList is configured just to create service object of SP Lists public override List <ServiceObject> DescribeServiceObjects() { List <ServiceObject> SOs = new List <ServiceObject>(); using (ClientContext context = InitializeContext(base.SiteURL)) { Web spWeb = context.Web; ListCollection lists = spWeb.Lists; context.Load(lists); context.ExecuteQuery(); foreach (List list in lists) { if (list.Hidden == false || (list.Hidden && base.IncludeHiddenLists)) { ServiceObject so = Helper.CreateServiceObject(list.Title, list.Title, list.Description); so.MetaData.DisplayName = list.Title; so.MetaData.Description = list.Description; if (list.BaseType == BaseType.DocumentLibrary) { so.MetaData.ServiceProperties.Add(Constants.InternalProperties.ServiceFolder, "Document Libraries"); } else { so.MetaData.ServiceProperties.Add(Constants.InternalProperties.ServiceFolder, "List Items"); } so.MetaData.ServiceProperties.Add(Constants.InternalProperties.ListId, list.Id); so.MetaData.ServiceProperties.Add(Constants.InternalProperties.ListTitle, list.Title); so.MetaData.ServiceProperties.Add(Constants.InternalProperties.IsFolderEnabled, list.EnableFolderCreation); so.MetaData.ServiceProperties.Add(Constants.InternalProperties.ListBaseType, list.BaseType); FieldCollection fields = list.Fields; context.Load(fields); context.ExecuteQuery(); foreach (Field f in fields) { if (f.Hidden == false || (f.Hidden == true && base.IncludeHiddenFields)) { // We'll use InternalName as the system name and Title as the display name. // See http://blogs.perficient.com/microsoft/2009/04/static-name-vs-internal-name-vs-display-name-in-sharepoint/ for some background // Some fields have no title, so then we just take the internalname. string fieldTitle = f.Title; if (string.IsNullOrEmpty(fieldTitle)) { fieldTitle = f.InternalName; } // Because the field title can be duplicate, we see if it already exists. // If it does, we change the displayname of both existing and newly found property to something unique. // This behaviour can also be forced by the Show Internal Names option. Property existingProp = GetExistingProperty(so, fieldTitle); string displayName = fieldTitle; if (ShowInternalNames) { displayName = string.Format("{0} ({1})", fieldTitle, f.InternalName); } if (existingProp != null) { existingProp.MetaData.DisplayName = string.Format("{0} ({1})", existingProp.MetaData.GetServiceElement <string>(Constants.InternalProperties.Title), existingProp.MetaData.GetServiceElement <string>(Constants.InternalProperties.InternalName)); displayName = string.Format("{0} ({1})", fieldTitle, f.InternalName); } AddFieldProperty(so, f); FieldType _fieldtype; //We will find the Fieldtype from the MapHelper class (To get the correctoutput for field type Calculated) SoType soType = MapHelper.SPTypeField(f, out _fieldtype); Property prop = Helper.CreateSpecificProperty(f.InternalName, displayName, f.Description, soType); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.Hidden, f.Hidden); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.Title, fieldTitle); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.InternalName, f.InternalName); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.Id, f.Id); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.ReadOnly, AssignReadonly(f)); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.Required, f.Required); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.FieldTypeKind, _fieldtype); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.SPFieldType, f.TypeAsString); prop.MetaData.ServiceProperties.Add(Constants.InternalProperties.Internal, false); so.Properties.Add(prop); } } so.Properties.Add(NewProperty(Constants.SOProperties.DestinationURL, Constants.SOProperties.DestinationURL_DisplayName, true, SoType.Text, "The destination URL")); so.Properties.Add(NewProperty(Constants.SOProperties.DestinationListTitle, Constants.SOProperties.DestinationListTitle_DisplayName, true, SoType.Text, "The system name of the list")); so.Properties.Add(NewProperty(Constants.SOProperties.DestinationFolder, Constants.SOProperties.DestinationFolder_DisplayName, true, SoType.Text, "The foldername to apply this operation to")); so.Properties.Add(NewProperty(Constants.SOProperties.FolderName, Constants.SOProperties.FolderName, true, SoType.Text, "The foldername to apply this operation to")); so.Properties.Add(NewProperty(Constants.SOProperties.Recursively, Constants.SOProperties.Recursively, true, SoType.YesNo, "Recursively do this operation")); AddGetByIdMethod(so); AddCreateMethod(so); AddDeleteMethod(so); AddGetListMethod(so); AddUpdateMethod(so); if (so.IsSPFolderEnabled()) { AddCreateFolderMethod(so); AddDeleteFolderMethod(so); } //Non library methods if (!so.IsDocumentLibrary()) { AddMoveListItemMethod(so); AddCopyListItemMethod(so); } SOs.Add(so); } } return(SOs); } }