private static IRValueNode CreateConstant(ParseContext context) { TokenStream<RToken> tokens = context.Tokens; RToken currentToken = tokens.CurrentToken; IRValueNode term = null; switch (currentToken.TokenType) { case RTokenType.NaN: case RTokenType.Infinity: case RTokenType.Number: term = new NumericalValue(); break; case RTokenType.Complex: term = new ComplexValue(); break; case RTokenType.Logical: term = new LogicalValue(); break; case RTokenType.String: term = new StringValue(); break; case RTokenType.Null: term = new NullValue(); break; case RTokenType.Missing: term = new MissingValue(); break; } Debug.Assert(term != null); term.Parse(context, null); return term; }
/// <summary> /// Learn how to use KVLite by examples. /// </summary> public static void Main() { // Some variables used in the examples. var examplePartition1 = "example partition 1"; var examplePartition2 = "example partition 2"; var exampleKey1 = "example key 1"; var exampleKey2 = "example key 2"; var simpleValue = Math.PI; var complexValue = new ComplexValue { Integer = 21, NullableBoolean = null, String = "Learning KVLite", Dictionary = new Dictionary<short, ComplexValue> { [1] = new ComplexValue { NullableBoolean = true }, [2] = new ComplexValue { String = "Nested..." } } }; /* * KVLite stores its values inside a given partition and each value is linked to a key. * KVLite can contain more than one partition and each partition can contain more than one key. * * Therefore, values are stored according to this logical layout: * * [partition1] --> key1/value1 * --> key2/value2 * [partition2] --> key1/value1 * --> key2/value2 * --> key3/value3 * * A key is unique inside a partition, not inside all cache. * A partition, instead, is unique inside all cache. */ // You can start using the default caches immediately. Let's try to store some values in // a way similar to the figure above, using the default persistent cache. ICache persistentCache = PersistentCache.DefaultInstance; persistentCache.AddTimed(examplePartition1, exampleKey1, simpleValue, persistentCache.Clock.UtcNow.AddMinutes(5)); persistentCache.AddTimed(examplePartition1, exampleKey2, simpleValue, persistentCache.Clock.UtcNow.AddMinutes(10)); persistentCache.AddTimed(examplePartition2, exampleKey1, complexValue, persistentCache.Clock.UtcNow.AddMinutes(10)); persistentCache.AddTimed(examplePartition2, exampleKey2, complexValue, persistentCache.Clock.UtcNow.AddMinutes(5)); PrettyPrint(persistentCache); // Otherwise, you can customize you own cache... Let's see how we can use a volatile // cache. Let's define the settings that we will use in new volatile caches. var volatileCacheSettings = new VolatileCacheSettings { CacheName = "My In-Memory Cache", // The backend. StaticIntervalInDays = 10 // How many days static values will last. }; // Then the settings that we will use in new persistent caches. var persistentCacheSettings = new PersistentCacheSettings { CacheFile = "CustomCache.sqlite", // The SQLite DB used as the backend for the cache. InsertionCountBeforeAutoClean = 10, // Number of inserts before a cache cleanup is issued. MaxCacheSizeInMB = 64, // Max size in megabytes for the cache. MaxJournalSizeInMB = 16, // Max size in megabytes for the SQLite journal log. StaticIntervalInDays = 10 // How many days static values will last. }; // We create both a volatile and a persistent cache. var volatileCache = new VolatileCache(volatileCacheSettings); persistentCache = new PersistentCache(persistentCacheSettings); // Use the new volatile cache! volatileCache.AddStatic(examplePartition1, exampleKey1, Tuple.Create("Volatile!", 123)); PrettyPrint(volatileCache); // Use the new persistent cache! persistentCache.AddStatic(examplePartition2, exampleKey2, Tuple.Create("Persistent!", 123)); PrettyPrint(persistentCache); /* * An item can be added to the cache in three different ways. * * "Timed" values last until the specified date and time, or for a specified timespan. * Reading them will not extend their lifetime. * * "Sliding" values last for the specified lifetime, but, if read, * their lifetime will be extended by the timespan specified initially. * * "Static" values are a special form of "sliding" values. * They use a very long timespan, 30 days by default, and they can be used for seldom changed data. */ // Let's clear the volatile cache and let's a value for each type. volatileCache.Clear(); volatileCache.AddTimed(examplePartition1, exampleKey1, simpleValue, volatileCache.Clock.UtcNow.AddMinutes(10)); volatileCache.AddTimed(examplePartition1, exampleKey2, complexValue, TimeSpan.FromMinutes(15)); volatileCache.AddStatic(examplePartition2, exampleKey1, simpleValue); volatileCache.AddSliding(examplePartition2, exampleKey2, complexValue, TimeSpan.FromMinutes(15)); PrettyPrint(volatileCache); Console.Read(); }
public ComplexDomainEvent(string text, ComplexValue value) { Text = text; Value = value; }
public void SerializeSingleCustomData() { Project p = new Project(); Dictionary<Guid, Guid> emptyMappings = new Dictionary<Guid, Guid>(); Dictionary<Guid, Signal> signals = new Dictionary<Guid, Signal>(); Dictionary<Guid, Bus> buses = new Dictionary<Guid, Bus>(); ComplexValue cv = new ComplexValue(Constants.Pi, Constants.E); string xml = Serializer.SerializeToString(cv, emptyMappings, emptyMappings); ComplexValue ret = Serializer.DeserializeFromString<ComplexValue>(xml, signals, buses); Assert.AreEqual(cv.TypeId, ret.TypeId, "B"); Assert.AreEqual(cv.ToString(), ret.ToString(), "C"); }
private static ComplexField ElementToComplexField(XmlElement fieldElm, string fieldId, string fieldName) { if (fieldElm == null) { return(null); } ComplexField complexField = (ComplexField)SchemaFactory.CreateField(FieldTypeEnum.COMPLEX); complexField.Id = fieldId; complexField.Name = fieldName; XmlElement fieldsEle = XmlUtils.GetChildElement(fieldElm, "fields"); if (fieldsEle != null) { List <XmlElement> fieldEleList = XmlUtils.GetChildElements(fieldsEle, "field"); foreach (XmlElement subFieldEle in fieldEleList) { Field fieldFromEle = ElementToField(subFieldEle); complexField.Add(fieldFromEle); } } //rules XmlElement rulesEle = XmlUtils.GetChildElement(fieldElm, "rules"); if (rulesEle != null) { List <XmlElement> ruleEleList = XmlUtils.GetChildElements(rulesEle, "rule"); foreach (XmlElement ruleEle in ruleEleList) { Rule rule = ElementToRule(ruleEle, complexField.Id); complexField.Add(rule); } } //property XmlElement propertiesEle = XmlUtils.GetChildElement(fieldElm, "properties"); if (propertiesEle != null) { List <XmlElement> propertyEleList = XmlUtils.GetChildElements(propertiesEle, "property"); foreach (XmlElement propertyEle in propertyEleList) { Property.Property property = ElementToProperty(propertyEle, complexField.Id); complexField.Add(property); } } //default-complex-value XmlElement defaultComplexValueEle = XmlUtils.GetChildElement(fieldElm, "default-complex-values"); if (defaultComplexValueEle != null) { List <XmlElement> defaultValuesSubFieldList = XmlUtils.GetChildElements(defaultComplexValueEle, "field"); ComplexValue defaultCvalue = new ComplexValue(); foreach (XmlElement subFiledValueEle in defaultValuesSubFieldList) { Field field = ElementToField(subFiledValueEle); defaultCvalue.Put(field); } complexField.SetDefaultValue(defaultCvalue); } //complex-value XmlElement complexValueEle = XmlUtils.GetChildElement(fieldElm, "complex-values"); if (complexValueEle != null) { List <XmlElement> valuesSubFieldList = XmlUtils.GetChildElements(complexValueEle, "field"); ComplexValue cvalue = new ComplexValue(); foreach (XmlElement subFiledValueEle in valuesSubFieldList) { Field field = ElementToField(subFiledValueEle); cvalue.Put(field); } complexField.SetComplexValue(cvalue); } return(complexField); }
public void SerializeFilledCustomDataList() { Project p = new Project(); Dictionary<Guid, Guid> emptyMappings = new Dictionary<Guid, Guid>(); Dictionary<Guid, Signal> signals = new Dictionary<Guid, Signal>(); Dictionary<Guid, Bus> buses = new Dictionary<Guid, Bus>(); LiteralValue lv = new LiteralValue("test"); IntegerValue iv = new IntegerValue(42); ComplexValue cv = new ComplexValue(Constants.Pi, Constants.E); RealValue rv = new RealValue(Constants.TwoInvSqrtPi); List<IValueStructure> values = new List<IValueStructure>(); values.Add(lv); values.Add(iv); values.Add(cv); values.Add(rv); string xml = Serializer.SerializeListToString(values, emptyMappings, emptyMappings, "Structures"); List<IValueStructure> ret = Serializer.DeserializeListFromString<IValueStructure>(xml, signals, buses, "Structures"); Assert.AreEqual(4, ret.Count, "A"); Assert.AreEqual(values[0].TypeId, ret[0].TypeId, "B1"); Assert.AreEqual(values[1].TypeId, ret[1].TypeId, "B2"); Assert.AreEqual(values[2].TypeId, ret[2].TypeId, "B3"); Assert.AreEqual(values[3].TypeId, ret[3].TypeId, "B4"); Assert.AreEqual(values[0].ToString(), ret[0].ToString(), "C1"); Assert.AreEqual(values[1].ToString(), ret[1].ToString(), "C2"); Assert.AreEqual(values[2].ToString(), ret[2].ToString(), "C3"); Assert.AreEqual(values[3].ToString(), ret[3].ToString(), "C4"); }
public void AddComplexValue(ComplexValue value) { this.values.Add(value); }
public CounterRecord(string key) { this.Key = key; this.Value = new ComplexValue("vroot", "none"); }
private CableConfiguration setupCableConfiguration() { CableConfiguration.PhasingEnum pe = (CableConfiguration.PhasingEnum)comboboxPhasing.SelectedItem; Cable.MaterialEnum me = (Cable.MaterialEnum)materialKind.SelectedItem; ComplexValue primarValue = new ComplexValue() { Real_part = Double.Parse(real_part1_1.Text), Imaginary_part = Double.Parse(imaginary_part1_1.Text) }; List <ComplexValue> secondaryValues = new List <ComplexValue>(); ComplexValue secondaryValue1 = new ComplexValue() { Real_part = Double.Parse(real_part1_2.Text), Imaginary_part = Double.Parse(imaginary_part1_2.Text) }; ComplexValue secondaryValue2 = new ComplexValue() { Real_part = Double.Parse(real_part2_2.Text), Imaginary_part = Double.Parse(imaginary_part2_2.Text) }; secondaryValues.Add(secondaryValue1); secondaryValues.Add(secondaryValue2); List <ComplexValue> terciarValues = new List <ComplexValue>(); ComplexValue terciarValue1 = new ComplexValue() { Real_part = Double.Parse(real_part1_3.Text), Imaginary_part = Double.Parse(imaginary_part1_3.Text) }; ComplexValue terciarValue2 = new ComplexValue() { Real_part = Double.Parse(real_part2_3.Text), Imaginary_part = Double.Parse(imaginary_part2_3.Text) }; ComplexValue terciarValue3 = new ComplexValue() { Real_part = Double.Parse(real_part3_3.Text), Imaginary_part = Double.Parse(imaginary_part3_3.Text) }; terciarValues.Add(terciarValue1); terciarValues.Add(terciarValue2); terciarValues.Add(terciarValue3); Cable cable = new Cable() { MaterialKind = me, SizeDescription = sizeDescription.Text, PhaseWireSpacing = Double.Parse(wireSpacing.Text) }; CableConfiguration cableConfiguration = new CableConfiguration() { Name = conf_id.Text, Phasing = pe, Primar_value = primarValue, Secondary_value = secondaryValues, Terciar_value = terciarValues, Cable = cable, Susceptance = Double.Parse(suscenptance_per_length.Text) }; return(cableConfiguration); }
public static bool IsConstantComplex(Signal signal) { return(IsConstant(signal) && ComplexValue.CanConvertLosslessFrom(signal.Value)); }