Exemplo n.º 1
0
		/// <summary>
		/// Shares a remote file with link.
		/// </summary>
		/// <returns>instance of PublicShare with the share info.</returns>
		/// <param name="path">path to the remote file to share.</param>
		/// <param name="perms">(optional) permission of the shared object.</param>
		/// <param name="password">(optional) sets a password.</param>
		/// <param name="public_upload">(optional) allows users to upload files or folders.</param>
		public PublicShare ShareWithLink(string path, int perms = -1, string password = null, OcsBoolParam public_upload = OcsBoolParam.None) {
			var request = new RestRequest(GetOcsPath(ocsServiceShare, "shares"), Method.POST);
			request.AddHeader("OCS-APIREQUEST", "true");

			request.AddParameter ("shareType", Convert.ToInt32 (OcsShareType.Link));
			request.AddParameter ("path", path);

			if (perms != Convert.ToInt32(OcsPermission.None))
				request.AddParameter("permissions", Convert.ToInt32(perms) + "");
			if (password != null)
				request.AddParameter ("password", password);
			if (public_upload == OcsBoolParam.True)
				request.AddParameter ("publicUpload", "true");
			else if (public_upload == OcsBoolParam.False)
				request.AddParameter ("publicUpload", "false");

			var response = rest.Execute (request);

			CheckOcsStatus (response);

			PublicShare share = new PublicShare ();
			share.ShareId = Convert.ToInt32(GetFromData(response.Content, "id"));
			share.Url = GetFromData(response.Content, "url");
			share.Token = GetFromData(response.Content, "token");
			share.TargetPath = path;
            share.Perms = (perms > -1) ? perms : Convert.ToInt32(OcsPermission.Read);

			return share;
		}
Exemplo n.º 2
0
		/// <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;
        }