private void LoadCache() { var filePath = Path.Combine(SirenixAssetPaths.OdinTempPath, tempCacheFilename).Replace("\\", "/"); FileInfo file = new FileInfo(filePath); #if SIRENIX_INTERNAL // This detects if a crash happened during deserialization of the persistent cache; if so it's likely due to the unsafe bug. // Delete the cache file so that the user has a chance to rebuild the project. string deserializedCacheFinishedKey = SirenixAssetPaths.OdinTempPath.Replace('/', '.') + ".CacheDeserializationFinished"; if (EditorPrefs.GetBool(deserializedCacheFinishedKey, true) == false) { Debug.LogError("Detected failed deserialization of PersistentContextCache. Deleting cache file. Try forcing a rebuild."); if (file.Exists) { file.Delete(); } } EditorPrefs.SetBool(deserializedCacheFinishedKey, false); #endif try { this.approximateSizePerEntry = defaultApproximateSizePerEntry; if (file.Exists) { using (FileStream stream = file.OpenRead()) { DeserializationContext context = new DeserializationContext(); context.Config.DebugContext.LoggingPolicy = LoggingPolicy.Silent; // Shut up... context.Config.DebugContext.ErrorHandlingPolicy = ErrorHandlingPolicy.Resilient; // ... and do your job! this.cache = SerializationUtility.DeserializeValue <IndexedDictionary <IContextKey, GlobalPersistentContext> >(stream, DataFormat.Binary, new List <UnityEngine.Object>(), context); } if (this.EntryCount > 0) { this.approximateSizePerEntry = (int)(file.Length / this.EntryCount); } } else { this.cache.Clear(); } } catch (Exception ex) { this.cache = new IndexedDictionary <IContextKey, GlobalPersistentContext>(); Debug.LogError("Exception happened when loading Persistent Context from file."); Debug.LogException(ex); } #if SIRENIX_INTERNAL finally { EditorPrefs.SetBool(deserializedCacheFinishedKey, true); } #endif }
public static void insert_data_to_db(string table_name, IndexedDictionary <string, string> field_value, int dict_count) { try { //Helper.Logger.LOG_IT("\nDB begin"); con.Open(); //SQLiteCommand cmd = new SQLiteCommand(con); //begin sqlite transaction SQLiteTransaction sqlite_tran = con.BeginTransaction(); InsertQueryBuilder insert_query = new InsertQueryBuilder(); insert_query.Table = table_name; for (int i = 0; i < field_value.Count; i++) { Debug.Write("\nDB -" + "==" + i + field_value.GetKeyByIndex(i) + field_value[field_value.GetKeyByIndex(i)]); insert_query.SetField(field_value.GetKeyByIndex(i), field_value[field_value.GetKeyByIndex(i)]); } cmdd_string = insert_query.BuildQuery(); cmd.CommandText = cmdd_string; Debug.Write("\nSQL insert_data_to_db: " + cmd.CommandText + "\n"); cmd.ExecuteNonQuery(); sqlite_tran.Commit(); cmd.Dispose(); con.Close(); } catch (SQLiteException ex) { Debug.Write("\n" + ex.Message); } catch (System.Exception ex) { Debug.Write("\n" + ex.Message); } }
public static FeatureSet createSchema(FeatureSet fs, IndexedDictionary <string, string[]> data) { try { foreach (var item in data) { if (!item.Key.Equals("Geometry") || !item.Key.Equals("coordinates")) { string dataType = data[item.Key][0]; string value = data[item.Key][1]; Debug.Write("\nProperty: " + item.Key); Debug.Write("\ndataType: " + dataType); Debug.Write("\nvalue: " + value); if (getDataType(dataType) != null) { fs.DataTable.Columns.Add(new DataColumn(item.Key, getDataType(dataType))); } } } } catch (SystemException ex) { Debug.Write("\n" + ex.ToString()); } return(fs); }
public override void Serialize(IJsonWriter writer, object value) { if (writer == null) { throw new ArgumentNullException("writer"); } if (value == null) { throw new ArgumentNullException("value"); } var container = new IndexedDictionary <DataMemberDescription, object>(); this.CollectMemberValues(value, container); if (this.SuppressTypeInformation || this.objectTypeDescription.IsAnonymousType) { writer.WriteObjectBegin(container.Count); } else { writer.WriteObjectBegin(container.Count + 1); writer.WriteMember(TYPE_MEMBER_NAME); writer.WriteString(objectTypeNameWithoutVersion); } foreach (var kv in container) { writer.WriteMember(kv.Key.Name); writer.WriteValue(kv.Value, kv.Key.ValueType); } writer.WriteObjectEnd(); }
[Test()] //, Repeat(2)] public void AddRemoveCollide() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new IndexedDictionary <Collider, int>(); //**************************************** for (var Index = 0; Index < 16; Index++) { MyRecords.Add(new Collider(MyRandom.Next()), MyRandom.Next()); } for (var Index = 0; Index < 1024; Index++) { if (Index % 10 >= 5 && MyRecords.Count > 0) { var Key = MyRecords.Get(MyRandom.Next(0, MyRecords.Count)).Key; MyRecords.Remove(Key); } else { MyRecords[new Collider(MyRandom.Next())] = MyRandom.Next(); } } }
public void AddRangeDuplicateInDictionary() { //**************************************** var MyRecords = new IndexedDictionary <int, int>(64); //**************************************** MyRecords[9] = 1; MyRecords[10] = 2; MyRecords[11] = 3; MyRecords[12] = 4; try { MyRecords.AddRange(new[] { new KeyValuePair <int, int>(1, 1), new KeyValuePair <int, int>(2, 2), new KeyValuePair <int, int>(3, 3), new KeyValuePair <int, int>(9, 4) }); Assert.Fail("Range succeeded"); } catch (ArgumentException) { } //**************************************** Assert.AreEqual(4, MyRecords.Count, "Items were added"); }
public void GetIndexOutOfRange() { //**************************************** var MyRecords = new IndexedDictionary <int, int>(); //**************************************** MyRecords[10] = 42; //**************************************** try { var Pair = ((IList <KeyValuePair <int, int> >)MyRecords)[1]; Assert.Fail("Key found"); } catch (ArgumentOutOfRangeException) { } try { var Pair = ((IList <KeyValuePair <int, int> >)MyRecords)[-1]; Assert.Fail("Key found"); } catch (ArgumentOutOfRangeException) { } }
[Test()] //, Repeat(2)] public void AddRemoveAllAddCollide() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new IndexedDictionary <Collider, int>(); //**************************************** for (var Index = 0; Index < 16; Index++) { MyRecords[new Collider(MyRandom.Next(0, 128))] = MyRandom.Next(0, 128); } while (MyRecords.Count > 0) { var Key = MyRecords.Get(MyRandom.Next(0, MyRecords.Count)).Key; MyRecords.Remove(Key); } for (var Index = 0; Index < 16; Index++) { MyRecords[new Collider(MyRandom.Next(0, 128))] = MyRandom.Next(0, 128); } }
protected IndexedDictionary <string, object> GetRawData() { var data = new IndexedDictionary <string, object> (); var players = new IndexedDictionary <string, object> (); players.Add("key1", new IndexedDictionary <string, object>(new Dictionary <string, object> { { "id", "key1" }, { "position", new IndexedDictionary <string, object>(new Dictionary <string, object> { { "x", 0 }, { "y", 10 } }) } })); players.Add("key2", new IndexedDictionary <string, object>(new Dictionary <string, object> { { "id", "key2" }, { "position", new IndexedDictionary <string, object>(new Dictionary <string, object> { { "x", 10 }, { "y", 20 } }) } })); data.Add("game", new IndexedDictionary <string, object>(new Dictionary <string, object> { { "turn", 0 } })); data.Add("players", players); data.Add("turn", "none"); data.Add("null", null); data.Add("messages", new List <object> { "one", "two", "three" }); return(data); }
public void ListenReplace() { var newData = GetRawData(); var players = (IndexedDictionary <string, object>)newData ["players"]; players ["key1"] = new IndexedDictionary <string, object>(new Dictionary <string, object> { { "id", "key1" }, { "position", new IndexedDictionary <string, object>(new Dictionary <string, object> { { "x", 50 }, { "y", 100 } }) } }); newData ["players"] = players; var listenCalls = 0; container.Listen("players/:id/position/:axis", (DataChange change) => { listenCalls++; Assert.AreEqual(change.path["id"], "key1"); if (change.path["axis"] == "x") { Assert.AreEqual(change.value, 50); } else if (change.path["axis"] == "y") { Assert.AreEqual(change.value, 100); } }); container.Set(newData); Assert.AreEqual(2, listenCalls); }
public ActionEntry(InputAction action, AxisRange axisRange) { this.action = action; this.axisRange = axisRange; this.actionSet = new InputActionSet(action.id, axisRange); fieldSets = new IndexedDictionary <int, FieldSet>(); }
public override GameLobbyUpdate UpdateTeams(IndexedDictionary <string, object> state) { var update = GameLobbyUpdatesParser.Parse(state); layoutGroup.HandlePlayersList(update.Players); return(update); }
public async Task <Auth> Save() { var uploadData = new IndexedDictionary <string, string>(); if (!string.IsNullOrEmpty(Username)) { uploadData["username"] = Username; } if (!string.IsNullOrEmpty(DisplayName)) { uploadData["displayName"] = DisplayName; } if (!string.IsNullOrEmpty(AvatarUrl)) { uploadData["avatarUrl"] = AvatarUrl; } if (!string.IsNullOrEmpty(Lang)) { uploadData["lang"] = Lang; } if (!string.IsNullOrEmpty(Location)) { uploadData["location"] = Location; } if (!string.IsNullOrEmpty(Timezone)) { uploadData["timezone"] = Timezone; } var bodyString = Json.SerializeToString(uploadData); await Request <UserData>("PUT", "/auth", null, new UploadHandlerRaw(Encoding.UTF8.GetBytes(bodyString))); return(this); }
void OnPlayerChange(DataChange change) { Debug.Log("OnPlayerChange"); Debug.Log(change.operation); Debug.Log(change.path["id"]); Debug.Log(change.value); if (change.operation == "add") { IndexedDictionary <string, object> value = (IndexedDictionary <string, object>)change.value; GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(Convert.ToSingle(value ["x"]), Convert.ToSingle(value ["y"]), 0); // add "player" to map of players by id. players.Add(change.path ["id"], cube); } else if (change.operation == "remove") { // remove player from scene GameObject cube; players.TryGetValue(change.path ["id"], out cube); Destroy(cube); players.Remove(change.path ["id"]); } }
public void OnStateChangeHandler(object sender, RoomUpdateEventArgs e) { if (e.isFirstState) { IndexedDictionary <string, object> players = (IndexedDictionary <string, object>)e.state ["players"]; return; } if (e.state.ContainsKey("command")) { switch (e.state["command"] as string) { case "queued": Debug.Log("Queued for matchmaking"); break; default: break; } } else { Debug.Log("-----Keys:"); foreach (string key in e.state.Keys) { Debug.Log(key); } Debug.Log("-----values:"); foreach (object v in e.state.Values) { Debug.Log(v); } } }
public static FeatureSet SHPLineDataHandler(FeatureSet fs, IndexedDictionary <string, string[]> data) { try { Debug.Write("\nCoor: " + Convert.ToDouble(data["coordinates"][1]) + "| " + Convert.ToDouble(data["coordinates"][2]) + "| " + Convert.ToDouble(data["coordinates"][3]) + "| " + Convert.ToDouble(data["coordinates"][4])); DotSpatial.Topology.Coordinate ptcoor1 = new DotSpatial.Topology.Coordinate(Convert.ToDouble(data["coordinates"][1]), Convert.ToDouble(data["coordinates"][2])); DotSpatial.Topology.Coordinate ptcoor2 = new DotSpatial.Topology.Coordinate(Convert.ToDouble(data["coordinates"][3]), Convert.ToDouble(data["coordinates"][4])); List <DotSpatial.Topology.Coordinate> lineCoor = new List <DotSpatial.Topology.Coordinate>(); lineCoor.Add(ptcoor1); lineCoor.Add(ptcoor2); LineString line = new LineString(lineCoor); DotSpatial.Data.IFeature feature = fs.AddFeature(line); //remove geometry data.Remove("Geometry"); //now fill in rest of the columns foreach (var item in data) { string dataType = data[item.Key][0]; string value = data[item.Key][1]; Debug.Write("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~SHP null AND dOUBLE DEBUG~~~~~~~~~~~~~~~~ VALUE : " + value + " =" + (string.IsNullOrEmpty(value))); //check if value is null - double dont accept string null values. need to fix it before sending. if (value.Equals("null") && dataType.Equals("Double")) { //for double double d; if (double.TryParse(value, out d)) { // valid number Debug.Write("\n~~~~VALID"); } else { // not a valid number Debug.Write("\n~~~~VALID Assigning 0"); value = "0"; } } if (!item.Key.Equals("Geometry") || !item.Key.Equals("coordinates")) { Debug.Write("\n~~SHP WRITE Property: " + item.Key); Debug.Write("\n~~SHP WRITE dataType: " + dataType); Debug.Write("\n~~SHP WRITE value: " + value); feature.DataRow.BeginEdit(); feature.DataRow[item.Key] = value; feature.DataRow.EndEdit(); } Debug.Write("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~SHP null AND dOUBLE DEBUG~~~~~~~~~~~~~~~~\n"); } } catch (SystemException ex) { Debug.Write("\n" + ex.ToString()); } return(fs); }
public void AddRangePrePopulatedCollide() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new IndexedDictionary <Collider, int>(64); var MyDictionary = new Dictionary <Collider, int>(64); var MySecondSet = new List <KeyValuePair <Collider, int> >(32); //**************************************** for (var Index = 0; Index < 32; Index++) { Collider Key; int Value; do { Key = new Collider(MyRandom.Next()); } while (MyDictionary.ContainsKey(Key)); Value = MyRandom.Next(); MyDictionary.Add(Key, Value); MyRecords.Add(Key, Value); } for (var Index = 0; Index < 32; Index++) { Collider Key; int Value; do { Key = new Collider(MyRandom.Next()); } while (MyDictionary.ContainsKey(Key)); Value = MyRandom.Next(); MyDictionary.Add(Key, Value); MySecondSet.Add(new KeyValuePair <Collider, int>(Key, Value)); } MyRecords.AddRange(MySecondSet); //**************************************** Assert.AreEqual(64, MyRecords.Count, "Count incorrect. Bad Seed was {0}", MySeed); CollectionAssert.AreEquivalent(MyDictionary, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed); foreach (var MyPair in MyDictionary) { Assert.IsTrue(MyRecords.TryGetValue(MyPair.Key, out var Value)); Assert.AreEqual(MyPair.Value, Value); } Thread.Sleep(1); }
/// <summary> /// Constructs a new instance of the <see cref="DictionarySubject{TKey,TValue}" /> class. /// </summary> /// <param name="dictionary">The dictionary from which elements are copied to the new dictionary.</param> /// <param name="comparer">The <see cref="IEqualityComparer{TKey}"/> implementation to use when comparing keys, /// or <see langword="null" /> to use the default <see cref="EqualityComparer{TKey}"/> for the type of the key.</param> public DictionarySubject(IDictionary <TKey, TValue> dictionary, IEqualityComparer <TKey> comparer) { Contract.Requires(dictionary != null); this.dictionary = new IndexedDictionary(comparer); dictionary.ForEach(this.dictionary.Add); }
void OnStateChangeHandler(object sender, RoomUpdateEventArgs e) { // Setup room first state if (e.isFirstState) { IndexedDictionary <string, object> players = (IndexedDictionary <string, object>)e.state ["players"]; } }
/// <summary> /// Constructs a new instance of the <see cref="DictionarySubject{TKey,TValue}" /> class. /// </summary> /// <param name="dictionary">The dictionary from which elements are copied to the new dictionary.</param> public DictionarySubject(IDictionary <TKey, TValue> dictionary) { Contract.Requires(dictionary != null); this.dictionary = new IndexedDictionary(); dictionary.ForEach(this.dictionary.Add); }
private object DeserializeMembers(IJsonReader reader, IndexedDictionary <string, object> container, ref ObjectSerializer serializerOverride) { while (reader.NextToken() && reader.Token != JsonToken.EndOfObject) { if (reader.Token != JsonToken.Member) { throw JsonSerializationException.UnexpectedToken(reader, JsonToken.Member); } string memberName = null; object value = null; memberName = reader.Value.AsString; // string if (string.Equals(memberName, TYPE_MEMBER_NAME) && this.SuppressTypeInformation == false) { reader.NextToken(); var typeName = reader.ReadString(false); var type = reader.Context.GetType(typeName, true, true); var serializer = reader.Context.GetSerializerForType(type); if (serializer is ObjectSerializer) { serializerOverride = (ObjectSerializer)serializer; serializerOverride.DeserializeMembers(reader, container, ref serializerOverride); return(null); } else { reader.NextToken(); // nextToken to next member serializerOverride = null; return(serializer.Deserialize(reader)); } } var member = default(DataMemberDescription); var valueType = typeof(object); if (this.TryGetMember(memberName, out member)) { valueType = member.ValueType; } reader.NextToken(); try { value = reader.ReadValue(valueType, false); } catch (Exception e) { throw new SerializationException(string.Format("Failed to read value for member '{0}' of '{1}' type.\r\nMore detailed information in inner exception.", memberName, this.objectType.Name), e); } container[memberName] = value; } return(null); }
public async void OnShipBuilderMessage(object msg) { if (msg is Statistics) { Statistics stats = msg as Statistics; RoomManager.HandleStats(stats); } else if (msg is UnlockMessage) { Debug.Log("Unlock message received."); UnlockMessage unlocks = msg as UnlockMessage; PlayerData.SetUnlocks(unlocks); } else if (msg is ShipList) { Debug.Log("ShipList message received."); ShipList sl = msg as ShipList; PlayerData.myShips = sl.ships; RoomManager.HandleShipListUpdated(); } else if (msg is ErrorMessage) { ErrorMessage er = msg as ErrorMessage; RoomManager.HandleErrorMessage(er.message); } else { IndexedDictionary <string, object> message = (IndexedDictionary <string, object>)msg; string action = message["action"].ToString(); if (action == "message") { RoomManager.HandleMessage((string)message["message"]); } if (action == "ship_upgrade_success") { PlayerData.ResetUpgrades(); RoomManager.HandleUpgradeSuccess(); } if (action == "enter_match_making") { await shipBuilderRoom.Leave(); shipBuilderRoom = null; Dictionary <string, object> options = new Dictionary <string, object>() { { "token", PlayerPrefs.GetString("token") }, { "rank", PlayerData.CurrentShip().rank } }; RoomManager.HandleEnterMatchMaking(options); } } }
public PatchObject[] Set(IndexedDictionary <string, object> newData) { var patches = Compare.GetPatchList(this.state, newData); this.CheckPatches(patches); this.state = newData; return(patches); }
public static PatchObject[] GetPatchList(IndexedDictionary <string, object> tree1, IndexedDictionary <string, object> tree2) { List <PatchObject> patches = new List <PatchObject>(); List <string> path = new List <string>(); Generate(tree1, tree2, patches, path); return(patches.ToArray()); }
public void IndexOfKeyMissing() { //**************************************** var MyRecords = new IndexedDictionary <int, int>(); //**************************************** MyRecords[10] = 42; //**************************************** Assert.AreEqual(-1, MyRecords.IndexOfKey(11)); }
public void IndexOfKeyCollideMissing() { //**************************************** var MyRecords = new IndexedDictionary <Collider, int>(); //**************************************** MyRecords[new Collider(10)] = 42; //**************************************** Assert.AreEqual(-1, MyRecords.IndexOfKey(new Collider(11))); }
public void GetIndex() { //**************************************** var MyRecords = new IndexedDictionary <int, int>(); //**************************************** MyRecords[10] = 42; //**************************************** Assert.AreEqual(new KeyValuePair <int, int>(10, 42), ((IList <KeyValuePair <int, int> >)MyRecords)[0]); }
public void OnServerMessage(object sender, Colyseus.MessageEventArgs e) { IndexedDictionary <string, object> args = (IndexedDictionary <string, object>)e.message; if (args.ContainsKey("type")) { } else { Debug.LogError("Unexpected formatting of server message: " + e.message); } }
public void IndexOfMissingValue() { //**************************************** var MyRecords = new IndexedDictionary <int, int>(); //**************************************** MyRecords[10] = 42; //**************************************** Assert.AreEqual(-1, MyRecords.IndexOf(new KeyValuePair <int, int>(10, 30))); }
public void GetKey() { //**************************************** var MyRecords = new IndexedDictionary <int, int>(); //**************************************** MyRecords[10] = 42; //**************************************** Assert.AreEqual(42, MyRecords[10]); }
public FieldSet(GameObject groupContainer) { this.groupContainer = groupContainer; fields = new IndexedDictionary<int, GUIInputField>(); }
public ActionEntry(InputAction action, AxisRange axisRange) { this.action = action; this.axisRange = axisRange; this.actionSet = new InputActionSet(action.id, axisRange); fieldSets = new IndexedDictionary<int, FieldSet>(); }
public Apriori() { _allFrequentItems = new IndexedDictionary(); }
public MapCategoryEntry() { _actionList = new List<ActionEntry>(); _actionCategoryList = new IndexedDictionary<int, ActionCategoryEntry>(); }
/// <summary> /// IndexedDictionary /// </summary> private static void benchmark5() { GC.Collect(); var tree = new IndexedDictionary<int, int>(); tree[default(int)] = 0; tree.Clear(); var keys = new int[10000000]; for (int i = 0; i < 10000000; i++) keys[i] = i; var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < keys.Length; i++) tree[keys[i]] = i; sw.Stop(); Console.WriteLine(sw.Elapsed); GC.GetTotalMemory(true); sw.Restart(); foreach (var t in tree) { } sw.Stop(); Console.WriteLine(sw.Elapsed); GC.GetTotalMemory(true); sw.Restart(); for (int i = 0; i < keys.Length; i++) { if (!tree.ContainsKey(keys[i])) throw new Exception(); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public InputGridEntryList() { entries = new IndexedDictionary<int, MapCategoryEntry>(); }