public static RemoteResource Deserialize(String linkFormat) { RemoteResource root = new RemoteResource(String.Empty); Scanner scanner = new Scanner(linkFormat); String path = null; while ((path = scanner.Find(ResourceNameRegex)) != null) { path = path.Substring(2, path.Length - 3); // Retrieve specified resource, create if necessary RemoteResource resource = new RemoteResource(path); LinkAttribute attr = null; while (scanner.Find(DelimiterRegex, 1) == null && (attr = ParseAttribute(scanner)) != null) { AddAttribute(resource.Attributes, attr); } root.AddSubResource(resource); } return(root); }
public RemoteResource ToEntity(IfyContext context, RemoteResource input) { RemoteResource result = (input == null ? new RemoteResource(context) : input); result.Location = this.Location; result.Name = this.Name; return(result); }
public void ConcreteTest() { String link = "</careless>;rt=\"SepararateResponseTester\";title=\"This resource will ACK anything, but never send a separate response\",</feedback>;rt=\"FeedbackMailSender\";title=\"POST feedback using mail\",</helloWorld>;rt=\"HelloWorldDisplayer\";title=\"GET a friendly greeting!\",</image>;ct=21;ct=22;ct=23;ct=24;rt=\"Image\";sz=18029;title=\"GET an image with different content-types\",</large>;rt=\"block\";title=\"Large resource\",</large_update>;rt=\"block observe\";title=\"Large resource that can be updated using PUT method\",</mirror>;rt=\"RequestMirroring\";title=\"POST request to receive it back as echo\",</obs>;obs;rt=\"observe\";title=\"Observable resource which changes every 5 seconds\",</query>;title=\"Resource accepting query parameters\",</seg1/seg2/seg3>;title=\"Long path resource\",</separate>;title=\"Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way\",</storage>;obs;rt=\"Storage\";title=\"PUT your data here or POST new resources!\",</test>;title=\"Default test resource\",</timeResource>;rt=\"CurrentTime\";title=\"GET the current time\",</toUpper>;rt=\"UppercaseConverter\";title=\"POST text here to convert it to uppercase\",</weatherResource>;rt=\"ZurichWeather\";title=\"GET the current weather in zurich\""; RemoteResource res = RemoteResource.NewRoot(link); String result = LinkFormat.Serialize(res); Assert.AreEqual(link, result); }
/// <summary> /// Adds the resource item. /// </summary> /// <param name="item">Item.</param> public void AddResourceItem(RemoteResource item) { item.ResourceSet = this; var res = Resources; res.AllowDuplicates = false; res.Include(item); res.StoreNew(); }
public void ConversionTest() { String link1 = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10"; String link2 = "</myUri>;rt=\"NonDefault\""; String link3 = "</a>"; String format = link1 + "," + link2 + "," + link3; RemoteResource res = RemoteResource.NewRoot(format); String result = LinkFormat.Serialize(res); Assert.AreEqual(link3 + "," + link2 + "," + link1, result); }
public void SimpleTest() { String input = "</sensors/temp>;ct=41;rt=\"TemperatureC\""; Resource root = RemoteResource.NewRoot(input); Resource res = root.GetResource("/sensors/temp"); Assert.IsNotNull(res); Assert.IsEqualTo(res.Name, "temp"); Assert.IsEqualTo(41, res.ContentTypeCode); Assert.IsEqualTo("TemperatureC", res.ResourceType); }
public async override void ViewDidLoad() { base.ViewDidLoad(); SetupRefreshControl(); var factory = new BookListStateFactory(View, tableView, emptyView, activityIndicator, refreshControl); var resource = new RemoteResource(); viewModel = new BookListViewModel(resource, factory); SetupDesign(); await LoadData(); }
public void SaveDataPackage() { DataPackage def = DataPackage.GetTemporaryForCurrentUser(context); var res = new RemoteResource(context); res.Location = "https://catalog.terradue.com:443/landsat8/search?format=json&uid=LC08_L1GT_070119_20190306_20190306_01_RT"; def.AddResourceItem(res); def.LoadItems(); Assert.AreEqual(1, def.Items.Count); DataPackage dp = new DataPackage(context); dp.Name = "test-dp"; dp.Kind = RemoteResourceSet.KINDRESOURCESETNORMAL; dp.Store(); dp.LoadItems(); Assert.AreEqual(0, dp.Items.Count); foreach (RemoteResource r in def.Resources) { RemoteResource tmpres = new RemoteResource(context); tmpres.Location = r.Location; dp.AddResourceItem(tmpres); } dp.LoadItems(); Assert.AreEqual(1, dp.Items.Count); var res2 = new RemoteResource(context); res2.Location = "https://catalog.terradue.com:443/sentinel3/search?format=json&uid=S3A_SR_2_LAN____20190307T092733_20190307T093355_20190307T102301_0382_042_136______LN3_O_NR_003"; def.AddResourceItem(res2); def.LoadItems(); Assert.AreEqual(2, def.Items.Count); foreach (var r in dp.Resources) { r.Delete(); } dp.Items = new EntityList <RemoteResource>(context); foreach (RemoteResource r in def.Resources) { RemoteResource tmpres = new RemoteResource(context); tmpres.Location = r.Location; dp.AddResourceItem(tmpres); } dp.LoadItems(); Assert.AreEqual(2, dp.Items.Count); }
public void SimpleTest() { String input = "</sensors/temp>;ct=41;rt=\"TemperatureC\""; RemoteResource root = RemoteResource.NewRoot(input); RemoteResource res = root.GetResource("/sensors/temp"); Assert.IsNotNull(res); Assert.AreEqual(res.Name, "/sensors/temp"); List <string> contents = res.Attributes.GetContentTypes().ToList(); Assert.AreEqual(1, contents.Count); Assert.AreEqual("41", contents[0]); Assert.AreEqual("TemperatureC", res.ResourceType); }
public void SimpleTest_JSON() { String input = "[{\"href\":\"/sensors/temp\",\"ct\":\"41\",\"rt\":\"TemperatureC\"}]"; RemoteResource root = RemoteResource.NewRoot(input, MediaType.ApplicationJson); RemoteResource res = root.GetResource("/sensors/temp"); Assert.IsNotNull(res); Assert.AreEqual(res.Name, "/sensors/temp"); List <string> contents = res.Attributes.GetContentTypes().ToList(); Assert.AreEqual(1, contents.Count); Assert.AreEqual("41", contents[0]); Assert.AreEqual("TemperatureC", res.ResourceType); }
public void ParseFailures() { string[] tests = new string[] { "/myuri;ct=42", "</myuri;ct=42", "</myrui>;x=\"This has one quote" }; foreach (string test in tests) { ArgumentException e = Assert.Throws <ArgumentException>( () => RemoteResource.NewRoot(test)); Assert.AreEqual("Value does not fall within the expected range.", e.Message); } }
public ChunkedHttpDownloader(string destinationFilePath, RemoteResource resource, int timeout) { Checks.ArgumentParentDirectoryExists(destinationFilePath, "destinationFilePath"); Checks.ArgumentValidRemoteResource(resource, "resource"); Checks.ArgumentMoreThanZero(timeout, "timeout"); DebugLogger.LogConstructor(); DebugLogger.LogVariable(destinationFilePath, "destinationFilePath"); DebugLogger.LogVariable(resource, "resource"); DebugLogger.LogVariable(timeout, "timeout"); _destinationFilePath = destinationFilePath; _resource = resource; _timeout = timeout; }
public static RemoteResource Deserialize(string linkFormat) { RemoteResource root = new RemoteResource(string.Empty); if (string.IsNullOrEmpty(linkFormat)) { return(root); } string[] links = SplitOn(linkFormat, ','); foreach (string link in links) { string[] attributes = SplitOn(link, ';'); if (attributes[0][0] != '<' || attributes[0][attributes[0].Length - 1] != '>') { throw new ArgumentException(); } RemoteResource resource = new RemoteResource(attributes[0].Substring(1, attributes[0].Length - 2)); for (int i = 1; i < attributes.Length; i++) { int eq = attributes[i].IndexOf('='); if (eq == -1) { resource.Attributes.Add(attributes[i]); } else { string value = attributes[i].Substring(eq + 1); if (value[0] == '"') { if (value[value.Length - 1] != '"') { throw new ArgumentException(); } value = value.Substring(1, value.Length - 2); } resource.Attributes.Add(attributes[i].Substring(0, eq), value); } } root.AddSubResource(resource); } return(root); }
public void UseChunkedHttpDownloader() { RemoteResource resource = CreateTestRemoteResource(); var httpDownloader = Substitute.For <IHttpDownloader>(); var chunkedHttpDownloader = Substitute.For <IChunkedHttpDownloader>(); var downloader = new RemoteResourceDownloader(_filePath, _metaFilePath, resource, (path, urls) => httpDownloader, (path, urls, data, size) => chunkedHttpDownloader); downloader.Download(CancellationToken.Empty); httpDownloader.DidNotReceiveWithAnyArgs().Download(CancellationToken.Empty); chunkedHttpDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); }
public DownloadPackageCommand(RemoteResource resource, string destinationPackagePath, string destinationMetaPath, bool useTorrents) { Checks.ArgumentValidRemoteResource(resource, "resource"); Checks.ArgumentNotNullOrEmpty(destinationPackagePath, "destinationPackagePath"); Checks.ParentDirectoryExists(destinationPackagePath); DebugLogger.LogConstructor(); DebugLogger.LogVariable(resource, "resource"); DebugLogger.LogVariable(destinationPackagePath, "destinationPackagePath"); DebugLogger.LogVariable(useTorrents, "useTorrents"); _resource = resource; _destinationPackagePath = destinationPackagePath; _destinationMetaPath = destinationMetaPath; _useTorrents = useTorrents; }
public void MatchTest() { String link1 = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10"; String link2 = "</myUri>;ct=50;rt=\"MyName\""; String link3 = "</a>;sz=10;rt=\"MyNope\""; String format = link1 + "," + link2 + "," + link3; Resource res = RemoteResource.NewRoot(format); List <Option> query = new List <Option>(); query.Add(Option.Create(OptionType.UriQuery, "rt=MyName")); String queried = LinkFormat.Serialize(res, query, true); Assert.IsEqualTo(link2 + "," + link1, queried); }
public void MatchTest() { String link1 = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10"; String link2 = "</myUri>;ct=50;rt=\"MyName\""; String link3 = "</a>;sz=10;rt=\"MyNope\""; String format = link1 + "," + link2 + "," + link3; RemoteResource res = RemoteResource.NewRoot(format); List <String> query = new List <string>(); query.Add("rt=MyName"); String queried = LinkFormat.Serialize(res, query); Assert.AreEqual(link2 + "," + link1, queried); }
protected static void ValidRemoteResource(RemoteResource resource, ValidationFailedHandler validationFailed) { if (resource.Size <= 0) { validationFailed("Resource size is not more than zero - " + resource.Size); } // TODO: Sometimes it is... /*else if (string.IsNullOrEmpty(resource.HashCode)) * { * validationFailed("Resource hash code is null or empty."); * }*/ else if (resource.GetUrls().Length == 0) { validationFailed("Resource urls are null or empty."); } }
public void ConversionTestsToCbor() { string link = "</sensors>;ct=40;title=\"Sensor Index\",</sensors/temp>;rt=\"temperature-c\";if=\"sensor\"," + "</sensors/light>;rt=\"light-lux\";if=\"sensor\",<http://www.example.com/sensors/t123>;anchor=\"/sensors/temp\"" + ";rel=\"describedby\",</t>;anchor=\"/sensors/temp\";rel=\"alternate\""; byte[] cborX = new byte[] { 0x85, 0xA3, 0x01, 0x68, 0x2F, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x73, 0x0C, 0x62, 0x34, 0x30, 0x07, 0x6C, 0x53, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x20, 0x49, 0x6E, 0x64, 0x65, 0x78, 0xA3, 0x01, 0x6E, 0x2F, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x73, 0x2F, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x0A, 0x66, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x09, 0x69, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x2D, 0x6C, 0x75, 0x78, 0xA3, 0x01, 0x6D, 0x2F, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x73, 0x2F, 0x74, 0x65, 0x6D, 0x70, 0x0A, 0x66, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x09, 0x6D, 0x74, 0x65, 0x6D, 0x70, 0x65, 0x72, 0x61, 0x74, 0x75, 0x72, 0x65, 0x2D, 0x63, 0xA3, 0x01, 0x62, 0x2F, 0x74, 0x03, 0x6D, 0x2F, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x73, 0x2F, 0x74, 0x65, 0x6D, 0x70, 0x02, 0x69, 0x61, 0x6C, 0x74, 0x65, 0x72, 0x6E, 0x61, 0x74, 0x65, 0xA3, 0x01, 0x78, 0x23, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x73, 0x2F, 0x74, 0x31, 0x32, 0x33, 0x03, 0x6D, 0x2F, 0x73, 0x65, 0x6E, 0x73, 0x6F, 0x72, 0x73, 0x2F, 0x74, 0x65, 0x6D, 0x70, 0x02, 0x6B, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x64, 0x62, 0x79 }; RemoteResource res = RemoteResource.NewRoot(link); byte[] cborOut = LinkFormat.SerializeCbor(res, null); Assert.AreEqual(cborOut, cborX); }
/// <summary> /// Put the specified request. /// </summary> /// <param name="request">Request.</param> public object Put(DataPackageUpdateDefaultRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebDataPackageTep result; try{ context.Open(); context.LogInfo(this, string.Format("/data/package/default PUT")); DataPackage def = DataPackage.GetTemporaryForCurrentUser(context); //we want to do the copy of a datapackage into the default one if (def.Identifier != request.Identifier) { foreach (RemoteResource res in def.Resources) { res.Delete(); } def.LoadItems(); var tmp = DataPackage.FromIdentifier(context, request.Identifier); foreach (RemoteResource res in tmp.Resources) { RemoteResource tmpres = new RemoteResource(context); tmpres.Location = res.Location; def.AddResourceItem(tmpres); } ActivityTep activity = new ActivityTep(context, tmp, EntityOperationType.View); activity.SetParam("items", tmp.Resources.Count + ""); activity.Store(); } else { def = (DataPackage)request.ToEntity(context, def); } result = new WebDataPackageTep(def); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public void UseTorrentDownloaderFirst() { RemoteResource resource = CreateTestRemoteResource(); var httpDownloader = Substitute.For <IHttpDownloader>(); var chunkedHttpDownloader = Substitute.For <IChunkedHttpDownloader>(); var torrentDownloader = Substitute.For <ITorrentDownloader>(); var downloader = new RemoteResourceDownloader(_filePath, _metaFilePath, resource, true, (path, remoteResource, timeout) => httpDownloader, (path, remoteResource, timeout) => chunkedHttpDownloader, (path, remoteResource, timeout) => torrentDownloader); downloader.Download(CancellationToken.Empty); httpDownloader.DidNotReceiveWithAnyArgs().Download(CancellationToken.Empty); chunkedHttpDownloader.DidNotReceiveWithAnyArgs().Download(CancellationToken.Empty); torrentDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); }
public RepairFilesCommand( RemoteResource resource, Pack1Meta meta, Pack1Meta.FileEntry[] fileEntries, string destinationPackagePath, string packagePassword, ILocalDirectory localData) { _resource = resource; _meta = meta; _entries = fileEntries; _packagePath = destinationPackagePath; _packagePassword = packagePassword; _localData = localData; _logger = PatcherLogManager.DefaultLogger; }
public void SearchDataPackage() { Terradue.Tep.DataPackage datapackage = DataPackage.GetTemporaryForCurrentUser(context); datapackage.LoadItems(); foreach (RemoteResource res in datapackage.Resources) { res.Delete(); } datapackage.LoadItems(); Assert.AreEqual(0, datapackage.Items.Count); var ressourceItem = new RemoteResource(context); ressourceItem.Location = "https://catalog.terradue.com:443/sentinel1/search?uid=S1A_EW_OCN__2SDH_20200108T051332_20200108T051348_030704_038509_0C1C"; datapackage.AddResourceItem(ressourceItem); ressourceItem = new RemoteResource(context); ressourceItem.Location = "https://catalog.terradue.com:443/sentinel1/search?uid=S1A_IW_RAW__0SSH_20200108T050838_20200108T050910_030704_038508_ED48"; datapackage.AddResourceItem(ressourceItem); ressourceItem = new RemoteResource(context); ressourceItem.Location = "https://catalog.terradue.com:443/sentinel1/search?uid=S1A_IW_OCN__2SDV_20200108T043336_20200108T043412_030704_038504_3458"; datapackage.AddResourceItem(ressourceItem); datapackage.LoadItems(); Assert.AreEqual(3, datapackage.Items.Count); datapackage.SetOpenSearchEngine(MasterCatalogue.OpenSearchEngine); List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>(); osentities.AddRange(datapackage.GetOpenSearchableArray()); var settings = MasterCatalogue.OpenSearchFactorySettings; MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, settings, true); var parameters = new NameValueCollection(); IOpenSearchResultCollection osr = ose.Query(multiOSE, parameters); Assert.AreEqual(3, osr.TotalResults); }
public void SimpleTest_CBOR() { byte[] input = new byte[] { 0x81, 0xa3, 0x01, 0x6d, 0x2f, 0x73, 0x65, 0x6e, 0x73, 0x6F, 0x72, 0x73, 0x2F, 0x74, 0x65, 0x6D, 0x70, 0x0C, 0x62, 0x34, 0x31, 0x09, 0x6C, 0x54, 0x65, 0x6D, 0x70, 0x65, 0x72, 0x61, 0x74, 0x75, 0x72, 0x65, 0x43 }; RemoteResource root = RemoteResource.NewRoot(input, MediaType.ApplicationCbor); RemoteResource res = root.GetResource("/sensors/temp"); Assert.IsNotNull(res); Assert.AreEqual(res.Name, "/sensors/temp"); List <string> contents = res.Attributes.GetContentTypes().ToList(); Assert.AreEqual(1, contents.Count); Assert.AreEqual("41", contents[0]); Assert.AreEqual("TemperatureC", res.ResourceType); }
public void UseChunkedHttpDownloaderIfTorrentFails() { RemoteResource resource = CreateTestRemoteResource(); var httpDownloader = Substitute.For <IHttpDownloader>(); var chunkedHttpDownloader = Substitute.For <IChunkedHttpDownloader>(); var torrentDownloader = Substitute.For <ITorrentDownloader>(); torrentDownloader.When(t => t.Download(CancellationToken.Empty)).Do( info => { throw new DownloadFailureException("Test."); }); var downloader = new RemoteResourceDownloader(_filePath, _metaFilePath, resource, true, (path, urls) => httpDownloader, (path, urls, data, size) => chunkedHttpDownloader, (path, filePath, bytes) => torrentDownloader); downloader.Download(CancellationToken.Empty); chunkedHttpDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); torrentDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); }
public void UseHttpDownloaderIfChunksAreNotAvailable() { RemoteResource resource = CreateTestRemoteResource(); resource.ChunksData.Chunks = new Chunk[0]; var httpDownloader = Substitute.For <IHttpDownloader>(); var chunkedHttpDownloader = Substitute.For <IChunkedHttpDownloader>(); var torrentDownloader = Substitute.For <ITorrentDownloader>(); var downloader = new RemoteResourceDownloader(_filePath, _metaFilePath, resource, false, (path, remoteResource, timeout) => httpDownloader, (path, remoteResource, timeout) => chunkedHttpDownloader, (path, remoteResource, timeout) => torrentDownloader); downloader.Download(CancellationToken.Empty); httpDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); chunkedHttpDownloader.DidNotReceiveWithAnyArgs().Download(CancellationToken.Empty); torrentDownloader.DidNotReceiveWithAnyArgs().Download(CancellationToken.Empty); }
/// <summary> /// Delete the specified request. /// </summary> /// <param name="request">Request.</param> public object Delete(RemoveItemFromDataPackage request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebDataPackageTep result; try{ context.Open(); context.LogInfo(this, string.Format("/data/package/{{DpId}}/item/{{Id}} POST DpId='{0}', Id='{1}'", request.DpId, request.Id)); RemoteResource tmp = RemoteResource.FromId(context, request.Id); tmp.Delete(); DataPackage dp = DataPackage.FromId(context, request.DpId); result = new WebDataPackageTep(dp); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public void UseChunkedHttpDownloaderIfTorrentFails() { RemoteResource resource = CreateTestRemoteResource(); var httpDownloader = Substitute.For <IHttpDownloader>(); var chunkedHttpDownloader = Substitute.For <IChunkedHttpDownloader>(); var torrentDownloader = Substitute.For <ITorrentDownloader>(); torrentDownloader.When(t => t.Download(CancellationToken.Empty)).Do( info => { throw new DownloaderException("Test.", DownloaderExceptionStatus.Other); }); var downloader = new RemoteResourceDownloader(_filePath, _metaFilePath, resource, true, (path, remoteResource, timeout) => httpDownloader, (path, remoteResource, timeout) => chunkedHttpDownloader, (path, remoteResource, timeout) => torrentDownloader); downloader.Download(CancellationToken.Empty); httpDownloader.DidNotReceiveWithAnyArgs().Download(CancellationToken.Empty); chunkedHttpDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); torrentDownloader.ReceivedWithAnyArgs().Download(CancellationToken.Empty); }
public void ConversionTestsToJson() { string link = "</sensors>;ct=40;title=\"Sensor Index\"," + "</sensors/light>;if=\"sensor\";rt=\"light-lux\"," + "</sensors/temp>;if=\"sensor\";obs;rt=\"temperature-c\"," + "</t>;anchor=\"/sensors/temp\";rel=\"alternate\"," + "<http://www.example.com/sensors/t123>;anchor=\"/sensors/temp\";ct=4711;foo=\"bar\";foo=3;rel=\"describedby\""; string jsonX = "[{\"href\":\"/sensors\",\"ct\":\"40\",\"title\":\"Sensor Index\"}," + "{\"href\":\"/sensors/light\",\"if\":\"sensor\",\"rt\":\"light-lux\"}," + "{\"href\":\"/sensors/temp\",\"if\":\"sensor\",\"obs\":true,\"rt\":\"temperature-c\"}," + "{\"href\":\"/t\",\"anchor\":\"/sensors/temp\",\"rel\":\"alternate\"}," + "{\"href\":\"http://www.example.com/sensors/t123\",\"anchor\":\"/sensors/temp\",\"ct\":\"4711\",\"foo\":[\"bar\",\"3\"],\"rel\":\"describedby\"}]"; RemoteResource res = RemoteResource.NewRoot(link); string jsonOut = LinkFormat.SerializeJson(res, null); Assert.AreEqual(jsonOut, jsonX); res = RemoteResource.NewRoot(jsonX, MediaType.ApplicationJson); jsonOut = LinkFormat.Serialize(res, null); Assert.AreEqual(jsonOut, link); }
public object Post(DataPackageAddItemToDefaultRequestTep request) { //Get all requests from database var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebDataPackageTep result; try{ context.Open(); context.LogInfo(this, string.Format("/data/package/default/item POST Location='{0}'", request.Location)); DataPackage tmp = DataPackage.GetTemporaryForCurrentUser(context); RemoteResource tmp2 = new RemoteResource(context); tmp2 = request.ToEntity(context, tmp2); tmp.AddResourceItem(tmp2); result = new WebDataPackageTep(tmp); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }