public void SimpleReader() { var count = 100; var before = new Envelope[count]; var after = new Envelope[count]; var name = nameof(this.SimpleReader); using (var p = Pipeline.Create("write")) { var writeStore = Store.Create(p, name, this.path); var seq = Generators.Sequence(p, 0, i => i + 1, count); seq.Write("seq", writeStore); seq.Do((m, e) => before[m] = e); p.Run(); } // now read using the simple reader using (var reader = new SimpleReader(name, this.path)) { reader.OpenStream <int>("seq", (s, e) => after[s] = e); reader.ReadAll(ReplayDescriptor.ReplayAll); } for (int i = 0; i < count; i++) { Assert.AreEqual(before[i], after[i]); } }
public void SimpleReaderLargeStream() { var count = 10; var name = nameof(this.SimpleReaderLargeStream); var size = 10240; var bytes = new byte[size]; using (var p = Pipeline.Create("write")) { var writeStore = Store.Create(p, name, this.path); var seq = Generators.Sequence(p, 0, i => i + 1, count); var big = seq.Select(i => bytes.Select(_ => i).ToArray()); seq.Write("seq", writeStore); big.Write("big", writeStore, largeMessages: true); p.Run(); } // now replay the contents and verify we get something List <IndexEntry> index = new List <IndexEntry>(); // now read using the simple reader var result = new int[size]; using (var reader = new SimpleReader(name, this.path)) { reader.OpenStreamIndex <int[]>("big", (ie, e) => index.Add(ie)); reader.ReadAll(ReplayDescriptor.ReplayAll); Assert.AreEqual(count, index.Count()); var probe = count / 2; var entry = index[probe]; reader.Read <int[]>(entry, ref result); Assert.AreEqual(result.Sum(x => x), probe * size); } }
public void ReadTagEPC() { string MethodeName = MethodBase.GetCurrentMethod().ToString(); // string wyn = ""; // use USB autodetect SimpleReader reader = new SimpleReader(); // or connect to reader at specified COM port // SimpleReader reader = new SimpleReader("serial://COM10"); // or connect to reader at specified IP address // SimpleReader reader = new SimpleReader("tcp://10.1.2.3"); try { reader.ResponseReceived += reader_ResponseReceived; reader.ObservationReceived += reader_ObservationReceived; reader.ErrorReceived += reader_ErrorReceived; reader.ConnectionClosed += reader_ConnectionClosed; reader.ConnectionSucceeded += reader_ConnectionSucceeded; reader.Connect(Region.Europe); reader.ReadBlocking(100); // 0,1 sekundy // Console.ReadKey(); reader.Disconnect(); // return wyn; } catch (IdReaderException e) { throw e; // throw new IdReaderExc(e.Message); // Console.WriteLine(e.Message); // Console.ReadKey(); } // return wyn; }
public void Setup() { // Establish as much that can be pre-calculated as possible. dataPipe = new Pipe(); writer = dataPipe.Writer; delimitedMessageReader = new SimpleReader(MessageSize); data = new byte[MessageSize]; data.AsSpan().Fill(1); halfDataSize = MessageSize / 2; protReader = new ProtocolReader(dataPipe.Reader); }
public void CopyStore() { var count = 100; var before = new Envelope[count + 1]; var after = new Envelope[count + 1]; var name = nameof(this.CopyStore); using (var p = Pipeline.Create("write")) { var writeStore = Store.Create(p, name, this.path); var seq = Generators.Sequence(p, 1, i => i + 1, count); seq.Write("seq", writeStore); seq.Select(i => i.ToString()).Write("seqString", writeStore); seq.Do((m, e) => before[m] = e); p.Run(); } // copy to a second store using (var p = Pipeline.Create("write2")) { var readStore = Store.Open(p, name, this.path); var writeStore = Store.Create(p, name, this.path); readStore.CopyStream("seq", writeStore); readStore.CopyStream("seqString", writeStore); p.Run(); } // now read the latest using the simple reader bool intStreamCorrect = true; bool stringStreamCorrect = true; using (var reader = new SimpleReader(name, this.path)) { reader.OpenStream <int>("seq", (s, e) => { after[s] = e; intStreamCorrect &= e.SequenceId == s; }); reader.OpenStream <string>("seqString", (s, e) => { stringStreamCorrect &= e.SequenceId.ToString() == s; }); reader.ReadAll(ReplayDescriptor.ReplayAll); } for (int i = 0; i < count; i++) { Assert.AreEqual(before[i], after[i]); } Assert.IsTrue(intStreamCorrect); Assert.IsTrue(stringStreamCorrect); }
public static Object load(String filename) { //this creates an XML reader, which will be used to de-serialize the object XmlTextReader xmlReader = new XmlTextReader(filename); //this creates the WOX reader ObjectReader woxReader = new SimpleReader(); //Read the next node from the Stream. In this case it will be the Root Element xmlReader.Read(); //reads the object from the XML file. We pass the xmlReader positioned in the first node! Object ob = woxReader.read(xmlReader); xmlReader.Close(); Console.Out.WriteLine("Load object from " + filename); return(ob); }
private static void Main(string[] args) { Console.WriteLine("Simple with reader"); SimpleWithReader simpleWithReader = SimpleWithReader.Load("source\\simple.json"); Console.WriteLine($"string: {simpleWithReader.StringProperty}"); Console.WriteLine($"number: {simpleWithReader.NumberProperty}"); Console.WriteLine($"boolean: {simpleWithReader.BooleanProperty}"); Console.WriteLine(); Console.WriteLine("Simple with extern reader"); Simple simple = SimpleReader.Load("source\\simple.json"); Console.WriteLine($"string: {simple.StringProperty}"); Console.WriteLine($"number: {simple.NumberProperty}"); Console.WriteLine($"boolean: {simple.BooleanProperty}"); Console.WriteLine(); Console.WriteLine("Press key to EXIT..."); Console.ReadKey(); }
public void RetrieveStreamSupplementalMetadata() { var name = nameof(this.RetrieveStreamSupplementalMetadata); // create store with supplemental meta using (var p = Pipeline.Create("write")) { var store = Store.Create(p, name, this.path); var stream0 = Generators.Range(p, 0, 10, TimeSpan.FromTicks(1)); var stream1 = Generators.Range(p, 0, 10, TimeSpan.FromTicks(1)); stream0.Write("NoMeta", store, true); stream1.Write(("Favorite irrational number", Math.E), "WithMeta", store); } // read it back with a simple reader var reader = new SimpleReader(name, this.path); Assert.IsNull(reader.GetMetadata("NoMeta").SupplementalMetadataTypeName); Assert.AreEqual(typeof(ValueTuple <string, double>).AssemblyQualifiedName, reader.GetMetadata("WithMeta").SupplementalMetadataTypeName); var supplemental1 = reader.GetSupplementalMetadata <(string, double)>("WithMeta"); Assert.AreEqual("Favorite irrational number", supplemental1.Item1); Assert.AreEqual(Math.E, supplemental1.Item2); }
/* * This test can be used to make sure the GC can keep up * with the allocations in a LockFreeQueue */ //[Test] public void LFQMemTest() { /* * We dump a huge amount of data into the queue and * make sure memory doesn't blow up */ LockFreeQueue <object> queue = new LockFreeQueue <object>(); SimpleReader read = new SimpleReader(null, queue); //We should try about 2^30 so make sure we would fill nearly fill the //memory if there was a leak int runs = 1 << 30; SimpleWriter write = new SimpleWriter(runs, new object(), queue); Thread rt = new Thread(read.Run); Thread wt = new Thread(write.Run); rt.Start(); wt.Start(); wt.Join(); //Put in the stop value: queue.Enqueue(null); rt.Join(); //We added one more item (null) Assert.AreEqual(write.Writes + 1, read.Reads, "Writes equals reads"); }
public static List <T> ToListWithInvalidation <T>(this IQueryable <T> simpleQuery, Type type, string exceptionContext, Action <SqlNotificationEventArgs> invalidation) { if (!WithSqlDependency) { throw new InvalidOperationException("ToListWithInvalidation requires SqlDependency"); } ITranslateResult tr; using (ObjectName.OverrideOptions(new ObjectNameOptions { AvoidDatabaseName = true })) tr = ((DbQueryProvider)simpleQuery.Provider).GetRawTranslateResult(simpleQuery.Expression); void onChange(object sender, SqlNotificationEventArgs args) { try { if (args.Type != SqlNotificationType.Change) { throw new InvalidOperationException( "Problems with SqlDependency (Type : {0} Source : {1} Info : {2}) on query: \r\n{3}" .FormatWith(args.Type, args.Source, args.Info, tr.MainCommand.PlainSql())); } if (args.Info == SqlNotificationInfo.PreviousFire) { throw new InvalidOperationException("The same transaction that loaded the data is invalidating it!") { Data = { { "query", tr.MainCommand.PlainSql() } } } } ; if (CacheLogic.LogWriter != null) { CacheLogic.LogWriter.WriteLine("Change ToListWithInvalidations {0} {1}".FormatWith(typeof(T).TypeName()), exceptionContext); } invalidation(args); } catch (Exception e) { e.LogException(c => c.ControllerName = exceptionContext); } } SimpleReader?reader = null; Expression <Func <IProjectionRow, T> > projectorExpression = (Expression <Func <IProjectionRow, T> >)tr.GetMainProjector(); Func <IProjectionRow, T> projector = projectorExpression.Compile(); List <T> list = new List <T>(); CacheLogic.AssertSqlDependencyStarted(); Table table = Schema.Current.Table(type); DatabaseName?db = table.Name.Schema?.Database; SqlServerConnector subConnector = (SqlServerConnector)Connector.Current.ForDatabase(db); if (CacheLogic.LogWriter != null) { CacheLogic.LogWriter.WriteLine("Load ToListWithInvalidations {0} {1}".FormatWith(typeof(T).TypeName()), exceptionContext); } using (new EntityCache()) using (var r = EntityCache.NewRetriever()) { subConnector.ExecuteDataReaderDependency(tr.MainCommand, onChange, StartSqlDependencyAndEnableBrocker, fr => { if (reader == null) { reader = new SimpleReader(fr, r); } list.Add(projector(reader)); }, CommandType.Text); r.CompleteAll(); } return(list); }
public void Run() { Settings appSettings = new Settings(); //init settings (hardcoded- can be .json too) IFileManager fileManager = new FileManager(); UnitOfWork fileUnit = new UnitOfWork(fileManager); fileUnit.ReadFiles(); //read all tables from files to storage ITopView topView = new TopView(appSettings); //top menu plank view instance IKeyReader arrowsFull = new ArrowsKeyReader(); //key reader for categories and lists IKeyReader arrowsSimple = new SimpleReader(); //key reader for main top menu ITreePrinter <TopCategory> topPrinter = new TreeView <TopCategory>(appSettings); ITreePrinter <Category> treePrinter = new TreeView <Category>(appSettings); //tree category printer IItemsView listPrinter = new ItemsView(appSettings); //list items printer RecipeView recipeView = new RecipeView(fileUnit, topView); //to show selected recipe TreeNavigator <TopCategory> topNavigator = new TreeNavigator <TopCategory>(); TreeNavigator <Category> treeNavigator = new TreeNavigator <Category>(); //tree navigator ListNavigator listNavigator = new ListNavigator(arrowsFull, listPrinter); //list navigator IItemChooseView ingredientChooserView = new ItemChooseView(fileUnit); //view for choose ingredients new recipe IRecipeCreatorView recipeCreatorView = new RecipeCreatorView(fileUnit); //all recipe creator view IItemCreator itemCreator = new ItemCreator(topView, fileUnit); //ingredient creator view while (true) { topView.ShowMenu(string.Empty); ICategory mainMenuItem = topNavigator.Navigate(fileUnit.TopMenu.GetAll(), arrowsSimple, topPrinter, appSettings.AutoexpandTree); switch (mainMenuItem.Id) { case 1: //working with recipes ICategory recipeCategory = treeNavigator.Navigate(fileUnit.Categories.GetAll(), arrowsFull, treePrinter, appSettings.AutoexpandTree); RecipesSelector recipesSelector = new RecipesSelector(); //recipes selector for displaying if (recipeCategory == null) { break; } topView.ShowMenu(recipeCategory.Name); var recipesIn = recipesSelector.SelectRecipes(recipeCategory, fileUnit.Recipes.GetAll(), fileUnit.Categories.GetAll()); var recipeChosen = listNavigator.Navigate(recipesIn, out var action, false); if (recipeChosen == null && action == Action.Create) { Recipe newRecipe = new Recipe(); topView.ShowMenu($"Категория {recipeCategory.Name} > Новый рецепт . " + $"Выберите ингридиенты c помощью Space", true); var selectedIingredients = ingredientChooserView.Choose(listNavigator, itemCreator); //Get ingredients topView.ShowMenu($"Категория {recipeCategory.Name} > Новый рецепт "); recipeCreatorView.FillRecipe(newRecipe, selectedIingredients, recipeCategory); } if (recipeChosen != null && action == Action.Select) { recipeView.ShowRecipe(recipeChosen); } break; case 2: // working with ingredients Action action1; do { topView.ShowMenu(mainMenuItem.Name); var ingredientChosen = listNavigator.Navigate(fileUnit.Ingredients.GetListables(), out action1, false); if (ingredientChosen == null && action1 == Action.Create) { topView.ShowMenu(string.Empty); itemCreator.Create(); } } while (action1 != Action.Esc); break; case 3: fileUnit.Dispose(true); return; } } }