public RestOperation Get() { if (HttpRuntime.Cache[_pathManager.FindRootPath()] != null) { return (RestOperation)HttpRuntime.Cache[_pathManager.FindRootPath()]; } var restClientBuilder = new RestClientBuilder() .WithUri(_pathManager.CreatePath()) .WithOAuth2Token(_token.GetAccessToken()) .WithAcceptHeader(_acceptHeader) .Build(); var response = restClientBuilder.Get(); if (!String.IsNullOrEmpty(response.GetResponseHeader(HttpResponseHeader.Location))) { var redirect = (response.GetResponseHeader(HttpResponseHeader.Location)); var redirectFinder = new ResourceFinder(redirect, _token, _acceptHeader); var redirectResponse = redirectFinder.Get(); HttpRuntime.Cache.Insert(_pathManager.FindRootPath(), redirectResponse, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0)); return redirectResponse; } HttpRuntime.Cache.Insert(_pathManager.FindRootPath(), response, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0)); return response; }
//try removing me if stuff breaks because -> 17/08/2012 not tested protected override bool HasChildItems(string path) { var resource = new ResourceFinder(path, _token, AcceptHeader); var item = _responseChildItemFactory.Create(resource.Get()); return item.Any(); }
protected override void GetItem(string path) { var resource = new ResourceFinder(path, _token, AcceptHeader); var item = _responseItemFactory.Create(resource.Get()); var selfLink = item.Links.Single(l => l.Rel == "self").Href; WriteItemObject(item, selfLink, IsItemContainer(selfLink)); }
protected override void GetChildItems(string path, bool recurse) { var resource = new ResourceFinder(path, _token, AcceptHeader); var item = _responseChildItemFactory.Create(resource.Get()); foreach (var childItem in item) { if (childItem == null) continue; var selfLink = childItem.Links.Single(l => l.Rel == "self").Href; WriteItemObject(childItem, selfLink, IsItemContainer(selfLink)); } }
private HuddleResourceObject GetEntityFromPath(string path) { var resource = new ResourceFinder(path, _token, AcceptHeader); RestOperation restOperation = resource.Get(); return _responseItemFactory.Create(restOperation); }
private string GetChildNameFromParentName(string parent) { if (IgnoreRequestToProvider(parent)) return string.Empty; HuddleResourceObject matchedItem = CurrentChildItems.FirstOrDefault(ci => ci.Title == parent); if (matchedItem != null) return matchedItem.LinkSelf; WriteDebug("GetChildNameFromParentName:" + parent); if (parent == "" || parent == "entry") { return parent; } var parentDivider = parent.LastIndexOf('/'); var resource = new ResourceFinder(PSDriveInfo.CurrentLocation, _token, AcceptHeader); //check to see if the word they typed is an item RestOperation restOperation = resource.Get(); CurrentChildItems = _responseChildItemFactory.Create(restOperation); foreach (var childItem in CurrentChildItems) //now we have the child items find the 1 with our name { if (childItem == null) continue; if (parentDivider > 0 && childItem.Title.Equals(parent.Substring(parentDivider + 1),StringComparison.CurrentCultureIgnoreCase)) //found the bugger now return its self link { return childItem.LinkSelf; } if (childItem.Title == parent) { return childItem.LinkSelf; } } var linksInItem = _responseItemFactory.Create(restOperation).Links; //still not found? check if its a link they are looking for Link link; if (parentDivider > 0) { link = linksInItem.FirstOrDefault(l => l.Rel == parent.Substring(parentDivider + 1)); if (link != null) return link.Href; } link = linksInItem.FirstOrDefault(l => l.Rel == parent.Substring(parentDivider + 1)); if (link != null) { return link.Href; } return parent; }
protected override void SetItem(string path, object value) { WriteDebug("SetItem - Path:" + path); PSObject fileEntity = PSObject.AsPSObject(value); var itemEntityValue = fileEntity.Properties.ToArray(); var resource = new ResourceFinder(path, _token, AcceptHeader); CurrentItem = _responseItemFactory.Create(resource.Get()); if (itemEntityValue[0].Name == "uploadPath") { path = CurrentItem.LinkFor("upload"); var uploadResource = new ResourceUploader(path, _token, AcceptHeader, itemEntityValue[0].Value.ToString()); CurrentItem = _responseItemFactory.Create(uploadResource.SendMutiPartRequest()); } else { CurrentItem.Title = itemEntityValue[2].Value.ToString(); CurrentItem.Description = itemEntityValue[1].Value.ToString(); path = CurrentItem.LinkFor("edit"); var editedResource = new ResourceModifier(path, _token, AcceptHeader, CurrentItem); editedResource.Put(); } }
protected override bool ItemExists(string path) { if (IgnoreRequestFromPowershell(path)) return true; if (CurrentUser.LinkSelf == path) return true; if (CurrentUser.Workspaces.Any(w => w.LinkSelf == path)) return true; WriteDebug("ItemExists - Path:" + path); var resource = new ResourceFinder(path, _token, AcceptHeader); RestOperation restOperation = resource.Get(); if (restOperation != null) { return true; } return true; }
protected override bool IsItemContainer(string path) { var resource = new ResourceFinder(path, _token, AcceptHeader); return resource.Get().Result.Name != "document"; }
private string GetChildNameFromParentName(string parent) { if(parent == "" || parent == "entry") { return parent; } var parentDivider = parent.LastIndexOf('/'); var resource = new ResourceFinder(PSDriveInfo.CurrentLocation, _token, AcceptHeader); //check to see if the word they typed is an item var item = _responseChildItemFactory.Create(resource.Get()); foreach (var childItem in item) //now we have the child items find the 1 with our name { if (childItem == null) continue; if (parentDivider > 0 && childItem.Title.Equals(parent.Substring(parentDivider + 1),StringComparison.CurrentCultureIgnoreCase)) //found the bugger now return its self link { var selfLink = childItem.Links.Single(l => l.Rel == "self").Href; return selfLink; } if (childItem.Title == parent) { var selfLink = childItem.Links.Single(l => l.Rel == "self").Href; return selfLink; } } var linksInItem = _responseItemFactory.Create(resource.Get()).Links; //still not found? check if its a link they are looking for Link link; if (parentDivider > 0) { link = linksInItem.FirstOrDefault(l => l.Rel == parent.Substring(parentDivider + 1)); if (link != null) return link.Href; } link = linksInItem.FirstOrDefault(l => l.Rel == parent.Substring(parentDivider + 1)); if (link != null) { return link.Href; } return parent; }
private string GetChildMatcheFromParent(string match) { return string.Empty; match = match.Substring(0, match.Length - 1); var resource = new ResourceFinder(PSDriveInfo.CurrentLocation, _token, AcceptHeader); var item = _responseChildItemFactory.Create(resource.Get()); var selectedItem= item.FirstOrDefault(l => l.Title.StartsWith(match,StringComparison.CurrentCultureIgnoreCase)); return selectedItem.Title; }
protected override void SetItem(string path, object value) { PSObject fileEntity = PSObject.AsPSObject(value); var itemEntityValue = fileEntity.Properties.ToArray(); var resource = new ResourceFinder(path, _token, AcceptHeader); HuddleResourceObject item; if (itemEntityValue[0].Name == "uploadPath") { item = _responseItemFactory.Create(resource.Get()); path = item.Links.Single(l => l.Rel == "upload").Href; var uploadResource = new ResourceUploader(path, _token, AcceptHeader, itemEntityValue[0].Value.ToString()); item = _responseItemFactory.Create(uploadResource.SendMutiPartRequest()); } else { item = _responseItemFactory.Create(resource.Get()); item.Title = itemEntityValue[2].Value.ToString(); item.Description = itemEntityValue[1].Value.ToString(); path = item.Links.Single(l => l.Rel == "edit").Href; var editedResource = new ResourceModifier(path, _token, AcceptHeader, item); editedResource.Put(); } }
protected override void NewItem(string path, string itemTypeName, object newItemValue) { PSObject fileEntity = PSObject.AsPSObject(newItemValue); var itemEntityValue = fileEntity.Properties.ToArray(); var xmlBody = ""; var getPath = new ResourceFinder(path, _token, AcceptHeader); //we want to get the uri of the match folder they specififed var pathItem = _responseItemFactory.Create(getPath.Get()); //we do this to get the folders create-document and create-folder links if (itemTypeName == "folder") { path = pathItem.Links.Single(l => l.Rel == "create-folder").Href; xmlBody = String.Format("<folder title='{0}' description='{1}' />", itemEntityValue[2].Value, itemEntityValue[1].Value); } else if (itemTypeName == "document") { path = pathItem.Links.Single(l => l.Rel == "create-document").Href; xmlBody = String.Format("<document title='{0}' description='{1}' />", itemEntityValue[2].Value, itemEntityValue[1].Value); } else { var error = new ArgumentException("Invalid type!"); WriteError(new ErrorRecord(error, "Invalid Item", ErrorCategory.InvalidArgument, itemTypeName)); } var resource = new ResourceCreater(path, _token, AcceptHeader, xmlBody); var item = _responseItemFactory.Create(resource.Post()); var selfLink = item.Links.Single(l => l.Rel == "self").Href; WriteItemObject(item, selfLink, IsItemContainer(selfLink)); }
protected override bool ItemExists(string path) { var resource = new ResourceFinder(path, _token, AcceptHeader); if (resource.Get() != null) { return true; } return true; }
private string GetChildNameWhenKnownParent(string path) { var parentDivider = path.LastIndexOf('/'); var parentPath = path.Substring(0, parentDivider); var resource = new ResourceFinder(parentPath, _token, AcceptHeader); var item = _responseChildItemFactory.Create(resource.Get()); foreach (var childItem in item) //now we have the child items find the 1 with our name { if (childItem == null) continue; if (childItem.Title == path.Substring(parentDivider + 1)) //found the bugger now return its self link { var selfLink = childItem.Links.Single(l => l.Rel == "self").Href; GetChildName(selfLink); break; } } return String.Empty; }