예제 #1
0
 public void GetHit()
 {
     Shards.ExplodeAt(t.position, Color.white, 10, 20);
     Shards.ExplodeAt(t.position, Color.red, 10, 20);
     Shards.ExplodeAt(t.position, new Color(0.231f, 0.38f, 0.235f), 80, 10);
     Shards.ExplodeAt(t.position, new Color(0.988f, 0.933f, 0.914f), 50, 8);
     Shards.ExplodeAt(t.position, new Color(0.831f, 0.831f, 0.831f), 30, 7);
     t.position         = new Vector3(0f, 11f);
     rigidBody.velocity = Vector2.zero;
     anim.SetTrigger("Freefall");
     EverythingMoves.MoveSpeed = GameData.DefaultSpeed;
     Ghost.EagleCombo          = 0;
     Ghost.OtterCombo          = 0;
     OtterC.StopCombo();
     EagleC.StopCombo();
     AudioManager.PlaySFX(SFX.Die);
     CameraFixer.Screenshake();
     GameData.PlayerDied = true;
     hits++;
     if (hits == 2)
     {
         Pause.Die();
         gameObject.SetActive(false);
     }
 }
예제 #2
0
        public void DistributedService_RouterServer_SendToAllShards_ExcludingMany_PacketsReceived()
        {
            var routerShardSvc = Router.ShardController.Context.Services.Get <TestDistributedService>();
            var routerUserSvc  = Router.UserController.Context.Services.Get <TestDistributedService>();
            var user           = Users.First();
            var shard          = Shards.First();
            var usvc           = user.Context.Services.Get <TestDistributedService>();
            var ssvc           = shard.Context.Services.Get <TestDistributedService>();
            var pck            = new TestPacket();

            int recv = 0;

            foreach (var sh in Shards)
            {
                sh.Context.Services.Get <TestDistributedService>().ShardChannel.Receive += (s, e) => {
                    recv++;
                };
            }

            Router.UpdateServer();
            foreach (var sh in Shards)
            {
                sh.UpdateClient();
            }
            foreach (var us in Users)
            {
                us.UpdateClient();
            }

            usvc.ShardChannel.Send(pck, Shards.Select(i => i.Model).Skip(3));
            Assert.AreEqual(recv, Shards.Count - 3);
        }
예제 #3
0
		static void Main()
		{
			var shards = new Shards
			             	{
			             		new DocumentStore {Url = "http://localhost:8080", Identifier = "Posts"},
			             		new DocumentStore
			             			{
			             				Url = "http://localhost:8081",
			             				Identifier = "Users",
			             				Conventions = {DocumentKeyGenerator = user => "users/" + ((User) user).Name}
			             			}
			             	};

			var shardStrategy = new ShardStrategy
			{
				ShardAccessStrategy = new ParallelShardAccessStrategy(),
				ShardSelectionStrategy = new BlogShardSelectionStrategy(),
				ShardResolutionStrategy = new BlogShardResolutionStrategy()
			};

			using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
			{
				var posts = shards[0].DatabaseCommands.StartsWith("post", 0, 50);
				foreach (var post in posts) shards[0].DatabaseCommands.Delete(post.Key, post.Etag);

				var users = shards[1].DatabaseCommands.StartsWith("user", 0, 50);
				foreach (var user in users) shards[1].DatabaseCommands.Delete(user.Key, user.Etag);
			}
		}
예제 #4
0
    void Start()
    {
        EverythingMoves.MoveSpeed = GameData.DefaultSpeed;
        Score.PlayerScore         = 0;
        Player           = this;
        OtterC           = ComboText.ComboTexts["Otter"];
        EagleC           = ComboText.ComboTexts["Eagle"];
        Ghost.OtterCombo = 0;
        Ghost.EagleCombo = 0;
        rigidBody        = GetComponent <Rigidbody2D>();
        anim             = GetComponent <Animator>();
        t         = GetComponent <Transform>();
        animIndex = anim.GetLayerIndex("Base Layer");

        if (Shards.shards != null)
        {
            Shards.shards.Clear();
        }
        Shards.Generate(200);
        if (AudioManager.manager != null)
        {
            AudioManager.PlayMusic();
        }
        GameData.Paused = true;
        hits            = 0;
        inLevel3        = SceneManager.GetActiveScene().name == "Stage 3";
    }
예제 #5
0
 public ShardsValues Add(short shardId, string parameterName, object parameterValue)
 {
     if (Shards.TryGetValue(shardId, out var prms))
     {
         if (prms is null)
         {
             Shards[shardId] = new Dictionary <string, object>()
             {
                 { parameterName, parameterValue }
             };
         }
         else
         {
             prms.Add(parameterName, parameterValue);
         }
     }
     else
     {
         Shards.Add(shardId, new Dictionary <string, object>()
         {
             { parameterName, parameterValue }
         });
     }
     return(this);
 }
예제 #6
0
        static void Main()
        {
            var shards = new Shards
            {
                CreateShard("Asia", "http://localhost:8080"),
                CreateShard("Middle-East", "http://localhost:8081"),
            };

            using (var documentStore = new ShardedDocumentStore(new ShardStrategy(), shards).Initialize())
                using (var session = documentStore.OpenSession())
                {
                    //store 2 items in the 2 shards
                    session.Store(new Company {
                        Name = "Company 1", Region = "Asia"
                    });
                    session.Store(new Company {
                        Name = "Company 2", Region = "Middle East"
                    });
                    session.SaveChanges();

                    //get all, should automagically retrieve from each shard
                    var allCompanies = session.Advanced.LuceneQuery <Company>()
                                       .WaitForNonStaleResults().ToArray();

                    foreach (var company in allCompanies)
                    {
                        Console.WriteLine(company.Name);
                    }
                }
        }
예제 #7
0
        private ShardManager()
        {
            Shards.Add(new ShardEntry
            {
                Name = "UOGamers: Demise", Address = "login.uodemise.com", Port = 2593, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "UOGamers: Hybrid", Address = "login.uohybrid.com", Port = 2593, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "Heritage UO", Address = "play.trueuo.com", Port = 2593, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "UO Forever", Address = "login.uoforever.com", Port = 2599, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name              = "UO Outlands",
                Address           = "play.uooutlands.com",
                Port              = 2593,
                IsPreset          = true,
                HasStatusProtocol = false
            });
        }
예제 #8
0
        private ShardManager()
        {
            Shards.Add(new ShardEntry
            {
                Name              = "Official EA Servers",
                Address           = "login.ultimaonline.com",
                Port              = 7775,
                IsPreset          = true,
                HasStatusProtocol = false,
                Encryption        = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "UOGamers: Demise", Address = "login.uodemise.com", Port = 2593, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "UOGamers: Hybrid", Address = "login.uohybrid.com", Port = 2593, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "Heritage UO", Address = "play.trueuo.com", Port = 2593, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name = "UO Forever", Address = "login.uoforever.com", Port = 2599, IsPreset = true
            });

            Shards.Add(new ShardEntry
            {
                Name              = "UO Outlands",
                Address           = "play.uooutlands.com",
                Port              = 2593,
                IsPreset          = true,
                HasStatusProtocol = false,
                ShardType         = 2
            });

            Shards.Add(new ShardEntry
            {
                Name              = "UO Players",
                Address           = "login.uoplayers.com",
                Port              = 2593,
                IsPreset          = true,
                HasStatusProtocol = true
            });

            Shards.Add(new ShardEntry
            {
                Name              = "UO:Renaissance",
                Address           = "login.uorenaissance.com",
                Port              = 2593,
                IsPreset          = true,
                HasStatusProtocol = true
            });
        }
		public When_Using_Sharded_Servers()
		{
			server = "localhost";

			port1 = 8079;
			port2 = 8081;

			path1 = GetPath("TestShardedDb1");
			path2 = GetPath("TestShardedDb2");

			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);

			company1 = new Company { Name = "Company1" };
			company2 = new Company { Name = "Company2" };

			server1 = GetNewServer(port1, path1);
			server2 = GetNewServer(port2, path2);

			shards = new Shards { 
				new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1}, 
				new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2} 
			};

			shardSelection = MockRepository.GenerateStub<IShardSelectionStrategy>();
			shardSelection.Stub(x => x.ShardIdForNewObject(company1)).Return("Shard1");
			shardSelection.Stub(x => x.ShardIdForNewObject(company2)).Return("Shard2");

			shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();

			shardStrategy = MockRepository.GenerateStub<IShardStrategy>();
			shardStrategy.Stub(x => x.ShardSelectionStrategy).Return(shardSelection);
			shardStrategy.Stub(x => x.ShardResolutionStrategy).Return(shardResolution);
		}
예제 #10
0
        internal async Task <int> InitializeShardsAsync()
        {
            if (Shards.Count != 0)
            {
                return(Shards.Count);
            }

            var shardc = Config.ShardCount == 1 ? await GetShardCountAsync().ConfigureAwait(false) : Config.ShardCount;

            for (var i = 0; i < shardc; i++)
            {
                var cfg = new DiscordConfiguration(Config)
                {
                    ShardId               = i,
                    ShardCount            = shardc,
                    UseInternalLogHandler = false
                };

                var client = new DiscordClient(cfg);
                if (!Shards.TryAdd(i, client))
                {
                    throw new Exception("Could not initialize shards.");
                }
            }

            return(shardc);
        }
예제 #11
0
        public void Cleanup()
        {
            if (Router.IsActive)
            {
                Router.Shutdown();
            }
            foreach (var shard in Shards)
            {
                if (shard.IsConnected)
                {
                    shard.StopClient();
                }
            }
            foreach (var user in Users)
            {
                if (user.IsConnected)
                {
                    user.StopClient();
                }
            }

            Router.Dispose();
            foreach (var shard in Shards)
            {
                shard.Dispose();
            }
            foreach (var user in Users)
            {
                user.Dispose();
            }

            Shards.Clear();
            Users.Clear();
        }
예제 #12
0
 public ShardsValues Add(short shardId)
 {
     if (!Shards.ContainsKey(shardId))
     {
         Shards.Add(shardId, new Dictionary <string, object>());
     }
     return(this);
 }
예제 #13
0
        static void Main(string[] args)
        {
            var shard1 = new DocumentStore
            {
                Identifier = "Shard1",
                Url        = "http://localhost:8080"
            }.Initialize();

            var shard2 = new DocumentStore
            {
                Identifier = "Shard2",
                Url        = "http://localhost:8081"
            }.Initialize();

            var shards = new Shards
            {
                shard1,
                shard2
            };
            var shardStrategy = new ShardStrategy
            {
                ShardAccessStrategy     = new SequentialShardAccessStrategy(),
                ShardResolutionStrategy = new MyShardsResolutionStrategy(shards),
                ShardSelectionStrategy  = new MyShardSelectionStrategy(shards)
            };

            var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize();


            for (int i = 0; i < 3; i++)
            {
                using (var s = documentStore.OpenSession())
                {
                    var user = new User
                    {
                        Name = "Ayende"
                    };
                    s.Store(user);
                    s.Store(new ReadingList
                    {
                        UserId = user.Id,
                        Books  = new List <ReadingList.ReadBook>()
                    });
                    s.SaveChanges();
                }
            }
            using (var session = documentStore.OpenSession())
            {
                var load = session.Load <User>("users/Shard2/33");
            }

            using (var session = documentStore.OpenSession())
            {
                var load = session.Advanced.LuceneQuery <ReadingList>().ToList();
            }
        }
예제 #14
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ShardedDocumentStore"/> class.
		/// </summary>
		/// <param name="shardStrategy">The shard strategy.</param>
		/// <param name="shards">The shards.</param>
		public ShardedDocumentStore(IShardStrategy shardStrategy, Shards shards)
		{
			if (shards == null || shards.Count == 0) 
				throw new ArgumentException("Must have one or more shards", "shards");
			if (shardStrategy == null)
				throw new ArgumentException("Must have shard strategy", "shardStrategy");

			this.shardStrategy = shardStrategy;
			this.shards = shards;
		}
        public static List <Shards> Generate(int count)
        {
            List <Shards> shards = new List <Shards>();

            for (int i = 0; i < count; i++)
            {
                Shards shard = Generate();
                shards.Add(shard);
            }
            return(shards);
        }
예제 #16
0
        public object Clone()
        {
            var tConfiguration = new DeploymentConfiguration
            {
                Shards = Shards != null?Shards.Clone() : null,
                             DeploymentList = DeploymentList != null?DeploymentList.Clone() : null,
                                                  DeploymentName = DeploymentName != null?DeploymentName.Clone() : null
            };

            return(tConfiguration);
        }
        public static Shards Generate()
        {
            Shards shards = new Shards
            {
                Failed     = RandomNumberGenerator.GetRandomInt(),
                Skipped    = RandomNumberGenerator.GetRandomInt(),
                Successful = RandomNumberGenerator.GetRandomInt(),
                Total      = RandomNumberGenerator.GetRandomInt(100, 300)
            };

            return(shards);
        }
예제 #18
0
        static void Main()
        {
            var shards = new Shards
            {
                new DocumentStore {
                    Url = "http://localhost:8080", Identifier = "Posts"
                },
                new DocumentStore
                {
                    Url         = "http://localhost:8081",
                    Identifier  = "Users",
                    Conventions = { DocumentKeyGenerator = user => "users/" + ((User)user).Name }
                }
            };

            var shardStrategy = new ShardStrategy
            {
                ShardAccessStrategy     = new ParallelShardAccessStrategy(),
                ShardSelectionStrategy  = new BlogShardSelectionStrategy(),
                ShardResolutionStrategy = new BlogShardResolutionStrategy()
            };

            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
            {
                using (var session = documentStore.OpenSession())
                {
                    var user = new User {
                        Name = "PastyGeek"
                    };
                    session.Store(user);
                    session.SaveChanges();

                    var post = new Post
                    {
                        AuthorId = user.Id,
                        Name     = user.Name,
                        BlogId   = "blogs/1",
                        Title    = "More CodeMash Gloating!",
                        Body     = "You wouldn't believe how much more fun I'm having than you!",
                        PostDate = DateTime.Now,
                        Tags     = new List <string> {
                            "codemash", "gloating"
                        }
                    };
                    session.Store(post);
                    session.SaveChanges();
                }
            }
        }
예제 #19
0
        public PUBGApiClient(Shards shard, Endpoint endpoint, string apiKey = null, bool testmode = false)
        {
            _shard       = Helpers.GetShard(shard) ?? throw new ArgumentNullException(nameof(shard));
            _endpoint    = Helpers.GetEndpoint(endpoint) ?? throw new ArgumentNullException(nameof(endpoint));
            _apiUrl      = API_URL;
            _apiKey      = apiKey;
            _limit       = MAXLIMIT;
            _firstUrl    = "";
            Testmode     = testmode;
            SortingOrder = "ASC";

            var url = _shard;

            url += _endpoint;
        }
예제 #20
0
        private async Task ConnectWebSocketAsync()
        {
            WebSocket = new ClientWebSocket();

            var options = WebSocket.Options;

            options.SetRequestHeader("Authorization", Authorization);
            options.SetRequestHeader("User-Id", DiscordClient.CurrentUser.Id.ToString());
            options.SetRequestHeader("Num-Shards", Shards.ToString());
            options.SetRequestHeader("Resume-Key", ConfigureResume.ResumeKey);

            await WebSocket.ConnectAsync(new Uri(string.Format("ws://{0}/", _connectionEndpoint)), _cts.Token).ConfigureAwait(false);

            await ConfigureResume.SendAsync(WebSocket);
        }
예제 #21
0
        public void DistributedService_UserClient_SendToShard_ReceivesPacket()
        {
            var userSvc  = Users.First().Context.Services.Get <TestDistributedService>();
            var shardSvc = Shards.First().Context.Services.Get <TestDistributedService>();
            var pck      = new TestPacket();

            bool recv = false;

            shardSvc.ShardChannel.Receive += (s, e) => {
                recv = true;
            };

            userSvc.ShardChannel.Send(pck, Shards.First().Model);
            Assert.IsTrue(recv);
        }
예제 #22
0
        public void DistributedService_ShardClient_SendToShard_PacketReceived()
        {
            var shardSvc1 = Shards.First().Context.Services.Get <TestDistributedService>();
            var shardSvc2 = Shards.Skip(1).First().Context.Services.Get <TestDistributedService>();
            var pck       = new TestPacket();

            bool recv = false;

            shardSvc2.ShardChannel.Receive += (s, e) => {
                recv = true;
            };

            shardSvc1.ShardChannel.Send(pck, Shards.Skip(1).First().Model);
            Assert.IsTrue(recv);
        }
예제 #23
0
        public static string GetShard(Shards shard)
        {
            switch (shard)
            {
            case (Shards.PcKAKAO):
                return("shards/pc-kakao/");

            case (Shards.PcNorthAmerica):
                return("shards/pc-na/");

            case (Shards.PcAsia):
                return("shards/pc-as/");

            case (Shards.PcKoreaJapan):
                return("shards/pc-krjp/");

            case (Shards.PcSouthAndCentralAmerica):
                return("shards/pc-sa/");

            case (Shards.PcEurope):
                return("shards/pc-eu/");

            case (Shards.PcOceania):
                return("shards/pc-oc/");

            case (Shards.PcSouthEastAsia):
                return("shards/pc-sea/");

            case (Shards.XboxNorthAmerica):
                return("shards/xbox-na/");

            case (Shards.XboxAsia):
                return("shards/xbox-as/");

            case (Shards.XboxEurope):
                return("shards/xbox-eu/");

            case (Shards.XboxOceania):
                return("shards/xbox-oc/");

            case (Shards.empty):
                return("");

            default:
                return(null);
            }
        }
예제 #24
0
        public void DistributedService_UserClient_SendToAllShards_ExcludingMany_ReceivesPackets()
        {
            var userSvc = Users.First().Context.Services.Get <TestDistributedService>();
            var pck     = new TestPacket();

            int recv = 0;

            foreach (var sh in Shards)
            {
                sh.Context.Services.Get <TestDistributedService>().ShardChannel.Receive += (s, e) => {
                    recv += 1;
                }
            }
            ;

            userSvc.ShardChannel.Send(pck, Shards.Select(i => i.Model).Skip(3));
            Assert.AreEqual(Shards.Count - 3, recv);
        }
예제 #25
0
    void OnTriggerEnter2D(Collider2D other)
    {
        switch (faction)
        {
        case Faction.Wolf:
            OtterCombo = 0;
            EagleCombo = 0;
            WolfV.Flash();
            OtterC.StopCombo();
            EagleC.StopCombo();
            Shards.ExplodeAt(transform.position, Color.red, 3);
            AudioManager.PlaySFX(SFX.GhostBad);
            break;

        case Faction.Otter:
            OtterCombo++;
            EagleCombo = 0;
            OtterV.Flash();
            EagleC.StopCombo();
            Score.AddScore(OtterCombo * OtterCombo * (Movement.Player.currentClip == "DiagAttack" ? 8000 : 1000));
            if (OtterCombo > 3)
            {
                OtterC.CreateComboText(OtterCombo);
            }
            Shards.ExplodeAt(transform.position, Color.green, 3);
            AudioManager.PlaySFX(SFX.GhostGood);
            break;

        case Faction.Eagle:
            EagleCombo++;
            OtterCombo = 0;
            EagleV.Flash();
            OtterC.StopCombo();
            Score.AddScore(EagleCombo * EagleCombo * (Movement.Player.currentClip == "DiagAttack" ? 8000 : 1000));
            if (EagleCombo > 3)
            {
                EagleC.CreateComboText(EagleCombo);
            }
            Shards.ExplodeAt(transform.position, new Color(0.4f, 0, 0.5f), 3);
            AudioManager.PlaySFX(SFX.GhostGood);
            break;
        }
        Destroy(gameObject);
    }
예제 #26
0
 public static void ExplodeAt(Vector2 pos, Color c, int count, float force = 1)
 {
     for (int i = 0; i < count; i++)
     {
         if (shards.Count == 0)
         {
             return;
         }
         Shards s = shards.Pop();
         s.t.position      = new Vector3(pos.x, pos.y, 2);
         s.t.rotation      = Quaternion.Euler(0, 0, Random.Range(0f, 360f));
         s.t.localScale    = new Vector3(Random.Range(0, 2) * 2 - 1, 1, 1);
         s.angularVelocity = Random.Range(0.5f, 1f + force) * (Random.Range(0, 2) * 2 - 1);
         s.velocity        = new Vector3(Random.Range(-2f, 2f), Random.Range(-2f, 2f), 0) * force / 60f;
         s.s.color         = c;
         s.m.enabled       = true;
         s.pooled          = false;
     }
 }
예제 #27
0
		static void Main()
		{
			var shards = new Shards
			             	{
			             		new DocumentStore {Url = "http://localhost:8080", Identifier = "Posts"},
			             		new DocumentStore
			             			{
			             				Url = "http://localhost:8081",
			             				Identifier = "Users",
			             				Conventions = {DocumentKeyGenerator = user => "users/" + ((User) user).Name}
			             			}
			             	};

			var shardStrategy = new ShardStrategy
			{
				ShardAccessStrategy = new ParallelShardAccessStrategy(),
				ShardSelectionStrategy = new BlogShardSelectionStrategy(),
				ShardResolutionStrategy = new BlogShardResolutionStrategy()
			};

			using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
			{
				using (var session = documentStore.OpenSession())
				{
					var user = new User { Name = "PastyGeek" };
					session.Store(user);
					session.SaveChanges();

					var post = new Post
					{
						AuthorId = user.Id,
						Name = user.Name,
						BlogId = "blogs/1",
						Title = "More CodeMash Gloating!",
						Body = "You wouldn't believe how much more fun I'm having than you!",
						PostDate = DateTime.Now,
						Tags = new List<string> { "codemash", "gloating" }
					};
					session.Store(post);
					session.SaveChanges();
				}
			}
		}
예제 #28
0
        public void DistributedService_RouterServer_SendToShard_PacketReceived()
        {
            var routerShardSvc = Router.ShardController.Context.Services.Get <TestDistributedService>();
            var routerUserSvc  = Router.UserController.Context.Services.Get <TestDistributedService>();
            var user           = Users.First();
            var shard          = Shards.First();
            var usvc           = user.Context.Services.Get <TestDistributedService>();
            var ssvc           = shard.Context.Services.Get <TestDistributedService>();
            var pck            = new TestPacket();

            bool recv = false;

            ssvc.ShardChannel.Receive += (s, e) => {
                recv = true;
            };

            usvc.ShardChannel.Send(pck, shard.Model);
            Assert.IsTrue(recv);
        }
예제 #29
0
        public void DistributedService_ShardClient_SendToAllShards_ExcludingOne_PacketsReceived()
        {
            var shardSvc1 = Shards.First().Context.Services.Get <TestDistributedService>();
            var shardSvc2 = Shards.Skip(1).First().Context.Services.Get <TestDistributedService>();
            var pck       = new TestPacket();

            int recv = 0;

            foreach (var sh in Shards)
            {
                sh.Context.Services.Get <TestDistributedService>().ShardChannel.Receive += (s, e) => {
                    recv += 1;
                }
            }
            ;

            shardSvc1.ShardChannel.Send(pck, Shards.Select(i => i.Model).Skip(1));
            Assert.AreEqual(Shards.Count - 1, recv);
        }
예제 #30
0
        public When_Using_Sharded_Servers()
        {
            server = "localhost";

            port1 = 8080;
            port2 = 8081;

            path1 = GetPath("TestShardedDb1");
            path2 = GetPath("TestShardedDb2");

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);

            company1 = new Company {
                Name = "Company1"
            };
            company2 = new Company {
                Name = "Company2"
            };

            server1 = GetNewServer(port1, path1);
            server2 = GetNewServer(port2, path2);

            shards = new Shards {
                new DocumentStore {
                    Identifier = "Shard1", Url = "http://" + server + ":" + port1
                },
                new DocumentStore {
                    Identifier = "Shard2", Url = "http://" + server + ":" + port2
                }
            };

            shardSelection = MockRepository.GenerateStub <IShardSelectionStrategy>();
            shardSelection.Stub(x => x.ShardIdForNewObject(company1)).Return("Shard1");
            shardSelection.Stub(x => x.ShardIdForNewObject(company2)).Return("Shard2");

            shardResolution = MockRepository.GenerateStub <IShardResolutionStrategy>();

            shardStrategy = MockRepository.GenerateStub <IShardStrategy>();
            shardStrategy.Stub(x => x.ShardSelectionStrategy).Return(shardSelection);
            shardStrategy.Stub(x => x.ShardResolutionStrategy).Return(shardResolution);
        }
예제 #31
0
        public void Init(NameValueCollection appSettings)
        {
            Config = new ApiConfig();
            Config.Maintainance       = bool.Parse(appSettings["maintainance"]);
            Config.AuthTicketDuration = int.Parse(appSettings["authTicketDuration"]);
            Config.Regkey             = appSettings["regkey"];
            Config.Secret             = appSettings["secret"];
            Config.UpdateUrl          = appSettings["updateUrl"];
            Config.CDNUrl             = appSettings["cdnUrl"];
            Config.NFSdir             = appSettings["nfsdir"];
            Config.UseProxy           = bool.Parse(appSettings["useProxy"]);
            Config.UpdateID           = (appSettings["updateID"] == "") ? (int?)null : int.Parse(appSettings["updateID"]);
            Config.BranchName         = appSettings["branchName"] ?? "beta";

            // new smtp config vars
            if (appSettings["smtpHost"] != null &&
                appSettings["smtpUser"] != null &&
                appSettings["smtpPassword"] != null &&
                appSettings["smtpPort"] != null)
            {
                Config.SmtpEnabled  = true;
                Config.SmtpHost     = appSettings["smtpHost"];
                Config.SmtpUser     = appSettings["smtpUser"];
                Config.SmtpPassword = appSettings["smtpPassword"];
                Config.SmtpPort     = int.Parse(appSettings["smtpPort"]);
            }

            JWT = new JWTFactory(new JWTConfiguration()
            {
                Key = System.Text.UTF8Encoding.UTF8.GetBytes(Config.Secret)
            });

            DAFactory = new MySqlDAFactory(new Database.DatabaseConfiguration()
            {
                ConnectionString = appSettings["connectionString"]
            });

            Shards = new Shards(DAFactory);
            Shards.AutoUpdate();
        }
예제 #32
0
파일: Program.cs 프로젝트: torkelo/ravendb
        static void Main(string[] args)
        {
            var shards = new Shards {
                new DocumentStore("localhost", 8080) { Identifier="Shard1" },
                new DocumentStore("localhost", 8081) { Identifier="Shard2" }
            };

            using (var documentStore = new ShardedDocumentStore(new ShardStrategy(), shards).Initialise())
            using (var session = documentStore.OpenSession())
            {
                //store 2 items in the 2 shards
                session.Store(new Company { Name = "Company 1", Region = "A" });
                session.Store(new Company { Name = "Company 2", Region = "B" });
                session.SaveChanges();

                //get all, should automagically retrieve from each shard
                var allCompanies = session.Query<Company>().WaitForNonStaleResults().ToArray();

                foreach (var company in allCompanies)
                    Console.WriteLine(company.Name);
            }
        }
예제 #33
0
        public void DistributedService_RouterServer_SendToAllShards_PacketsReceived()
        {
            var routerShardSvc = Router.ShardController.Context.Services.Get <TestDistributedService>();
            var routerUserSvc  = Router.UserController.Context.Services.Get <TestDistributedService>();
            var user           = Users.First();
            var shard          = Shards.First();
            var usvc           = user.Context.Services.Get <TestDistributedService>();
            var ssvc           = shard.Context.Services.Get <TestDistributedService>();
            var pck            = new TestPacket();

            int recv = 0;

            foreach (var sh in Shards)
            {
                sh.Context.Services.Get <TestDistributedService>().ShardChannel.Receive += (s, e) => {
                    recv++;
                };
            }

            usvc.ShardChannel.Send(pck);
            Assert.IsTrue(recv == Shards.Count);
        }
예제 #34
0
파일: Api.cs 프로젝트: fourks/FreeSO
        public void Init(NameValueCollection appSettings)
        {
            Config = new ApiConfig();
            Config.Maintainance       = bool.Parse(appSettings["maintainance"]);
            Config.AuthTicketDuration = int.Parse(appSettings["authTicketDuration"]);
            Config.Regkey             = appSettings["regkey"];
            Config.Secret             = appSettings["secret"];
            Config.UpdateUrl          = appSettings["updateUrl"];
            Config.NFSdir             = appSettings["nfsdir"];

            JWT = new JWTFactory(new JWTConfiguration()
            {
                Key = System.Text.UTF8Encoding.UTF8.GetBytes(Config.Secret)
            });

            DAFactory = new MySqlDAFactory(new Database.DatabaseConfiguration()
            {
                ConnectionString = appSettings["connectionString"]
            });

            Shards = new Shards(DAFactory);
            Shards.AutoUpdate();
        }
예제 #35
0
        static void Main()
        {
            var shards = new Shards
            {
                CreateShard("Asia", "http://localhost:8080"),
                CreateShard("Middle-East", "http://localhost:8081"),
            };

            using (var documentStore = new ShardedDocumentStore(new ShardStrategy(), shards).Initialize())
            using (var session = documentStore.OpenSession())
            {
                //store 2 items in the 2 shards
                session.Store(new Company { Name = "Company 1", Region = "Asia" });
                session.Store(new Company { Name = "Company 2", Region = "Middle East" });
                session.SaveChanges();

                //get all, should automagically retrieve from each shard
                var allCompanies = session.LuceneQuery<Company>().WaitForNonStaleResults().ToArray();

                foreach (var company in allCompanies)
                    Console.WriteLine(company.Name);
            }
        }
예제 #36
0
        static void Main()
        {
            var shards = new Shards
            {
                new DocumentStore {
                    Url = "http://localhost:8080", Identifier = "Posts"
                },
                new DocumentStore
                {
                    Url         = "http://localhost:8081",
                    Identifier  = "Users",
                    Conventions = { DocumentKeyGenerator = user => "users/" + ((User)user).Name }
                }
            };

            var shardStrategy = new ShardStrategy
            {
                ShardAccessStrategy     = new ParallelShardAccessStrategy(),
                ShardSelectionStrategy  = new BlogShardSelectionStrategy(),
                ShardResolutionStrategy = new BlogShardResolutionStrategy()
            };

            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
            {
                var posts = shards[0].DatabaseCommands.StartsWith("post", 0, 50);
                foreach (var post in posts)
                {
                    shards[0].DatabaseCommands.Delete(post.Key, post.Etag);
                }

                var users = shards[1].DatabaseCommands.StartsWith("user", 0, 50);
                foreach (var user in users)
                {
                    shards[1].DatabaseCommands.Delete(user.Key, user.Etag);
                }
            }
        }
예제 #37
0
파일: Program.cs 프로젝트: VirtueMe/ravendb
		static void Main()
		{
			var consoleAppender = new ConsoleAppender
			{
				Layout = new SimpleLayout(),
			};
			consoleAppender.AddFilter(new LoggerMatchFilter
			{
				AcceptOnMatch = true,
				LoggerToMatch = "Raven.Client"
			});
			consoleAppender.AddFilter(new DenyAllFilter());
			BasicConfigurator.Configure(consoleAppender);

			// start 5 instances of Raven's servers
			Console.WriteLine("Starting...");
			DeleteDirectories("Users", "Blogs", "Posts.1", "Posts.2", "Posts.3");
			var ravenDbServers = StartServers();
			Console.WriteLine("All servers started...");

			var shards = new Shards
			{
				new DocumentStore
				{
					Identifier = "Users",
					Url = "http://*****:*****@ Rahien" };

				session.Store(user);
				session.Store(blog);

				// we have to save to Raven to get the generated id for the blog instance
				session.SaveChanges();
				var posts = new List<Post>();
				for (var i = 0; i < 6; i++)
				{
					var post = new Post
					{
						BlogId = blog.Id,
						UserId = user.Id,
						Content = "Just a post",
						Title = "Post #" + (i + 1)
					};
					posts.Add(post);
					session.Store(post);
				}

				session.SaveChanges();
			}

			// queries
			using (var session = documentStore.OpenSession())
			{
				session.LuceneQuery<User>().WaitForNonStaleResults().ToArray();
				session.LuceneQuery<Blog>().WaitForNonStaleResults().ToArray();
				session.LuceneQuery<Post>().WaitForNonStaleResults().ToArray();
			}

			// loading
			using (var session = documentStore.OpenSession())
			{
				session.Load<User>("users/ayende");
				session.Load<Blog>("blogs/1");
				session.Load<Post>("posts/1/2");
				session.Load<Post>("posts/2/2");
			}

			documentStore.Dispose();

			foreach (var server in ravenDbServers)
			{
				server.Dispose();
			}
		}
예제 #38
0
		protected ShardingScenario()
		{
			RavenDbServer users = null;
			RavenDbServer blogs = null;
			RavenDbServer posts1 = null;
			RavenDbServer posts2 = null;
			RavenDbServer posts3 = null;
			try
			{
				users = GetNewServer(8079, "shard1");
				blogs = GetNewServer(8078, "shard2");
				posts1 = GetNewServer(8077, "shard3");
				posts2 = GetNewServer(8076, "shard4");
				posts3 = GetNewServer(8075, "shard5");
			}
			catch (Exception)
			{
				if (users != null)
					users.Dispose();
				if (blogs != null)
					blogs.Dispose();
				if (posts1 != null)
					posts1.Dispose();
				if (posts2 != null)
					posts2.Dispose();
				if (posts3 != null)
					posts3.Dispose();
				throw;
			}

			servers = new Dictionary<string, RavenDbServer>
			{
				{"Users", users},
				{"Blogs", blogs},
				{"Posts01", posts1},
				{"Posts02", posts2},
				{"Posts03", posts3}
			};

			var shards = new Shards
			{
				new DocumentStore {Identifier = "Users", Url = "http://localhost:8079"},
				new DocumentStore {Identifier = "Blogs", Url = "http://localhost:8078"},
				new DocumentStore {Identifier = "Blogs", Url = "http://localhost:8078"},
				new DocumentStore {Identifier = "Posts01", Url = "http://localhost:8077"},
				new DocumentStore {Identifier = "Posts02", Url = "http://localhost:8076"},
				new DocumentStore {Identifier = "Posts03", Url = "http://localhost:8075"}
			};


			foreach (var shard in shards)
			{
				shard.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately;
				shard.Initialize();
			}

			shardedDocumentStore = new ShardedDocumentStore(new ShardStrategy
															{
																ShardAccessStrategy = new SequentialShardAccessStrategy(),
																ShardSelectionStrategy = new BlogShardSelectionStrategy(3),
																ShardResolutionStrategy = new BlogShardResolutionStrategy(3)
															}, shards);
		}