/// <summary> /// Shares a remote file with specified group. /// </summary> /// <returns>instance of GroupShare with the share info.</returns> /// <param name="path">path to the remote file to share.</param> /// <param name="groupName">name of the group whom we want to share a file/folder.</param> /// <param name="perms">permissions of the shared object.</param> public GroupShare ShareWithGroup(string path, string groupName, int perms = -1) { if ((perms == -1) || (perms > Convert.ToInt32 (OcsPermission.All)) || (groupName == null) || (groupName.Equals (""))) return null; var request = new RestRequest(GetOcsPath(ocsServiceShare, "shares"), Method.POST); request.AddHeader("OCS-APIREQUEST", "true"); request.AddParameter ("shareType", Convert.ToInt32 (OcsShareType.Group)); request.AddParameter ("path", path); if (perms != Convert.ToInt32(OcsPermission.None)) request.AddParameter("permissions", perms + ""); else request.AddParameter("permissions", Convert.ToInt32(OcsPermission.Read) + ""); request.AddParameter ("shareWith", groupName); var response = rest.Execute (request); CheckOcsStatus (response); var share = new GroupShare(); share.ShareId = Convert.ToInt32(GetFromData(response.Content, "id")); share.TargetPath = path; share.Perms = perms; share.SharedWith = groupName; return share; }
/// <summary> /// Gets the share list from a OCS Data response. /// </summary> /// <returns>The share list.</returns> /// <param name="response">XML OCS Response.</param> private List<Share> GetShareList(string response) { List<Share> shares = new List<Share>(); XDocument xdoc = XDocument.Parse(response); foreach (XElement data in xdoc.Descendants(XName.Get("element"))) { Share share = null; var node = data.Element(XName.Get("share_type")); if (node != null) { #region Share Type var shareType = Convert.ToInt32 (node.Value); if (shareType == Convert.ToInt32 (OcsShareType.Link)) share = new PublicShare (); else if (shareType == Convert.ToInt32 (OcsShareType.User)) share = new UserShare (); else if (shareType == Convert.ToInt32 (OcsShareType.Group)) share = new GroupShare (); else share = new Share (); share.AdvancedProperties = new AdvancedShareProperties (); #endregion #region General Properties node = data.Element(XName.Get("id")); if (node != null) share.ShareId = Convert.ToInt32(node.Value); node = data.Element(XName.Get("file_target")); if (node != null) share.TargetPath = node.Value; node = data.Element(XName.Get("permissions")); if (node != null) share.Perms = Convert.ToInt32(node.Value); #endregion #region Advanced Properties node = data.Element(XName.Get("item_type")); if (node != null) share.AdvancedProperties.ItemType = node.Value; node = data.Element(XName.Get("item_source")); if (node != null) share.AdvancedProperties.ItemSource = node.Value; node = data.Element(XName.Get("parent")); if (node != null) share.AdvancedProperties.Parent = node.Value; node = data.Element(XName.Get("file_source")); if (node != null) share.AdvancedProperties.FileSource = node.Value; node = data.Element(XName.Get("stime")); if (node != null) share.AdvancedProperties.STime = node.Value; node = data.Element(XName.Get("expiration")); if (node != null) share.AdvancedProperties.Expiration = node.Value; node = data.Element(XName.Get("mail_send")); if (node != null) share.AdvancedProperties.MailSend = node.Value; node = data.Element(XName.Get("uid_owner")); if (node != null) share.AdvancedProperties.Owner = node.Value; node = data.Element(XName.Get("storage_id")); if (node != null) share.AdvancedProperties.StorageId = node.Value; node = data.Element(XName.Get("storage")); if (node != null) share.AdvancedProperties.Storage = node.Value; node = data.Element(XName.Get("file_parent")); if (node != null) share.AdvancedProperties.FileParent = node.Value; node = data.Element(XName.Get("share_with_displayname")); if (node != null) share.AdvancedProperties.ShareWithDisplayname = node.Value; node = data.Element(XName.Get("displayname_owner")); if (node != null) share.AdvancedProperties.DisplaynameOwner = node.Value; #endregion #region ShareType specific if (shareType == Convert.ToInt32(OcsShareType.Link)) { node = data.Element(XName.Get("url")); if (node != null) ((PublicShare)share).Url = node.Value; node = data.Element(XName.Get("token")); if (node != null) ((PublicShare)share).Token = node.Value; } else if (shareType == Convert.ToInt32(OcsShareType.User)) { node = data.Element(XName.Get("share_with")); if (node != null) ((UserShare)share).SharedWith = node.Value; } else if (shareType == Convert.ToInt32(OcsShareType.Group)) { node = data.Element(XName.Get("share_with")); if (node != null) ((GroupShare)share).SharedWith = node.Value; } #endregion shares.Add (share); } } return shares; }