public void IndexedCollection_AddDuplicate() { var collection = new IndexedCollection <int, TestObject>(t => t.Sequence); collection.Add(_objects[0]); collection.Add(_objects[0]); }
public void IndexedCollection_Add() { var collection = new IndexedCollection <int, TestObject>(t => t.Sequence); collection.Add(_objects[0]); collection.Add(_objects[1]); Assert.AreEqual(2, collection.Count); Assert.AreEqual("Test0", collection[0].Name); Assert.AreEqual("Test1", collection[1].Name); }
public void IndexedCollection_Clear() { var collection = new IndexedCollection <int, TestObject>(t => t.Sequence); collection.Add(_objects[0]); collection.Add(_objects[1]); Assert.AreEqual(2, collection.Count); collection.Clear(); Assert.AreEqual(0, collection.Count); }
public void AddTest() { Collection.Add("Name"); Assert.AreEqual(Collection.Length, 1); Collection.Add("Name"); Assert.AreEqual(Collection.Length, 1); }
private async Task Accept() { ListenerFactory listenerFactory = new ListenerFactory(); listenerFactory.Uri = new Uri(webSockets ? "http://localhost:5001/" : "tcp://127.0.0.1:7000"); Listener listener = listenerFactory.Create(); for (int i = 0; i < Connections; i++) { DataPacket dataPacket = dataPackets[1][i]; Transporter transporter = await listener.Execute(cancellationTokenSource.Token); tasks.Add(transporter, Receive(transporter, dataPacket)); } }
public Provider GetOrCreateAccumulator(FramingPlan plan, Getter getter, ProjectionElement parent, ProjectionElement child, ParameterNames parameters) { var alreadyCreated = _cache.FirstOrDefault(k => k.Child == child && k.Parent == parent && k.Parameters == parameters); if (alreadyCreated != null) { return(alreadyCreated.Provider); } var storage = new GroupStorage(FrameNode.InPlanComparer); plan.AddTempStorage(storage); var pusher = CreatePusher(storage); var checker = CreateChecker(storage); var taker = CreateGetter(storage); var packTaker = CreatePackagerGetter(getter, parameters); var acc = new Provider(pusher, checker, taker, packTaker, FrameNode.InPlanComparer); var node = new FactoryNode { Parent = parent, Child = child, Parameters = parameters, Provider = acc }; _cache.Add(node); return(acc); }
public void IndexedCollection_Contains() { var collection = new IndexedCollection <int, TestObject>(t => t.Sequence); collection.Add(_objects[0]); Assert.AreEqual(true, collection.Contains(_objects[0])); Assert.AreEqual(false, collection.Contains(_objects[1])); }
public void Send <TMessage>(Expression <Func <TSaga, bool> > filter, ISagaPolicy <TSaga, TMessage> policy, TMessage message, Action <TSaga> consumerAction) where TMessage : class { IEnumerable <TSaga> existingSagas = _collection.Where(filter).ToList(); if (SendMessageToExistingSagas(existingSagas, policy, consumerAction, message, RemoveSaga)) { return; } SendMessageToNewSaga(policy, message, saga => { lock (_collection) _collection.Add(saga); consumerAction(saga); }, RemoveSaga); }
public IndexedCollection Stack(int SlotID) { if (!zCol.ContainsKey(SlotID)) { zCol.Add(SlotID, new IndexedCollection()); } return((IndexedCollection)zCol.Item(SlotID)); }
protected Publisher <Publishable> CreatePublisher <Publishable>(IndirectAggregate <Publishable> indirectAggregate) where Publishable : Deserializable <byte> { DeserializablePublisher <Publishable> deserializablePublisher = new DeserializablePublisher <Publishable>(indirectAggregate, deserializables); indirectAggregate.Remove(out Publishable publishable); index.Add(publishable.Identity, deserializablePublisher); indirectAggregate.Add(publishable); return(deserializablePublisher); }
/// <summary> /// Добавляет записи о регистрации типа-ресурса. /// </summary> /// <param name="registration">Регистрация</param> /// <exception cref="System.InvalidOperationException">Тип регистрируется два раза: + registration.ResourceType</exception> private void AddRegistrations(Registration registration) { try { _registrations.Add(registration); _subscriptor.AddResourceName(registration.ResourceName); } catch (ArgumentException) { throw new InvalidOperationException("Тип регистрируется два раза:" + registration.ResourceType); } }
internal VirtualServer Add(string Host, string Username = "", string Password = "", int Port = 119, int MaxConnections = 1, bool SSL = false, ServerPriority Priority = ServerPriority.Default) { VirtualServer SrvInfo = new VirtualServer(Connections, Host, Username, Password, Port, MaxConnections, SSL, Priority); if (!zServers.Add(SrvInfo)) { return(null); } for (int iC = 0; iC < SrvInfo.Allowed; iC++) { Connections.Add(SrvInfo.ID); } return(SrvInfo); }
private void button1_Click(object sender, EventArgs e) { // create data source var contacts = new IndexedCollection <Contact>(); // bind list to grid (before adding elements) this.dataGridView1.DataSource = from c in contacts.AsLive() where c.Name.Contains("g") select c; // add elements to collection (after binding) foreach (string s in names.Split(',')) { contacts.Add(new Contact() { Name = s }); } }
//internal bool Remove(string ServerSID = "") //{ // if (ServerSID.Length == 0) { return Remove(-1); } // return Remove(zServers.GetID(ServerSID)); //} internal IndexedCollection Stack(int ServerID, int SlotID) { if (!SlotExist(SlotID)) { return(null); } if (Servers.Item(ServerID) == null) { return(null); } if (!zStacks.ContainsKey(ServerID)) { zStacks.Add(ServerID, new VirtualStack()); } VirtualStack zItem = (VirtualStack)zStacks.Item(ServerID); return(zItem.Stack(SlotID)); }
public void Should_use_indices_to_improve_query_performance() { IndexedCollection<IndexedClass> collection = new IndexedCollection<IndexedClass>(); collection.Add(new IndexedClass {Name = "Chris"}); collection.Add(new IndexedClass {Name = "David"}); collection.Add(new IndexedClass {Name = "Jason"}); collection.Add(new IndexedClass {Name = "Matt"}); collection.Add(new IndexedClass {Name = "Terry"}); collection.Add(new IndexedClass {Name = "Zach"}); var result = collection.Where(x => x.Name == "Matt").First(); Assert.AreEqual("Matt", result.Name); }
public async Task ShopAdd(List _, int price, [Remainder] string name) { var entry = new ShopEntry() { Name = name.TrimTo(100), Price = price, Type = ShopEntryType.List, AuthorId = Context.User.Id, Items = new HashSet <ShopEntryItem>(), }; using (var uow = DbHandler.UnitOfWork()) { var entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries); entries.Add(entry); uow.GuildConfigs.For(Context.Guild.Id, set => set).ShopEntries = entries; uow.Complete(); } await Context.Channel.EmbedAsync(EntryToEmbed(entry) .WithTitle(GetText("shop_item_add"))); }
public Form1() { InitializeComponent(); XDocument doc; using (var xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LiveLinqToObjects.Northwind.xml")) { System.Diagnostics.Debug.Assert(xmlStream != null); XmlReaderSettings settings = new XmlReaderSettings { IgnoreWhitespace = true }; XmlReader reader = XmlReader.Create(xmlStream, settings); doc = XDocument.Load(reader); } foreach (XElement c in doc.Descendants("Customers")) { customers.Add(new Customer { CustomerID = (string)c.Element("CustomerID"), City = (string)c.Element("City"), DateRegistered = (DateTime)c.Element("DateRegistered") }); } foreach (XElement o in doc.Descendants("Orders")) { orders.Add(new Order { OrderID = (int)o.Attribute("OrderID"), CustomerID = (string)o.Attribute("CustomerID"), ShipCity = (string)o.Attribute("ShipCity"), Freight = (decimal)o.Attribute("Freight"), OrderDate = (DateTime)o.Attribute("OrderDate"), }); } }
public async Task ShopAdd(Role _, int price, [Remainder] IRole role) { var entry = new ShopEntry() { Name = "-", Price = price, Type = ShopEntryType.Role, AuthorId = Context.User.Id, RoleId = role.Id, RoleName = role.Name }; using (var uow = DbHandler.UnitOfWork()) { var entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries); entries.Add(entry); uow.GuildConfigs.For(Context.Guild.Id, set => set).ShopEntries = entries; uow.Complete(); } await Context.Channel.EmbedAsync(EntryToEmbed(entry) .WithTitle(GetText("shop_item_add"))); }
public IssueTracker() { var doc = new XDocument(); using (var xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LiveLinqIssueTrackerObjects.Data.IssueTracking.xml")) { Debug.Assert(xmlStream != null); XmlReaderSettings settings = new XmlReaderSettings { IgnoreWhitespace = true }; XmlReader reader = XmlReader.Create(xmlStream, settings); XElement data = XElement.Load(reader); doc.ReplaceNodes(data); } foreach (var x in doc.AsLive().Root().Elements("Employees")) { Employees.Add(new EmployeeItem { EmployeeID = (int)x.Element("EmployeeID"), FullName = (string)x.Element("FullName") }); } foreach (var x in doc.AsLive().Root().Elements("Features")) { Features.Add(new FeatureItem { ProductID = (int)x.Element("ProductID"), FeatureID = (int)x.Element("FeatureID"), FeatureName = (string)x.Element("FeatureName") }); } foreach (var x in doc.AsLive().Root().Elements("Products")) { Products.Add(new ProductItem { ProductID = (int)x.Element("ProductID"), ProductName = (string)x.Element("ProductName"), }); } foreach (var x in doc.AsLive().Root().Elements("Issues")) { Issues.Add(new IssueItem { IssueID = (int)x.Element("IssueID"), ProductID = (int)x.Element("ProductID"), FeatureID = (int)x.Element("FeatureID"), Description = (string)x.Element("Description"), AssignedTo = (int)x.Element("AssignedTo"), Fixed = (bool)x.Element("Fixed") }); } foreach (var x in doc.AsLive().Root().Elements("Assignments")) { Assignments.Add(new AssignmentItem { EmployeeID = (int)x.Element("EmployeeID"), ProductID = (int)x.Element("ProductID"), FeatureID = (int)x.Element("FeatureID"), }); } _issuesById = Issues.Indexes.Add(i => i.IssueID, true); _assignmentsByEmployeeId = Assignments.Indexes.Add(a => a.EmployeeID); }
public Form1() { InitializeComponent(); using (var xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LiveViewsObjects.Northwind.xml")) { System.Diagnostics.Debug.Assert(xmlStream != null); XmlReaderSettings settings = new XmlReaderSettings { IgnoreWhitespace = true }; XmlReader reader = XmlReader.Create(xmlStream, settings); // Filling the collections with base data XDocument doc = XDocument.Load(reader); foreach (XElement c in doc.Descendants("Customers")) { customers.Add(new Customer { CustomerID = (string)c.Element("CustomerID"), City = (string)c.Element("City"), DateRegistered = (DateTime)c.Element("DateRegistered") }); } foreach (XElement o in doc.Descendants("Orders")) { orders.Add(new Order { OrderID = (int)o.Attribute("OrderID"), CustomerID = (string)o.Attribute("CustomerID"), ShipCity = (string)o.Attribute("ShipCity"), }); } } // Creating indexes. It is optional, only for performance optimization. // If you delete this, the functionality will be the same and slowdown will be noticeable only on large data sets. customers.Indexes.Add(c => c.CustomerID, true); orders.Indexes.Add(o => o.CustomerID); orders.Indexes.Add(o => o.ShipCity); //...end of creating indexes // Make the base data collection live: View <Customer> customersView = customers.AsLive(); View <Order> ordersView = orders.AsLive().AsUpdatable(); // AsUpdatable() makes it possible for // the user to change data directly in the grid showing the join view below. // Order fields can be changed by the user there, Customer fields can't be changed by the user // Specifying this argument is needed only if you need to change data directly in the view instead // of changing the base data, and then only for query operators with more than one argument such as Join. // Creating a live view over the base data IListSource view = from o in ordersView where o.ShipCity == "London" || o.ShipCity == "Colchester" select o; ShowViewInGrid(view, dataGridView1); // Creating another live view over the base data customerOrderView = from c in customersView join o in ordersView on c.CustomerID equals o.CustomerID where o.ShipCity == "London" || o.ShipCity == "Colchester" // Using a user-defined class like CustomerOrder is not mandatory. Anonymous class could be used instead as in the // query above, but in that case we could not assign it to a variable like customerOrderView, defined outside // of the scope of this method, because anonymous classes are only available in local scope. select new CustomerOrder { CustomerID = c.CustomerID, City = c.City, OrderID = o.OrderID, ShipCity = o.ShipCity }; ShowViewInGrid(customerOrderView, dataGridView2); // See the readme.txt file in the project folder for a description of the live view functionality you can try in this sample }