public void GetHashCodeHappyPathTest <TKey, TVal>(IReadOnlyDictionary <TKey, TVal> left, IReadOnlyDictionary <TKey, TVal> right) { var leftHash = DictionaryHelpers.GetHashCode(left); var rightHash = DictionaryHelpers.GetHashCode(right); Assert.AreEqual(leftHash, rightHash); }
public void FindKeysWithPrefix() { // Arrange Dictionary <string, string> dict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "FOO", "fooValue" }, { "FOOBAR", "foobarValue" }, { "FOO.BAR", "foo.barValue" }, { "FOO[0]", "foo[0]Value" }, { "BAR", "barValue" } }; // Act var matchingEntries = DictionaryHelpers.FindKeysWithPrefix(dict, "foo"); // Assert var matchingEntriesList = matchingEntries.OrderBy(entry => entry.Key).ToList(); Assert.Equal(3, matchingEntriesList.Count); Assert.Equal("foo", matchingEntriesList[0].Key); Assert.Equal("fooValue", matchingEntriesList[0].Value); Assert.Equal("FOO.BAR", matchingEntriesList[1].Key); Assert.Equal("foo.barValue", matchingEntriesList[1].Value); Assert.Equal("FOO[0]", matchingEntriesList[2].Key); Assert.Equal("foo[0]Value", matchingEntriesList[2].Value); }
/// <summary> /// Adds a new <typeparamref name="TIntermediateSignature"/> with the <paramref name="name"/> /// and <paramref name="signature"/> provided. /// </summary> /// <param name="name">The <see cref="String"/> value which represents the unique identifier associated /// to the new <typeparamref name="TIntermediateSignature"/>.</param> /// <param name="signature">The <see cref="IDelegateType"/> which denotes the return-type /// and parameters of the <typeparamref name="TIntermediateSignature"/>.</param> /// <returns>A new <typeparamref name="TIntermediateSignature"/> with the <paramref name="name"/> provided /// which has the <paramref name="signature"/> provided.</returns> public TIntermediateSignature Add(string name, IDelegateType signature) { /* * * Setup, create a new series of typed names with the type-parameters of the signature * replaced with a string-variant. * */ return(DictionaryHelpers.AddIntermediateMethodByDelegate <TSignatureParameter, TIntermediateSignatureParameter, TSignature, TIntermediateSignature, TSignatureParent, TIntermediateSignatureParent>(name, signature, this.Add, this.Add)); }
public void PopulateTopLevel(object inputObject) { var wrapper = new GameObject("root_wrapper"); wrapper.AddComponent <PositionWindowUnderPorts>(); wrapper.transform.position = new Vector3(0, 0, 0); wrapper.transform.SetParent(this.transform, false); wrapper.AddComponent <VerticalLayoutGroup>(); //wrapper.GetComponent<RectTransform>().sizeDelta = new Vector2(1,1); wrapper.AddComponent <Canvas>(); wrapper.GetComponent <Canvas>().worldCamera = Camera.main; wrapper.AddComponent <GraphicRaycaster>(); wrapper.GetComponent <RectTransform>().localScale = new Vector3(.0003f, .0003f, .0003f); var fitter = wrapper.AddComponent <ContentSizeFitter>(); fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; //wrapper.transform.Rotate(0,90,0); TopLevelElement = inputObject; /*if (IsList(inputObject)) * { * * /*Debug.Log("inputobject is a list"); * foreach (var item in (IEnumerable)inputObject) * { * * var inspectabelgo = generateInspectableElementGameObject(item,wrapper); * * * } * } * * else*/if (IsDictionary(inputObject)) { Debug.Log("inputobject is a dictionary"); foreach (var pair in (IEnumerable)inputObject) { var realpair = DictionaryHelpers.CastFrom(pair); var key = realpair.Key; var value = realpair.Value; var inspectabelgo = generateInspectableElementGameObject(value, wrapper); } } else { Debug.Log("inputobject is a object"); //because this is the top level, we wont reflect over this object //but instead just generate an element that represents it as the root. var inspectabelgo = generateInspectableElementGameObject(inputObject, wrapper); } }
public Strategy Build(Item item, Dictionary <int, double> destinationBuyPrices) { if (DictionaryHelpers.GetSellPriceForItemOrMin(_item.Id, _destinationBuyPrices) < 0) { return(new NullOffloadingStrategy(_item)); } return(new LocalSellOrdersOffloadingStrategy(_item, destinationBuyPrices)); }
/// <summary> /// Callback method for DataBridge mechanism. /// This callback only gets called when /// - The AST is executed /// - After the BuildOutputAST function is executed /// - The AST is fully built /// </summary> /// <param name="data">The data passed through the data bridge.</param> private void DataBridgeCallback(object data) { // Grab input data which always returned as an ArrayList var inputs = data as ArrayList; // Each of the list inputs are also returned as ArrayLists Dictionary <string, object> dataframeDictionary = DictionaryHelpers.ToCDictionary(inputs[0] as DesignScript.Builtin.Dictionary); DataframeDictionary = dataframeDictionary; // Notify UI the data has been modified RaisePropertyChanged("DataUpdated"); }
public void DoesAnyKeyHavePrefixSuccess() { // Arrange Dictionary <string, object> dict = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "FOO.BAR", 42 } }; // Act bool wasPrefixFound = DictionaryHelpers.DoesAnyKeyHavePrefix(dict, "foo"); // Assert Assert.True(wasPrefixFound); }
public List <Guid> GetMatchmakingGroupIds(Dictionary <byte, object> playerProperties) { lock (_mutex) { var result = new List <Guid>(); foreach (var group in _groupsToProperties) { if (DictionaryHelpers.AreDictionariesEqual(group.Value, playerProperties)) { result.Add(group.Key); } } return(result); } }
public static DataFrame ByDictionary(Dictionary dataDictionary) { var dict = DictionaryHelpers.ToCDictionary(dataDictionary); string jsonStr = JsonConvert.SerializeObject(dict, Formatting.None); // Build argument JSON objec dynamic arguments = new JObject(); arguments.jsonStr = jsonStr; string dataframeJson = DynamoPandas.Pandamo.PythonRestCall .webUriPostCaller(PythonConstants.webUri + "api/create_dataframe/by_dict/", arguments); DataFrame df = new DataFrame(dataframeJson); return(df); }
/// <summary> /// Callback method for DataBridge mechanism. /// This callback only gets called when /// - The AST is executed /// - After the BuildOutputAST function is executed /// - The AST is fully built /// </summary> /// <param name="data">The data passed through the data bridge.</param> private void DataBridgeCallback(object data) { // Grab input data which always returned as an ArrayList var inputs = data as ArrayList; if (inputs[0] == null) { return; } // Each of the list inputs are also returned as ArrayLists Dictionary <string, object> dataframeDictionary = DictionaryHelpers.ToCDictionary(inputs[0] as DesignScript.Builtin.Dictionary); DataframeDictionary = dataframeDictionary; DataTable = DataTabelFromDictionary(DataframeDictionary); }
/// <summary> /// /// </summary> /// <param name="dataframe"></param> /// <param name="columns"></param> /// <returns></returns> public static DataFrame DropOutliers(DataFrame dataframe, DesignScript.Builtin.Dictionary zValues, int standardDeviation) { string jsonStr = dataframe.InternalDfJson; Dictionary <string, object> zValsDict = DictionaryHelpers.ToCDictionary(zValues); // Build argument JSON objec dynamic arguments = new JObject(); arguments.jsonStr = jsonStr; arguments.z_values = JToken.FromObject(zValsDict); arguments.standard_deviation = JToken.FromObject(standardDeviation); string dataframeJson = DynamoPandas.Pandamo.PythonRestCall .webUriPostCaller(PythonConstants.webUri + UrlPrefix + "/drop_outliers/", arguments); DataFrame df = new DataFrame(dataframeJson); return(df); }
private IRoom GetRandomRoomOrCreateOne(Guid sessionId, Dictionary <byte, object> roomProperties) { IRoom result = null; var openRooms = _rooms.Where(r => r.Value.IsOpen() && DictionaryHelpers.AreDictionariesEqual(roomProperties, r.Value.GetPropertiesContainer().GetRoomProperties())).Select(i => i.Value).ToList(); var players = new Dictionary <Guid, Dictionary <byte, object> > { { sessionId, new Dictionary <byte, object>() } }; if (!openRooms.Any()) { var roomId = CreateRoom(roomProperties, players, null); result = GetRoomById(roomId); } else { result = openRooms[_rnd.Next(0, openRooms.Count)]; UpdateRoom(result.GetRoomId(), players); } return(result); }
private object BindCslaCollectionModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var collection = (IList)bindingContext.Model; for (int idx = 0; ; idx++) { var subIndexKey = CreateSubIndexName(bindingContext.ModelName, idx); // TODO: investigagte when sub index not exist but element model exist, if this model should be deleted // if no more value element to work with, exit. if (!DictionaryHelpers.DoesAnyKeyHavePrefix(bindingContext.ValueProvider, subIndexKey)) { break; } // TODO: investigate way to append new element in BindCslaCollectionModel // for now, we're done when no collection element to update if (idx >= collection.Count) { break; } object elementModel = collection[idx]; var innerContext = new ModelBindingContext() { Model = elementModel, ModelName = subIndexKey, ModelState = bindingContext.ModelState, ModelType = elementModel.GetType(), PropertyFilter = bindingContext.PropertyFilter, ValueProvider = bindingContext.ValueProvider }; BindProperties(controllerContext, innerContext); } return(bindingContext.Model); }
protected virtual object BindCslaModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { // BindComplexModel should be made overridable so the following code is more appropriate there. object model = bindingContext.Model ?? CreateCslaModel(controllerContext, bindingContext, bindingContext.ModelType); // We also need to repeat the fallback to empty prefix (ModelName) before continue bool usePrefix = true; if (!string.IsNullOrEmpty(bindingContext.ModelName) && !DictionaryHelpers.DoesAnyKeyHavePrefix(bindingContext.ValueProvider, bindingContext.ModelName)) { if (!bindingContext.FallbackToEmptyPrefix) { return(null); } usePrefix = false; } var newBindingContext = new ModelBindingContext() { Model = model, ModelName = usePrefix ? bindingContext.ModelName : string.Empty, ModelState = bindingContext.ModelState, ModelType = bindingContext.ModelType, PropertyFilter = bindingContext.PropertyFilter, ValueProvider = bindingContext.ValueProvider }; if (typeof(Csla.Core.IEditableCollection).IsAssignableFrom((bindingContext.ModelType))) { return(BindCslaCollectionModel(controllerContext, newBindingContext)); } // bind IEditableBusinessObject BindProperties(controllerContext, newBindingContext); return(model); }
private void populateNextLevel(System.Object subTreeRoot) { //build a new wrapper for this next level var wrapper = new GameObject("sub_tree_wrapper"); //wrapper.transform.position = this.transform.position; wrapper.transform.SetParent(this.transform.parent, false); wrapper.AddComponent <HorizontalLayoutGroup>(); wrapper.GetComponent <HorizontalLayoutGroup>().spacing = 5; if (InspectorVisualization.IsList(subTreeRoot)) { Debug.Log("inputobject is a list"); foreach (var item in (IEnumerable)subTreeRoot) { var inspectabelgo = InspectorVisualization.generateInspectableElementGameObject(item, wrapper); } } else if (InspectorVisualization.IsDictionary(subTreeRoot)) { Debug.Log("inputobject is a dictionary"); foreach (var pair in (IEnumerable)subTreeRoot) { var realpair = DictionaryHelpers.CastFrom(pair); var key = realpair.Key; var value = realpair.Value; InspectorVisualization.generateInspectableElementGameObject(value, wrapper); } } else { Debug.Log("inputobject is a object"); if (subTreeRoot is IDynamicMetaObjectProvider) { Debug.Log("inputobject is a dynamic object"); var names = new List <string>(); var dynobj = subTreeRoot as IronPython.Runtime.Binding.IPythonExpandable; if (dynobj != null) { names.AddRange(dynobj.Context.LanguageContext.GetMemberNames(Expression.Constant(dynobj))); } //filter names so that python private and builtin members do not show var filterednames = names.Where(x => x.StartsWith("__") != true).ToList(); foreach (var name in filterednames) { var value = InspectorVisualization.GetDynamicValue(dynobj, name); if (value != null) { InspectorVisualization.generateInspectableElementGameObject(value, wrapper); } } } // if object was not dynamic use regular reflection else { Debug.Log("inputobject is a non dynamic object"); var propertyInfos = subTreeRoot.GetType().GetProperties( BindingFlags.Public | BindingFlags.NonPublic // Get public and non-public | BindingFlags.Static | BindingFlags.Instance // Get instance + static | BindingFlags.FlattenHierarchy); // Search up the hierarchy foreach (var prop in propertyInfos.ToList()) { if (prop.GetIndexParameters().Length > 0) { // Property is an indexer Debug.Log("this property is an indexed property, for now we won't reflect further"); continue; } try { var value = prop.GetValue(subTreeRoot, null); InspectorVisualization.generateInspectableElementGameObject(value, wrapper, prop.Name); } catch (Exception e) { Debug.Log("could not get property" + prop.Name); } } } } }
public void Try_get_strings(ITracer tracer) { TryGetHelper <string>(tracer, DictionaryHelpers.GetStringKeyArray(Size)); }
public void Add_ints_with_capacity(ITracer tracer) { AddWithCapacityHelper <int>(tracer, DictionaryHelpers.GetIntKeyArray(Size)); }
public void Add_strings_with_capacity(ITracer tracer) { AddWithCapacityHelper <string>(tracer, DictionaryHelpers.GetStringKeyArray(Size)); }
public void Try_get_ints(ITracer tracer) { TryGetHelper <int>(tracer, DictionaryHelpers.GetIntKeyArray(Size)); }
public bool EqualsUnhappyPathTest <TKey, TVal>(IReadOnlyDictionary <TKey, TVal> left, IReadOnlyDictionary <TKey, TVal> right) where TVal : IEquatable <TVal> => DictionaryHelpers.DictionaryEquals(left, right);