public void SendEvent(string json)
    {
        JSonReader reader = new JSonReader();
        IJSonObject jsonObj = reader.ReadAsJSonObject(json);

        if (jsonObj.Contains("method") && jsonObj.Contains("parameters"))
        {
            switch (jsonObj["method"].ToString())
            {
                case ("PlatformEvent"):
                    if (jsonObj["parameters"].Contains("eventName"))
                        SendMessageToSupport("PlatformEvent", jsonObj["parameters"]["eventName"].ToString());
                    break;
                case ("LowFeedback"):
                    if (jsonObj["parameters"].Contains("message"))
                        if (null != interfaces)
                            interfaces.SendMessage("ShowLowFeedback", jsonObj["parameters"]["message"].ToString(), SendMessageOptions.DontRequireReceiver);
                    break;
                case ("HighFeedback"):
                    if (jsonObj["parameters"].Contains("message"))
                        if (null != interfaces)
                            interfaces.SendMessage("ShowHighFeedback", jsonObj["parameters"]["message"].ToString(), SendMessageOptions.DontRequireReceiver);
                    break;
                case ("Highlight"):
                    if (jsonObj["parameters"].Contains("target"))
                        if (null != workspace)
                            workspace.SendMessage("Highlight", jsonObj["parameters"]["target"].ToString(), SendMessageOptions.DontRequireReceiver);
                    break;
                case ("RemoveHighlight"):
                    if (null != workspace)
                        workspace.SendMessage("DestroyHighlight", SendMessageOptions.DontRequireReceiver);
                    break;
            }
        }
    }
        public void ParseISODateWithoutTimeZone()
        {
            var reader = new JSonReader("\"2012-05-17 09:58:33\"");
            var item = reader.ReadAsJSonObject();
            var date = item.DateTimeValue;

            Assert.AreEqual(new DateTime(2012, 05, 17, 09, 58, 33, DateTimeKind.Local), date);
        }
        public void ParseDateWithoutTimeAsUnspecified()
        {
            var reader = new JSonReader("\"1999-01-07\"");
            var item = reader.ReadAsJSonObject();
            var date = item.DateTimeValue;

            Assert.AreEqual(new DateTime(1999, 01, 07, 0, 0, 0, DateTimeKind.Unspecified), date);
        }
        public void ParseISODateWithTimeZone()
        {
            var reader = new JSonReader("\"2012-06-16T21:09:45+00:00\"");
            var item = reader.ReadAsJSonObject();
            var date = item.DateTimeValue;

            Assert.AreEqual(new DateTime(2012, 06, 16, 21, 9, 45, DateTimeKind.Utc).ToLocalTime(), date);
        }
    public void ProcessTaskInformationPackage(string jsonString)
    {
        JSonReader reader = new JSonReader();
        IJSonObject jsonObj = reader.ReadAsJSonObject(jsonString);
        elements = new List<Element>();

        ParseInitialModel(jsonObj);
        ParseInitialConfiguration(jsonObj);
        ParseExtraInformation(jsonString);
         taskDescriptionIsActive = ParseTaskDescription(jsonObj);
    }
        public void ParseSerializedCurrentDateAsISO()
        {
            var writer = new JSonWriter();
            var now = DateTime.Now;

            // remove miliseconds:
            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0, now.Kind);

            using(writer.WriteObject())
                writer.WriteMember("date", now);
            
            var reader = new JSonReader(writer.ToString());
            var item = reader.ReadAsJSonObject();
            var date = item["date"].DateTimeValue;

            Assert.AreEqual(now, date);
        }
Esempio n. 7
0
        public void ParseToJSon()
        {
            const string jsonText = "[{\"minimumVersion\":\"1.0\",\"type\": null,\"channel\":\"\\/meta\\/handshake\",\"supportedConnectionTypes\":[\"request-response\"],\"successful\":true}]";

            var reader = new JSonReader(jsonText);
            var result = reader.ReadAsJSonObject();
            Assert.AreEqual("/meta/handshake", result[0]["channel"].StringValue, "Invalid channel");
            Assert.IsTrue(result[0]["type"].IsNull, "Type should be null");
            Assert.AreEqual(1, result[0]["supportedConnectionTypes"].Count, "Supported types are an array with 1 element");
            Assert.AreEqual(1.0, result[0]["minimumVersion"].DoubleValue, "Current version is 1.0");
            Assert.IsTrue(result[0]["successful"].IsTrue, "Operation finished with success!");
        }
Esempio n. 8
0
        public void ParseChineseTextWithEmbeddedArray()
        {
            var jsonText = LoadTestInputFile("chinese_encoding.json");

            var reader = new JSonReader(jsonText);
            var result = reader.ReadAsJSonObject();
            Assert.IsNotNull(result);

            var internalData = reader.ReadAsJSonObject(result["DataObject"].StringValue);
            Assert.IsNotNull(internalData);
            Assert.AreEqual(2, internalData.Count);
            Assert.AreEqual("业务员", internalData[0]["EmployeeType"].StringValue);
        }
Esempio n. 9
0
	// Obtem o resultado do vinculo com o Facebook
	private IEnumerator handleLink()
	{
#if UNITY_IPHONE
		EtceteraBinding.hideActivityView();
#elif UNITY_ANDROID
		EtceteraAndroid.hideProgressDialog();
#endif
		//GameGUI.game_native.stopLoading();
		
		// Numero maximo de tentativas
		int max_attempts = 5;
		
		WWW conn = null;
		
		WWWForm form = new WWWForm();
		form.AddField("token", Save.GetString(PlayerPrefsKeys.TOKEN.ToString()));
		form.AddField("device", SystemInfo.deviceUniqueIdentifier.Replace("-",""));
		
		while (max_attempts > 0)
		{
			conn = new WWW(Flow.URL_BASE + "login/facebook/fblresult.php", form);
			yield return conn;
			
			if (conn.error != null || conn.text != "") break;
			
			max_attempts--;
			yield return new WaitForSeconds(1);
		}
		
		if (max_attempts == 0 || conn.error != null)
		{
			Debug.LogError("Server error: " + conn.error);
			sendToCallback(GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE, null);
			
			yield break;
		}
		
		JSonReader reader = new JSonReader();
		IJSonObject data = reader.ReadAsJSonObject(conn.text);
		
		// Salva o token
		if (data.Contains("token")) GameToken.save(data);
		
		// Verifica se houve erro
		if (data == null || data.Contains("error"))
		{
			Debug.LogError("Json error: " + conn.text);
			
			string message;
			
			switch(data["error"].ToString())
			{
				case "access_denied":
					message = "You have to authorize our app on Facebook.";
					break;
					
				case "facebook_already_used":
					message = "Your Facebook is already in use on another account.";
					break;
					
				case "different_account":
					message = "Your account already has another Facebook linked.";
					break;
				
				default:
					message = GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE;
					break;
			}
			
			sendToCallback(message, null);
			yield break;
		}
		
		data = data["result"];
		
		Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString() , data["fbtoken"].ToString(), true);
		sendToCallback(null, data);
	}
        private IJSonObject ConvertToJSon(string data)
        {
            if (!string.IsNullOrEmpty(data))
            {
                try
                {
                    var reader = new JSonReader(data);
                    return reader.ReadAsJSonObject();
                }
                catch (Exception ex)
                {
                    DebugLog.WriteBayeuxLine("Request is not in JSON format!");
                    DebugLog.WriteBayeuxException(ex);
                }
            }

            return null;
        }
	// Convida os amigos a partir do canvas
	public void inviteFriendsFromCanvas(string request)
	{
		if (request.IsEmpty())
		{
			Debug.Log("empty request");
			//Scene.First.Load();
			return;
		}
		
		JSonReader reader = new JSonReader();
		IJSonObject json = null;
		
		// Tenta ler o retorno
		try
		{
			json = reader.ReadAsJSonObject(request);
		}
		catch (JSonReaderException e)
		{
			Debug.Log("exception: "+e.Message);
			//Scene.First.Load();
			return;
		}
		
		GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/facebook/invite.php", handleInviteFriendsFromCanvas);
		
		WWWForm form = new WWWForm();
		form.AddField("request", json["request"].StringValue);
		form.AddField("redirect", "no");
		
		int i = 0;
		foreach (IJSonObject friend in json["to"].ArrayItems)
		{
			form.AddField("to[" + i + "]", friend.StringValue);
			i++;
		}
		
		conn.connect(form);
	}
Esempio n. 12
0
        public void ParseDate1970_Variant4()
        {
            var reader = new JSonReader("\"@" + (11 * 60 * 60 * 1000 + 22 * 60 * 1000 + 30 * 1000) + " @\" ");
            var result = reader.ReadAsJSonObject();
            Assert.IsNotNull(result);

            var date = result.DateTimeValue.ToUniversalTime();

            Assert.AreEqual(1970, date.Year);
            Assert.AreEqual(1, date.Month);
            Assert.AreEqual(1, date.Day);
            Assert.AreEqual(11, date.Hour);
            Assert.AreEqual(22, date.Minute);
            Assert.AreEqual(30, date.Second);
        }
Esempio n. 13
0
        public void ParseDate1970_Variant2()
        {
            var reader = new JSonReader("\"/ DATE (" + (2 * 60 * 60 * 1000) + " )/\"");
            var result = reader.ReadAsJSonObject();
            Assert.IsNotNull(result);

            var date = result.DateTimeValue.ToUniversalTime();

            Assert.AreEqual(1970, date.Year);
            Assert.AreEqual(1, date.Month);
            Assert.AreEqual(1, date.Day);
            Assert.AreEqual(2, date.Hour);
        }
Esempio n. 14
0
        public void ParseCurrentDate()
        {
            var reader = new JSonReader("\"/DATE()/\"");
            var result = reader.ReadAsJSonObject();
            Assert.IsNotNull(result);

            var currentDate = DateTime.Now;
            var date = result.DateTimeValue;

            Assert.AreEqual(currentDate.Year, date.Year);
            Assert.AreEqual(currentDate.Month, date.Month);
            Assert.AreEqual(currentDate.Day, date.Day);
        }
Esempio n. 15
0
        public void ParseSerializedCurrentDateAsEpochSeconds()
        {
            var writer = new JSonWriter();
            var now = DateTime.Now;

            using (writer.WriteObject())
                writer.WriteMember("date", now, JSonWriterDateFormat.UnixEpochSeconds);

            // remove below seconds:
            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0, now.Kind);

            var reader = new JSonReader(writer.ToString());
            var item = reader.ReadAsJSonObject();
            var date = item["date"].ToDateTimeValue(JSonDateTimeKind.UnixEpochSeconds);

            Assert.AreNotEqual(0, item["date"].Int64Value);
            Assert.AreEqual(now, date);
        }
Esempio n. 16
0
        //this returns the json object as defined for data transfer
        public IJSonObject readJson(String data)
        {
            JSonReader jr = new JSonReader();
            IJSonObject ijo = jr.ReadAsJSonObject(data);
            String jdata;
            SHA512Managed checksum = new System.Security.Cryptography.SHA512Managed();
            if (ijo[0].BooleanValue)
            {
                //using ijo[3].StringValue != null throws ArrayOutOfBounds exception
                if (ijo.Count > 3)
                {
                    jdata = DecryptIt(ijo[2].StringValue, Convert.FromBase64String(Properties.Settings.Default.cryptKey), Convert.FromBase64String(ijo[3].StringValue));
                }
                else
                {
                    jdata = DecryptIt(ijo[2].StringValue);
                }
            }
            else
            {
                jdata = Encoding.ASCII.GetString(Convert.FromBase64String(ijo[2].StringValue));
            }
            String sha512 = Convert.ToBase64String(checksum.ComputeHash(Encoding.ASCII.GetBytes(jdata)));
            String osha512 = ijo[1].StringValue;
            IJSonObject r;
            //make sure the message is identical to original
            if (osha512 == sha512)
            {
                r = jr.ReadAsJSonObject(jdata);

            }
            else
            {
                //if this comes up data doesn't match the checksum
                r = null;
            }
            return r;
        }
Esempio n. 17
0
        public void ParseAsIEnumerable()
        {
            var jsonText = @"[{""title"":""Title1"",""children"":[{""title"":""Child1"",""children"":[{""title"":""grandchild1"",""children"":[{""title"":""Huh""}]}] }] }, {""title"": ""Title2"" }]";

            JSonReader jr = new JSonReader(jsonText);
            IJSonObject json = jr.ReadAsJSonObject();
            IEnumerable items = json.ArrayItems;

            foreach (var arrayItem in json.ArrayItems)
            {
                //Console.WriteLine(arrayItem.ToString());
                foreach (var objItem in arrayItem.ObjectItems)
                {
                    Console.WriteLine(objItem);
                }
            }
        }
        public void ConvertImmutableJSonObjectToMutableAndUpdateIt()
        {
            var jsonText = "{ \"a\": 1, \"b\": 2, \"c\": [1,2,3,4] }";

            var reader = new JSonReader(jsonText);
            var result = reader.ReadAsJSonObject();

            Assert.IsNotNull(result, "Invalid data read!");
            Assert.AreEqual(1, result["a"].Int32Value, "Unexpected value for field 'a'.");

            var clone = result.CreateMutableClone();
            Assert.IsNotNull(clone, "Unexpected null clone!");
            Assert.AreEqual(1, clone["a"].Int32Value, "Unexpected value for clonned field 'a'.");
            Assert.IsTrue(clone["a"].IsMutable, "Value should be mutable!");

            clone["a"].AsMutable.SetValue(3);
            clone.SetValue("b", 4);
            clone["c"].AsMutable.SetValueAt(2, 55);
            Assert.AreEqual(3, clone["a"].Int32Value, "Expected value to be updated for field 'a'!");
            Assert.AreEqual(4, clone["b"].Int32Value, "Expected value to be updated for field 'b'!");
            Assert.AreEqual(55, clone["c"][2].Int32Value, "Expected array item to be updated!");

            // verify, that original object was left intact:
            Assert.AreEqual(1, result["a"].Int32Value, "Unexpected update!");
            Assert.AreEqual(2, result["b"].Int32Value, "Unexpected update!");
            Assert.AreEqual(3, result["c"][2].Int32Value, "Unexpected update!");
        }
        public void TryToUpdateImmutableJSonObject()
        {
            var jsonText = "{ \"a\": 1, \"b\": 2 }";

            var reader = new JSonReader(jsonText);
            var result = reader.ReadAsJSonObject();

            Assert.IsNotNull(result, "Invalid data read!");
            Assert.AreEqual(1, result["a"].Int32Value, "Unexpected value for field 'a'.");

            result.AsMutable.SetValue("a", 3);
        }
Esempio n. 20
0
        public void ParseExplicitDate_Varian1()
        {
            var reader = new JSonReader("\"\\/ DATE (1920,12,31)\\/\"");
            var result = reader.ReadAsJSonObject();
            Assert.IsNotNull(result);

            var date = result.DateTimeValue.ToUniversalTime();

            Assert.AreEqual(1920, date.Year);
            Assert.AreEqual(12, date.Month);
            Assert.AreEqual(31, date.Day);
        }
	private void handleLoginFromCanvas(string error, WWW data)
	{
		// Up Top Fix Me
		//GameGUI.enableGui();
		//game_native.stopLoading();
		
		Debug.Log("esta acontecendo: "+data.text);
		
		JSonReader reader = new JSonReader();
		IJSonObject json = null;
		
		// Tenta ler o retorno
		try
		{
			if (error == null) json = reader.ReadAsJSonObject(data.text);
		}
		catch (JSonReaderException e)
		{
			Debug.Log(e.StackTrace);
			Debug.Log(e.Source);
			Debug.Log(e.InnerException);
			Debug.Log(e.Message);
			error = MESSAGE_LOGIN_FAILED;
		}
		
		//Debug.Log(json);
		
		if (error != null || json == null || !json["logged"].BooleanValue)
		{
			Debug.Log(error);
			// Up Top Fix Me
			//game_native.showMessage("Error", MESSAGE_LOGIN_FAILED);
			return;
		}
		
		Save.Set(PlayerPrefsKeys.TOKEN.ToString(), json["token"].ToString());
		Save.Set(PlayerPrefsKeys.NAME.ToString(), json["username"].ToString());
		Save.Set(PlayerPrefsKeys.ID.ToString(), json["user_id"].ToString());
		
		Save.Set(PlayerPrefsKeys.FIRST_NAME.ToString(), json["first_name"].ToString());
		Save.Set(PlayerPrefsKeys.LAST_NAME.ToString(), json["last_name"].ToString());
		Save.Set(PlayerPrefsKeys.LOCATION.ToString(), json["location"].ToString());
		if(!json["gender"].IsNull) Save.Set(PlayerPrefsKeys.GENDER.ToString(), json["gender"].ToString());
		string day, month, year;
		string[] separator = {"-"};
		string[] birthday = json["birthday"].StringValue.Split(separator,System.StringSplitOptions.None);
		
		day = birthday[2];
		month = birthday[1];
		year = birthday[0];
		
		Save.Set(PlayerPrefsKeys.DATE_DAY.ToString(), day);
		Save.Set(PlayerPrefsKeys.DATE_MONTH.ToString(), month);
		Save.Set(PlayerPrefsKeys.DATE_YEAR.ToString(), year);
		
		Debug.Log(json);
		
		// Se a conta nao for nova, redireciona a cena
		if (!json["new_account"].BooleanValue) 
		{
			Debug.Log("conta velha");
			//Scene.First.Load();
		}
		else 
		{
			Debug.Log("conta nova");
			Application.ExternalEval("inviteFriends()");
		}
		
		ConfigManager.offlineUpdater.UpdateOfflineItems();
	}
Esempio n. 22
0
        public void ParseExplicitDate_Varian2()
        {
            var reader = new JSonReader("\"\\/ DATE (1999,  1 , 1, 12, 22, 33, 500)\\/\"");
            var result = reader.ReadAsJSonObject();
            Assert.IsNotNull(result);

            var date = result.DateTimeValue.ToUniversalTime();
            Assert.AreEqual(1999, date.Year);
            Assert.AreEqual(1, date.Month);
            Assert.AreEqual(1, date.Day);
            Assert.AreEqual(12, date.Hour);
            Assert.AreEqual(22, date.Minute);
            Assert.AreEqual(33, date.Second);
            Assert.AreEqual(500, date.Millisecond);
        }
        /// <summary>
        /// Method called just after selection of response performed, but before taking any other action.
        /// It might be used to:
        ///  1) update the data-source based on request data
        ///  2) update the response with request specific data
        ///  3) replace the whole response object
        ///  4) send some other extra notifications, when subclassed
        /// </summary>
        protected override void InternalPreProcessResponse(RecordedDataSourceSelectorEventArgs e)
        {
            // find fields inside the request:
            string id = ReadSharedFieldsAndID(ConvertToJSon(e));

            // update token value, if allowed:
            if (!AllowUpdateTokenOnRequest)
                UpdateTokenValue();

            // update response fields, depending if it is a single or array response:
            var response = e.SelectedResponse as RecordedBayeuxDataSourceResponse;
            if (response != null)
            {
                if (response.AsJSon != null)
                {
                    UpdateSharedFields(e.RequestDataAsJSon as IJSonObject, response.AsJSon, id);
                }
                else
                {
                    IJSonObject responseJSon = null;
                    try
                    {
                        var reader = new JSonReader(response.AsString);
                        responseJSon = reader.ReadAsJSonObject();
                    }
                    catch (Exception ex)
                    {
                        DebugLog.WriteBayeuxLine("Response AsString is not in JSON format!");
                        DebugLog.WriteBayeuxException(ex);
                    }

                    UpdateSharedFields(e.RequestDataAsJSon as IJSonObject, responseJSon, id);
                }
            }
        }
Esempio n. 24
0
	// Obtem as informacoes do Facebook no servidor
	private IEnumerator getFacebookInfo()
	{
		Debug.Log("pegando info face");
		// Numero maximo de tentativas
		int max_attempts = 5;
		
		WWW conn = null;
		
		WWWForm form = new WWWForm();
		form.AddField("device", SystemInfo.deviceUniqueIdentifier.Replace("-", ""));
		form.AddField("authentication", authentication);
		
		while (max_attempts > 0)
		{
			conn = new WWW(Flow.URL_BASE + "login/facebook/fbinfo.php", form);
			yield return conn;
			
			if (conn.error != null || conn.text != "") break;
			
			max_attempts--;
			
			yield return new WaitForSeconds(1);
		}
		
		Flow.game_native.stopLoading();
		
		if (max_attempts == 0 || conn.error != null)
		{
			Debug.LogError("Server error: " + conn.error);
			Flow.game_native.showMessage("Error", GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE);
			
			yield break;
		}
		
		JSonReader reader = new JSonReader();
		IJSonObject data = reader.ReadAsJSonObject(conn.text);
		
		if (data == null || data.Contains("error"))
		{
			Debug.LogError("Json error: " + conn.text);
			Flow.game_native.showMessage("Error", GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE);
			
			yield break;
		}
		
		Debug.Log("data: " + data);
		
		GameToken.save(data);
		Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), data["fbtoken"].ToString(), true);
		Save.Set(PlayerPrefsKeys.NAME.ToString(), data["username"].ToString(),true);
		Save.Set(PlayerPrefsKeys.ID.ToString(), data["user_id"].ToString(),true);
		if(!data["email"].IsNull) Save.Set(PlayerPrefsKeys.EMAIL.ToString(), data["email"].ToString(), true);
		if(!data["first_name"].IsNull) Save.Set(PlayerPrefsKeys.FIRST_NAME.ToString(), data["first_name"].ToString(), true);
		if(!data["last_name"].IsNull) Save.Set(PlayerPrefsKeys.LAST_NAME.ToString(), data["last_name"].ToString(), true);
		if(!data["location"].IsNull) Save.Set(PlayerPrefsKeys.LOCATION.ToString(), data["location"].ToString(), true);
		if(!data["gender"].IsNull) Save.Set(PlayerPrefsKeys.GENDER.ToString(), data["gender"].ToString(), true);
		
		if(!data["birthday"].IsNull)
		{
			string day, month, year;
			string[] separator = {"-"};
			string[] birthday = data["birthday"].StringValue.Split(separator,System.StringSplitOptions.None);
			
			day = birthday[2];
			month = birthday[1];
			year = birthday[0];
			
			Save.Set(PlayerPrefsKeys.DATE_DAY.ToString(), day,true);
			Save.Set(PlayerPrefsKeys.DATE_MONTH.ToString(), month,true);
			Save.Set(PlayerPrefsKeys.DATE_YEAR.ToString(), year,true);
		}
		
		// Atualiza token da FacebookAPI
		if (Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) {
			FacebookAPI facebook = new FacebookAPI();
			facebook.SetToken(Save.GetString(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString()));
		}
		
		Save.SaveAll();
		
		ConfigManager.offlineUpdater.UpdateOfflineItems();
		
		CheckLogin();
	}
Esempio n. 25
0
	// Obtem as informacoes do Facebook no servidor
	private IEnumerator getLoginResult(string auth, object state, LoginCallback callback)
	{
		// Numero maximo de tentativas
		int max_attempts = 5;
		
		WWW conn = null;
		
		WWWForm form = new WWWForm();
		form.AddField("device", SystemInfo.deviceUniqueIdentifier.Replace("-", ""));
		form.AddField("authentication", auth);
		
		while (max_attempts > 0)
		{
			conn = new WWW(Flow.URL_BASE + "login/facebook/fbinfo.php", form);
			yield return conn;
			
			if (conn.error != null || conn.text != "") break;
			
			max_attempts--;
			
			yield return new WaitForSeconds(1);
		}
		
		if (max_attempts == 0 || conn.error != null)
		{
			Debug.LogError("Server error: " + conn.error);
			yield break;
		}
		
		JSonReader reader = new JSonReader();
		IJSonObject data = reader.ReadAsJSonObject(conn.text);
		
		if (data == null || data.Contains("error"))
		{
			Debug.LogError("Json error: " + conn.text);
			yield break;
		}
		
		GameToken.save(data);
		
		// Verifica se houve erro
		if (data.Contains("fb_error_reason") && data["fb_error_reason"].ToString() == "user_denied")
		{
			// Up Top Fix Me
			//GameGUI.game_native.showMessage("Error", "You need to authorize our app on Facebook.");
			
			// Redireciona para o login caso necessario
			// Up Top Fix Me
			//if (Scene.GetCurrent() != GameGUI.components.login_scene)
				//Scene.Login.Load(Info.firstScene);
			
			yield break;
		}
		
		// Salva o token do Facebook
		Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), data["fbtoken"].ToString(), true);		
		
		// Atualiza token da FacebookAPI
		FacebookAPI facebook = new FacebookAPI();
		facebook.UpdateToken();
		if (callback != null) callback(state);
	}
Esempio n. 26
0
 public void ParseInvalidKeywordWithinArray_AndFail()
 {
     try
     {
         var reader = new JSonReader(" [ \t abcdef ]");
         reader.ReadAsJSonObject();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(5, ex.Offset);
         throw;
     }
 }
Esempio n. 27
0
	public static IJSonObject ToJSon(this string value)
    {
		JSonReader reader = new JSonReader();
		
		try
		{
			IJSonObject data = reader.ReadAsJSonObject(value);
			return data;
		}
		catch (JSonReaderException)
		{
			return reader.ReadAsJSonObject(ERROR_INVALID_JSON);
		}
    }
Esempio n. 28
0
        public void ParseNumberWithDecimalForced_AndCheckItemType()
        {
            var reader = new JSonReader((ulong.MaxValue + 1d).ToString(CultureInfo.InvariantCulture));
            var result = reader.ReadAsJSonObject(JSonReaderNumberFormat.AsDecimal);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType().Name.Contains("DecimalDecimal"));
        }
Esempio n. 29
0
	// Processa o resultado da conexao de login
	private void connectionResult(string error, WWW data)
	{
		//Debug.Log("resultado chegou");
		JSonReader reader = new JSonReader();
		IJSonObject json = null;
		
		//Debug.Log("data: "+data.text);
		
		// Tenta ler o retorno
		if (data == null) error = "json_error";
		else
		{
			try
			{
				if (error == null) json = reader.ReadAsJSonObject(data.text);
			}
			catch (JSonReaderException)
			{
				error = "json_error";
			}
		}
		
		// Verifica se houve erro
		if (error == null && json.Contains("error")) error = json["error"].ToString();
		
		Flow.game_native.stopLoading();
		
		// Trata o erro
		if (error != null)
		{
			switch (error)
			{
				case "empty_email": error = "Please inform an e-mail."; break;
				case "invalid_email": error = "Invalid e-mail. Please try another account."; break;
				default: error = GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE; break;
			}
			Flow.game_native.showMessage("Error", error);
			
			return;
		}
		
		if (json.Contains("ask") && json["ask"].ToString() == "password")
		{			
			passwordDialog.SetActive(true);
			UIManager.instance.FocusObject = passwordField;
			
			return;
		}
		
		Debug.Log(json);
		
		GameToken.save(json);
		Save.Set(PlayerPrefsKeys.EMAIL.ToString(), email,true);
		Save.Set(PlayerPrefsKeys.PASSWORD.ToString(), password, true);
		
		Save.Set(PlayerPrefsKeys.NAME.ToString(), json["username"].ToString(),true);
		Save.Set(PlayerPrefsKeys.ID.ToString(), json["user_id"].ToString(),true);
		
		if(!json["first_name"].IsNull) Save.Set(PlayerPrefsKeys.FIRST_NAME.ToString(), json["first_name"].ToString(), true);
		if(!json["last_name"].IsNull) Save.Set(PlayerPrefsKeys.LAST_NAME.ToString(), json["last_name"].ToString(), true);
		if(!json["location"].IsNull) Save.Set(PlayerPrefsKeys.LOCATION.ToString(), json["location"].ToString(), true);
		if(!json["gender"].IsNull) Save.Set(PlayerPrefsKeys.GENDER.ToString(), json["gender"].ToString(), true);
		if(!json["birthday"].IsNull)
		{
			string day, month, year;
			string[] separator = {"-"};
			string[] birthday = json["birthday"].StringValue.Split(separator,System.StringSplitOptions.None);
			
			day = birthday[2];
			month = birthday[1];
			year = birthday[0];
			
			Save.Set(PlayerPrefsKeys.DATE_DAY.ToString(), day,true);
			Save.Set(PlayerPrefsKeys.DATE_MONTH.ToString(), month,true);
			Save.Set(PlayerPrefsKeys.DATE_YEAR.ToString(), year,true);
		}
		
		
		
		// Verifica se possui Facebook
		if (json.Contains("fbtoken") && json.Contains("facebook_id"))
		{
			Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), json["fbtoken"].ToString(), true);
			Save.Set(PlayerPrefsKeys.FACEBOOK_ID.ToString(), json["facebook_id"].ToString(), true);
		}
		
		// Atualiza token da FacebookAPI
		if (Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) 
		{
			FacebookAPI facebook = new FacebookAPI();
			facebook.SetToken(Save.GetString(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString()));
		}
		
		ConfigManager.offlineUpdater.UpdateOfflineItems();
		
		// Verifica se e uma conta nova
		if (json["new_account"].ToString() != "0")
		{						
			//messageOkDialog.transform.FindChild("ConfirmButtonPanel").FindChild("ConfirmButton").GetComponent<UIButton>().methodToInvoke = "BringInInvite";
			Flow.game_native.showMessage("Hello!", "Hi! You've registered with us! We've emailed you your password.");
			return;
		}
		
		
		
		
		
		// Redireciona a proxima cena
		
		panelManager.BringIn("MultiplayerScenePanel");
	}
Esempio n. 30
0
 public void ParseInvalidToken_AndFail()
 {
     try
     {
         var reader = new JSonReader("  \t /-~~");
         reader.ReadAsJSonObject();
     }
     catch (JSonReaderException ex)
     {
         Assert.AreEqual(0, ex.Line);
         Assert.AreEqual(4, ex.Offset);
         throw;
     }
 }