Last active
January 29, 2017 06:14
-
-
Save Sohojoe/d7f8a452c5e60d70ab62e2794fa3d11b to your computer and use it in GitHub Desktop.
argh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using ServiceStack; | |
using ServiceStack.Text; | |
using System; | |
using System.Threading.Tasks; | |
using Orions.Cloud.Client.Http; | |
using Orions.Cloud.Common.Data; | |
using System.Collections.Generic; | |
const string AppAccessToken = "eyJ0eXAiOiJDU1AiLCAiZW5jIjoiUlNBX09BRVAifQ.GiJl1NAy9E64OtcqoeE5NedwGylIXwK5F39m_5v0NnGm2zWmJ3x6Hhx0c65QbCZL8v2wJRe6kxTf4KYBaFohSoyu2Z-LJmJFOScSQqeUgbi62amT636Y6wIDoM84oQ23R5v2NPL8n7wwtQecx7_xa5lYgnNFDlq1pb41KXQT65I.66yEgL7AapwReAGV.jEhvqHMvF_TGr0eMIK2X1yBw2paVxUq8eW9JUlXdArISpg3cVNqcWhcSKpHvig.YB9A05OjxOCEonAOXJDXlw"; | |
static var LogOutput = new List<string>(); | |
static void Log(string str) | |
{ | |
Console.WriteLine(str); | |
//str.PrintDump(); | |
//LogOutput += str + "\n"; | |
LogOutput.Add(str); | |
} | |
LogOutput.PrintDump(); | |
// Save a copy of this *public* Gist by clicking the "Save As" below | |
Log("--- Test OrionsCloud ---"); | |
try | |
{ | |
HelloDataAsync().GetAwaiter().GetResult(); | |
HelloTypedDataAsync().GetAwaiter().GetResult(); | |
} | |
catch (Exception ex) | |
{ | |
Log(""); | |
Log(ex.Message); | |
Log(""); | |
} | |
Log("...completed!"); | |
//----- Typed cl;ass example ------ | |
static async Task HelloDataAsync() | |
{ | |
Log("Create a new object"); | |
var p = new HttpDataProxy<GenericIdDataObject>("TestData1", AppAccessToken); | |
var data = new GenericIdDataObject(); | |
data.Set("Name", "fred"); | |
var result = await p.CreateAsync(data); | |
if (result.IsNotSuccess) | |
throw new Exception(result.Message); | |
// update date with the object that was created | |
data = result.Result; | |
Log(String.Format("Id: {0} = the unique id", data.Id)); | |
Log(String.Format("Created: {0} = DateTime when created (on server)", data.Created)); | |
Log(String.Format("Updated: {0} = DateTime of last update", data.Updated)); | |
Log(String.Format("Read our object")); | |
var getRes = await p.GetAsync(data.Id); | |
if (getRes.IsNotSuccess) | |
throw new Exception(result.Message); | |
var copy = getRes.Result; | |
Log(String.Format("Origonal Id:{0} Copy Id:{1}", data.Id, copy.Id)); | |
} | |
//----- Typed cl;ass example ------ | |
class TestData1 : IdDataObject | |
{ | |
public string Name { get; set; } | |
public int Age { get; set; } | |
} | |
static async Task HelloTypedDataAsync() | |
{ | |
Log(String.Format("Create a new typed object")); | |
var p = new HttpDataProxy<TestData1>(AppAccessToken); | |
var data = new TestData1 { | |
Name = "Jane", | |
Age = 23 | |
}; | |
var result = await p.CreateAsync(data); | |
if (result.IsNotSuccess) | |
throw new Exception(result.Message); | |
// update date with the object that was created | |
data = result.Result; | |
Log(String.Format("Id: {0} = the unique id", data.Id)); | |
Log(String.Format("Created: {0} = DateTime when created (on server)", data.Created)); | |
Log(String.Format("Updated: {0} = DateTime of last update", data.Updated)); | |
Log(String.Format("Name: {0}", data.Name)); | |
Log(String.Format("Age: {0}", data.Age)); | |
Log("Read our object"); | |
var getRes = await p.GetAsync(data.Id); | |
if (getRes.IsNotSuccess) | |
throw new Exception(result.Message); | |
var copy = getRes.Result; | |
Log(String.Format("Origonal Id:{0} Copy Id:{1}", data.Id, copy.Id)); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="ServiceStack.Text" version="4.0.62" targetFramework="net45" /> | |
<package id="ServiceStack.Client" version="4.0.62" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="4.0.62" targetFramework="net45" /> | |
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" /> | |
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" /> | |
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" /> | |
<package id="Microsoft.Bcl.Build" version="1.0.14" /> | |
<package id="Orions.Cloud.Client.Core" version="2.14.35" targetFramework="net45" /> | |
<package id="Orions.Cloud.Client.Http" version="2.14.35" targetFramework="net45" /> | |
<package id="Orions.Cloud.Common" version="2.14.35" targetFramework="net45" /> | |
<package id="Orions.Common.Portable.Develop" version="2.0.239" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment