public async void Subscribe() { var app = new KZApplication(Constants.marketplace, Constants.application); await app.Initialize(); var user = await app.Authenticate (Constants.user, Constants.pass, Constants.provider); var channel = app.PubSubChannel ["pubsubchanneltest"]; var rnd = Guid.NewGuid ().ToString (); channel.Susbscribe<ChannelMessage> (msg=> { Assert.Equals(rnd, msg.value); autoEvent.Set(); }, err=>{ if(err!=null) Assert.Fail(); }) ; var message = new ChannelMessage { value = rnd}; var response = channel.Publish (message); //Assert.AreEqual(HttpStatusCode.Created, response.Result.StatusCode); if (autoEvent.WaitOne (60000)) { Assert.True (1 == 1); } else { Assert.Fail(); } }
public async void ShouldReturnIsInitialized () { var app = new KZApplication(Constants.marketplace, Constants.application); await app.Initialize (); Assert.That (app.Initialized, Is.True); }
static public async Task ClassInit(TestContext context) #endif { app = new KZApplication(test.Constants.MarketplaceUrl, test.Constants.AppName); await app.Initialize(); EnqueueTestComplete(); }
internal Files(KZApplication app, Uri endpoint) { if (app == null) throw new ArgumentNullException("app"); if (endpoint == null) throw new ArgumentNullException("endpoint"); this.app = app; Url = endpoint; }
internal Notification(KZApplication app, Uri endpoint) { if (app == null) { throw new ArgumentNullException("app"); } if (endpoint == null) { throw new ArgumentNullException("endpoint"); } this.app = app; this.Url = endpoint; this.ChannelName = CHANNEL_PREFIX + app.Name; app.OnAuthentication += async(sender, e) => { // If the device has a subscription // initialize Windows Phone infrastrucutre var resultCount = await GetSubscriptionsCount(); if (resultCount.Data > 0) { EnableNotifications(); } }; }
private async Task InitApplication(){ if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application); await app.Initialize(); await app.Authenticate (Constants.user, Constants.pass, Constants.provider); } await InitStorage (); }
internal Notification(KZApplication app, Uri endpoint) { if (app == null) throw new ArgumentNullException("app"); this.app = app; this.Url = endpoint; this.ChannelName = CHANNEL_PREFIX + app.Name; }
internal Indexes(KZApplication app, Uri url) { if (app == null) throw new ArgumentNullException("app"); this.app = app; if (url == null) throw new ArgumentNullException("url"); Url = url.Concat("indexes"); }
internal SmsSender(KZApplication app, Uri endpoint, string number) { if (app == null) throw new ArgumentNullException("app"); this.app = app; this.endpoint = endpoint; Url = endpoint; Number = number; }
public async void ShouldAuthenticate () { var app = new KZApplication(Constants.marketplace, Constants.application); await app.Initialize (); var t = app.Authenticate(Constants.user, Constants.pass, Constants.provider); await t.ContinueWith ((r) => { Assert.IsNotNull(r.Result.TokenMarketplace); }); }
static public async Task ClassInit(TestContext context) #endif { app = new KZApplication(test.Constants.MarketplaceUrl, test.Constants.AppName); await app.Initialize(); var user = await app.Authenticate(test.Constants.User, test.Constants.Password, test.Constants.Provider); service = app.Service["echo"]; EnqueueTestComplete(); }
public void ShouldInitialize () { //arrange var app = new KZApplication(Constants.marketplace, Constants.application, Constants.applicationKey); //act app.Initialize().Wait(); //assert Assert.AreEqual(true, app.Initialized); }
internal Notification(KZApplication app, Uri endpoint) { if (app == null) { throw new ArgumentNullException("app"); } this.app = app; this.Url = endpoint; this.ChannelName = CHANNEL_PREFIX + app.Name; }
public void Login(KZApplication.OnEventHandler onAuthFinish) { #if __ANDROID__ this.kidozenApplication.Authenticate (App.AndroidContext, onAuthFinish); #else this.kidozenApplication.Authenticate (onAuthFinish); #endif database = kidozenApplication.Storage["todo"]; queryDataSource = kidozenApplication.DataSource["QueryTodo"]; saveDataSource = kidozenApplication.DataSource["AddTodo"]; }
public void ShouldAuthenticate () { //arrange var app = new KZApplication(Constants.marketplace, Constants.application,Constants.applicationKey); app.Initialize().Wait(); //act var user = app.Authenticate(Constants.user, Constants.pass, Constants.provider).Result; //assert Assert.IsNotNull(user.TokenMarketplace); Assert.AreEqual(true, app.Authenticated); }
internal SmsSender(KZApplication app, Uri endpoint, string number) { if (app == null) { throw new ArgumentNullException("app"); } this.app = app; this.endpoint = endpoint; Url = endpoint; Number = number; }
public void SetUp () { Console.WriteLine ("Setting up"); if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application,Constants.applicationKey); app.Initialize().Wait(); app.Authenticate(Constants.user, Constants.pass, Constants.provider).Wait(); } if (sms == null) { sms = app.SmsSender["+13053038639"]; } }
public void SetUp () { Console.WriteLine ("Setting up"); if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application,Constants.applicationKey); app.Initialize().Wait(); app.Authenticate(Constants.user, Constants.pass, Constants.provider).Wait(); } if (queue == null) { queue = app.Queue["foo"]; } }
internal PubSubChannel(KZApplication app, Uri endpoint, Uri wsEndpoint, string name) { if (app == null) { throw new ArgumentNullException("app"); } this.app = app; this.Url = endpoint.Concat(name); this.Name = name; this.endpoint = endpoint; this.wsEndpoint = wsEndpoint; }
internal Files(KZApplication app, Uri endpoint) { if (app == null) { throw new ArgumentNullException("app"); } if (endpoint == null) { throw new ArgumentNullException("endpoint"); } this.app = app; Url = endpoint; }
internal Indexes(KZApplication app, Uri url) { if (app == null) { throw new ArgumentNullException("app"); } this.app = app; if (url == null) { throw new ArgumentNullException("url"); } Url = url.Concat("indexes"); }
static public async Task ClassInit(TestContext context) #endif { var bytes = UTF8Encoding.UTF8.GetBytes("sample file"); file = new MemoryStream(); file.Write(bytes, 0, bytes.Length); file.Flush(); app = new KZApplication(test.Constants.MarketplaceUrl, test.Constants.AppName); await app.Initialize(); var user = await app.Authenticate(test.Constants.User, test.Constants.Password, test.Constants.Provider); files = app.Files; EnqueueTestComplete(); }
public void SetUp () { Console.WriteLine ("Setting up"); if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application,Constants.applicationKey); app.Initialize().Wait(); app.Authenticate(Constants.user, Constants.pass, Constants.provider).Wait(); } if (logging == null) { logging = app.Logger; } logging.Write("foo", LogLevel.LogLevelVerbose).Wait(); logging.Clear().Wait(); }
static public async Task ClassInit(TestContext context) #endif { if (app==null) { app = new KZApplication(Constants.MarketplaceUrl, Constants.AppName); await app.Initialize(); var user = await app.Authenticate(Constants.User, Constants.Password, Constants.Provider); } if (queryDataSrc == null) { queryDataSrc = app.DataSource["test-query"]; } if (invokeDataSrc == null) { invokeDataSrc = app.DataSource["test-operation"]; } EnqueueTestComplete(); }
internal Notification(KZApplication app, Uri endpoint) { if (app == null) throw new ArgumentNullException("app"); if (endpoint == null) throw new ArgumentNullException("endpoint"); this.app = app; this.Url = endpoint; this.ChannelName = CHANNEL_PREFIX + app.Name; app.OnAuthentication += async (sender, e) => { // If the device has a subscription // initialize Windows Phone infrastrucutre var resultCount = await GetSubscriptionsCount(); if (resultCount.Data > 0) EnableNotifications(); }; }
internal Storage(KZApplication app, Uri endpoint, string name) { if (app == null) { throw new ArgumentNullException("app"); } if (endpoint == null) { throw new ArgumentNullException("endpoint"); } this.app = app; this.endpoint = endpoint; this.Url = endpoint.Concat(name); this.Name = name; this.Indexes = new Indexes(app, Url); }
public void SetUp () { Console.WriteLine ("Setting up"); Stopwatch sw = new Stopwatch(); sw.Start(); if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application,Constants.applicationKey); app.Initialize().Wait(); app.Authenticate(Constants.user, Constants.pass, Constants.provider).Wait(); } sw.Stop(); Console.WriteLine("Elapsed={0}",sw.Elapsed); if (mail == null) { mail = app.MailSender; } }
static private void addAuthenticationHeader(KZApplication app, UseToken useToken, Dictionary <string, string> headers) { Token token = null; switch (useToken) { case UseToken.Application: token = app.Authentication.User.TokenApplication; break; case UseToken.Marketplace: token = app.Authentication.User.TokenMarketplace; break; case UseToken.ServiceBus: token = app.Authentication.User.TokenServiceBus; break; } if (token != null) { headers["Authorization"] = "WRAP access_token=\"" + token.Value + "\""; } }
internal Service(KZApplication app, Uri endpoint, string name) { if (app == null) { throw new ArgumentNullException("app"); } if (endpoint == null) { throw new ArgumentNullException("endpoint"); } this.app = app; this.endpoint = endpoint; Name = name; if (name != null) { Url = endpoint.Concat(name); } }
public void SetUp () { Console.WriteLine ("Setting up"); ServicePointManager.ServerCertificateValidationCallback = (x,w,y,z)=> true; if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application, Constants.applicationKey); app.Initialize().Wait(); app.Authenticate(Constants.user, Constants.pass, Constants.provider).Wait(); } if (objectSet == null) { objectSet = app.Storage["test-monodroid"]; } //insert just in case the object set doesn't exist objectSet.Insert (new { Foo = "foo" }).Wait (); //drop the object set. var dropResult = objectSet.Drop().Result; Assert.AreEqual(HttpStatusCode.OK, dropResult.StatusCode); }
public void SetUp () { Console.WriteLine ("Setting up"); if (app==null) { app = new KZApplication(Constants.marketplace, Constants.application,Constants.applicationKey); app.Initialize().Wait(); app.Authenticate(Constants.user, Constants.pass, Constants.provider).Wait(); } if (queryDataSrc == null) { queryDataSrc = app.DataSource["GetCityWeather"]; } if (invokeDataSrc == null) { invokeDataSrc = app.DataSource["InvokeCityWeather"]; } if (queryWithData == null) { queryWithData = app.DataSource["GetCityWeather"]; } if (invokeWithData == null) { invokeWithData = app.DataSource["InvokeCityWeather"]; } }
internal Configuration(KZApplication app, Uri endpoint, string name) { if (app == null) { throw new ArgumentNullException("app"); } if (endpoint == null) { throw new ArgumentNullException("endpoint"); } this.app = app; if (name != null) { name = name.ToLower(); Url = endpoint.Concat(name); } Name = name; this.endpoint = endpoint; }
public static void Authenticate (this KZApplication application, KZApplication.OnEventHandler onAuthFinish) { PassiveAuthSettings = new Dictionary<string, string>(); if (!application.Initialized) application.Initialize ().Wait (); KidozenApplicationConfig = application.ApplicationConfiguration; PassiveAuthSettings.Add ("grant_type", "refresh_token"); PassiveAuthSettings.Add ("client_secret", application.applicationKey); PassiveAuthSettings.Add ("client_id", Validate (KidozenApplicationConfig, "domain")); PassiveAuthSettings.Add ("scope", Validate (KidozenApplicationConfig.Value<JObject> ("authConfig"), "applicationScope")); PassiveAuthSettings.Add ("oauthTokenEndpoint", Validate (KidozenApplicationConfig.Value<JObject> ("authConfig"), "oauthTokenEndpoint")); var signInUrl = Validate (KidozenApplicationConfig.Value<JObject> ("authConfig"), "signInUrl"); var authController = new PassiveAuthViewController (signInUrl); var wv = new UINavigationController (authController); authController.AuthenticationResponseArrived+= (object sender, AuthenticationResponseEventArgs e) => { Console.WriteLine("*** Success : " + e.Success); application.Authenticated = e.Success; if(e.Success) { application.PassiveAuthenticationInformation = new Dictionary<string,string>( e.TokenInfo); } else { //TODO: display alert } if(onAuthFinish!=null) { onAuthFinish.Invoke(application, e); } }; UIApplication.SharedApplication.Delegate.Window.RootViewController.PresentViewController (wv, true, new NSAction(()=>{ Console.WriteLine("loading"); })); //OnPassiveAuthentication.Invoke(application, new PassiveAuthenticationEventArgs {Success=e.Success}); }
internal static async Task <ServiceEvent <T> > ExecuteAsync <T>(this Uri uri, KZApplication app, JToken content, string method = "GET", bool cache = false, TimeSpan?timeout = null, Dictionary <string, string> headers = null, UseToken useToken = UseToken.Application, Action <long[]> onProgress = null, bool cors = false) { MemoryStream stream = null; TextWriter writer = null; if (content != null) { stream = new MemoryStream(); writer = new StreamWriter(stream); content.SerializeJson(writer); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); if (headers == null) { headers = new Dictionary <string, string>(); } headers["Content-Type"] = "application/json"; } var result = await uri.ExecuteAsync <T>(app, stream, method, cache, timeout, headers, useToken, onProgress, cors); if (writer != null) { writer.Dispose(); } if (stream != null) { writer.Dispose(); } return(result); }
internal Queue(KZApplication app, Uri endpoint) : this(app, endpoint, null) { }
internal Storage(KZApplication app, Uri endpoint) : this(app, endpoint, null) { }
public async Task Delete() { var app = new KZApplication(test.Constants.MarketplaceUrl, test.Constants.AppName); await app.Initialize(); var user = await app.Authenticate(test.Constants.User, test.Constants.Password, test.Constants.Provider); var files = app.Files; var uploadResult = await files.Upload(file, "/foo.txt"); var result = await files.Browse("/"); Assert.AreEqual(1, result.Data.files .Where(f => f.name == "foo.txt") .Count()); var delResult = await files.Delete("/foo.txt"); Assert.AreEqual(HttpStatusCode.NoContent, delResult.StatusCode); Assert.IsTrue(delResult.Data); result = await files.Browse("/"); Assert.AreEqual(0, result.Data.files .Where(f => f.name == "foo.txt") .Count()); EnqueueTestComplete(); }
internal Marketplace(KZApplication app, Uri endpoint) { this.Url = endpoint; this.app = app; }
internal SmsSender(KZApplication app, Uri endpoint) : this(app, endpoint, null) { }
internal static async Task <ServiceEvent <T> > ExecuteStreamAsync <T>(this Uri uri, KZApplication app, Stream content = null, string method = "GET", bool cache = false, TimeSpan?timeout = null, Dictionary <string, string> headers = null, UseToken useToken = UseToken.Application, Action <long[]> onProgress = null, bool cors = false) where T : Stream { Request request = null; Response response = null; if (headers == null) { headers = new Dictionary <string, string>(); } try { // Does the URL require a no cache? if (!cache) { uri = addNoCache(uri); headers.Add("Cache-Control", "no-cache"); headers.Add("Pragma", "no-cache"); } // Adds authentication's header if (useToken != UseToken.None && app != null && app.Authentication != null && app.Authentication.User != null) { addAuthenticationHeader(app, useToken, headers); } request = await Request.Create(uri, method.ToUpper(), content, headers, timeout); response = (method == "POST" || method == "GET" || method == "PUT") ? await request.Send_POST_GET_PUT(onProgress) : await request.Send_OTHERS(onProgress); // Is token expired? if (response.StatusCode == HttpStatusCode.Unauthorized && app.User != null) { // Refresh token if it is expired var authHeader = response.Headers["WWW-Authenticate"]; if (!string.IsNullOrWhiteSpace(authHeader)) { var realm = authHeader .Split(',') .Where(r => r.StartsWith("error=")) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(realm)) { var message = realm.Split('=')[1].Trim(); if (string.Compare(message, "\"Token is expired\"", StringComparison.CurrentCultureIgnoreCase) == 0) { // Do refresh tokens app.Authentication.RemoveFromCache(app.User.Credential.UserName, app.User.Credential.Password, app.User.Provider); await app.Authentication.Authenticate(app.User.Credential.UserName, app.User.Credential.Password, app.User.Provider); // Set new auth header addAuthenticationHeader(app, useToken, request.Headers); request.Content.Seek(0, SeekOrigin.Begin); // Send request response = (method == "POST" || method == "GET" || method == "PUT") ? await request.Send_POST_GET_PUT(onProgress) : await request.Send_OTHERS(onProgress); } } } } // Process response var evt = new ServiceEvent <T>(); evt.StatusCode = response.StatusCode; evt.Headers = response.Headers; var read = 0L; var total = response.Body == null ? 0 : response.Body.Length; // Download the body as stream an send progress information // Sends initial progress notification if (onProgress != null) { onProgress(new[] { read, total }); } // Creates the stream that will be returned to the client var result = new MemoryStream(); if (total > 0) { // Copies the response body's stream var buffer = new byte[4096]; var bytesRead = await response.Body.ReadAsync(buffer, 0, 4096); while (bytesRead > 0) { result.WriteAsync(buffer, 0, bytesRead); if (onProgress != null) { read += bytesRead; onProgress(new[] { read, total }); } bytesRead = await response.Body.ReadAsync(buffer, 0, 4096); } // Rewinds the stream result.Seek(0, SeekOrigin.Begin); } evt.DataAsStream = (Stream)result; return(evt); } catch (Exception) { throw; } finally { if (request != null) { request.Dispose(); } if (response != null) { response.Dispose(); } } }
internal PubSubChannel(KZApplication app, Uri endpoint, Uri wsEndpoint) : this(app, endpoint, wsEndpoint, null) { }
internal static async Task <ServiceEvent <T> > ExecuteAsync <T>(this Uri uri, KZApplication app, Stream content = null, string method = "GET", bool cache = false, TimeSpan?timeout = null, Dictionary <string, string> headers = null, UseToken useToken = UseToken.Application, Action <long[]> onProgress = null, bool cors = false) { Request request = null; Response response = null; if (headers == null) { headers = new Dictionary <string, string>(); } try { // Does the URL require a no cache? if (!cache) { uri = addNoCache(uri); headers.Add("Cache-Control", "no-cache"); headers.Add("Accept", "*/*"); headers.Add("Pragma", "no-cache"); } if (timeout != null && timeout.HasValue) { headers.Add("timeout", timeout.Value.TotalSeconds.ToString()); } //**** Passive Auth HotFix **** if (app != null && app.PassiveAuthenticationInformation != null) { headers["Authorization"] = "WRAP access_token=\"" + app.PassiveAuthenticationInformation["access_token"] + "\""; } else { // Adds authentication's header if (useToken != UseToken.None && app != null && app.Authentication != null && app.Authentication.User != null) { addAuthenticationHeader(app, useToken, headers); } } request = await Request.Create(uri, method.ToUpper(), content, headers, timeout); response = (method == "POST" || method == "GET" || method == "PUT")? await request.Send_POST_GET_PUT(onProgress) : await request.Send_OTHERS(onProgress); // Is token expired? if (response.StatusCode == HttpStatusCode.Unauthorized && app.User != null) { // Refresh token if it is expired var authHeader = response.Headers["WWW-Authenticate"]; if (!string.IsNullOrWhiteSpace(authHeader)) { var realm = authHeader .Split(',') .Where(r => r.StartsWith("error=")) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(realm)) { var message = realm.Split('=')[1].Trim(); if (string.Compare(message, "\"Token is expired\"", StringComparison.CurrentCultureIgnoreCase) == 0) { //**** Passive Auth HotFix **** if (app.PassiveAuthenticationInformation != null) { var newAuthToken = refreshPassiveToken(app.PassiveAuthenticationInformation); request.Headers["Authorization"] = "WRAP access_token=\"" + newAuthToken + "\""; request.Content.Seek(0, SeekOrigin.Begin); // Send request response = (method == "POST" || method == "GET" || method == "PUT") ? await request.Send_POST_GET_PUT(onProgress) : await request.Send_OTHERS(onProgress); } else { // Do refresh tokens app.Authentication.RemoveFromCache(app.User.Credential.UserName, app.User.Credential.Password, app.User.Provider); await app.Authentication.Authenticate(app.User.Credential.UserName, app.User.Credential.Password, app.User.Provider); // Set new auth header addAuthenticationHeader(app, useToken, request.Headers); request.Content.Seek(0, SeekOrigin.Begin); // Send request response = (method == "POST" || method == "GET" || method == "PUT") ? await request.Send_POST_GET_PUT(onProgress) : await request.Send_OTHERS(onProgress); } } } } } // Process response var evt = new ServiceEvent <T>(); evt.StatusCode = response.StatusCode; evt.Headers = response.Headers; if (typeof(T) == typeof(object)) { using (var stream = response.Body) { using (var reader = new StreamReader(stream, UTF8Encoding.UTF8)) { var data = await reader.ReadToEndAsync(); evt.DataAsString = data; } evt.DataAsStream = response.Body; } } else if (response.Headers.ContainsKey("Content-Type") && response.Headers["Content-Type"].Contains("application/json")) { using (var reader = new StreamReader(response.Body, Encoding.UTF8)) { using (var jsonReader = new JsonTextReader(reader)) { evt.Data = serializer.Deserialize <T>(jsonReader); } } } return(evt); } catch (Exception e) { throw; } finally { if (request != null) { request.Dispose(); } if (response != null) { response.Dispose(); } } }
public CreateSubscriptionBody(Uri id) { platform = "wns"; subscriptionId = id.ToString(); deviceId = KZApplication.GetDeviceUniqueID(); }
public TodoItemDatabase() { this.kidozenApplication = new KZApplication (Settings.Marketplace, Settings.Application, Settings.Key); }
internal Service(KZApplication app, Uri endpoint) : this(app, endpoint, null) { }
internal DataSource(KZApplication app, Uri endpoint) : this(app, endpoint, null) { }
internal Configuration(KZApplication app, Uri endpoint) : this(app, endpoint, null) { }