Exemplo n.º 1
0
 public GrainStateStorageBridge(string grainTypeName, Grain grain, IStorageProvider store)
 {
     if (grainTypeName == null)
     {
         throw new ArgumentNullException("grainTypeName", "No grain type name supplied");
     }
     if (store == null)
     {
         throw new ArgumentNullException("store", "No storage provider supplied");
     }
     if (grain == null || grain.GrainState == null)
     {
         throw new ArgumentNullException("grain.GrainState", "No grain state object supplied");
     }
     this.grainTypeName = grainTypeName;
     this.grain = grain;
     this.store = store;
 }
Exemplo n.º 2
0
        public static List <Color> NeighbourColors(Grain g)
        {
            List <Color> colorlist = new List <Color>();
            int          i         = g.X;
            int          j         = g.Y;

            for (int k = i - 1; k < i + 2; k++)
            {
                for (int l = j - 1; l < j + 2; l++)
                {
                    if (k >= 0 && k < MainWindow.XNumOfCells && l >= 0 && l < MainWindow.YNumOfCells)
                    {
                        if (MainWindow.GrainTable[k, l].Color != g.Color)
                        {
                            if (!colorlist.Contains(MainWindow.GrainTable[k, l].Color))
                            {
                                colorlist.Add(MainWindow.GrainTable[k, l].Color);
                            }
                        }
                    }
                }
            }
            return(colorlist);
        }
Exemplo n.º 3
0
 public IDisposable RegisterTimer(Grain grain, Func<object, Task> asyncCallback, object state, TimeSpan dueTime, TimeSpan period)
 {
     return grain.Data.RegisterTimer(asyncCallback, state, dueTime, period);
 }
Exemplo n.º 4
0
 internal ActivationService(Grain grain)
 {
     this.grain = grain;
 }
Exemplo n.º 5
0
 public void DelayDeactivation(Grain grain, TimeSpan timeSpan)
 {
     grain.Data.DelayDeactivation(timeSpan);
 }
Exemplo n.º 6
0
        public ActivationData(
            ActivationAddress addr,
            string genericArguments,
            PlacementStrategy placedUsing,
            IActivationCollector collector,
            TimeSpan ageLimit,
            IOptions <SiloMessagingOptions> messagingOptions,
            TimeSpan maxWarningRequestProcessingTime,
            TimeSpan maxRequestProcessingTime,
            IRuntimeClient runtimeClient,
            ILoggerFactory loggerFactory)
        {
            if (null == addr)
            {
                throw new ArgumentNullException(nameof(addr));
            }
            if (null == placedUsing)
            {
                throw new ArgumentNullException(nameof(placedUsing));
            }
            if (null == collector)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            logger         = loggerFactory.CreateLogger <ActivationData>();
            this.lifecycle = new GrainLifecycle(loggerFactory.CreateLogger <LifecycleSubject>());
            this.maxRequestProcessingTime        = maxRequestProcessingTime;
            this.maxWarningRequestProcessingTime = maxWarningRequestProcessingTime;
            this.messagingOptions = messagingOptions.Value;
            ResetKeepAliveRequest();
            Address     = addr;
            State       = ActivationState.Create;
            PlacedUsing = placedUsing;
            if (!Grain.IsSystemTarget())
            {
                this.collector = collector;
            }

            CollectionAgeLimit = ageLimit;

            GrainReference = GrainReference.FromGrainId(addr.Grain, runtimeClient.GrainReferenceRuntime, genericArguments, Grain.IsSystemTarget() ? addr.Silo : null);
        }
Exemplo n.º 7
0
 public void DeactivateOnIdle(Grain grain)
 {
     this.runtimeClient.DeactivateOnIdle(grain.Data.ActivationId);
 }
Exemplo n.º 8
0
 internal ReminderService(Grain grain)
 {
     registry = grain.Runtime().ReminderRegistry;
 }
Exemplo n.º 9
0
        public async ValueTask <IFollowSnapshotStorage <PrimaryKey> > CreateFollowSnapshotStorage <PrimaryKey>(Grain grain, PrimaryKey grainId)
        {
            var grainType = grain.GetType();

            if (configureContainer.TryGetValue(grainType, out var value) &&
                value is ConfigureBuilderWrapper <PrimaryKey, StorageConfig, ConfigParameter> builder)
            {
                var dictKey    = builder.Parameter.Singleton ? grainType.FullName : $"{grainType.FullName}-{grainId.ToString()}";
                var configTask = grainConfigDict.GetOrAdd(dictKey, async key =>
                {
                    var newConfig = builder.Generator(grain, grainId, builder.Parameter);
                    var task      = newConfig.Build();
                    if (!task.IsCompletedSuccessfully)
                    {
                        await task;
                    }
                    return(newConfig);
                });
                if (!configTask.IsCompletedSuccessfully)
                {
                    await configTask;
                }
                var storage = FollowSnapshotStorageDict.GetOrAdd(dictKey, key =>
                {
                    return(new FollowSnapshotStorage <PrimaryKey>(configTask.Result));
                });
                return(storage as FollowSnapshotStorage <PrimaryKey>);
            }
            else
            {
                throw new NotImplementedException($"{nameof(ConfigureBuilderWrapper<PrimaryKey, StorageConfig, ConfigParameter>)} of {grainType.FullName}");
            }
        }
Exemplo n.º 10
0
 public static IGrainRuntime Runtime(this Grain grain) => grain.Runtime;
Exemplo n.º 11
0
        public async Task MigrateDuplicateGroups_HasDuplicateIdentifiers_SuccessAsync()
        {
            var container            = _fixture.Bootstrapper.TinyIoCContainer;
            var dbContext            = container.Resolve <IAuthorizationDbContext>();
            var groupMigratorService = container.Resolve <GroupMigratorService>();

            #region Data Setup

            var client = new Client
            {
                ClientId = $"client1-{Guid.NewGuid()}",
                Name     = $"Client 1-{Guid.NewGuid()}"
            };

            var grain = new Grain
            {
                Name = $"dos-{Guid.NewGuid()}"
            };

            var securableItem = new SecurableItem
            {
                Name        = $"datamarts-{Guid.NewGuid()}",
                Grain       = grain,
                ClientOwner = client.ClientId
            };

            client.TopLevelSecurableItem = securableItem;

            var customGroup1 = new Group
            {
                GroupId            = Guid.NewGuid(),
                Name               = $"Custom Group 1-{Guid.NewGuid()}",
                Source             = GroupConstants.CustomSource,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var customGroup2 = new Group
            {
                GroupId            = Guid.NewGuid(),
                Name               = $"Custom Group 2-{Guid.NewGuid()}",
                Source             = GroupConstants.CustomSource,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var groupGuid = Guid.NewGuid();
            var group1    = new Group
            {
                GroupId            = Guid.NewGuid(),
                Name               = $"Group 1-{groupGuid}",
                IdentityProvider   = IdentityConstants.ActiveDirectory,
                TenantId           = "12345",
                Source             = GroupConstants.DirectorySource,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var group2 = new Group
            {
                GroupId            = Guid.NewGuid(),
                Name               = $"groUP 1-{groupGuid}",
                IdentityProvider   = IdentityConstants.ActiveDirectory,
                TenantId           = "12345",
                Source             = GroupConstants.DirectorySource,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var group3 = new Group
            {
                GroupId            = Guid.NewGuid(),
                Name               = $"groUP 1-{groupGuid}",
                IdentityProvider   = IdentityConstants.AzureActiveDirectory,
                TenantId           = "12345",
                Source             = GroupConstants.DirectorySource,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var role1 = new Role
            {
                RoleId        = Guid.NewGuid(),
                Name          = "Role 1",
                Grain         = grain.Name,
                SecurableItem = securableItem
            };

            var role2 = new Role
            {
                RoleId        = Guid.NewGuid(),
                Name          = "Role 2",
                Grain         = grain.Name,
                SecurableItem = securableItem,
            };

            var role3 = new Role
            {
                RoleId        = Guid.NewGuid(),
                Name          = "Role 3",
                Grain         = grain.Name,
                SecurableItem = securableItem,
            };

            var role4 = new Role
            {
                RoleId        = Guid.NewGuid(),
                Name          = "Role 4",
                Grain         = grain.Name,
                SecurableItem = securableItem,
            };

            var group1Role1 = new GroupRole
            {
                Group = group1,
                Role  = role1
            };

            var group2Role1 = new GroupRole
            {
                Group = group2,
                Role  = role1
            };

            var group2Role2 = new GroupRole
            {
                Group = group2,
                Role  = role2
            };

            var group2Role3 = new GroupRole
            {
                Group     = group2,
                Role      = role3,
                IsDeleted = true
            };

            var group3Role4 = new GroupRole
            {
                Group = group3,
                Role  = role4
            };

            var user1 = new User
            {
                IdentityProvider = IdentityConstants.ActiveDirectory,
                SubjectId        = Guid.NewGuid().ToString()
            };

            var customGroup1User1 = new GroupUser
            {
                Group = customGroup1,
                User  = user1
            };

            var customGroup2User1 = new GroupUser
            {
                Group = customGroup2,
                User  = user1
            };

            var childGroup1 = new ChildGroup
            {
                ChildGroupId       = group1.GroupId,
                ParentGroupId      = customGroup1.GroupId,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var childGroup2 = new ChildGroup
            {
                ChildGroupId       = group2.GroupId,
                ParentGroupId      = customGroup1.GroupId,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            var childGroup3 = new ChildGroup
            {
                ChildGroupId       = group2.GroupId,
                ParentGroupId      = customGroup2.GroupId,
                CreatedBy          = "test",
                CreatedDateTimeUtc = DateTime.UtcNow
            };

            dbContext.Clients.Add(client);
            dbContext.Grains.Add(grain);
            dbContext.SecurableItems.Add(securableItem);

            dbContext.Roles.AddRange(new List <Role>
            {
                role1,
                role2,
                role3,
                role4
            });

            dbContext.Groups.AddRange(new List <Group>
            {
                customGroup1,
                customGroup2,
                group1,
                group2,
                group3
            });

            dbContext.GroupRoles.AddRange(new List <GroupRole>
            {
                group1Role1,
                group2Role1,
                group2Role2,
                group2Role3,
                group3Role4
            });

            dbContext.Users.Add(user1);

            dbContext.GroupUsers.AddRange(new List <GroupUser>
            {
                customGroup1User1,
                customGroup2User1
            });

            dbContext.ChildGroups.AddRange(new List <ChildGroup>
            {
                childGroup1,
                childGroup2,
                childGroup3
            });

            dbContext.SaveChanges();

            #endregion

            var results = await groupMigratorService.MigrateDuplicateGroups();

            Assert.Equal(1, results.GroupMigrationRecords.Count);
            Assert.Empty(results.GroupMigrationRecords.SelectMany(r => r.Errors));

            var principal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
            {
                new Claim(Claims.Scope, Scopes.ManageClientsScope),
                new Claim(Claims.Scope, Scopes.ReadScope),
                new Claim(Claims.Scope, Scopes.WriteScope),
                new Claim(Claims.ClientId, client.ClientId),
                new Claim(Claims.IdentityProvider, "idP1")
            }, "rolesprincipal"));

            var browser = _fixture.GetBrowser(principal, _storageProvider);

            var getResponse = await browser.Get(HttpUtility.UrlEncode($"/groups/Group 1-{groupGuid}"), with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.Query("identityProvider", IdentityConstants.ActiveDirectory);
                with.Query("tenantId", "12345");
            });

            var groupRoleApiModel = getResponse.Body.DeserializeJson <GroupRoleApiModel>();
            var roles             = groupRoleApiModel.Roles.ToList();
            Assert.Equal(2, roles.Count);
            Assert.Contains(roles, r => r.Name == role1.Name);
            Assert.Contains(roles, r => r.Name == role2.Name);

            var parents = groupRoleApiModel.Parents.ToList();
            Assert.Contains(parents, p => p.GroupName == customGroup1.Name);
            Assert.Contains(parents, p => p.GroupName == customGroup2.Name);

            var groupStore = container.Resolve <IGroupStore>();
            await groupStore.Delete(customGroup1.ToModel());

            await groupStore.Delete(customGroup2.ToModel());

            await groupStore.Delete(group1.ToModel());

            await groupStore.Delete(group2.ToModel());

            await groupStore.Delete(group3.ToModel());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("Name,Calories")] Ingredient ingredient, [Bind("Carbohydrate")] Grain grain)
        {
            if (ModelState.IsValid)
            {
                _context.Ingredient.Add(ingredient);
                grain.Id = ingredient.Id;
                _context.Add(grain);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Id"] = new SelectList(_context.Ingredient, "Id", "Id", grain.Id);
            return(View(grain));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Edit(int id, [Bind("Name,Calories")] Ingredient ingredient, [Bind("Id,Carbohydrate")] Grain grain)
        {
            if (id != grain.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ingredient.Id = id;
                    _context.Ingredient.Update(ingredient);
                    _context.Update(grain);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GrainExists(grain.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Id"] = new SelectList(_context.Ingredient, "Id", "Id", grain.Id);
            return(View(grain));
        }
Exemplo n.º 14
0
 public static Placement GetPlacement(this Grain grain)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public void DeactivateOnIdle(Grain grain)
 {
     RuntimeClient.Current.DeactivateOnIdle(grain.Data.ActivationId);
 }
Exemplo n.º 16
0
 public bool Matches(ActivationAddress other)
 {
     return(Grain.Equals(other.Grain) && (Activation?.Equals(other.Activation) ?? other.Activation is null));
 }
Exemplo n.º 17
0
 public override int GetHashCode()
 {
     return((Silo != null ? Silo.GetHashCode() : 0) ^
            (Grain != null ? Grain.GetHashCode() : 0) ^
            (Activation != null ? Activation.GetHashCode() : 0));
 }
Exemplo n.º 18
0
        public async ValueTask <IArchiveStorage <PrimaryKey, State> > CreateArchiveStorage <PrimaryKey, State>(Grain grain, PrimaryKey grainId)
            where State : class, new()
        {
            var grainType = grain.GetType();

            if (configureContainer.TryGetValue(grainType, out var value) &&
                value is ConfigureBuilderWrapper <PrimaryKey, StorageConfig, ConfigParameter> builder)
            {
                var dictKey    = builder.Parameter.Singleton ? grainType.FullName : $"{grainType.FullName}-{grainId.ToString()}";
                var configTask = grainConfigDict.GetOrAdd(dictKey, async key =>
                {
                    var newConfig = builder.Generator(grain, grainId, builder.Parameter);
                    var task      = newConfig.Build();
                    if (!task.IsCompletedSuccessfully)
                    {
                        await task;
                    }
                    return(newConfig);
                });
                if (!configTask.IsCompletedSuccessfully)
                {
                    await configTask;
                }
                var storage = ArchiveStorageDict.GetOrAdd(dictKey, key =>
                {
                    return(new ArchiveStorage <PrimaryKey, State>(serviceProvider.GetService <ISerializer>(), configTask.Result));
                });
                return(storage as IArchiveStorage <PrimaryKey, State>);
            }
            else
            {
                throw new NotImplementedException($"{nameof(ConfigureBuilderWrapper<PrimaryKey, StorageConfig, ConfigParameter>)} of {grainType.FullName}");
            }
        }
Exemplo n.º 19
0
        public void InitializeData()
        {
            if (Repository <Age> .Get().Count() == 0)
            {
                var list = new List <Age>();
                var root = new Age()
                {
                    Name = "中国历史学年代"
                };
                var ndbx = new Age()
                {
                    Name = "年代不详"
                };
                list.Add(root);
                list.Add(ndbx);
                list.Add(new Age()
                {
                    Name = "夏(约前2070~前1600)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "商(前1600~前1046)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "秦(前221~前206)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "西晋(265~317)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "隋(581~618)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "唐(618~907)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "辽(907~1125)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "西夏(1038~1227)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "金(1115~1234)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "元(1206~1368)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "明(1368~1644)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "清(1616~1911)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "中华民国(1912~1949)", Parent = root
                });
                list.Add(new Age()
                {
                    Name = "中华人民共和国(1949年10月1日成立)", Parent = root
                });

                var zhou = new Age()
                {
                    Name = "周", Parent = root
                };
                list.Add(zhou);
                list.Add(new Age()
                {
                    Name = "西周(前1046~前771)", Parent = zhou
                });
                list.Add(new Age()
                {
                    Name = "东周(前770~前256)", Parent = zhou
                });
                list.Add(new Age()
                {
                    Name = "春秋时代(前770~前476)", Parent = zhou
                });
                list.Add(new Age()
                {
                    Name = "战国时代(前475~前221)", Parent = zhou
                });

                var han = new Age()
                {
                    Name = "汉", Parent = root
                };
                list.Add(han);
                list.Add(new Age()
                {
                    Name = "西汉(前206~公元25)", Parent = han
                });
                list.Add(new Age()
                {
                    Name = "东汉(25~220)", Parent = han
                });

                var sanguo = new Age()
                {
                    Name = "三国", Parent = root
                };
                list.Add(sanguo);
                list.Add(new Age()
                {
                    Name = "三国·魏(220~265)", Parent = sanguo
                });
                list.Add(new Age()
                {
                    Name = "三国·蜀(221~263)", Parent = sanguo
                });
                list.Add(new Age()
                {
                    Name = "三国·吴(222~280)", Parent = sanguo
                });

                var djslg = new Age()
                {
                    Name = "东晋十六国", Parent = root
                };
                list.Add(djslg);
                list.Add(new Age()
                {
                    Name = "东晋(317~420)", Parent = djslg
                });
                list.Add(new Age()
                {
                    Name = "十六国(304~439)", Parent = djslg
                });

                var nbc = new Age()
                {
                    Name = "南北朝", Parent = root
                };
                list.Add(nbc);
                var nc = new Age()
                {
                    Name = "南朝", Parent = nbc
                };
                list.Add(nc);
                var bc = new Age()
                {
                    Name = "北朝", Parent = nbc
                };
                list.Add(bc);
                list.Add(new Age()
                {
                    Name = "南朝·宋(420~479)", Parent = nc
                });
                list.Add(new Age()
                {
                    Name = "南朝·齐(479~502)", Parent = nc
                });
                list.Add(new Age()
                {
                    Name = "南朝·梁(502~557)", Parent = nc
                });
                list.Add(new Age()
                {
                    Name = "南朝·陈(557~589)", Parent = nc
                });
                list.Add(new Age()
                {
                    Name = "北魏(386~534)", Parent = bc
                });
                list.Add(new Age()
                {
                    Name = "东魏(534~550)", Parent = bc
                });
                list.Add(new Age()
                {
                    Name = "北齐(550~577)", Parent = bc
                });
                list.Add(new Age()
                {
                    Name = "北周(557~581)", Parent = bc
                });

                var wdsg = new Age()
                {
                    Name = "五代十国", Parent = root
                };
                list.Add(wdsg);
                list.Add(new Age()
                {
                    Name = "五代·后梁(907~923)", Parent = wdsg
                });
                list.Add(new Age()
                {
                    Name = "五代·后唐(923~936)", Parent = wdsg
                });
                list.Add(new Age()
                {
                    Name = "五代·后晋(936~947)", Parent = wdsg
                });
                list.Add(new Age()
                {
                    Name = "五代·后汉(947~950)", Parent = wdsg
                });
                list.Add(new Age()
                {
                    Name = "五代•后周(951~960)", Parent = wdsg
                });
                list.Add(new Age()
                {
                    Name = "十国(902~979)", Parent = wdsg
                });

                var song = new Age()
                {
                    Name = "宋", Parent = root
                };
                list.Add(song);
                list.Add(new Age()
                {
                    Name = "北宋(960~1127)", Parent = wdsg
                });
                list.Add(new Age()
                {
                    Name = "南宋(1127~1279)", Parent = wdsg
                });
                list.ForEach(x => Repository <Age> .Add(x));
                foreach (var age in Repository <Age> .Get())
                {
                    if (age.Parent != null)
                    {
                        if (age.Parent.Children == null)
                        {
                            age.Parent.Children = new HashSet <Age>();
                        }
                        age.Parent.Children.Add(age);
                    }
                }
            }

            if (Repository <Author> .Get().Count() == 0)
            {
                Repository <Author> .Add(new Author()
                {
                    Name = "朱屺瞻"
                });
            }
            if (Repository <Category> .Get().Count() == 0)
            {
                new List <Category>()
                {
                    new Category()
                    {
                        Name = "玉石器、宝石"
                    },
                    new Category()
                    {
                        Name = "陶器"
                    },
                    new Category()
                    {
                        Name = "瓷器"
                    },
                    new Category()
                    {
                        Name = "铜器"
                    },
                    new Category()
                    {
                        Name = "金银器"
                    },
                    new Category()
                    {
                        Name = "铁器、其他金属器"
                    },
                    new Category()
                    {
                        Name = "漆器"
                    },
                    new Category()
                    {
                        Name = "雕塑、造像"
                    },
                    new Category()
                    {
                        Name = "石器、石刻、砖瓦"
                    },
                    new Category()
                    {
                        Name = "书法、绘画"
                    },
                    new Category()
                    {
                        Name = "文具"
                    },
                    new Category()
                    {
                        Name = "甲骨"
                    },
                    new Category()
                    {
                        Name = "玺印符牌"
                    },
                    new Category()
                    {
                        Name = "钱币"
                    },
                    new Category()
                    {
                        Name = "牙骨角器"
                    },
                    new Category()
                    {
                        Name = "竹木雕"
                    },
                    new Category()
                    {
                        Name = "家具"
                    },
                    new Category()
                    {
                        Name = "珐琅器"
                    },
                    new Category()
                    {
                        Name = "织绣"
                    },
                    new Category()
                    {
                        Name = "古籍图书"
                    },
                    new Category()
                    {
                        Name = "碑帖拓本"
                    },
                    new Category()
                    {
                        Name = "武器"
                    },
                    new Category()
                    {
                        Name = "邮品"
                    },
                    new Category()
                    {
                        Name = "文件、宣传品"
                    },
                    new Category()
                    {
                        Name = "档案文书"
                    },
                    new Category()
                    {
                        Name = "名人遗物"
                    },
                    new Category()
                    {
                        Name = "玻璃器"
                    },
                    new Category()
                    {
                        Name = "乐器、法器"
                    },
                    new Category()
                    {
                        Name = "皮革"
                    },
                    new Category()
                    {
                        Name = "音像制品"
                    },
                    new Category()
                    {
                        Name = "票据"
                    },
                    new Category()
                    {
                        Name = "交通、运输工具"
                    },
                    new Category()
                    {
                        Name = "度量衡器"
                    },
                    new Category()
                    {
                        Name = "标本、化石"
                    },
                    new Category()
                    {
                        Name = "其他"
                    }
                }.ForEach(p => Repository <Category> .Add(p));
            }
            if (Repository <CollectedTimeRange> .Get().Count() == 0)
            {
                new List <CollectedTimeRange>()
                {
                    new CollectedTimeRange()
                    {
                        Name = "1949.10.1前"
                    },
                    new CollectedTimeRange()
                    {
                        Name = "1949.10.1-1965"
                    },
                    new CollectedTimeRange()
                    {
                        Name = "1966-1976"
                    },
                    new CollectedTimeRange()
                    {
                        Name = "1977-2000"
                    },
                    new CollectedTimeRange()
                    {
                        Name = "2001至今"
                    }
                }.ForEach(p => Repository <CollectedTimeRange> .Add(p));
            }
            if (Repository <DisabilityLevel> .Get().Count() == 0)
            {
                new List <DisabilityLevel>()
                {
                    new DisabilityLevel()
                    {
                        Name = "完整"
                    },
                    new DisabilityLevel()
                    {
                        Name = "基本完整"
                    },
                    new DisabilityLevel()
                    {
                        Name = "残缺"
                    },
                    new DisabilityLevel()
                    {
                        Name = "严重残缺(含缺失部件)"
                    }
                }.ForEach(p => Repository <DisabilityLevel> .Add(p));
            }
            if (Repository <Grain> .Get().Count() == 0)
            {
                var list = new List <Grain>();
                var dyzd = new Grain()
                {
                    Name = "单一质地"
                };
                list.Add(dyzd);
                var yjz = new Grain()
                {
                    Name = "有机质", Parent = dyzd
                };
                list.Add(yjz);
                list.Add(new Grain()
                {
                    Name = "木", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "竹", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "纸", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "毛", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "丝", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "皮革", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "骨角牙", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "棉麻纤维", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "其他植物质", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "其他动物质", Parent = yjz
                });
                list.Add(new Grain()
                {
                    Name = "其他有机质", Parent = yjz
                });

                var wjz = new Grain()
                {
                    Name = "无机质", Parent = dyzd
                };
                list.Add(wjz);
                list.Add(new Grain()
                {
                    Name = "石", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "瓷", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "砖瓦", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "泥", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "陶", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "玻璃", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "铁", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "铜", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "宝玉石", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "金", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "银", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "其他金属", Parent = wjz
                });
                list.Add(new Grain()
                {
                    Name = "其他无机质", Parent = wjz
                });
                var fh = new Grain()
                {
                    Name = "复合或组合质地"
                };
                list.Add(fh);
                list.Add(new Grain()
                {
                    Name = "有机复合或组合", Parent = fh
                });
                list.Add(new Grain()
                {
                    Name = "无机复合或组合", Parent = fh
                });
                list.Add(new Grain()
                {
                    Name = "有机无机复合或组合", Parent = fh
                });
                list.ForEach(x => Repository <Grain> .Add(x));
                foreach (var grain in Repository <Grain> .Get())
                {
                    if (grain.Parent != null)
                    {
                        if (grain.Parent.Children == null)
                        {
                            grain.Parent.Children = new HashSet <Grain>();
                        }
                        grain.Parent.Children.Add(grain);
                    }
                }
            }
            if (Repository <Level> .Get().Count() == 0)
            {
                new List <Level>()
                {
                    new Level()
                    {
                        Name = "一级"
                    },
                    new Level()
                    {
                        Name = "二级"
                    },
                    new Level()
                    {
                        Name = "三级"
                    },
                    new Level()
                    {
                        Name = "一般"
                    },
                    new Level()
                    {
                        Name = "未定级"
                    }
                }.ForEach(p => Repository <Level> .Add(p));
            }
            if (Repository <Location> .Get().Count() == 0)
            {
                new List <Location>()
                {
                    new Location()
                    {
                        Name = "研究所"
                    },
                    new Location()
                    {
                        Name = "所内书籍储藏室"
                    },
                    new Location()
                    {
                        Name = "所内文物储藏室"
                    },
                    new Location()
                    {
                        Name = "琉璃河"
                    },
                    new Location()
                    {
                        Name = "琉璃河仓库"
                    }
                }.ForEach(x => Repository <Location> .Add(x));
            }
            if (Repository <RelicIdType> .Get().Count() == 0)
            {
                new List <RelicIdType>()
                {
                    new RelicIdType()
                    {
                        Name = "藏品总登记号"
                    },
                    new RelicIdType()
                    {
                        Name = "辅助账号"
                    },
                    new RelicIdType()
                    {
                        Name = "索书号"
                    },
                    new RelicIdType()
                    {
                        Name = "档案编号"
                    },
                    new RelicIdType()
                    {
                        Name = "固定资产登记号"
                    },
                    new RelicIdType()
                    {
                        Name = "财产登记号"
                    },
                    new RelicIdType()
                    {
                        Name = "出土(水)登记号"
                    },
                    new RelicIdType()
                    {
                        Name = "其他编号"
                    }
                }.ForEach(p => Repository <RelicIdType> .Add(p));
            }
            if (Repository <Source> .Get().Count() == 0)
            {
                new List <Source>()
                {
                    new Source()
                    {
                        Name = "征集购买"
                    },
                    new Source()
                    {
                        Name = "接受捐赠"
                    },
                    new Source()
                    {
                        Name = "依法交换"
                    },
                    new Source()
                    {
                        Name = "拨交"
                    },
                    new Source()
                    {
                        Name = "移交"
                    },
                    new Source()
                    {
                        Name = "旧藏"
                    },
                    new Source()
                    {
                        Name = "发掘"
                    },
                    new Source()
                    {
                        Name = "采集"
                    },
                    new Source()
                    {
                        Name = "拣选"
                    },
                    new Source()
                    {
                        Name = "其他"
                    }
                }.ForEach(p => Repository <Source> .Add(p));
            }
            if (Repository <StoringCondition> .Get().Count() == 0)
            {
                new List <StoringCondition>()
                {
                    new StoringCondition()
                    {
                        Name = "状态稳定,不需修复"
                    },
                    new StoringCondition()
                    {
                        Name = "部分损腐,需要修复"
                    },
                    new StoringCondition()
                    {
                        Name = "腐蚀损毁严重,急需修复"
                    },
                    new StoringCondition()
                    {
                        Name = "已修复"
                    }
                }.ForEach(p => Repository <StoringCondition> .Add(p));
            }
            if (Repository <Unit> .Get().Count() == 0)
            {
                new List <Unit>()
                {
                    new Unit()
                    {
                        Name = "cm", Type = UnitTypes.Length
                    },
                    new Unit()
                    {
                        Name = "m", Type = UnitTypes.Length
                    },
                    new Unit()
                    {
                        Name = "g", Type = UnitTypes.Weight
                    },
                    new Unit()
                    {
                        Name = "kg", Type = UnitTypes.Weight
                    },
                    new Unit()
                    {
                        Name = "件", Type = UnitTypes.Relic
                    },
                    new Unit()
                    {
                        Name = "本", Type = UnitTypes.Relic
                    },
                    new Unit()
                    {
                        Name = "枚", Type = UnitTypes.Relic
                    },
                }.ForEach(x => Repository <Unit> .Add(x));
            }
            if (Repository <WeightRange> .Get().Count() == 0)
            {
                new List <WeightRange>()
                {
                    new WeightRange()
                    {
                        Name = "<0.01 kg"
                    },
                    new WeightRange()
                    {
                        Name = "0.01-1 kg"
                    },
                    new WeightRange()
                    {
                        Name = "1-50 kg"
                    },
                    new WeightRange()
                    {
                        Name = "50-100 kg"
                    },
                    new WeightRange()
                    {
                        Name = "100-1000 kg"
                    },
                    new WeightRange()
                    {
                        Name = ">1000 kg"
                    }
                }.ForEach(p => Repository <WeightRange> .Add(p));
            }
            if (Repository <Storage> .Get().Count() == 0)
            {
                var list  = new List <Storage>();
                var sjccs = new Storage()
                {
                    Name = "所内书籍储藏室", Location = Repository <Location> .Get().Single(x => x.Name == "研究所")
                };
                list.Add(sjccs);
                list.Add(new Storage()
                {
                    Name     = "储物架1",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内书籍储藏室"),
                    Parent   = sjccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架2",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内书籍储藏室"),
                    Parent   = sjccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架3",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内书籍储藏室"),
                    Parent   = sjccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架4",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内书籍储藏室"),
                    Parent   = sjccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架5",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内书籍储藏室"),
                    Parent   = sjccs
                });

                var wwccs = new Storage()
                {
                    Name = "所内文物储藏室", Location = Repository <Location> .Get().Single(x => x.Name == "研究所")
                };
                list.Add(wwccs);
                list.Add(new Storage()
                {
                    Name     = "储物架1",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内文物储藏室"),
                    Parent   = wwccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架2",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内文物储藏室"),
                    Parent   = wwccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架3",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内文物储藏室"),
                    Parent   = wwccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架4",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内文物储藏室"),
                    Parent   = wwccs
                });
                list.Add(new Storage()
                {
                    Name     = "储物架5",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "所内文物储藏室"),
                    Parent   = wwccs
                });

                var llhck = new Storage()
                {
                    Name = "琉璃河仓库", Location = Repository <Location> .Get().Single(x => x.Name == "研究所")
                };
                list.Add(llhck);
                list.Add(new Storage()
                {
                    Name     = "储物架1",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "琉璃河仓库"),
                    Parent   = llhck
                });
                list.Add(new Storage()
                {
                    Name     = "储物架2",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "琉璃河仓库"),
                    Parent   = llhck
                });
                list.Add(new Storage()
                {
                    Name     = "储物架3",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "琉璃河仓库"),
                    Parent   = llhck
                });
                list.Add(new Storage()
                {
                    Name     = "储物架4",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "琉璃河仓库"),
                    Parent   = llhck
                });
                list.Add(new Storage()
                {
                    Name     = "储物架5",
                    Location = Repository <Location> .Get().FirstOrDefault(x => x.Name == "琉璃河仓库"),
                    Parent   = llhck
                });
                list.ForEach(x => Repository <Storage> .Add(x));
            }
            if (Repository <ReceiptType> .Get().Count() == 0)
            {
                new List <ReceiptType>()
                {
                    new ReceiptType()
                    {
                        Type = ReceiptTypes.NewReceipt,
                        Name = "新增入库"
                    },
                    new ReceiptType()
                    {
                        Type = ReceiptTypes.Return,
                        Name = "提借归还"
                    },
                    new ReceiptType()
                    {
                        Type = ReceiptTypes.BorrowFromOuterUnit,
                        Name = "借用外馆"
                    }
                }.ForEach(x => Repository <ReceiptType> .Add(x));
            }
            if (Repository <DeliveryType> .Get().Count() == 0)
            {
                new List <DeliveryType>()
                {
                    new DeliveryType()
                    {
                        Type = DeliveryTypes.Borrow,
                        Name = "藏品提借"
                    },
                    new DeliveryType()
                    {
                        Type = DeliveryTypes.ReturnToOutUnit,
                        Name = "归还外馆"
                    },
                    new DeliveryType()
                    {
                        Type = DeliveryTypes.Unregister,
                        Name = "藏品注销"
                    }
                }.ForEach(x => Repository <DeliveryType> .Add(x));
            }
            if (Repository <Department> .Get().Count() == 0)
            {
                new List <Department>()
                {
                    new Department()
                    {
                        Name = "综合科"
                    },
                    new Department()
                    {
                        Name = "宣传科"
                    },
                    new Department()
                    {
                        Name = "后勤科"
                    },
                    new Department()
                    {
                        Name = "仓库管理科"
                    },
                    new Department()
                    {
                        Name = "古籍研究室"
                    }
                }.ForEach(x => Repository <Department> .Add(x));
            }
            if (Repository <User> .Get().Count() == 0)
            {
                new List <User>()
                {
                    new User()
                    {
                        Name       = "admin",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "综合科")
                    },
                    new User()
                    {
                        Name       = "张某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "综合科")
                    },
                    new User()
                    {
                        Name       = "李某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "宣传科")
                    },
                    new User()
                    {
                        Name       = "刘某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "宣传科")
                    },
                    new User()
                    {
                        Name       = "赵某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "后勤科")
                    },
                    new User()
                    {
                        Name       = "徐某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "后勤科")
                    },
                    new User()
                    {
                        Name       = "钟某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "仓库管理科")
                    },
                    new User()
                    {
                        Name       = "杨某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "仓库管理科")
                    },
                    new User()
                    {
                        Name       = "王某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "古籍研究室")
                    },
                    new User()
                    {
                        Name       = "董某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "古籍研究室")
                    },
                    new User()
                    {
                        Name       = "夏某",
                        Password   = "******",
                        Department = Repository <Department> .Get().First(x => x.Name == "古籍研究室")
                    }
                }.ForEach(x => Repository <User> .Add(x));
            }

            //if (Repository<Relic>.Get().Count() == 0)
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        Repository<Relic>.Add(new Relic()
            //        {
            //            RootAge = Repository<Age>.Get().First(),
            //            Category = Repository<Category>.Get().First(),
            //            CollectedTimeRange = Repository<CollectedTimeRange>.Get().First(),
            //            DisabilityLevel = Repository<DisabilityLevel>.Get().First(),
            //            RootGrain = Repository<Grain>.Get().First(),
            //            Level = Repository<Level>.Get().First(),
            //            IdType = Repository<RelicIdType>.Get().First(),
            //            Source = Repository<Source>.Get().First(),
            //            StoringCondition = Repository<StoringCondition>.Get().First(),
            //            WeightRange = Repository<WeightRange>.Get().First(),
            //            Unit = Repository<Unit>.Get().First(x => x.Name == "件"),
            //            TotalAmount = 100,
            //            Name = "测试文物 -- " + i.ToString(),
            //            OriginalName = "测试文物",
            //            RelicId = (i + 1000).ToString(),
            //            CollectedYearOfTime = "2001"
            //        });
            //    }
            //}
        }
Exemplo n.º 20
0
        /// <summary>
        /// Generates the streamset paths.
        /// </summary>
        /// <param name="streamPath">The stream path.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="startSerialNum">The start serial number.</param>
        /// <param name="endSerialNum">The end serial number.</param>
        /// <param name="grain">The grain.</param>
        /// <returns>List&lt;string&gt;.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// startDate
        /// or
        /// endDate
        /// or
        /// startSerialNum or endSerialNum is null
        /// </exception>
        public static List <string> GenerateStreamsetPaths(string streamPath, DateTime?startDate, DateTime?endDate, int?startSerialNum, int?endSerialNum, Grain grain)
        {
            if (startDate == null)
            {
                throw new ArgumentNullException(nameof(startDate));
            }

            if (endDate == null)
            {
                throw new ArgumentNullException(nameof(endDate));
            }

            bool requireSerial = streamPath.Contains("%n");

            if (requireSerial && (startSerialNum == null || endSerialNum == null))
            {
                throw new ArgumentNullException("startSerialNum or endSerialNum is null");
            }

            var streams = new List <string>();
            var dates   = GenerateDates((DateTime)startDate, (DateTime)endDate, grain);

            foreach (var date in dates)
            {
                var year   = date.Year.ToString();
                var month  = date.Month.ToString("00");
                var day    = date.Day.ToString("00");
                var hour   = date.Hour;
                var stream = CreateStreamPath(streamPath, year, month, day, hour);
                if (requireSerial)
                {
                    for (int currentNum = (int)startSerialNum; currentNum <= (int)endSerialNum; currentNum++)
                    {
                        var path = stream.Replace("%n", currentNum.ToString());
                        streams.Add(path);
                    }
                }
                else
                {
                    streams.Add(stream);
                }
            }

            return(streams);
        }
Exemplo n.º 21
0
        internal void SetGrainInstance(Grain grainInstance)
        {
            GrainInstance = grainInstance;
            if (grainInstance != null)
            {
                GrainInstanceType = grainInstance.GetType();

                // Don't ever collect system grains or reminder table grain or memory store grains.
                bool doNotCollect = typeof(IReminderTableGrain).IsAssignableFrom(GrainInstanceType) || typeof(IMemoryStorageGrain).IsAssignableFrom(GrainInstanceType);
                if (doNotCollect)
                {
                    this.collector = null;
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Generates the dates.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="grain">The grain.</param>
        /// <returns>List&lt;DateTime&gt;.</returns>
        private static List <DateTime> GenerateDates(DateTime startDate, DateTime endDate, Grain grain)
        {
            var currentDate = startDate;
            var dates       = new List <DateTime>();

            while (currentDate <= endDate)
            {
                dates.Add(currentDate);
                currentDate = DateUtils.GetNextDate(currentDate, grain);
            }

            return(dates);
        }
Exemplo n.º 23
0
 public void DelayDeactivation(Grain grain, TimeSpan timeSpan)
 {
     grain.Data.DelayDeactivation(timeSpan);
 }
Exemplo n.º 24
0
 public void DeactivateOnIdle(Grain grain)
 {
     RuntimeClient.Current.DeactivateOnIdle(grain.Data.ActivationId);
 }
Exemplo n.º 25
0
 public void DeactivateOnIdle(Grain grain)
 {
     this.runtimeClient.DeactivateOnIdle(grain.Data.ActivationId);
 }
Exemplo n.º 26
0
 public void DeactivateOnIdle(Grain grain)
 {
     CheckRuntimeContext();
     this.runtimeClient.DeactivateOnIdle(grain.Data.ActivationId);
 }
Exemplo n.º 27
0
 internal TimerService(Grain grain)
 {
     this.grain    = grain;
     this.registry = grain.Runtime().TimerRegistry;
 }
Exemplo n.º 28
0
 public void DelayDeactivation(Grain grain, TimeSpan timeSpan)
 {
     CheckRuntimeContext();
     grain.Data.DelayDeactivation(timeSpan);
 }
Exemplo n.º 29
0
 internal void SetGrainInstance(Grain grainInstance)
 {
     GrainInstance = grainInstance;
 }
Exemplo n.º 30
0
 public IStorage <TGrainState> GetStorage <TGrainState>(Grain grain) =>
 _storageManager.GetStorage <TGrainState>(grain.GetType().FullName);
Exemplo n.º 31
0
 public override int GetHashCode() => Grain.GetHashCode() ^ (Activation?.GetHashCode() ?? 0) ^ (Silo?.GetHashCode() ?? 0);
 public TState State <TState>(Grain grain) where TState : class =>
 _grainStateManager.GetState <TState>(grain);
Exemplo n.º 33
0
 /// <summary>
 /// Deactivate the given <see cref="Grain"/>
 /// </summary>
 /// <param name="grain">Grain to Deactivate</param>
 public Task DeactivateAsync(Grain grain)
 {
     return(_grainLifecycle.TriggerStopAsync());
 }
 /// <summary>
 /// Deactivate the given <see cref="Grain"/>
 /// </summary>
 /// <param name="grain">Grain to Deactivate</param>
 public void Deactivate(Grain grain)
 {
     grain.OnDeactivateAsync().Wait(1000);
 }
Exemplo n.º 35
0
    public void SetNewCellSizeAndDraw(PictureBox pictureBox, Graphics g, Simulation simulation)
    {
        int maxSizeX = pictureBox.Width / CELL_SIZE + 1;
        int maxSizeY = pictureBox.Height / CELL_SIZE + 1;

        g.FillRectangle(cellBrushClear, 0, 0, maxSizeX * CELL_SIZE + 1, maxSizeY * CELL_SIZE + 1);

        Grain[,] tabTmp = new Grain[SIZE_Y, SIZE_X];

        for (int i = 0; i < SIZE_Y; i++)
        {
            for (int j = 0; j < SIZE_X; j++)
            {
                tabTmp[i, j] = simulation.Tab[i, j].Copy();
            }
        }

        int startSizeX = SIZE_X;
        int startSizeY = SIZE_Y;


        // setting new sizes

        SET_SIZES(pictureBox.Width / CELL_SIZE, pictureBox.Height / CELL_SIZE);

        // --------


        simulation.Tab = new Grain[SIZE_Y, SIZE_X];

        for (int i = 0; i < SIZE_Y; i++)
        {
            for (int j = 0; j < SIZE_X; j++)
            {
                simulation.Tab[i, j] = new Grain(j, i, 0);
            }
        }

        int y = SIZE_Y < startSizeY ? SIZE_Y : startSizeY;
        int x = SIZE_X < startSizeX ? SIZE_X : startSizeX;

        for (int i = 0; i < y; i++)
        {
            for (int j = 0; j < x; j++)
            {
                simulation.Tab[i, j].State = tabTmp[i, j].State;
            }
        }


        // resizing previous grains

        simulation.Resize();

        if (GRID_STATE == GridState.Enable)
        {
            Draw(g, pictureBox);
        }

        simulation.Display(g);
    }
Exemplo n.º 36
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            PointerEventData pointerData = new PointerEventData(EventSystem.current);

            pointerData.position = Input.mousePosition;

            List <RaycastResult> results = new List <RaycastResult>();
            EventSystem.current.RaycastAll(pointerData, results);

            if (results.Count > 0)
            {
                if (results[0].gameObject.layer == LayerMask.NameToLayer("RetryUI"))
                {
                    ResetGame();
                }
            }

            if (inControl)
            {
                if (results.Count > 0)
                {
                    if (results[0].gameObject.layer == LayerMask.NameToLayer("CarrotUI"))
                    {
                        selectedPlot.PlacePlant(plants[1], Team.PLAYER);

                        seedCount       -= plantCost;
                        seedCountUI.text = "" + seedCount;

                        if (!gameStarted)
                        {
                            opponent.Activate();
                            HideTutorialUI();
                            gameStarted = true;
                        }
                    }
                    else if (results[0].gameObject.layer == LayerMask.NameToLayer("BeetUI"))
                    {
                        selectedPlot.PlacePlant(plants[0], Team.PLAYER);
                        seedCount       -= plantCost;
                        seedCountUI.text = "" + seedCount;

                        if (!gameStarted)
                        {
                            opponent.Activate();
                            HideTutorialUI();
                            gameStarted = true;
                        }
                    }
                    else if (results[0].gameObject.layer == LayerMask.NameToLayer("OptionsUI"))
                    {
                        results[0].gameObject.GetComponentInParent <OptionsUI>().TogglePullDown();
                    }
                    else if (results[0].gameObject.layer == LayerMask.NameToLayer("AudioButton"))
                    {
                        results[0].gameObject.GetComponentInParent <OptionsUI>().ToggleAudio();
                    }
                    else if (results[0].gameObject.layer == LayerMask.NameToLayer("CamShakeButton"))
                    {
                        results[0].gameObject.GetComponentInParent <OptionsUI>().ToggleCamShake();
                    }
                    else if (results[0].gameObject.layer == LayerMask.NameToLayer("QuitButton"))
                    {
                        Application.Quit();
                    }
                    else if (results[0].gameObject.layer == LayerMask.NameToLayer("GrainPickup"))
                    {
                        Grain g = results[0].gameObject.GetComponentInParent <Grain>();

                        ChangeSeedCount(g.GrainValue);

                        g.Interact();
                    }
                }
                else
                {
                    if (seedCount >= plantCost)
                    {
                        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                        RaycastHit hit;

                        if (Physics.Raycast(ray, out hit))
                        {
                            Plot plot = hit.transform.GetComponent <Plot>();

                            if (plot != null)
                            {
                                if (selectedPlot == null)
                                {
                                    selectedPlot = plot;
                                    selectedPlot.ShowPopup();
                                }
                                else
                                {
                                    selectedPlot.HidePopup();

                                    if (selectedPlot != plot)
                                    {
                                        selectedPlot = plot;
                                        selectedPlot.ShowPopup();
                                    }
                                    else
                                    {
                                        selectedPlot = null;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }