Add() public method

public Add ( Product, product ) : void
product Product,
return void
Esempio n. 1
0
    public static void Main()
    {
        var store = new Store ();

        //Handling the event
        store.ProductAdded += OnProductAdded;

        store.Add (new Product ());
    }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var store = new Store();
            store.Add<Egg>(999);
            store.Add<Bread>(999);

            var shopper = new ThisPoorGuy(12000, store);

            var wife = shopper.Wife;

            Console.WriteLine(shopper.Funds);

            wife.DemandEggs(12);

            Console.WriteLine("Store has {0} eggs, shopper has {1} eggs, shopper has {2} funds. Shopper's cart is worth {3}",
                              store.Items.Count(i => i is Egg), shopper.Cart.Items.Count(i => i is Egg),
                              shopper.Funds, shopper.Cart.Value);

            Console.ReadLine();
        }
Esempio n. 3
0
 public static Unit AddToStore(ProcessId id, IProcess process)
 {
     lock (storeLock)
     {
         var path = id.Value;
         if (Store.ContainsKey(path))
         {
             Store[path].Dispose();
             Store = Store.Remove(path);
         }
         Store = Store.Add(path, process);
     }
     return(unit);
 }
        public void Save(ILogViewerQuery entity)
        {
            var item = Get(entity.Id);

            if (item is null)
            {
                Store.Add(entity);
            }
            else
            {
                item.Name  = entity.Name;
                item.Query = entity.Query;
            }
        }
Esempio n. 5
0
        public void CanUpdateTodo()
        {
            const string expectedName = "buy chocolate";

            var store     = new Store();
            var persisted = store.Add(new Todo("buy milk"));
            var todo      = store.Get <Todo>(persisted);

            todo.Name = expectedName;
            var updatedToDo = store.Update(todo);

            store.Get <Todo>(0, 10).Should().HaveCount(1);
            store.Get <Todo>(updatedToDo).Name.Should().Be(expectedName);
        }
Esempio n. 6
0
        public static T GetById(Guid id)
        {
            var result = Store.ContainsKey(id) ? Store[id] : null;

            if (result == null)
            {
                result = m_FakeInstance.DataSelect(id);
                if (result != null)
                {
                    Store.Add(result.Id, result);
                }
            }
            return(result);
        }
Esempio n. 7
0
        public void Extract(Assembly assembly, Store rdfStore)
        {
            var types = assembly.GetExportedTypes();

            foreach (var t in types)
            {
                // store class hierarchy
                var typeEntity = GetEntity(t);
                if (t.IsInterface)
                {
                    var stType = new Statement(typeEntity, NS.Rdf.typeEntity, NS.CSO.interfaceEntity);
                    if (!rdfStore.Contains(stType))
                    {
                        rdfStore.Add(stType);
                        rdfStore.AddLabel(typeEntity, t.FullName);
                    }
                }
                else if (t.IsClass)
                {
                    var stType = new Statement(typeEntity, NS.Rdf.typeEntity, NS.CSO.classEntity);
                    if (!rdfStore.Contains(stType))
                    {
                        rdfStore.Add(stType);
                        rdfStore.AddLabel(typeEntity, t.FullName);
                    }
                }
                else
                {
                    continue;
                }
                if (t.BaseType != null)
                {
                    rdfStore.Add(new Statement(typeEntity, NS.Rdfs.subClassOfEntity, GetEntity(t.BaseType)));
                }
                // store info about interfaces
                var ifaces = t.GetInterfaces();
                foreach (var iType in ifaces)
                {
                    rdfStore.Add(new Statement(typeEntity, NS.CSO.Implements, GetEntity(iType)));
                    rdfStore.Add(new Statement(typeEntity, NS.Rdfs.subClassOfEntity, GetEntity(iType)));
                }
                // store info about properties
                var props = t.GetProperties(BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.DeclaredOnly | BindingFlags.Instance);
                foreach (var p in props)
                {
                    var propEntity = NS.DotNet.GetPropertyEntity(p.Name);
                    rdfStore.Add(new Statement(propEntity, NS.Rdf.typeEntity, NS.Rdf.PropertyEntity));
                    rdfStore.AddLabel(propEntity, p.Name);
                    rdfStore.Add(new Statement(propEntity, NS.Rdfs.domainEntity, typeEntity));
                }
            }
        }
Esempio n. 8
0
        public int Set(string key)
        {
            var ok    = Store.ContainsKey(key);
            int value = 0;

            if (!ok)
            {
                value = Count;
                Store.Add(key, value);
                Count++;
                return(value);
            }

            return(Store[key]);
        }
        public async Task <Thread> CreateChatThreadAsync(string topic, List <User> members)
        {
            if (Store.Exists(topic))
            {
                throw new Exception("Thread with topic already exists");
            }
            members.Add(UserService.ChatBotUser);
            var chatThreadMembers = members.ConvertAll(new Converter <User, ChatThreadMember>(UserToChatThreadMember));
            var chatThreadClient  = await Client.CreateChatThreadAsync(topic, chatThreadMembers);

            Thread thread = new Thread(chatThreadClient.Id, topic, members);

            Store.Add(thread);
            return(thread);
        }
Esempio n. 10
0
 public bool Add(Statement s)
 {
     s.Meta = Statement.DefaultMeta;
     if (store.Contains(s))
     {
         return(true);
     }
     if (variables.Contains(s.Subject) ||
         variables.Contains(s.Predicate) ||
         variables.Contains(s.Object))
     {
         store.Add(s);
     }
     return(true);
 }
Esempio n. 11
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     _store = new Store();
     _store.Model.Add(ComponentHelper.GetModel(new Dictionary <string, ModelFieldType>()
     {
         { "Id", ModelFieldType.Int }, { "Name", ModelFieldType.String }
     }));
     if (!Ext.Net.X.IsAjaxRequest)
     {
         DisplayField = "Name";
         ValueField   = "Id";
         SimpleSubmit = true;
     }
     Store.Add(_store);
 }
Esempio n. 12
0
 protected void imgBtnSumbit_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         //新建
         if (this.imgBtnSumbit.ImageUrl.IndexOf("imgNew1.gif") != -1)
         {
             if (txtCKID.Text.Trim().ToString().Length > 3)
             {
                 this.PrintfError("仓库编码超出了范围,只能是3位!");
                 return;
             }
             if (!CheckUI())
             {
                 this.PrintfError("仓库信息不全!");
                 return;
             }
             Store stroe = new Store(this.txtNCID.Text.Trim(), this.txtCKID.Text.Trim(), this.txtCKName.Text.Trim());
             if (stroe.Exists())
             {
                 this.PrintfError("已经存在该仓库信息!");
                 return;
             }
             stroe.Add();
             ClearUI();
             BindGridView();
         }
         else//修改
         {
             if (!CheckUI())
             {
                 this.PrintfError("仓库信息不全!");
                 return;
             }
             Store stroe = new Store(this.txtNCID.Text.Trim(), this.txtCKID.Text.Trim(), this.txtCKName.Text.Trim());
             stroe.Update();
             ClearUI();
             BindGridView();
         }
     }
     catch
     {
         this.PrintfError("数据库错误,请重试!");
         return;
     }
 }
Esempio n. 13
0
        public FleetResponse Add([FromBody] Fleet data)
        {
            FleetResponse fleet = new FleetResponse();

            try
            {
                fleet = Store.Add(data);
                return(fleet);
            }
            catch (Exception ex)
            {
                Log.LogError(ex);
                fleet.Message = Constants.Error;
                fleet.Status  = false;
                return(fleet);
            }
        }
Esempio n. 14
0
        public async Task <User> CreateUserAsync(string userId)
        {
            if (Store.Exists(userId))
            {
                throw new Exception("User ID Already exists");
            }
            var createResponse = await Client.IssueTokenAsync(await Client.CreateUserAsync(), Scope);

            if (Utils.IsFailure(createResponse))
            {
                throw new Exception("Was not able to create user");
            }
            User user = new User(userId, createResponse.Value);

            Store.Add(user);
            return(user);
        }
Esempio n. 15
0
 private void CreateChatBotUser()
 {
     if (Store.Exists(ChatBotName))
     {
         ChatBotUser = Store.Get(ChatBotName);
     }
     else
     {
         var createResponse = Client.IssueToken(Client.CreateUser(), Scope);
         if (Utils.IsFailure(createResponse))
         {
             throw new Exception("Failed to create super admin account");
         }
         ChatBotUser = new User(ChatBotName, createResponse.Value);
         Store.Add(ChatBotUser);
     }
 }
Esempio n. 16
0
        public string SetName(Account account, string name)
        {
            string result = Validation.Instance.TestName(name);

            if (result == string.Empty)
            {
                result = Store.Remove(this);
                account.ChangeCharacterName(_name, name);
                _name         = name;
                IsDirty       = true;
                _lastAccessed = DateTime.Now;
                if (result == string.Empty)
                {
                    result = Store.Add(this);
                }
            }
            return(result);
        }
Esempio n. 17
0
        /// <inheritdoc />
        public void Menu(string name, Action <IMenuBuilder> action)
        {
            IMenuBuilder menu2;

            if (!Store.TryGetValue(name, out var menu))
            {
                Store.Add(name, menu2 = new ConcreteMenuBuilder(this));
            }
            else if (menu is IMenuBuilder menu3)
            {
                menu2 = menu3;
            }
            else
            {
                throw new InvalidOperationException(
                          $"\"{name}\" is not a menu.");
            }
            action.Invoke(menu2);
        }
Esempio n. 18
0
        public TodosModule() : base("todos")
        {
            Get["/"] = _ => Response.AsJson(Store.Values);

            Post["/"] = _ =>
            {
                var newTodo = this.Bind <Todo>();
                if (newTodo.Id == 0)
                {
                    newTodo.Id = Store.Count + 1;
                }

                if (Store.ContainsKey(newTodo.Id))
                {
                    return(HttpStatusCode.NotAcceptable);
                }

                Store.Add(newTodo.Id, newTodo);
                return(Response.AsJson(newTodo).WithStatusCode(HttpStatusCode.Created));
            };

            // p.id refers to the {id} part, it is a dynamic parametercollection. could also be written as p["id"] (same as JavaScript)
            Put["/{id}"] = p =>
            {
                if (!Store.ContainsKey(p.id))
                {
                    return(HttpStatusCode.NotFound);
                }

                var updated = this.Bind <Todo>();
                Store[p.Id] = updated;
                return(Response.AsJson(updated));
            };
            Delete["/{id}"] = p =>
            {
                if (!Store.ContainsKey(p.id))
                {
                    return(HttpStatusCode.NotFound);
                }
                Store.Remove(p.Id);
                return(HttpStatusCode.OK);
            };
        }
        private void UpdateDeliveryHistory(List <SubscriptionDeliveryResult> results)
        {
            results.ForEach(incoming =>
            {
                var existing = Store.Search(incoming.SubscriptionId, results.Count);
                if (!existing.Any(exist => exist.Id.EqualsIgnoreCase(incoming.Id)))
                {
                    Store.Add(incoming.SubscriptionId, incoming);

                    if (incoming.StatusCode >= HttpStatusCode.BadRequest &&
                        incoming.StatusCode < HttpStatusCode.InternalServerError)
                    {
                        var subscription      = Store.Get(incoming.SubscriptionId);
                        subscription.IsActive = false;
                        Store.Update(incoming.SubscriptionId, subscription);
                    }
                }
            });
        }
Esempio n. 20
0
        private void Reload(IConfiguration configuration)
        {
            var allowedOrigins = configuration.Get <AllowedCorsOrigins>();

            if (allowedOrigins?.Count is not > 0)
            {
                throw new InvalidOperationException($"When using {nameof(AllowedCorsOriginsFilter)}, the application configuration file is used " +
                                                    "to read allowed cors origins. The config file is missing an 'AllowedCorsOrigins' array " +
                                                    "with at least one string item.");
            }
            foreach (var allowedOrigin in allowedOrigins)
            {
                if (string.IsNullOrWhiteSpace(allowedOrigin))
                {
                    continue;
                }
                Store.Add(new Uri(allowedOrigin));
            }
        }
Esempio n. 21
0
        public void ToStringTest()
        {
            var store = new Store <int>
            {
                1, 2, 4, 8, 16, 32, 64, 148, 256, 512, 1024, 2048, 4096
            };

            Assert.AreEqual(store.ToString(), "1;2;4;8;16;32;64;148;256;512;1024;2048;4096");

            store[1] = 0;
            Assert.AreEqual(store.ToString(), "1;0;4;8;16;32;64;148;256;512;1024;2048;4096");

            store[store.FindIndex(i => i == 64)] = 33;
            Assert.AreEqual(store.ToString(), "1;0;4;8;16;32;33;148;256;512;1024;2048;4096");

            store.Clear();
            store.Add(1);

            Assert.AreEqual(store.ToString(), "1");
        }
Esempio n. 22
0
        public void TestCollectionSizeIncrease()
        {
            Store <Product> bestBuy = new Store <Product>
            {
                new Product("PS", Product.ProductType.GameConsole),
                new Product("PSOne", Product.ProductType.GameConsole),
                new Product("PS2", Product.ProductType.GameConsole),
                new Product("PS2 Slim", Product.ProductType.GameConsole),
                new Product("PS3", Product.ProductType.GameConsole),
                new Product("PS3 Slim", Product.ProductType.GameConsole),
                new Product("PS4", Product.ProductType.GameConsole),
                new Product("PS4 Slim", Product.ProductType.GameConsole),
            };

            Assert.Equal(8, bestBuy.count);
            Assert.Equal(10, bestBuy.items.Length);
            bestBuy.Add(new Product("PS4 Pro", Product.ProductType.GameConsole));
            Assert.Equal(9, bestBuy.count);
            Assert.Equal(15, bestBuy.items.Length);
        }
Esempio n. 23
0
 public bool Add(Statement s)
 {
     if (msg.Contains(s))
     {
         return(true);
     }
     msg.Add(s);
     if (s.Subject.Uri == null)
     {
         add.Add(s.Subject);
     }
     if (s.Predicate.Uri == null)
     {
         add.Add(s.Predicate);
     }
     if (s.Object is Entity && s.Object.Uri == null)
     {
         add.Add(s.Object);
     }
     return(true);
 }
Esempio n. 24
0
        public IToken RetrieveAndStoreAccessToken(string userId, string tokenKey, string verfier, string organisationShortCode)
        {
            var existingAccessToken = Store.Find(userId);

            if (existingAccessToken != null)
            {
                if (!existingAccessToken.HasExpired)
                {
                    return(existingAccessToken);
                }
                else
                {
                    Store.Delete(existingAccessToken);
                }
            }

            var requestToken = _requestTokenStore.Find(userId);

            if (requestToken == null)
            {
                throw new ApplicationException("Failed to look up request token for user");
            }

            //Delete the request token from the _requestTokenStore as the next few lines will render it useless for the future.
            _requestTokenStore.Delete(requestToken);

            if (requestToken.TokenKey != tokenKey)
            {
                throw new ApplicationException("Request token key does not match");
            }

            var accessToken = Tokens.GetAccessToken(requestToken,
                                                    GetAuthorization(requestToken, "POST", Tokens.AccessUri, null, verfier));

            accessToken.UserId         = userId;
            accessToken.OrganisationId = organisationShortCode;
            Store.Add(accessToken);

            return(accessToken);
        }
        private void InitializeHardCodedValues()
        {
            var eventInfo = new ACSEvent
            {
                Id = "acs_ve_06_07_2021",
                ChatSessionThreadId = "19:[email protected]",
                Rooms = new Dictionary <string, ACSRoom>()
                {
                    {
                        "room1",
                        new ACSRoom
                        {
                            Id    = "room1",
                            Title = "Global All Hands",
                            ChatSessionThreadId = "19:[email protected]",
                            CallingSessionId    = "4fa24250-d478-11eb-a4fa-bb783cfd38e0"
                        }
                    },
                    {
                        "room2",
                        new ACSRoom
                        {
                            Id    = "room2",
                            Title = "Product Demos"
                        }
                    },
                    {
                        "room3",
                        new ACSRoom
                        {
                            Id    = "room3",
                            Title = "Ask Me Anything"
                        }
                    }
                }
            };

            Store.Add("acs_ve_06_07_2021", eventInfo);
        }
Esempio n. 26
0
        public void ParseAssembly(byte[] assemblyData, string fileName)
        {
            Assembly assembly = Assembly.Load(assemblyData);

            if (assembly != null)
            {
                //string name = Path.GetFileName(fileName);
                //Procedure proc = FlowEnvir.Procedures.GetByCode(name) as Procedure;
                //if (proc == null)
                //{
                //    proc = new Procedure();
                //    proc.Code = a.GetName().Name;
                //    proc.ProcedureType = ProcedureTypes.Group;
                //    proc.Name = Localize.Get(a.GetName().Name, a.GetName().Name);
                //    proc.Save();
                //}
                Type[] types = assembly.GetExportedTypes();
                foreach (Type type in types)
                {
                    if (type.GetInterface("IDockContent") != null || TypeHelper.IsInterface(type, typeof(IProjectEditor)))
                    {
                        DBProcedure procedure = Store[TypeHelper.FormatBinary(type)];
                        if (procedure == null)
                        {
                            procedure = new DBProcedure()
                            {
                                ProcedureType = ProcedureTypes.Assembly,
                                Name          = TypeHelper.FormatBinary(type),
                                DisplayName   = Locale.Get(type),
                                Group         = this,
                                DataName      = fileName
                            };
                            Store.Add(procedure);
                        }
                    }
                }
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Фильтрация продуктов по цене
        /// </summary>
        public static Store FilterByPrice()
        {
first:
            Console.WriteLine("Введи левую границу фильтра : ");
            if (!int.TryParse(Console.ReadLine(), out int left))
            {
                Console.WriteLine("Слабо набрать число?");
                goto first;// повтор ввода числа
            }
            Console.WriteLine("Введи правую границу фильтра : ");
            if (!int.TryParse(Console.ReadLine(), out int right))
            {
                Console.WriteLine("Слабо набрать число?");
                goto first;// повтор ввода числа
            }
            Store tmp = new Store();

            Console.WriteLine("Список товаров, подходящих под фильтр : ");
            bool isany = false;

            foreach (Item item in store)
            {
                if (item.GetCost(1.5f) >= left && item.GetCost(1.5f) <= right)
                {
                    Console.WriteLine(item.ToString());
                    tmp.Add(item);
                    isany = true;
                }
            }

            if (isany == false)
            {
                Console.WriteLine("Нет товаров, удовлетворяющих условию!\n"); MenuView();
            }

            return(tmp);
        }
Esempio n. 28
0
        IEnumerator GiveCards()
        {
            yield return(new WaitForSeconds(2f));

            var res = 0;

            for (int i = 0; i < niuNum.Length; i++)
            {
                niuNum[i] = App.GetGameData <Brnn3dGameData>().Nn.GetSFSObject(i).GetInt("niu");
                Result[i] = App.GetGameData <Brnn3dGameData>().Nn.GetSFSObject(i).GetBool("win");
                if (App.GetGameData <Brnn3dGameData>().Nn.GetSFSObject(i).GetBool("win"))
                {
                    res |= (1 << i);
                    //res = res |(1 << i);
                }
            }
            Store.Add(res);
            if (Replace == JiSuan)
            {
                Replace++;
            }
            JiSuan++;
            ThePaiModeMgr.SetPaiModeDataEx(); //设置发牌的数据
        }
Esempio n. 29
0
 protected override async Task Handle(Command request, CancellationToken cancellationToken)
 {
     store.Add(new Tweet {
         Contents = request.Contents
     });
 }
 //TODO: What do we do with the ContosoUserConfigModel?
 //This maps threadId > moderatorUid
 private void InitializeHardCodedValues()
 {
     Store.Add("19:[email protected]", "8:acs:85c99b9e-f6e1-408c-90d9-e37b6ad0e7c3_0000000b-17b9-7405-54b7-a43a0d0017fa");
     Store.Add("19:[email protected]", "8:acs:85c99b9e-f6e1-408c-90d9-e37b6ad0e7c3_0000000b-17b5-ce49-80f5-8b3a0d00e461");
 }
Esempio n. 31
0
 public bool AddHook(IUnityHook hook)
 {
     return(hooks.Add(hook));
 }
Esempio n. 32
0
 /// <summary>
 /// Adds a new list of items to the collection.
 /// </summary>
 /// <param name="item">The item to add.</param>
 public void Add(KeyValuePair <string, string[]> item)
 {
     Store.Add(item);
 }