Ejemplo n.º 1
0
		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();
			}
		}
Ejemplo n.º 2
0
		public async void ShouldReturnIsInitialized ()
		{
			var app = new KZApplication(Constants.marketplace, Constants.application);
			await app.Initialize ();

			Assert.That (app.Initialized, Is.True);
		}
Ejemplo n.º 3
0
        static public async Task ClassInit(TestContext context)
#endif
        {
            app = new KZApplication(test.Constants.MarketplaceUrl, test.Constants.AppName);
            await app.Initialize();
            EnqueueTestComplete();
        }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
        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();
                }
            };
        }
Ejemplo n.º 6
0
		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 ();
		}
Ejemplo n.º 7
0
        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;
		}
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
		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);
			});
		}
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
		public void ShouldInitialize ()
		{
			//arrange
			var app = new KZApplication(Constants.marketplace, Constants.application, Constants.applicationKey);
			//act
			app.Initialize().Wait();
			//assert
			Assert.AreEqual(true, app.Initialized);
		}
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
		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"];

		}
Ejemplo n.º 15
0
		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);
		}
Ejemplo n.º 16
0
        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;
        }
Ejemplo n.º 17
0
		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"];
			}
		}
Ejemplo n.º 18
0
		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"];
			}
		}
Ejemplo n.º 19
0
        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;
        }
Ejemplo n.º 20
0
 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;
 }
Ejemplo n.º 21
0
        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");
        }
Ejemplo n.º 22
0
        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();
        }
Ejemplo n.º 23
0
		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();
		}
Ejemplo n.º 24
0
        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();
        }
Ejemplo n.º 25
0
        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();
            };
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
		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;
			}
		}
Ejemplo n.º 28
0
        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 + "\"";
            }
        }
Ejemplo n.º 29
0
        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);
            }
        }
Ejemplo n.º 30
0
		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);
		}
Ejemplo n.º 31
0
		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"];
			}
		}
Ejemplo n.º 32
0
        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});
		}
Ejemplo n.º 34
0
        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);
        }
Ejemplo n.º 35
0
 internal Queue(KZApplication app, Uri endpoint) :
     this(app, endpoint, null)
 {
 }
Ejemplo n.º 36
0
 internal Storage(KZApplication app, Uri endpoint)
     : this(app, endpoint, null)
 {
 }
Ejemplo n.º 37
0
        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();
        }
Ejemplo n.º 38
0
 internal Marketplace(KZApplication app, Uri endpoint)
 {
     this.Url = endpoint;
     this.app = app;
 }
Ejemplo n.º 39
0
 internal Marketplace(KZApplication app, Uri endpoint)
 {
     this.Url = endpoint;
     this.app = app;
 }
Ejemplo n.º 40
0
 internal SmsSender(KZApplication app, Uri endpoint)
     : this(app, endpoint, null)
 {
 }
Ejemplo n.º 41
0
        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();
                }
            }
        }
Ejemplo n.º 42
0
 internal PubSubChannel(KZApplication app, Uri endpoint, Uri wsEndpoint) :
     this(app, endpoint, wsEndpoint, null)
 {
 }
Ejemplo n.º 43
0
        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();
                }
            }
        }
Ejemplo n.º 44
0
 public CreateSubscriptionBody(Uri id)
 {
     platform       = "wns";
     subscriptionId = id.ToString();
     deviceId       = KZApplication.GetDeviceUniqueID();
 }
Ejemplo n.º 45
0
		public TodoItemDatabase()
		{
			this.kidozenApplication = new KZApplication (Settings.Marketplace, Settings.Application, Settings.Key);
		}
Ejemplo n.º 46
0
 internal Service(KZApplication app, Uri endpoint) :
     this(app, endpoint, null)
 {
 }
Ejemplo n.º 47
0
 internal DataSource(KZApplication app, Uri endpoint) :
     this(app, endpoint, null)
 {
 }
Ejemplo n.º 48
0
 internal SmsSender(KZApplication app, Uri endpoint)
     : this(app, endpoint, null)
 {
 }
Ejemplo n.º 49
0
 internal Configuration(KZApplication app, Uri endpoint)
     : this(app, endpoint, null)
 {
 }