public void TestInternalTimeSource() { var config = SupportConfigFactory.GetConfiguration(); config.EngineDefaults.ThreadingConfig.IsInternalTimerEnabled = true; var serviceProvider = EPServiceProviderManager.GetDefaultProvider(config); serviceProvider.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(serviceProvider, GetType(), GetType().FullName); } var administrator = serviceProvider.EPAdministrator; var timeZone = "US Eastern Standard Time"; var counter = new Mutable <int>(0); // Create a crontab that fires in one minute var crontab = string.Format("*, *, *, *, *, */10, '{0}'", timeZone); var statement = administrator.CreatePattern( "@Name('MarketMakerNonContinuousAlert:Update') every timer:at(" + crontab + ")"); statement.Events += (sender, e) => counter.Value++; // now go to sleep for the next 1 minute SleepForSpan(TimeSpan.FromMinutes(1)); Assert.That(counter.Value, Is.EqualTo(6)); }
public static Mutable DeepCopy(Mutable ptype) { Mutable copy = null; if (ptype is Ptype.Hierarchical.HierarchicalMutable) { Ptype.Hierarchical.HierarchicalMutable hp = (Ptype.Hierarchical.HierarchicalMutable)ptype; copy = new Ptype.Hierarchical.HierarchicalMutable(); Ptype.Hierarchical.HierarchicalMutable hpcopy = (Ptype.Hierarchical.HierarchicalMutable)copy; hpcopy.children.AddRange(hp.children); hpcopy.childrenNames.AddRange(hp.childrenNames); } else { copy = new Mutable(); } copy.Regions = (Dictionary <String, Region>)ptype.Regions; copy.Features = (Dictionary <String, Bitmap>)ptype.Features; copy.Model = ptype.Model; copy.Id = ptype.Id; return(copy); }
public ICollection <EventBean> Lookup(EventBean theEvent, Cursor cursor, ExprEvaluatorContext context) { var events = new Mutable <ISet <EventBean> >(); using (Instrument.With( i => i.QIndexJoinLookup(this, null), i => i.AIndexJoinLookup(events.Value, null))) { _eventsPerStream[_lookupStream] = theEvent; var keys = new Object[_evaluators.Length]; for (var i = 0; i < _evaluators.Length; i++) { keys[i] = _evaluators[i].Evaluate(_eventsPerStream, context); } try { events.Value = _externalIndex.Lookup(keys, _eventsPerStream); } catch (Exception ex) { Log.Warn( "Exception encountered invoking virtual data window external index for window '" + _namedWindowName + "': " + ex.Message, ex); } return(events.Value); } }
public static void main() { var mutable = new Mutable(); mutable.Value = 10; mutable.Value = 20; }
public void Test(Immutable immutable, Mutable mutable, int i, DateTime dateTime) { InImmutable(immutable); InMutable(mutable); InInt32(i); InDateTime(dateTime); }
public async Task SelectAsyncTracksProperly() { var tracker = new IdleTracker(System.Threading.SynchronizationContext.Current); var value = Mutable.Create(0); var mapped = value.SelectAsync( 2, tracker, async v => { await Task.Delay(20); return(v + 2); }); Assert.IsTrue(tracker.Value); value.Value = 2; Assert.AreEqual(2, value.Value); // Mapped should be 2 immediately after setting Assert.AreEqual(2, mapped.Value); // Give us a chance to start... await Task.Delay(10); Assert.IsFalse(tracker.Value); // And now let us finish await Task.Delay(100); Assert.IsTrue(tracker.Value); Assert.AreEqual(2, value.Value); Assert.AreEqual(4, mapped.Value); }
public override void MatchEvent(EventBean theEvent, ICollection <FilterHandle> matches) { var attributeValue = Lookupable.Getter.Get(theEvent); var returnValue = new Mutable <bool?>(false); using (Instrument.With( i => i.QFilterReverseIndex(this, attributeValue), i => i.AFilterReverseIndex(returnValue.Value))) { if (attributeValue == null) { return; } // Look up in hashtable using (_constantsMapRwLock.AcquireReadLock()) { var evaluators = _constantsMap.Get(attributeValue); // No listener found for the value, return if (evaluators == null) { return; } foreach (var evaluator in evaluators) { evaluator.MatchEvent(theEvent, matches); } returnValue.Value = null; } } }
public static void Main() { var m = new Mutable(); m.Value = 20; m.Value = 30; }
public override void MatchEvent(EventBean theEvent, ICollection <FilterHandle> matches) { var attributeValue = Lookupable.Getter.Get(theEvent); var returnValue = new Mutable <bool?>(false); using (Instrument.With( i => i.QFilterReverseIndex(this, attributeValue), i => i.AFilterReverseIndex(returnValue.Value))) { // Look up in hashtable using (ConstantsMapRwLock.AcquireReadLock()) { foreach (var entry in ConstantsMap) { if (entry.Key == null) { if (attributeValue != null) { entry.Value.MatchEvent(theEvent, matches); } continue; } if (!entry.Key.Equals(attributeValue)) { entry.Value.MatchEvent(theEvent, matches); } } } returnValue.Value = null; } }
public ClassWithMutable() { _mutable = new Mutable() { Value = 1 }; }
/// <summary> /// Mutates the contents of this instance and get the mutated instance. /// </summary> /// <param name="action">The action to mutate the record.</param> /// <returns>The mutated instance.</returns> public CsvRecord Mutate(Action <Mutable> action) { var mutable = new Mutable(this); action(mutable); return(mutable.ToRecord()); }
public override void MatchEvent(EventBean theEvent, ICollection <FilterHandle> matches) { var attributeValue = Lookupable.Getter.Get(theEvent); var returnValue = new Mutable <bool>(false); using (Instrument.With( i => i.QFilterReverseIndex(this, attributeValue), i => i.AFilterReverseIndex(returnValue.Value))) { EventEvaluator evaluator = null; using (ConstantsMapRwLock.AcquireReadLock()) { evaluator = ConstantsMap.Get(attributeValue); } // No listener found for the value, return if (evaluator == null) { returnValue.Value = false; } else { evaluator.MatchEvent(theEvent, matches); returnValue.Value = true; } } }
public void TestSimpleUnchanged() { var w = Mutable.From(0); w.PropertyChanged += (s, e) => { throw new Exception("Shouldn't fire Changed event if value is unchanged"); }; w.Value = 0; }
/// <summary> /// Removes the node from the chain. /// </summary> /// <param name="head">The head.</param> /// <param name="key">The key.</param> /// <param name="level">The level.</param> /// <returns></returns> private Node Remove(Node head, TK key, int level, Mutable <bool> found) { for (var curr = head;; curr = curr.Next[level]) { if (curr.Next[level] == null) { return(head); // not in this chain } var comp = Compare(key, curr.Next[level].Key); if (comp == 0) { // change the reference of curr.Next to curr.Next.Next curr.Next[level] = curr.Next[level].Next[level]; found.Value = true; // return the current node return(curr); } else if (comp < 0) { // this case happens when we pass over the "key" - in a skip list // this can occur because the level has a gap that does not contain // the key. since our comparisons are always done on 'curr.Next', we // can safely return curr to indicate that it's removed from this // level and curr is a good starting point for the next level return(curr); } } }
public object Evaluate(EvaluateParams evaluateParams) { var result = new Mutable <object>(); Instrument.With( i => i.QExprCase(this), i => i.AExprCase(result.Value), () => { if (!_isCase2) { result.Value = EvaluateCaseSyntax1( evaluateParams.EventsPerStream, evaluateParams.IsNewData, evaluateParams.ExprEvaluatorContext); } else { result.Value = EvaluateCaseSyntax2( evaluateParams.EventsPerStream, evaluateParams.IsNewData, evaluateParams.ExprEvaluatorContext); } }); return(result.Value); }
public static List <Mutable> BuildFromExamples(List <BuildPrototypeArgs> args) { List <Mutable> created = new List <Mutable>(); List <BuildPrototypeArgs> couldntCreate = new List <BuildPrototypeArgs>(); foreach (BuildPrototypeArgs arg in args) { Mutable result = BuildFromExamples(arg); if (result != null) { created.Add(result); } else { couldntCreate.Add(arg); } } if (couldntCreate.Count > 0) { throw new PtypeBuildException(couldntCreate); } return(created); }
public void TestRecursion() { var w = Mutable.From(0); // Not okay to set it to a different value (hence expected exception) w.PropertyChanged += (s, e) => w.Value++; w.Value++; }
public void TestReentrance() { var w = Mutable.From(0); // Okay to assign to writeable that just changed as long as it's the same (new) value w.PropertyChanged += (s, e) => w.Value = 1; w.Value++; }
public void SelectWorksOffSignal() { var value = Mutable.Create(42); var mapped = value.Select(v => (v + 2).ToString()); Assert.AreEqual(42, value.Value); Assert.AreEqual("44", mapped.Value); }
public void CanConstructMutables() { var value = Mutable.Create(42); var value2 = Mutable.Create("Foo"); Assert.AreEqual(42, value.Value); Assert.AreEqual("Foo", value2.Value); }
//Converts enum to string with slash. public static string ConvertMutable(Mutable mutable) { switch (mutable) { case Mutable.coinbaseAppend: { return("coinbase/append"); } case Mutable.timeDecrement: { return("time/decrement"); } case Mutable.timeIncrement: { return("time/increment"); } case Mutable.versionForce: { return("version/force"); } case Mutable.versionReduce: { return("version/reduce"); } case Mutable.prevblock: { return("prevblock"); } case Mutable.transactions: { return("transactions"); } case Mutable.time: { return("time"); } case Mutable.generation: { return("generation"); } case Mutable.coinbase: { return("coinbase"); } } return(null); }
public void MutableUpdateWorks() { var value = Mutable.Create(0); Mutable.Update(value, o => o + 1); Mutable.Update(value, o => o - 3); Assert.AreEqual(-2, value.Value); }
public static void Main() { var m = new Mutable(); m.Value = 20; Console.WriteLine(m.Value); // 20 m.Value = 30; Console.WriteLine(m.Value); // 30 }
public void TestSimpleChanged() { var w = Mutable.From(0); var changed = false; w.PropertyChanged += (s, e) => changed = true; w.Value = 1; Assert.IsTrue(changed); }
public void MutableUpdateWorksWithCollection() { var value = Mutable.Create(new List <int> { 42, 54 }); Mutable.Update(value, (o => o.Concat(new[] { 21, 15 }).ToList())); CollectionAssert.AreEqual(new[] { 42, 54, 21, 15 }, value.Value); }
public void SelectWorksWithQuerySyntax() { var value = Mutable.Create(42); var mapped = from v in value let newV = v + 2 select newV.ToString(); Assert.AreEqual(42, value.Value); Assert.AreEqual("44", mapped.Value); }
static void Main(string[] args) { var ai = new Mutable(); var rui = new Immutable(); ai.Name = "ルイ"; //rui.Name = "アイ"; 実行できない Console.WriteLine(ai.Name); Console.WriteLine(rui.Name); }
public static void Run() { var mutable = new Mutable(); mutable.Value = new Something(); var readable = (IReadonly)mutable; var result = readable.Value; }
static void Main(string[] args) { #region Level 0 string name = " 123456 "; name.Trim(); Console.WriteLine(name.Length); name = name.Trim(); // immutable always returns a new string Console.WriteLine(name.Length); #endregion #region Basic var r1 = new MutableRectangle(); r1.Height = 10; r1.Length = 5; r1.Grow(10, 5); Console.WriteLine(r1.ToString()); #endregion #region Patterns #region 1. Mutable var m = new Mutable(); m.Value = 10; m.Value = 20; #endregion #region 2. ShallowMutable StringBuilder builder = new StringBuilder(); builder.Append("foo"); var sm = new ShallowMutable(10, builder); sm.Builder.Append("bar"); Console.WriteLine(sm.Builder); #endregion #region 3. Popsicle var p = new Popsicle(); p.Value = 10; p.Freeze(); //p.Value = 20; //Bang! #endregion #region 4. ObservableImmutable #endregion #endregion Console.ReadLine(); }
public void ProvidesHashCode_Mutation() { var o = new Mutable(); var a = Maybe.From(typeof(Mutable), o); Assert.AreEqual(-999, a.GetHashCode()); o._hashCode = 777; Assert.AreEqual(777, a.GetHashCode()); }
public MapReduceQuery(Node n, CacheList cl): base(n) { _cl = cl; _mut = new Mutable<MRQState>(new MRQState()); //Add the default query handlers: AddQueryMatcher("regex", delegate(object pattern) { return new RegexMatcher((string)pattern); }); AddQueryMatcher("exact", delegate(object pattern) { return new ExactMatcher(pattern); }); AddHitCombiner("concat", delegate(object arg) { return ConcatCombiner.Instance; }); AddHitCombiner("maxcount", delegate(object arg) { return new MaxCountCombiner((int)arg); }); }
public void PlayNext(string soundPrefix) { Mutable<int> mutable; if (!this.soundIndices.TryGetValue(soundPrefix, out mutable)) this.soundIndices.Add(soundPrefix, mutable = new Mutable<int>()); ++mutable.Value; try { SoundEffectExtensions.Emit(this.CMProvider.CurrentLevel.Load<SoundEffect>("Sounds/" + (object) soundPrefix + (string) (object) mutable.Value)); } catch (Exception ex) { Logger.Log("Sounds Service", LogSeverity.Warning, ex.Message); } }
public static Ptype LoadDummy(){ Bitmap bitmap = Bitmap.FromFile("../prefab/AdobePreferences.png"); Bitmap feature = Bitmap.Crop(bitmap, 606, 614, 2,2 ); Bitmap feature2 = Bitmap.Crop(bitmap, 681, 614, 2, 2); Bitmap feature3 = Bitmap.Crop(bitmap, 606, 637, 2, 2); Bitmap feature4 = Bitmap.Crop(bitmap, 681, 637, 2, 2); Bitmap top = Bitmap.Crop(bitmap, 608, 614, 1, 1); Bitmap bottom = Bitmap.Crop(bitmap, 608, 638, 1, 1); Bitmap left = Bitmap.Crop(bitmap, 606, 616, 1,1); Bitmap right = Bitmap.Crop(bitmap, 682, 616, 1, 1); Bitmap interior = Bitmap.Crop(bitmap, 608, 615, 1, 23); Dictionary<String, Bitmap> features = new Dictionary<String, Bitmap>(); Dictionary<String, Region> regions = new Dictionary<String, Region>(); features.Add("topleft", feature); features.Add("topright", feature2); features.Add("bottomleft", feature3); features.Add("bottomright", feature4); regions.Add("top", new Region("horizontal", top)); regions.Add("bottom", new Region("horizontal", bottom)); regions.Add("left", new Region("vertical", left)); regions.Add("right", new Region("right", right)); regions.Add("interior", new Region("horizontal", interior)); try{ Mutable mutable = new Mutable(features, regions); mutable.Model = "ninepart"; mutable.Id = Guid.NewGuid().ToString(); List<Mutable> all = new List<Mutable>(); all.Add(mutable); IEnumerable<Ptype> lib = CreatePrototypeLibrary( all); return lib.First(); }catch{ } return null; }
public Queue( Guid objectId, Guid userGuid, Uri mediaUrl, string title, string summary, DateTime publishedDate, Uri imageUri) { ObjectId = objectId; _userGuid = userGuid; MediaUrl = mediaUrl; Title = title; Summary = summary; PublishedDate = publishedDate; ImageUri = imageUri; _playhead = new Mutable<double>(userGuid.ToCanonicalString()); }
public Visualizer(Mutable<Signal<Maybe<View>>> Feed) { this._Feed = Feed; }
public static void Main() { var m = new Mutable(); m.Value = 20; m.Value = 30; }
private static Ptype CreatePtypeFromMutable(Mutable prototypebuildargs, Model[] models, Feature.Factory features, IEnumerable<Mutable> allptypes) { Dictionary<string, Bitmap> ptypefeatureshash = prototypebuildargs.Features; Dictionary<string,Feature> ptypefeatures = new Dictionary<string, Feature>(); foreach (String fname in ptypefeatureshash.Keys) { Feature feature = features.Create(ptypefeatureshash[fname]); ptypefeatures.Add(fname, feature); } Model model = null; foreach(Model m in models) if(m.Name.Equals(prototypebuildargs.Model)) { model = m; break; } Dictionary<string, Region> rdict = (Dictionary<string,Region>)new Dictionary<string,Region>(prototypebuildargs.Regions); // if (prototypebuildargs instanceof Hierarchical.HierarchicalMutable) // { // Hierarchical.HierarchicalMutable mhp = (Hierarchical.HierarchicalMutable)prototypebuildargs; // Dictionary<String, Ptype> children = new Dictionary<String, Ptype>(); // for (int c = 0; c < mhp.childrenNames.size(); c++) // { // Mutable ptype = null; // for(Mutable p : allptypes){ // if(p.id.equals(mhp.children.get(c))){ // ptype = p; // break; // } // } // children.put(mhp.childrenNames.get(c), createPtypeFromMutable( ptype, models, features, allptypes)); // } // return new Hierarchical(mhp.id, fdict, rdict, model, children); // } // else return new Ptype(prototypebuildargs.Id, ptypefeatures, rdict, model); }
public static Mutable DeepCopy(Mutable ptype) { Mutable copy = null; if (ptype is Ptype.Hierarchical.HierarchicalMutable) { Ptype.Hierarchical.HierarchicalMutable hp = (Ptype.Hierarchical.HierarchicalMutable) ptype; copy = new Ptype.Hierarchical.HierarchicalMutable(); Ptype.Hierarchical.HierarchicalMutable hpcopy = (Ptype.Hierarchical.HierarchicalMutable)copy; hpcopy.children.AddRange(hp.children); hpcopy.childrenNames.AddRange(hp.childrenNames); } else { copy = new Mutable(); } copy.Regions = (Dictionary<String,Region>)ptype.Regions; copy.Features = (Dictionary<String,Bitmap>)ptype.Features; copy.Model = ptype.Model; copy.Id = ptype.Id; return copy; }
/// <summary> /// Same as <seealso cref="#copy(Reader, int, Mutable, int, int, int)"/> but using a pre-allocated buffer. </summary> internal static void Copy(Reader src, int srcPos, Mutable dest, int destPos, int len, long[] buf) { Debug.Assert(buf.Length > 0); int remaining = 0; while (len > 0) { int read = src.Get(srcPos, buf, remaining, Math.Min(len, buf.Length - remaining)); Debug.Assert(read > 0); srcPos += read; len -= read; remaining += read; int written = dest.Set(destPos, buf, 0, remaining); Debug.Assert(written > 0); destPos += written; if (written < remaining) { Array.Copy(buf, written, buf, 0, remaining - written); } remaining -= written; } while (remaining > 0) { int written = dest.Set(destPos, buf, 0, remaining); destPos += written; remaining -= written; Array.Copy(buf, written, buf, 0, remaining); } }
/// <summary> /// Copy <code>src[srcPos:srcPos+len]</code> into /// <code>dest[destPos:destPos+len]</code> using at most <code>mem</code> /// bytes. /// </summary> public static void Copy(Reader src, int srcPos, Mutable dest, int destPos, int len, int mem) { Debug.Assert(srcPos + len <= src.Size()); Debug.Assert(destPos + len <= dest.Size()); int capacity = (int)((uint)mem >> 3); if (capacity == 0) { for (int i = 0; i < len; ++i) { dest.Set(destPos++, src.Get(srcPos++)); } } else if (len > 0) { // use bulk operations long[] buf = new long[Math.Min(capacity, len)]; Copy(src, srcPos, dest, destPos, len, buf); } }
/** * Prefered constructor for a Connection */ public Connection(Edge e, Address a, string connectiontype, StatusMessage sm, LinkMessage peerlm) { Address = a; ConType = String.Intern(connectiontype); CreationTime = DateTime.UtcNow; MainType = StringToMainType(ConType); //Mutable state: var cs = new ConnectionState(e, sm, peerlm, false); _state = new Mutable<ConnectionState>(cs); }
/** * Prefered constructor for a Connection */ public Connection(Edge e, Address a, string connectiontype, StatusMessage sm, LinkMessage peerlm) { if( null == a ) { throw new System.ArgumentNullException( String.Format("Address cannot be null in Connection: Edge: {0} contype: {1}", e, connectiontype)); } Address = a; ConType = String.Intern(connectiontype); CreationTime = DateTime.UtcNow; MainType = StringToMainType(ConType); //Mutable state: var cs = new ConnectionState(e, sm, peerlm, false); _state = new Mutable<ConnectionState>(cs); }