コード例 #1
0
        private void PreCheckFields(BaseCollection <DCTFileField> fileFields, DocLibContext context)
        {
            (null == fileFields || fileFields.Count == 0).TrueThrow <ArgumentException>("Field集合为空或元素个数为0");

            foreach (DCTFileField fileField in fileFields)
            {
                (null == fileField.Field).TrueThrow <ArgumentException>("Field元素为空。");
                (string.IsNullOrEmpty(fileField.Field.Title) && string.IsNullOrEmpty(fileField.Field.InternalName) && string.IsNullOrEmpty(fileField.Field.ID)).TrueThrow <ArgumentException>("要设置文件夹的Field,请提供ID、Internal Name或Title.");

                if (string.IsNullOrEmpty(fileField.Field.InternalName))
                {
                    Field field = null;

                    if (!string.IsNullOrEmpty(fileField.Field.ID))
                    {
                        field = context.BaseList.Fields.GetById(new Guid(fileField.Field.ID));
                    }
                    else
                    if ((!string.IsNullOrEmpty(fileField.Field.Title)))
                    {
                        field = context.BaseList.Fields.GetByTitle(fileField.Field.Title);
                    }

                    context.Load(field);
                    context.ExecuteQuery();
                    fileField.Field.InternalName = field.InternalName;
                }
            }
        }
コード例 #2
0
        //TODO: GetxxxByID是否是个通用的逻辑?
        public DCTFile DCMGetFileById(int fileId)
        {
            (fileId <= 0).TrueThrow <ArgumentException>("ID({0})无效,请传入大于0的值.", fileId);

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                string uri = LoadUri(new DCTFile()
                {
                    ID = fileId
                }, context);
                File file = context.Web.GetFileByServerRelativeUrl(uri);

                context.Load(file);
                context.Load(file.Author);
                context.ExecuteQuery();

                if (file.CheckOutType != CheckOutType.None)
                {
                    context.Load(file.CheckedOutByUser);
                }

                context.Load(file.ListItemAllFields);
                context.Load(file.ModifiedBy);
                context.ExecuteQuery();

                DCTFile dctFile = new DCTFile();
                dctFile.AbsoluteUri = UriHelper.CombinePath(context.Url, uri);
                DCTConverterHelper.Convert(file, dctFile);

                return(dctFile);
            }
        }
コード例 #3
0
        private static BaseCollection <DCTFileField> BuildFileFields(DocLibContext context, IEnumerable <Field> spfields, File file)
        {
            BaseCollection <DCTFileField> results = new BaseCollection <DCTFileField>();

            context.Load(file.ListItemAllFields);
            context.Load(context.BaseList.Fields);
            context.ExecuteQuery();

            foreach (Field field in spfields)
            {
                DCTFileField fileField = new DCTFileField();
                DCTFieldInfo fieldInfo = new DCTFieldInfo();

                DCTConverterHelper.Convert(field, fieldInfo);

                if (string.IsNullOrEmpty(fieldInfo.ID))
                {
                    continue;
                }

                fileField.Field      = fieldInfo;
                fileField.FieldValue = file.ListItemAllFields[field.InternalName] == null ? "" : file.ListItemAllFields[field.InternalName].ToString();

                results.Add(fileField);
            }

            return(results);
        }
コード例 #4
0
        //TODO:重复功能
        private static File getFileById(int fileId, DocLibContext context)
        {
            ListItem listItem = GetListItemById(fileId, context);

            (listItem == null).TrueThrow <TargetNotFoundException>("文件(ID为{0})未找到。", fileId);
            return(listItem.File);
        }
コード例 #5
0
        public DCTFolder DCMGetFolderByUri(string uri)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                Folder folder = clientContext.Web.GetFolderByServerRelativeUrl(uri);
                clientContext.Load(folder);

                CamlQuery query = new CamlQuery();
                query.ViewXml = Caml.SimpleView(Caml.Field("FileRef").Eq(Caml.Value("Text", uri)), CamlBuilder.ViewType.RecursiveAll).ToCamlString();

                ListItemCollection items = clientContext.BaseList.GetItems(query);

                clientContext.Load(items);

                DCTFolder result;
                try
                {
                    clientContext.ExecuteQuery();
                    if (string.Compare(folder.ServerRelativeUrl, this.DCMGetRootFolder().Uri, true) == 0)
                        result = new DCTFolder() { ID = 0, IsRootFolder = true };
                    else
                        result = new DCTFolder() { ID = items[0].Id, IsRootFolder = false };

                    DCTConverterHelper.Convert(folder, result);
                }
                catch
                {

                    result = null;
                }

                return result;
            }
        }
コード例 #6
0
        private string LoadUri(DCTStorageObject folder, DocLibContext context)
        {
            if (folder is DCTFolder)
            {
                if ((folder as DCTFolder).IsRootFolder)
                {
                    context.Load(context.BaseList.RootFolder);
                    context.ExecuteQuery();

                    return(context.BaseList.RootFolder.ServerRelativeUrl);
                }
            }

            if (folder.Uri.IsNotEmpty())
            {
                return(folder.Uri);
            }

            ListItem listItem = GetListItemById(folder.ID, context);

            (listItem == null).TrueThrow <TargetNotFoundException>("文件或文件夹(ID={0})不存在。", folder.ID);


            return(listItem["FileRef"].ToString());
        }
コード例 #7
0
        private RoleDefinitionBindingCollection BuildRoleDefninitionBinding(DocLibContext context, DCTRoleAssignment dctRoleAssignment, out bool ignore)
        {
            RoleDefinitionBindingCollection binding = new RoleDefinitionBindingCollection(context);
            int count = 0;

            foreach (DCTRoleDefinition dctRoleDefinition in dctRoleAssignment.RoleDefinitions)
            {
                if (dctRoleDefinition.Name == IgnoreRole)
                {
                    continue;
                }
                RoleDefinition spRoleDefinition = null;

                if (!string.IsNullOrEmpty(dctRoleDefinition.Name))
                {
                    spRoleDefinition = context.Web.RoleDefinitions.GetByName(dctRoleDefinition.Name);
                }
                else
                {
                    spRoleDefinition = context.Web.RoleDefinitions.GetById(dctRoleDefinition.ID);
                }

                context.Load(spRoleDefinition);
                context.ExecuteQuery();
                binding.Add(spRoleDefinition);
                count++;
            }

            ignore = (count == 0);

            return(binding);
        }
コード例 #8
0
        public BaseCollection <DCTSearchResult> DCMSearchDoc(string[] keyWords)
        {
            MCS.Library.Core.ServerInfo  serverInfo  = MossServerInfoConfigurationSettings.GetConfig().Servers["documentServer"].ToServerInfo();
            System.Net.NetworkCredential Credentials = new System.Net.NetworkCredential(serverInfo.Identity.LogOnName, serverInfo.Identity.Password, serverInfo.Identity.Domain);
            string       searchServiceUrl            = MCS.Library.Core.UriHelper.CombinePath(MossServerInfoConfigurationSettings.GetConfig().Servers["documentServer"].ServerName, MossServerInfoConfigurationSettings.GetConfig().Servers["documentServer"].MossSearchServiceUrl);
            QueryService queryService = new QueryService(searchServiceUrl, Credentials);

            BaseCollection <DCTSearchResult> result = new BaseCollection <DCTSearchResult>();
            StringBuilder queryXml = new StringBuilder();

            queryXml.Append("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\">");
            queryXml.Append("<Query domain=\"QDomain\">");
            queryXml.Append("<SupportedFormats>");
            queryXml.Append("<Format>");
            queryXml.Append("urn:Microsoft.Search.Response.Document.Document");
            queryXml.Append("</Format>");
            queryXml.Append("</SupportedFormats>");
            queryXml.Append("<Range>");
            queryXml.Append("<Count>50</Count>");
            queryXml.Append("</Range>");
            queryXml.Append("<Context>");
            queryXml.Append("<QueryText language=\"en-US\" type=\"STRING\">");
            foreach (string item in keyWords)
            {
                queryXml.Append(string.Format("{0} ", item));
            }

            queryXml.Append("</QueryText>");
            queryXml.Append("</Context>");
            queryXml.Append("</Query>");

            queryXml.Append("</QueryPacket>");
            try
            {
                using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
                {
                    DataSet dsQueryResult = queryService.QueryEx(queryXml.ToString());
                    IEnumerable <DataRow> drQueryResult = from row in dsQueryResult.Tables[0].AsEnumerable()
                                                          where row.Field <bool>("IsDocument") == true
                                                          select row;
                    foreach (var item in drQueryResult)
                    {
                        DCTSearchResult searchResult = new DCTSearchResult();
                        searchResult.Title = item["Title"].ToString();
                        searchResult.Size  = int.Parse(item["Size"].ToString());
                        searchResult.HitHighlightedSummary = item["HitHighlightedSummary"].ToString();
                        searchResult.LastModifiedDate      = DateTime.Parse(item["Write"].ToString());
                        searchResult.Path = item["Path"].ToString().ToLower().Replace(context.Url.ToLower(), "");
                        result.Add(searchResult);
                    }
                    return(result);
                }
            }
            catch (SoapException ex)
            {
                throw ex;
            }
        }
コード例 #9
0
 public void DCMCheckIn(int fileId, string comment, MCS.Library.SOA.DocServiceContract.DCTCheckinType checkInType)
 {
     using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
     {
         File file = getFileById(fileId, context);
         file.CheckIn(comment, (CheckinType)checkInType);
         context.ExecuteQuery();
     }
 }
コード例 #10
0
		public BaseCollection<DCTFile> DCMQueryDocByField(BaseCollection<DCTFileField> fields)
		{
			BaseCollection<DCTFile> files = new BaseCollection<DCTFile>();
			using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				CamlQuery query = new CamlQuery();
				CamlExpression caml = null;
				foreach (DCTFileField item in fields)
				{
					string valueText = string.Empty;
					switch (item.Field.ValueType)
					{
						case DCTFieldType.Boolean:
							break;
						case DCTFieldType.DateTime:
							break;
						case DCTFieldType.Decimal:
							break;
						case DCTFieldType.Integer:
							valueText = "Counter";
							break;
						case DCTFieldType.Note:
							break;
						case DCTFieldType.Text:
							valueText = "Text";
							break;
						case DCTFieldType.User:
							break;
						default:
							break;
					}
					if (caml == null)
					{
						caml = Caml.Field(item.Field.InternalName).Eq(Caml.Value(valueText, item.FieldValue));
					}
					else
					{
						caml = caml.And(Caml.Field(item.Field.InternalName).Eq(Caml.Value(valueText, item.FieldValue)));
					}
				}

				query.ViewXml = Caml.SimpleView(caml, CamlBuilder.ViewType.RecursiveAll).ToCamlString();

				ListItemCollection items = clientContext.BaseList.GetItems(query);
				clientContext.Load(items);

				clientContext.ExecuteQuery();

				foreach (ListItem item in items)
				{
					DCTFile file = new DCTFile();
					DCTConverterHelper.Convert(item, file);
					files.Add(file);
				}
			}
			return files;
		}
コード例 #11
0
        public byte[] DCMGetVersionFileContent(int fileId, int versionId)
        {
            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                File file = getFileById(fileId, context);

                return(getVersionContetById(file, versionId, context));
            }
        }
コード例 #12
0
 public void DCMUndoCheckOut(int fileId)
 {
     using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
     {
         File file = getFileById(fileId, context);
         file.UndoCheckOut();
         context.ExecuteQuery();
     }
 }
コード例 #13
0
		public byte[] DCMGetVersionFileContent(int fileId, int versionId)
		{
			using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				File file = getFileById(fileId, context);

				return getVersionContetById(file, versionId, context);
			}
		}
コード例 #14
0
		public byte[] DCMBuildDocument(string templateUri, DCTWordDataObject wordData)
		{
			using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				byte[] templateBinary = context.OpenBinary(templateUri);
				
				return WordEntry.GenerateDocument(templateBinary, wordData);
			}
		}
コード例 #15
0
        public byte[] DCMBuildDocument(string templateUri, DCTWordDataObject wordData)
        {
            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                byte[] templateBinary = context.OpenBinary(templateUri);

                return(WordEntry.GenerateDocument(templateBinary, wordData));
            }
        }
コード例 #16
0
		public void DCMUndoCheckOut(int fileId)
		{
			using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				File file = getFileById(fileId, context);
				file.UndoCheckOut();
				context.ExecuteQuery();
			}
		}
コード例 #17
0
        public void DCMAddUserRole(int storageObjID, string userAccount, string rolename)
        {
            (storageObjID > 0).FalseThrow <ArgumentException>("ID值{0}无效,请传入大于0的值.", storageObjID);
            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                context.Load(context.Web.RoleDefinitions);
                context.ExecuteQuery();
                RoleDefinition selectedRoleDef = null;
                foreach (RoleDefinition role in context.Web.RoleDefinitions)
                {
                    if (role.Name == rolename)
                    {
                        selectedRoleDef = role;
                        break;
                    }
                }
                if (null == selectedRoleDef)
                {
                    return;
                }
                context.Load(selectedRoleDef);
                ListItem listItem = GetListItemById(storageObjID, context);
                if (null == listItem)
                {
                    return;
                }
                context.Load(listItem);
                context.Load(listItem.RoleAssignments);
                context.ExecuteQuery();

                RoleAssignmentCollection roleAssignments = listItem.RoleAssignments;

                bool userFound = false;
                foreach (RoleAssignment roleAssignment in roleAssignments)
                {
                    context.Load(roleAssignment.Member);
                    context.ExecuteQuery();
                    if (roleAssignment.Member.LoginName != userAccount)
                    {
                        continue;
                    }
                    userFound = true;
                    roleAssignment.RoleDefinitionBindings.Add(selectedRoleDef);
                    roleAssignment.Update();
                }
                if (!userFound)
                {
                    RoleDefinitionBindingCollection newBinding = new RoleDefinitionBindingCollection(context);
                    newBinding.Add(selectedRoleDef);
                    User user = context.Web.EnsureUser(userAccount);
                    listItem.RoleAssignments.Add(user, newBinding);
                    listItem.Update();
                }
                context.ExecuteQuery();
            }
        }
コード例 #18
0
		public void DCMCheckIn(int fileId, string comment, MCS.Library.SOA.DocServiceContract.DCTCheckinType checkInType)
		{
			using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				File file = getFileById(fileId, context);
				file.CheckIn(comment, (CheckinType)checkInType);
				context.ExecuteQuery();

			}
		}
コード例 #19
0
        public void DCMRemoveRole(string rolename)
        {
            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                RoleDefinition roleDefinition = context.Web.RoleDefinitions.GetByName(rolename);
                roleDefinition.DeleteObject();

                context.ExecuteQuery();
            }
        }
コード例 #20
0
 public DCTFile DCMGetFileByUri(string uri)
 {
     using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
     {
         File file = context.Web.GetFileByServerRelativeUrl(uri);
         context.Load(file.ListItemAllFields);
         context.ExecuteQuery();
         DCTFile dctFile = new DCTFile();
         DCTConverterHelper.Convert(file.ListItemAllFields, dctFile);
         return(dctFile);
     }
 }
コード例 #21
0
        public DCTFile DCMSave(DCTFolder folder, byte[] fileData, string filename, bool overwrite)
        {
            (null == folder).TrueThrow <ArgumentException>("文件夹对象为空.");
            (string.IsNullOrEmpty(folder.Uri) && (!folder.IsRootFolder) && folder.ID < 0).TrueThrow <ArgumentException>("文件夹无效.请提供ID或Uri");

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                string uri = LoadUri(folder, context);

                using (System.IO.MemoryStream stream = new System.IO.MemoryStream(fileData))
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    string fileUri = uri;

                    if (!fileUri.EndsWith("/"))
                    {
                        fileUri += "/";
                    }

                    fileUri += filename;

                    context.ExecuteQuery();
                    File.SaveBinaryDirect(context, fileUri, stream, overwrite);

                    File file = context.Web.GetFileByServerRelativeUrl(fileUri);
                    context.Load(file);
                    context.ExecuteQuery();
                    context.Load(file.Author);

                    if (file.CheckOutType != CheckOutType.None)
                    {
                        context.Load(file.CheckedOutByUser);
                    }

                    context.Load(file.ListItemAllFields);
                    context.Load(file.ModifiedBy);
                    context.ExecuteQuery();

                    DCTFile dctFile = new DCTFile();

                    Uri target = new Uri(fileUri, UriKind.RelativeOrAbsolute);
                    Uri refUri = new Uri(context.Url);


                    dctFile.AbsoluteUri = target.MakeAbsolute(refUri).ToString(); UriHelper.CombinePath(context.Url, fileUri);
                    DCTConverterHelper.Convert(file, dctFile);

                    return(dctFile);
                }
            }
        }
コード例 #22
0
        public byte[] DCMGetFileContent(int fileId)
        {
            (fileId <= 0).TrueThrow <ArgumentException>("ID({0})无效,请传入大于0的值.", fileId);

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                string uri = LoadUri(new DCTFile()
                {
                    ID = fileId
                }, context);

                return(context.OpenBinary(uri));
            }
        }
コード例 #23
0
        public DCTFolder DCMGetFolderById(int id)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                if (id == 0)
                    return DCMGetRootFolder();
                ListItem item = GetListItemById(id, clientContext);

                (item == null).TrueThrow<TargetNotFoundException>("无法根据ID:{0}找到对应的目录。", id);
                DCTFolder folder = new DCTFolder();
                DCTConverterHelper.Convert(item, folder);

                return folder;
            }
        }
コード例 #24
0
        public void UpdateFolder(DCTFolder folder)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                ListItem item = LoadItem(folder, clientContext);

                (item == null).TrueThrow <TargetNotFoundException>("文件夹(ID={0})不存在。", folder.ID);

                item.FieldValues["Title"]       = folder.Name;
                item.FieldValues["FileLeafRef"] = folder.Name;
                item.Update();

                clientContext.ExecuteQuery();
            }
        }
コード例 #25
0
        public DCTFolder DCMGetRootFolder()
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                Folder rootFolder = clientContext.BaseList.RootFolder;

                clientContext.Load(rootFolder);
                clientContext.ExecuteQuery();

                DCTFolder result = new DCTFolder() { ID = 0, IsRootFolder = true };

                DCTConverterHelper.Convert(rootFolder, result);

                return result;
            }
        }
コード例 #26
0
        public BaseCollection <DCTFileField> DCMGetAllFileFields(int fileId)
        {
            (fileId <= 0).TrueThrow <ArgumentException>("ID({0})无效,请传入大于0的值.", fileId);

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                string uri = LoadUri(new DCTFile()
                {
                    ID = fileId
                }, context);
                File file = context.Web.GetFileByServerRelativeUrl(uri);
                BaseCollection <DCTFileField> results = BuildFileFields(context, context.BaseList.Fields, file);

                return(results);
            }
        }
コード例 #27
0
        private static ListItem GetListItemById(int id, DocLibContext clientContext)
        {
            List list = clientContext.BaseList;
            CamlQuery query = new CamlQuery();
            Caml caml = Caml.SimpleView(Caml.Field("ID").Eq(Caml.Value("Counter", id.ToString())), CamlBuilder.ViewType.RecursiveAll);
            query.ViewXml = caml.ToCamlString();
            ListItemCollection items = list.GetItems(query);

            clientContext.Load(items);
            clientContext.ExecuteQuery();

            if (items.Count == 0)
                return null;

            return items[0];
        }
コード例 #28
0
        public BaseCollection <DCTFileField> DCMGetFileFields(int fileId, BaseCollection <DCTFieldInfo> fields)
        {
            (fileId <= 0).TrueThrow <ArgumentException>("ID({0})无效,请传入大于0的值.", fileId);

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                List <Field> spfields = GetSPFields(fields, context);

                string uri = LoadUri(new DCTFile()
                {
                    ID = fileId
                }, context);
                File file = context.Web.GetFileByServerRelativeUrl(uri);

                return(BuildFileFields(context, spfields, file));
            }
        }
コード例 #29
0
        public BaseCollection <DCTPermission> DCMGetRolePermissions(DCTRoleDefinition role)
        {
            (role.ID <= 0 && string.IsNullOrEmpty(role.Name)).TrueThrow <ArgumentException>("角色中必须包含名称或ID.");

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                RoleDefinition roleDef = null;

                if (!string.IsNullOrEmpty(role.Name))
                {
                    roleDef = context.Web.RoleDefinitions.GetByName(role.Name);
                }
                else
                {
                    roleDef = context.Web.RoleDefinitions.GetById(role.ID);
                }

                context.Load(roleDef);
                context.ExecuteQuery();

                BaseCollection <DCTPermission> permissions = new BaseCollection <DCTPermission>();

                if (roleDef.BasePermissions.Has(PermissionKind.ViewListItems))
                {
                    permissions.Add(DCTPermission.ViewFileOrFolder);
                }

                if (roleDef.BasePermissions.Has(PermissionKind.AddListItems))
                {
                    permissions.Add(DCTPermission.AddFileOrFolder);
                }

                if (roleDef.BasePermissions.Has(PermissionKind.EditListItems))
                {
                    permissions.Add(DCTPermission.UpdateFileOrFolder);
                }

                if (roleDef.BasePermissions.Has(PermissionKind.DeleteListItems))
                {
                    permissions.Add(DCTPermission.DeleteFileOrFolder);
                }


                return(permissions);
            }
        }
コード例 #30
0
        private ListItem GetListItemByUri(string uri, DocLibContext context)
        {
            CamlQuery query = new CamlQuery();

            query.ViewXml = Caml.SimpleView(Caml.Field("FileRef").Eq(Caml.Value("Text", uri)), CamlBuilder.ViewType.RecursiveAll).ToCamlString();

            ListItemCollection itemCollection = context.BaseList.GetItems(query);

            context.Load(itemCollection);
            context.ExecuteQuery();

            if (itemCollection.Count == 0)
            {
                return(null);
            }
            return(itemCollection[0]);
        }
コード例 #31
0
        private Principal BuildSharepointPrincipal(DocLibContext context, DCTRoleAssignment dctRoleAssignment)
        {
            Principal principal = null;

            if (dctRoleAssignment.Member.PricinpalType == DCTPrincipalType.SharePointGroup)
            {
                Group group = context.Web.SiteGroups.GetById(dctRoleAssignment.Member.ID);
                principal = group;
            }
            else
            {
                User user = context.Web.EnsureUser((dctRoleAssignment.Member as DCTUser).LoginName);
                principal = user;
            }

            return(principal);
        }
コード例 #32
0
        public DCTFolder DCMGetFolderById(int id)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                if (id == 0)
                {
                    return(DCMGetRootFolder());
                }
                ListItem item = GetListItemById(id, clientContext);

                (item == null).TrueThrow <TargetNotFoundException>("无法根据ID:{0}找到对应的目录。", id);
                DCTFolder folder = new DCTFolder();
                DCTConverterHelper.Convert(item, folder);

                return(folder);
            }
        }
コード例 #33
0
        private bool FieldExists(DCTFieldInfo field, DocLibContext context)
        {
            context.Load(context.BaseList.Fields);
            context.ExecuteQuery();
            bool found = false;

            foreach (Field spField in context.BaseList.Fields)
            {
                if (spField.Title == field.Title)
                {
                    found = true;
                    break;
                }
            }

            return(found);
        }
コード例 #34
0
        public void DCMSetRoleAssignments(int storageObjID, BaseCollection <DCTRoleAssignment> roleAssignments)
        {
            (storageObjID > 0).FalseThrow <ArgumentException>("ID值{0}无效,请传入大于0的值.", storageObjID);

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                ListItem listItem = GetListItemById(storageObjID, context);
                if (null == listItem)
                {
                    return;
                }
                context.Load(listItem);

                listItem.BreakRoleInheritance(true, true);

                context.Load(listItem.RoleAssignments);
                context.ExecuteQuery();

                foreach (RoleAssignment roleAssignment in listItem.RoleAssignments)
                {
                    roleAssignment.RoleDefinitionBindings.RemoveAll();
                    roleAssignment.Update();
                }

                context.ExecuteQuery();

                foreach (DCTRoleAssignment dctRoleAssignment in roleAssignments)
                {
                    bool ignore = false;
                    RoleDefinitionBindingCollection binding = BuildRoleDefninitionBinding(context, dctRoleAssignment, out ignore);

                    Principal principal = BuildSharepointPrincipal(context, dctRoleAssignment);

                    if (ignore)
                    {
                        continue;
                    }

                    listItem.RoleAssignments.Add(principal, binding);
                    listItem.Update();
                }

                context.ExecuteQuery();
            }
        }
コード例 #35
0
        private byte[] getVersionContetById(File file, int versionId, DocLibContext context)
        {
            context.Load(file.Versions);
            context.ExecuteQuery();
            FileVersion selectedVersion = null;

            foreach (FileVersion version in file.Versions)
            {
                if (version.ID == versionId)
                {
                    selectedVersion = version;
                    break;
                }
            }
            (null == selectedVersion).TrueThrow <TargetNotFoundException>("版本(ID={0})未找到。", versionId);

            return(context.OpenBinary(selectedVersion.Url));
        }
コード例 #36
0
        public DCTFolder DCMGetFolderByUri(string uri)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                Folder folder = clientContext.Web.GetFolderByServerRelativeUrl(uri);
                clientContext.Load(folder);

                CamlQuery query = new CamlQuery();
                query.ViewXml = Caml.SimpleView(Caml.Field("FileRef").Eq(Caml.Value("Text", uri)), CamlBuilder.ViewType.RecursiveAll).ToCamlString();

                ListItemCollection items = clientContext.BaseList.GetItems(query);

                clientContext.Load(items);

                DCTFolder result;
                try
                {
                    clientContext.ExecuteQuery();
                    if (string.Compare(folder.ServerRelativeUrl, this.DCMGetRootFolder().Uri, true) == 0)
                    {
                        result = new DCTFolder()
                        {
                            ID = 0, IsRootFolder = true
                        }
                    }
                    ;
                    else
                    {
                        result = new DCTFolder()
                        {
                            ID = items[0].Id, IsRootFolder = false
                        }
                    };

                    DCTConverterHelper.Convert(folder, result);
                }
                catch
                {
                    result = null;
                }

                return(result);
            }
        }
コード例 #37
0
        public BaseCollection <DCTRoleAssignment> DCMGetRoleAssignments(int storageObjID)
        {
            (storageObjID <= 0).TrueThrow <ArgumentException>("ID:{0}无效,请传入大于0的值.", storageObjID);

            using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                ListItem listItem = GetListItemById(storageObjID, context);
                if (null == listItem)
                {
                    return(new BaseCollection <DCTRoleAssignment>());
                }
                context.Load(listItem);
                context.Load(listItem.RoleAssignments);
                context.ExecuteQuery();

                RoleAssignmentCollection           roleAssignments = listItem.RoleAssignments;
                BaseCollection <DCTRoleAssignment> results         = new BaseCollection <DCTRoleAssignment>();

                foreach (RoleAssignment roleAssignment in roleAssignments)
                {
                    DCTRoleAssignment dctRoleAssignment = new DCTRoleAssignment();
                    context.Load(roleAssignment.Member);
                    context.Load(roleAssignment.RoleDefinitionBindings);
                    context.ExecuteQuery();

                    dctRoleAssignment.Member = GetPrinciple(roleAssignment.Member.PrincipalType);
                    DCTConverterHelper.Convert(roleAssignment.Member, dctRoleAssignment.Member);

                    dctRoleAssignment.RoleDefinitions = new BaseCollection <DCTRoleDefinition>();
                    RoleDefinitionBindingCollection bindingCollection = roleAssignment.RoleDefinitionBindings;
                    foreach (RoleDefinition roleDefinition in bindingCollection)
                    {
                        DCTRoleDefinition dctRoleDefinition = new DCTRoleDefinition();
                        DCTConverterHelper.Convert(roleDefinition, dctRoleDefinition);
                        dctRoleAssignment.RoleDefinitions.Add(dctRoleDefinition);
                    }

                    results.Add(dctRoleAssignment);
                }

                return(results);
            }
        }
コード例 #38
0
        private static ListItem GetListItemById(int id, DocLibContext clientContext)
        {
            List      list  = clientContext.BaseList;
            CamlQuery query = new CamlQuery();
            Caml      caml  = Caml.SimpleView(Caml.Field("ID").Eq(Caml.Value("Counter", id.ToString())), CamlBuilder.ViewType.RecursiveAll);

            query.ViewXml = caml.ToCamlString();
            ListItemCollection items = list.GetItems(query);

            clientContext.Load(items);
            clientContext.ExecuteQuery();

            if (items.Count == 0)
            {
                return(null);
            }

            return(items[0]);
        }
コード例 #39
0
        public DCTFolder DCMGetRootFolder()
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                Folder rootFolder = clientContext.BaseList.RootFolder;

                clientContext.Load(rootFolder);
                clientContext.ExecuteQuery();

                DCTFolder result = new DCTFolder()
                {
                    ID = 0, IsRootFolder = true
                };

                DCTConverterHelper.Convert(rootFolder, result);

                return(result);
            }
        }
コード例 #40
0
		public BaseCollection<DCTFile> DCMQueryDocByCaml(string camlText)
		{
			BaseCollection<DCTFile> files = new BaseCollection<DCTFile>();

			using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				CamlQuery query = new CamlQuery();
				query.ViewXml = camlText;
				ListItemCollection items = clientContext.BaseList.GetItems(query);
				clientContext.Load(items);
				clientContext.ExecuteQuery();
				foreach (ListItem item in items)
				{
					DCTFile file = new DCTFile();
					DCTConverterHelper.Convert(item, file);
					files.Add(file);
				}
			}
			return files;
		}
コード例 #41
0
		public BaseCollection<DCTFileVersion> DCMGetVersions(int fileId)
		{
			using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
			{
				File file = getFileById(fileId, context);
				context.Load(file.Versions);
				context.ExecuteQuery();

				BaseCollection<DCTFileVersion> results = new BaseCollection<DCTFileVersion>();

				foreach (FileVersion version in file.Versions)
				{
					context.Load(version.CreatedBy);
					context.ExecuteQuery();
					DCTFileVersion dctFileVersion = new DCTFileVersion();
					dctFileVersion.AbsoluteUri = UriHelper.CombinePath(context.Url, version.Url);
					DCTConverterHelper.Convert(version, dctFileVersion);

					results.Add(dctFileVersion);
				}

				return results;
			}
		}
コード例 #42
0
		public BaseCollection<DCTSearchResult> DCMSearchDoc(string[] keyWords)
		{
			MCS.Library.Core.ServerInfo serverInfo = MossServerInfoConfigurationSettings.GetConfig().Servers["documentServer"].ToServerInfo();
			System.Net.NetworkCredential Credentials = new System.Net.NetworkCredential(serverInfo.Identity.LogOnName, serverInfo.Identity.Password, serverInfo.Identity.Domain);
			string searchServiceUrl = MCS.Library.Core.UriHelper.CombinePath(MossServerInfoConfigurationSettings.GetConfig().Servers["documentServer"].ServerName, MossServerInfoConfigurationSettings.GetConfig().Servers["documentServer"].MossSearchServiceUrl);
			QueryService queryService = new QueryService(searchServiceUrl, Credentials);

			BaseCollection<DCTSearchResult> result = new BaseCollection<DCTSearchResult>();
			StringBuilder queryXml = new StringBuilder();
			queryXml.Append("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\">");
			queryXml.Append("<Query domain=\"QDomain\">");
			queryXml.Append("<SupportedFormats>");
			queryXml.Append("<Format>");
			queryXml.Append("urn:Microsoft.Search.Response.Document.Document");
			queryXml.Append("</Format>");
			queryXml.Append("</SupportedFormats>");
			queryXml.Append("<Range>");
			queryXml.Append("<Count>50</Count>");
			queryXml.Append("</Range>");
			queryXml.Append("<Context>");
			queryXml.Append("<QueryText language=\"en-US\" type=\"STRING\">");
			foreach (string item in keyWords)
			{
				queryXml.Append(string.Format("{0} ", item));
			}

			queryXml.Append("</QueryText>");
			queryXml.Append("</Context>");
			queryXml.Append("</Query>");

			queryXml.Append("</QueryPacket>");
			try
			{
				using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
				{
					DataSet dsQueryResult = queryService.QueryEx(queryXml.ToString());
					IEnumerable<DataRow> drQueryResult = from row in dsQueryResult.Tables[0].AsEnumerable()
														 where row.Field<bool>("IsDocument") == true
														 select row;
					foreach (var item in drQueryResult)
					{
						DCTSearchResult searchResult = new DCTSearchResult();
						searchResult.Title = item["Title"].ToString();
						searchResult.Size = int.Parse(item["Size"].ToString());
						searchResult.HitHighlightedSummary = item["HitHighlightedSummary"].ToString();
						searchResult.LastModifiedDate = DateTime.Parse(item["Write"].ToString());
						searchResult.Path = item["Path"].ToString().ToLower().Replace(context.Url.ToLower(), "");
						result.Add(searchResult);
					}
					return result;
				}
			}
			catch (SoapException ex)
			{
				throw ex;
			}
		}
コード例 #43
0
		//TODO:重复功能
		private static File getFileById(int fileId, DocLibContext context)
		{
			ListItem listItem = GetListItemById(fileId, context);
			(listItem == null).TrueThrow<TargetNotFoundException>("文件(ID为{0})未找到。", fileId);
			return listItem.File;
		}
コード例 #44
0
		private byte[] getVersionContetById(File file, int versionId, DocLibContext context)
		{
			context.Load(file.Versions);
			context.ExecuteQuery();
			FileVersion selectedVersion = null;
			foreach (FileVersion version in file.Versions)
			{
				if (version.ID == versionId)
				{
					selectedVersion = version;
					break;
				}

			}
			(null == selectedVersion).TrueThrow<TargetNotFoundException>("版本(ID={0})未找到。", versionId);

			return context.OpenBinary(selectedVersion.Url);
		}
コード例 #45
0
        public void DCMRemove(DCTStorageObject storageObject)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                string uri = LoadUri(storageObject, clientContext);
                if (storageObject is DCTFile)
                {
                    ClientObject clientObject = (File)clientContext.Web.GetFileByServerRelativeUrl(uri);
                    ((File)clientObject).Recycle();

                }
                else
                    if (storageObject is DCTFolder)
                    {
                        ClientObject clientObject = clientContext.Web.GetFolderByServerRelativeUrl(uri);
                        ((Folder)clientObject).Recycle();
                    }

                clientContext.ExecuteQuery();
            }
          
        }
コード例 #46
0
        public void UpdateFolder(DCTFolder folder)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                ListItem item = LoadItem(folder, clientContext);

                (item == null).TrueThrow<TargetNotFoundException>("文件夹(ID={0})不存在。", folder.ID);

                item.FieldValues["Title"] = folder.Name;
                item.FieldValues["FileLeafRef"] = folder.Name;
                item.Update();

                clientContext.ExecuteQuery();
            }
        }
コード例 #47
0
        public DCTFolder DCMCreateFolder(string name, DCTFolder parentFolder)
        {
            DCTFolder folder = new DCTFolder();
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                Folder cOMParentFolder = clientContext.Web.GetFolderByServerRelativeUrl(LoadUri(parentFolder, clientContext));
                if (cOMParentFolder != null)
                {

                    cOMParentFolder.Folders.Add(UriHelper.CombinePath(parentFolder.Uri, name));
                }

                clientContext.ExecuteQuery();

                CamlQuery query = new CamlQuery() { FolderServerRelativeUrl = parentFolder.Uri };
                query.ViewXml = Caml.SimpleView(Caml.Field("ServerUrl").Eq(Caml.Value("Text", (parentFolder.Uri[parentFolder.Uri.Length - 1] != '/' ? parentFolder.Uri + "/" : parentFolder.Uri) + name)), CamlBuilder.ViewType.Default).ToCamlString();
                ListItemCollection items = clientContext.BaseList.GetItems(query);
                clientContext.Load(items);

                clientContext.ExecuteQuery();

                if (items.Count != 0)
                {
                    folder.AbsoluteUri = UriHelper.CombinePath(parentFolder.AbsoluteUri, name);
                    folder.Name = name;
                    folder.Uri = UriHelper.CombinePath(parentFolder.Uri, name);
                    folder.IsRootFolder = false;
                    folder.ID = items[0].Id;
                }
            }

            return folder;
        }
コード例 #48
0
        public BaseCollection<DCTStorageObject> DCMGetChildren(DCTFolder folder, DCTContentType contentType)
        {
            BaseCollection<DCTStorageObject> childs = new BaseCollection<DCTStorageObject>();
            BaseCollection<DCTFile> childFiles = new BaseCollection<DCTFile>();
            BaseCollection<DCTFolder> childFolders = new BaseCollection<DCTFolder>();

            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                Folder clientOMFolder = clientContext.Web.GetFolderByServerRelativeUrl(folder.Uri);
                CamlQuery query = new CamlQuery();
                query.FolderServerRelativeUrl = LoadUri(folder, clientContext);
                query.ViewXml = Caml.SimpleView(Caml.EmptyCaml(), CamlBuilder.ViewType.Default).ToCamlString();

                ListItemCollection items = clientContext.BaseList.GetItems(query);

                clientContext.Load(items);
                clientContext.ExecuteQuery();

                foreach (ListItem item in items)
                {
                    switch (item.FileSystemObjectType)
                    {
                        case FileSystemObjectType.File:
                            if ((contentType & DCTContentType.File) != DCTContentType.None)
                            {
                                DCTFile itemFile = new DCTFile();
                                DCTConverterHelper.Convert(item, itemFile);

                                childs.Add(itemFile);
                                //childFiles.Add(itemFile);
                            }
                            break;
                        case FileSystemObjectType.Folder:
                            if ((contentType & DCTContentType.Folder) != DCTContentType.None)
                            {
                                DCTFolder itemFolder = new DCTFolder();

                                DCTConverterHelper.Convert(item, itemFolder);

                                childs.Add(itemFolder);
                                //childFolders.Add(itemFolder);
                            }
                            break;
                        case FileSystemObjectType.Invalid:
                            break;
                        case FileSystemObjectType.Web:
                            break;
                        default:
                            break;
                    }
                }
            }

            foreach (DCTFolder item in childFolders)
                childs.Add(item);

            foreach (DCTFile item in childFiles)
                childs.Add(item);

            return childs;
        }
コード例 #49
0
        public DCTFolder DCMGetParentFolder(DCTStorageObject storageObject)
        {
            using (DocLibContext clientContext = new DocLibContext(ServiceHelper.GetDocumentLibraryName()))
            {
                ListItem listItem = LoadItem(storageObject, clientContext);
                (listItem == null).TrueThrow<ArgumentException>("无法找到文件夹,传入的为根目录或文件、文件夹不存在。");

                DCTFolder folder = null;

                clientContext.Load(clientContext.BaseList.RootFolder);

                clientContext.ExecuteQuery();

                if (string.Compare(listItem.FieldValues["FileDirRef"].ToString(), clientContext.BaseList.RootFolder.ServerRelativeUrl, true) == 0)
                {
                    folder = new DCTFolder() { ID = 0, IsRootFolder = true };

                    DCTConverterHelper.Convert(clientContext.BaseList.RootFolder, folder);
                }
                else
                {
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = Caml.SimpleView(Caml.Field("ServerUrl").Eq(Caml.Value("Text", listItem.FieldValues["FileDirRef"].ToString())), CamlBuilder.ViewType.RecursiveAll).ToCamlString();

                    ListItemCollection parentListItem = clientContext.BaseList.GetItems(query);
                    clientContext.Load(parentListItem);
                    clientContext.ExecuteQuery();

                    folder = new DCTFolder();

                    DCTConverterHelper.Convert(parentListItem[0], folder);
                }

                return folder;
            }
        }