// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddProfileTransaction(MutableData mutableData) { List <object> profiles = mutableData.Value as List <object>; if (profiles == null) { profiles = new List <object>(); } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newProfile = new Dictionary <string, object>(); newProfile["named"] = name1; newProfile["company"] = company; newProfile["email"] = email; newProfile["title"] = title; newProfile["phone"] = phone; newProfile["email"] = email; newProfile["webpage"] = webpage; newProfile["linkedin"] = linkedin; newProfile["image"] = image; newProfile["profile"] = profile; profiles.Add(newProfile); // You must set the Value to indicate data at that location has changed. mutableData.Value = profiles; return(TransactionResult.Success(mutableData)); }
TransactionResult playGameTransaction(MutableData mutableData) { Dictionary <string, object> leaders = mutableData.Value as Dictionary <string, object>; string _color = settingplayer.Instances.Color; //inicializo un tablero de juegos, si no existe; if (leaders == null) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("no se ha creado la sala de juego " + tableroNAme)); return(TransactionResult.Abort()); } Debug.Log(leaders[_color].ToString()); if (leaders[_color].ToString() == UIHandler.instance.usuario.CurrentUser.UserId)//accedo a el valor de color de este usuario y verifico si este color no esta ocupado en el tablero de juego { mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); } else if (leaders[Otrocolor(_color)].ToString() == UIHandler.instance.usuario.CurrentUser.UserId) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("no ha actualizado el color de jugador a " + _color)); return(TransactionResult.Abort()); } else { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("sala de juego: " + tableroNAme + " llena")); return(TransactionResult.Abort()); } // You must set the Value to indicate data at that location has changed. }
// can return null public String ReadLine() { MutableData data = new MutableData(); byte[] buffer = new byte[1]; bool continueReading = true; while( continueReading ) { int bytesRead = _socket.Receive(buffer); if (0 == bytesRead) { return null; } if ('\n' == buffer[0]) { continueReading = false; } else { data.Append(buffer[0]); } } return DataHelper.ToUtf8String(data); }
public Transaction.Result DoTransaction(MutableData currentData) { if (transaction != null) { transaction.Invoke(new AndroidFirebaseMutableData <T>(currentData)); } return(Transaction.Success(currentData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } // If the current list of scores is greater or equal to our maximum allowed number, // we see if the new score should be added and remove the lowest existing score. long childScore = long.MaxValue; object overlap = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } //loop to see if the leaderboard contains the same Email //If a matching Email was found, then set the overlap variable to the found record Dictionary <string, object> dict = (Dictionary <string, object>)child; childScore = (long)((Dictionary <string, object>)child)["score"]; //If the database has this user's email already if (dict.ContainsValue(email)) { //If the score in the database is greater than the new score, then abort if (childScore >= score) { // If the new score is less than the highscore, we abort return(TransactionResult.Abort()); } else { // Otherwise, we remove the current lowest to be replaced with the new score. overlap = child; leaders.Remove(overlap); break; } } } // Now we add the new score as a new entry that contains the name, score and address. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["score"] = score; newScoreMap["name"] = firstName; newScoreMap["email"] = email; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; LeaderboardList = leaders; return(TransactionResult.Success(mutableData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } else if (mutableData.ChildrenCount < MaxScores) { foreach (var child in leaders) { scoreRet = (string)((Dictionary <string, object>)child)["score"]; Debug.Log(scoreRet); } } else if (mutableData.ChildrenCount >= MaxScores) { // If the current list of scores is greater or equal to our maximum allowed number, // we see if the new score should be added and remove the lowest existing score. long minScore = long.MaxValue; object minVal = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } long childScore = (long)((Dictionary <string, object>)child)["score"]; if (childScore < minScore) { minScore = childScore; minVal = child; } } // If the new score is lower than the current minimum, we abort. if (minScore > score) { return(TransactionResult.Abort()); } // Otherwise, we remove the current lowest to be replaced with the new score. leaders.Remove(minVal); } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["score"] = score; newScoreMap["email"] = email; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
private TransactionResult UpdateTopScore(MutableData md) { int newTopScore = 10; md.Value = new Dictionary <string, object>() { { "topscore", newTopScore } }; return(TransactionResult.Success(md)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. /* * TransactionResult AddScoreTransaction (MutableData mutableData) * { * List<object> leaders = mutableData.Value as List<object>; * * if (leaders == null) { * leaders = new List<object> (); * } else if (mutableData.ChildrenCount >= MaxScores) { * // If the current list of scores is greater or equal to our maximum allowed number, * // we see if the new score should be added and remove the lowest existing score. * long minScore = long.MaxValue; * object minVal = null; * foreach (var child in leaders) { * if (!(child is Dictionary<string, object>)) * continue; * long childScore = (long)((Dictionary<string, object>)child) ["score"]; * if (childScore < minScore) { * minScore = childScore; * minVal = child; * } * } * // If the new score is lower than the current minimum, we abort. * if (minScore > score) { * return TransactionResult.Abort (); * } * // Otherwise, we remove the current lowest to be replaced with the new score. * leaders.Remove (minVal); * } * * // Now we add the new score as a new entry that contains the email address and score. * Dictionary<string, object> newScoreMap = new Dictionary<string, object> (); * newScoreMap ["score"] = score; * newScoreMap ["email"] = email; * leaders.Add (newScoreMap); * * // You must set the Value to indicate data at that location has changed. * mutableData.Value = leaders; * return TransactionResult.Success (mutableData); * } * */ TransactionResult AddNewDb(MutableData mutableData) { List <object> listItem = new List <object>(); Dictionary <string, object> keyValue = new Dictionary <string, object> (); keyValue["description"] = "adsgasd"; listItem.Add(keyValue); mutableData.Value = listItem; return(TransactionResult.Success(mutableData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } nikname = null; childScore = 0; long max_score_base = 0; for (int i = 0; i < leaders.Count; i++) { childScore = (long)((Dictionary <string, object>)leaders[i])["score"]; nikname = (String)((Dictionary <string, object>)leaders[i])["email"]; if (childScore < score && email == nikname) { leaders.RemoveAt(i); } if (max_score_base < childScore) { max_score_base = childScore; } } // Now we add the new score as a new entry that contains the email address and score. if (max_score_base < score) { Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["score"] = score; newScoreMap["email"] = email; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; } return(TransactionResult.Success(mutableData)); }
TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["OpenBan"] = openCount; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddAnchorTransaction(MutableData mutableData) { List <object> Anchors = mutableData.Value as List <object>; if (Anchors == null) { Anchors = new List <object>(); } //else if (mutableData.ChildrenCount >= MaxScores) //{ // // If the current list of scores is greater or equal to our maximum allowed number, // // we see if the new score should be added and remove the lowest existing score. // long minScore = long.MaxValue; // object minVal = null; // foreach (var child in users) // { // if (!(child is Dictionary<string, object>)) // continue; // long childScore = (long)((Dictionary<string, object>)child)["hitCounter"]; // if (childScore < minScore) // { // minScore = childScore; // minVal = child; // } // } // // If the new score is lower than the current minimum, we abort. // if (minScore > hitCounter) // { // return TransactionResult.Abort(); // } // // Otherwise, we remove the current lowest to be replaced with the new score. // users.Remove(minVal); //} // Now we add the new score as a new entry that contains the email address and score. //newNameMap["hitCounter"] =hitCounter; //newNameMap["scale"] = treeScale; newNameMap["Room"] = roomNumber; newNameMap["IP"] = IPAddress; newNameMap["playerName"] = playerName; Anchors.Add(newNameMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = Anchors; return(TransactionResult.Success(mutableData)); }
private Dictionary <string, System.Object> PhaseMutate(MutableData mutableData, string battleStatusName, Action <Dictionary <string, System.Object>, int> action) { Dictionary <string, System.Object> battleStatus = (Dictionary <string, System.Object>)mutableData.Value; string battleState = battleStatus [MyConst.BATTLE_STATUS_STATE].ToString(); int battleCount = int.Parse(battleStatus [MyConst.BATTLE_STATUS_COUNT].ToString()); if (battleState.Equals(battleStatusName) && battleCount < 2) { battleCount++; battleStatus [MyConst.BATTLE_STATUS_COUNT] = battleCount.ToString(); action(battleStatus, battleCount); } Debug.Log("NEW BATTLE COUNT" + battleCount); return(battleStatus); }
// Uploads the time data to the top time list for a level, as a Firebase Database transaction. private static TransactionResult UploadScoreTransaction( MutableData mutableData, TimeData timeData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } // Only save a certain number of the best times. if (mutableData.ChildrenCount >= 5) { long maxTime = long.MinValue; object maxVal = null; foreach (object child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } string childName = (string)((Dictionary <string, object>)child)["name"]; long childTime = (long)((Dictionary <string, object>)child)["time"]; if (childTime > maxTime) { maxTime = childTime; maxVal = child; } } if (maxTime < timeData.time) { // Don't make any changes to the mutable data, but return it so we can use // the snapshot. return(TransactionResult.Success(mutableData)); } leaders.Remove(maxVal); } Dictionary <string, object> newTimeEntry = new Dictionary <string, object>(); newTimeEntry["name"] = timeData.name; newTimeEntry["time"] = timeData.time; leaders.Add(newTimeEntry); mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
public Transaction.Result DoTransaction(MutableData currentData) { if (currentData.Value != null) { var counts = currentData.Child("Watched").Value.ToString(); var newWatched = Int32.Parse(counts); currentData.Child("Watched").Value = newWatched + 1; return(Transaction.Success(currentData)); } else { currentData.Value = null; return(Transaction.Success(currentData)); } }
TransactionResult UpdateScore(MutableData nd) { if (nd.Value != null) { Dictionary <string, object> updatedScore = nd.Value as Dictionary <string, object>; topScore = (long)updatedScore["topScore"]; } if (currScore > topScore) { topScore = currScore; nd.Value = new Dictionary <string, object>() { { "topScore", currScore } }; return(TransactionResult.Success(nd)); } return(TransactionResult.Abort()); }
TransactionResult AddDataTransaction(MutableData mutableData) { List<object> datas = mutableData.Value as List<object>; if (datas == null) { datas = new List<object>(); } Dictionary<string, object> newData = new Dictionary<string, object>(); newData["Food"] = food; newData["Gold"] = gold; newData["Jewelry"] = jewelry; datas.Add(newData); mutableData.Value = datas; return TransactionResult.Success(mutableData); }
TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } else if (mutableData.ChildrenCount >= MaxScores) { long maxTime = 0; object maxVal = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } long childTime = (long)((Dictionary <string, object>)child)["time"]; if (childTime > maxTime) { maxTime = childTime; maxVal = child; } } // Not fast enough if (maxTime < finishTime) { return(TransactionResult.Abort()); } // Kick lowest score leaders.Remove(maxVal); } // Insert new player record time Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["time"] = finishTime; newScoreMap["playerName"] = playerName; leaders.Add(newScoreMap); mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
TransactionResult AddPlayerTransaction(MutableData mutableData) { Dictionary <string, object> leaders = mutableData.Value as Dictionary <string, object>; if (leaders == null) { leaders = new Dictionary <string, object>();; } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["color"] = color; newScoreMap["NombreTablero"] = tableroNAme; leaders = newScoreMap; // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
TransactionResult AddTransaction(MutableData mutableData) { int theValue = -1; bool parseResult = int.TryParse(mutableData.Value.ToString(), out theValue); Debug.Log("------ Mutable Data : " + theValue); if (parseResult) { mutableData.Value = theValue + 1; Debug.Log("The Value : " + mutableData.Value); return(TransactionResult.Success(mutableData)); } else { Debug.Log("Failed : " + mutableData.Value.ToString()); return(TransactionResult.Abort()); } }
private TransactionResult UpdateTopScore(MutableData md) { if (md.Value != null) { Dictionary <string, object> updatedScore = md.Value as Dictionary <string, object>; topScore = (long)updatedScore ["topScore"]; } // Compare the cur score to the top score. if (curScore > topScore) // Update topScore, triggers other UpdateTopScores to retry { topScore = curScore; md.Value = new Dictionary <string, object>() { { "topScore", curScore } }; return(TransactionResult.Success(md)); } return(TransactionResult.Abort()); // Aborts the transaction }
TransactionResult AddDataTransaction(MutableData mutableData) { //List<object> datas = mutableData.Value as List<object>; //Dictionary<string, object> newData = new Dictionary<string, object>(); //// List<object> datas = new List<object>(); //if (datas == null) // datas = new List<object>(); ////else if (datas[0] is Dictionary<string, object>) //// newData = (Dictionary<string, object>)datas[0]; //else // newData = (Dictionary<string, object>)datas[0]; ////foreach (var data in newData) //// Debug.Log(data); //// Dictionary<string, object> newData = new Dictionary<string, object>(); //newData["Food"] = foodCount; //newData["Gold"] = goldAmount; //newData["Jewelry"] = jewelryCount; //// datas.Clear(); //datas.Add(newData); //mutableData.Value = datas; //return TransactionResult.Success(mutableData); Dictionary <string, object> datas = mutableData.Value as Dictionary <string, object>; if (datas == null) { datas = new Dictionary <string, object>(); } datas["Food"] = foodCount; datas["Gold"] = goldAmount; datas["Jewelry"] = jewelryCount; mutableData.Value = datas; return(TransactionResult.Success(mutableData)); }
TransactionResult moveTransaction(MutableData mutableData) { Dictionary <string, object> leaders = mutableData.Value as Dictionary <string, object>; //inicializo un tablero de juegos, si no existe; if (leaders == null) { Debug.Log("no existe " + settingplayer.Instances.TableroName); return(TransactionResult.Abort()); } if (leaders[settingplayer.Instances.Color].ToString() == UIHandler.instance.usuario.CurrentUser.UserId) { leaders["posxOld"] = posxOld; leaders["posyOld"] = posyOld; leaders["posxNew"] = posxNew; leaders["posyNew"] = posyNew; } mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); // You must set the Value to indicate data at that location has changed. }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> Users = mutableData.Value as List <object>; if (Users == null) { Users = new List <object>(); } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["Message"] = score; newScoreMap["Name"] = name; newScoreMap["Email"] = Email; Users.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = Users; //return and log success return(TransactionResult.Success(mutableData)); }
//Function to help initialise up a full new device into the database. private TransactionResult UpdateNewDevice(MutableData md) { //check on the value of the mutable data if (md.Value == null) { Debug.Log("This Mutable Data has no specific value. Is your reference correct?"); } //If in the event the mutable data is not an empty fella, do the following to push it up else if (md.Value != null) { Debug.Log("MD IS " + md.Value); Dictionary <string, object> device = md.Value as Dictionary <string, object>; //Initiate a Dictionary Place holder for the new device to be added Dictionary <string, object> newDeviceAddition = new Dictionary <string, object>(); //device = new Dictionary<string, object>(); Debug.Log(newDeviceAddition); //Initiate an extra list that should act as the Player info to be kept under the device unique id Dictionary <string, object> PlayerStats = new Dictionary <string, object>(); PlayerStats["PlayerName"] = MessageHandler.playername; PlayerStats["GamesWon"] = "0"; PlayerStats["GamesLost"] = "0"; //Initialize a game_count and overwrite it at the top from 0 PlayerStats["WinRate"] = "N%"; newDeviceAddition["PlayerStats"] = PlayerStats; Debug.Log("ID addition into database is successful"); device.Add(deviceUniqueID, newDeviceAddition); md.Value = device; } return(TransactionResult.Success(md)); }
TransactionResult FoundCoinTransaction(MutableData mutableData) { return(TransactionResult.Abort()); }
public void testDelimiterDetection() { log.enteredMethod(); String[] multipartLines = { "", "-----------------------------114782935826962", "Content-Disposition: form-data; name=\"datafile\"; filename=\"test.txt\"", "Content-Type: text/plain", "", "0123", "4567", "89ab", "cdef", "-----------------------------114782935826962--", }; Entity entity = buildEntity(multipartLines); MultiPartReader reader = new MultiPartReader("---------------------------114782935826962", entity); DelimiterIndicator indicator = reader.skipToNextDelimiterIndicator(); Assert.NotNull(indicator); Assert.IsInstanceOf<DelimiterFound>(indicator); DelimiterFound delimiterFound = (DelimiterFound)indicator; Assert.AreEqual(0, delimiterFound.StartOfDelimiter); Assert.False(delimiterFound.IsCloseDelimiter); // Content-Disposition MutableData stringBuffer = new MutableData(); String contentDisposition = reader.ReadLine(stringBuffer); Assert.AreEqual(multipartLines[2], contentDisposition); // Content-Type String contentType = reader.ReadLine(stringBuffer); Assert.AreEqual(multipartLines[3], contentType); // empty line String emptyLine = reader.ReadLine(stringBuffer); Assert.AreEqual("", emptyLine); // ending indicator indicator = reader.skipToNextDelimiterIndicator(); Assert.NotNull(indicator); Assert.IsInstanceOf<DelimiterFound>(indicator); delimiterFound = (DelimiterFound)indicator; Assert.True(delimiterFound.IsCloseDelimiter); }
TransactionResult AddDataTransaction2(MutableData mutableData) { ////List<object> datas = mutableData.Value as List<object>; //List<object> datas = new List<object>(); ////if (datas == null) //// datas = new List<object>(); //Dictionary<string, object> newData = new Dictionary<string, object>(); //newData["Test"] = "test"; //datas.Add(newData); //mutableData.Value = newData; //return TransactionResult.Success(mutableData); //List<object> datas = mutableData.Value as List<object>; //Dictionary<string, object> newData = new Dictionary<string, object>(); //// List<object> datas = new List<object>(); //if (datas == null) // datas = new List<object>(); //else if (datas[0] is Dictionary<string, object>) // newData = (Dictionary<string, object>)datas[0]; //// Dictionary<string, object> newData = new Dictionary<string, object>(); //newData["Test"] = "test"; //datas.Clear(); //datas.Add(newData); //mutableData.Value = newData; //return TransactionResult.Success(mutableData); //List<object> datas = mutableData.Value as List<object>; //Dictionary<string, object> newData = new Dictionary<string, object>(); //// List<object> datas = new List<object>(); //if (datas == null) // datas = new List<object>(); ////else if (datas[0] is Dictionary<string, object>) //// newData = (Dictionary<string, object>)datas[0]; //else //{ // Debug.Log(datas); // newData = datas[0] as Dictionary<string, object>; //} ////foreach (var data in newData) //// Debug.Log(data); //// Dictionary<string, object> newData = new Dictionary<string, object>(); //newData["Test"] = "test"; //// datas.Clear(); //datas.Add(newData); //mutableData.Value = datas; //return TransactionResult.Success(mutableData); Dictionary <string, object> datas = mutableData.Value as Dictionary <string, object>; if (datas == null) { datas = new Dictionary <string, object>(); } datas["Gold"] = "good"; datas["Test"] = "test"; mutableData.Value = datas; return(TransactionResult.Success(mutableData)); }
TransactionResult AddTableroTransaction(MutableData mutableData) { Dictionary <string, object> leaders = mutableData.Value as Dictionary <string, object>; string _color = color; string _playerName; //inicializo un tablero de juegos, si no existe; if (leaders == null) { leaders = new Dictionary <string, object>(); leaders["blanco"] = ""; leaders["negro"] = ""; leaders["posxOld"] = 0; leaders["posyOld"] = 0; leaders["posxNew"] = 0; leaders["posyNew"] = 0; } /*DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("bartolo"); * IDebugLog("Running Transaction..."); * // Use a transaction to ensure that we do not encounter issues with * // simultaneous updates that otherwise might create more than MaxScores top scores. * reference.RunTransaction(ReadPlayerNameTransaction) * .ContinueWith(task => * { * if (task.Exception != null) * { * Debug.Log(/*task.Exception.ToString()+///"El error se presento cuando voy a leer los datos del jugador"); * _color = ""; * } * else if (task.IsCompleted) //accedo a leer los datos del jugador en la nube * { * Debug.Log("Transaction complete. " + "leer datos del jugador"); * _color = task.Result.Child("color").Value.ToString();//leo el color que tiene asignado este usuario en la nube * Debug.Log("color: " + _color + " " + string.IsNullOrEmpty(_color).ToString()); * } * }); * reference.GetValueAsync().ContinueWith(task => { * if (task.IsFaulted) * { * // Handle the error... * } * else if (task.IsCompleted) * { * _color = task.Result.Child("color").Value.ToString(); * // Do something with snapshot... * } * });*/ Debug.Log("busqueda: " + leaders[color] + "blanco" + _color); if (string.IsNullOrEmpty(leaders[_color].ToString())) //accedo a el valor de color de este usuario y verifico si este color no esta ocupado en el tablero de juego { if ((string)leaders[Otrocolor(_color)] != playerName) //rectifico que la sala, el otro color no esta ocupado por este jugador { leaders[_color] = UIHandler.instance.usuario.CurrentUser.UserId; UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("Configurado Sala de Juego")); Debug.Log(_color + " : " + leaders[_color]); } else { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("El usuario ya tiene asignado el color " + Otrocolor(_color) + " en la sala de juego " + tableroNAme + " así que se procede a cambiar de color")); leaders[Otrocolor(_color)] = ""; leaders[_color] = playerName; //return TransactionResult.Abort(); } } else { if (leaders[_color].ToString() == playerName) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("Ud ya eligio el color: " + _color + " en esta sala de juego")); } else if ((string)leaders[Otrocolor(_color)] == playerName) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("Ud ya eligio el color: " + Otrocolor(_color))); } else if (string.IsNullOrEmpty((string)leaders[Otrocolor(_color)])) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("Esta sala solo tiene libre el color " + Otrocolor(_color))); } else { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("no hay espacio para más jugadores" + " En la sala " + tableroNAme)); return(TransactionResult.Abort()); } } // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult ReadPlayerNameTransaction(MutableData mutableData) { return(TransactionResult.Success(mutableData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> Faculties = mutableData.Value as List <object>; if (Faculties == null) { Faculties = new List <object>(); } else if (mutableData.ChildrenCount >= MaxScores) { // If the current list of scores is greater or equal to our maximum allowed number, // we see if the new score should be added and remove the lowest existing score. long minScore = long.MaxValue; object minVal = null; foreach (var child in Faculties) { if (!(child is Dictionary <string, object>)) { continue; } long childScore = (long)((Dictionary <string, object>)child)["score"]; string extension = (string)((Dictionary <string, object>)child)["extension"]; Debug.Log("extension url get working **************************************** " + extension); if (childScore < minScore) { minScore = childScore; minVal = child; } } // If the new score is lower than the current minimum, we abort. if (minScore > score) { return(TransactionResult.Abort()); } // Otherwise, we remove the current lowest to be replaced with the new score. Faculties.Remove(minVal); } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); //newScoreMap["score"] = score; //newScoreMap["email"] = email; //*********************************************************************************************************************************************** newScoreMap["year"] = Global.year; newScoreMap["facultyname"] = Global.faculty_name; newScoreMap["subject"] = Global.subject; newScoreMap["section"] = Global.section; newScoreMap["category_name"] = Global.category_name; newScoreMap["filename"] = Global.destination_filename_with_extension_for_uploading; newScoreMap["extension"] = Global.extension; //newScoreMap["filename_url"] = Global.faculty_name + "/" + Global.year + "/" + Global.subject + "/" + Global.section + "/" + Global.category_name + "/" + Global.destination_filename_with_extension_for_uploading; //*********************************************************************************************************************************************** Faculties.Add(newScoreMap); //Faculties.Add("Faculties/" + Global.faculty_name + "/" + Global.year + "/" + Global.subject + "/" + Global.section + "/" + Global.category_name + "/" + Global.destination_filename_with_extension_for_uploading ); // You must set the Value to indicate data at that location has changed. mutableData.Value = Faculties; return(TransactionResult.Success(mutableData)); }
public IosMutableData(MutableData currentData) { this.currentData = currentData; }
// null corresponds to the end of a stream private static String readLine(Stream inputStream, MutableData buffer) { int byteRead = inputStream.ReadByte(); if (-1 == byteRead) { return null; } int i = 0; do { if (-1 != byteRead) { if (INVALID_CHARS[byteRead]) { log.errorFormat("INVALID_CHARS[ byteRead ]; byteRead = 0x{0:x}", byteRead); throw HttpErrorHelper.badRequest400FromOriginator(typeof(HttpRequestReader)); } } // end of stream or end of the line if (-1 == byteRead || '\n' == byteRead) { String answer = DataHelper.ToUtf8String(buffer); return answer; } // filter out '\r' if ('\r' != byteRead) { buffer.Append((byte)byteRead); } byteRead = inputStream.ReadByte(); i++; } while( i < LINE_LENGTH_UPPER_BOUND ); // line is too long log.errorFormat("line too long; i = {0}", i); throw HttpErrorHelper.badRequest400FromOriginator(typeof(HttpRequestReader)); }
private DelimiterFound TryProcessPart(PartHandler partHandler, DelimiterDetector detector) { MutableData stringBuffer = new MutableData(); String line = ReadLine(stringBuffer); while ( 0 != line.Length ) { int firstColon = line.IndexOf(":"); if (-1 == firstColon) { throw new BaseException(this, "-1 == firstColon; line = '{0}'", line); } String name = line.Substring(0, firstColon).ToLower(); // headers are case insensitive String value = line.Substring(firstColon + 1).Trim(); partHandler.HandleHeader(name, value); line = ReadLine(stringBuffer); } PartialDelimiterMatched partialDelimiterMatched = null; bool partCompleted = false; while (!partCompleted) { DelimiterIndicator delimiterIndicator = detector.update(_buffer, _currentOffset, _bufferEnd); // nothing detected ? if (null == delimiterIndicator) { // write existing partial match (if it exists) { WritePartialDelimiter(partialDelimiterMatched, partHandler); partialDelimiterMatched = null; } int length = _bufferEnd - _currentOffset; partHandler.HandleBytes(_buffer, _currentOffset, length); FillBuffer(); continue; } if (delimiterIndicator is DelimiterFound) { DelimiterFound delimiterFound = (DelimiterFound)delimiterIndicator; // more content to add ? if (!delimiterFound.CompletesPartialMatch) { // write existing partial match (if it exists) { WritePartialDelimiter(partialDelimiterMatched, partHandler); partialDelimiterMatched = null; } int length = delimiterFound.StartOfDelimiter - _currentOffset; partHandler.HandleBytes(_buffer, _currentOffset, length); } else // delimiterFound completesPartialMatch { partialDelimiterMatched = null; } _currentOffset = delimiterFound.EndOfDelimiter; partHandler.PartCompleted(); partCompleted = true; // not required, but signalling intent return delimiterFound; } if (delimiterIndicator is PartialDelimiterMatched) { // write existing partial match (if it exists) { WritePartialDelimiter(partialDelimiterMatched, partHandler); } partialDelimiterMatched = (PartialDelimiterMatched)delimiterIndicator; byte[] matchingBytes = partialDelimiterMatched.MatchingBytes; int startOfMatch = _bufferEnd - matchingBytes.Length; if (startOfMatch < _currentOffset) { // can happen when the delimiter straddles 2 distinct buffer reads of size `BUFFER_SIZE` startOfMatch = _currentOffset; } else { int length = startOfMatch - _currentOffset; partHandler.HandleBytes(_buffer, _currentOffset, length); } FillBuffer(); } } // will never happen ... we hope throw new BaseException(this, "unexpected code path followed"); }
internal String ReadLine(MutableData stringBuffer) { byte lastChar = 88; // 'X' stringBuffer.clear(); while (true) { byte currentChar = ReadByte(); if (0x0d == lastChar) // '\r' { if (0x0a == currentChar) // `\n` { return stringBuffer.getUtf8String(0, stringBuffer.getCount()); } else { stringBuffer.Append( lastChar); // add the previous '\r' } } if (0x0d != currentChar) // '\r' { stringBuffer.Append(currentChar); } lastChar = currentChar; } }
public MutableData Add(MutableData other) { AddCallsCount++; Interlocked.Add(ref m_value, other.m_value); return(this); }
public static HttpRequest readRequest(Stream inputStream) { MutableData buffer = new MutableData(); String firstLine = readLine(inputStream, buffer); log.debug(firstLine, "firstLine"); // null corresponds to the end of a stream if (null == firstLine) { return null; } HttpRequest answer = new HttpRequest(); setOperationDetailsForRequest(answer, firstLine); int i = 0; do { buffer.clear(); String line = readLine(inputStream, buffer); if (0 == line.Length) { break; } else { addHeader(line, answer); } } while (i < NUMBER_HEADERS_UPPER_BOUND); if (i > NUMBER_HEADERS_UPPER_BOUND) { log.errorFormat("i > NUMBER_HEADERS_UPPER_BOUND; i = {0}", i); throw HttpErrorHelper.badRequest400FromOriginator(typeof(HttpRequestReader)); } String contentLengthString = null; if (answer.headers.ContainsKey("content-length")) { contentLengthString = answer.headers["content-length"]; } // no body ? if (null == contentLengthString) { log.debug("null == contentLengthString"); return answer; } long contentLength = Int64.Parse(contentLengthString); log.debug(contentLength, "contentLength"); Entity body = new StreamEntity(contentLength, inputStream); answer.Entity = body; return answer; }