/// <summary> /// Gets the sharing information for the specified ContentItem which includes the groups /// the item is shared with and overall access permission (public/non public). /// </summary> public void GetSharingInfo(ContentItem item, EventHandler <SharingInfoEventArgs> callback) { if (_agol.User.Current == null) { if (callback != null) { callback(null, new SharingInfoEventArgs()); } return; } //find out if the item is located in a folder // GetFolder(item, (object sender, RequestEventArgs e) => { if (e.Error != null) { if (callback != null) { callback(null, new SharingInfoEventArgs() { Error = e.Error }); } return; } string folderUrl = ContentFolder.IsSubfolder(item.Folder) ? "/" + item.Folder.Id : ""; string url = _agol.Url + "content/users/" + _agol.User.Current.Username + folderUrl + "/items/" + item.Id + "?f=json&token=" + _agol.User.Token; // add a bogus parameter to avoid the caching that happens with the WebClient // url += "&tickCount=" + Environment.TickCount.ToString(); WebUtil.OpenReadAsync(url, null, (sender2, e2) => { if (e2.Error != null) { if (callback != null) { callback(null, new SharingInfoEventArgs() { Error = e2.Error }); } return; } UserItem userItem = WebUtil.ReadObject <UserItem>(e2.Result); if (callback != null) { callback(null, new SharingInfoEventArgs() { SharingInfo = (item == null) ? null : userItem.Sharing, Item = (item == null) ? null : userItem.ContentItem }); } }); }); }
/// <summary> /// Shares the specified item with the specified groups and sets the overall access level (everyone). /// </summary> /// <param name="itemId"></param> /// <param name="everyone">Overall access level - everyone or just available to the owner.</param> /// <param name="groupIds">A collection of group Ids which the specified item is shared with.</param> /// <param name="callback"></param> public void ShareItem(ContentItem item, bool everyone, string[] groupIds, EventHandler <RequestEventArgs> callback) { //find out if the item is located in a folder // GetFolder(item, (object sender, RequestEventArgs e) => { if (e.Error != null) { if (callback != null) { callback(null, e); } return; } List <HttpContentItem> items = new List <HttpContentItem>(); items.Add(new HttpContentItem() { Name = "everyone", Value = everyone }); items.Add(new HttpContentItem() { Name = "f", Value = "json" }); string groups = ""; if (groupIds != null) { foreach (string groupId in groupIds) { groups += groupId + ", "; } } items.Add(new HttpContentItem() { Name = "groups", Value = groups }); string folderUrl = ContentFolder.IsSubfolder(item.Folder) ? "/" + item.Folder.Id : ""; string url = _agol.Url + "content/users/" + _agol.User.Current.Username + folderUrl + "/items/" + item.Id + "/share?token=" + _agol.User.Token; WebUtil.MultiPartPostAsync(url, items, ApplicationUtility.Dispatcher, (sender2, e2) => { ShareItemResult result = WebUtil.ReadObject <ShareItemResult>(e2.Result); if (result != null) { callback(null, new RequestEventArgs()); } else { callback(null, new RequestEventArgs() { Error = new Exception(string.Format(ESRI.ArcGIS.Mapping.Controls.ArcGISOnline.Resources.Strings.ExceptionFailedToShareItem, item.Id)) }); } }); }); }
/// <summary> /// Deletes the content item specified by its Id. /// </summary> public void Delete(ContentItem item, EventHandler <ContentItemEventArgs> callback) { if (_agol.User.Current == null) { if (callback != null) { callback(null, new ContentItemEventArgs() { Error = new Exception(ESRI.ArcGIS.Mapping.Controls.ArcGISOnline.Resources.Strings.ExceptionDeleteFailedUserSignIn), Id = item.Id }); } return; } //find out if the item is located in a folder // GetFolder(item, (object sender, RequestEventArgs e) => { if (e.Error != null) { if (callback != null) { callback(null, new ContentItemEventArgs() { Error = e.Error }); } return; } string folderUrl = ContentFolder.IsSubfolder(item.Folder) ? "/" + item.Folder.Id : ""; string url = _agol.Url + "/content/users/" + _agol.User.Current.Username + folderUrl + "/items/" + item.Id + "/delete?f=json&token=" + _agol.User.Token; WebUtil.UploadStringAsync(url, null, "", (object sender2, UploadStringCompletedEventArgs e2) => { if (e2.Error != null) { if (callback != null) { callback(null, new ContentItemEventArgs() { Error = e2.Error, Id = item.Id }); } return; } Success result = WebUtil.ReadObject <Success>(new MemoryStream(Encoding.UTF8.GetBytes(e2.Result))); ContentItemEventArgs eventArgs = new ContentItemEventArgs() { Error = (result == null || !result.Succeeded) ? new Exception(ESRI.ArcGIS.Mapping.Controls.ArcGISOnline.Resources.Strings.ExceptionDeleteFailed) : null, Id = item.Id }; if (callback != null) { callback(null, eventArgs); } //raise event if (ItemDeleted != null) { ItemDeleted(null, eventArgs); } }); }); }