示例#1
0
        public Operation1()
        {
            InitializeComponent();

            mState           = NetCode.Srvr1DatRetriving;
            mClnt            = new Client2(ClntBufHndl, ClntBufPrep, true);
            mServer          = new Server2(SrvrBufHndl);
            mServer.SrvrPort = 23821;
            mCbMsg           = new UICbMsg();
            bRunning         = true;

            mBrd = new ExamBoard();

            if (!System.IO.File.Exists("Room.txt") ||
                !int.TryParse(System.IO.File.ReadAllText("Room.txt"), out uRId))
            {
                uRId = 0;
            }

            vfbLock = new List <SortedList <int, bool> >();

            System.Timers.Timer aTimer = new System.Timers.Timer(2000);
            // Hook up the Elapsed event for the timer.
            aTimer.Elapsed  += UpdateSrvrMsg;
            aTimer.AutoReset = true;
            aTimer.Enabled   = true;
        }
        public async Task UniqueServersTest()
        {
            var server3 = GenerateServer("host-3");
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            await StatisticStorage.UpdateServer(server3.GetIndex(), server3);

            var matches = new[]
            {
                GenerateMatch(Server2, Day1, scoreboard: new[] { Player1, Player2 }),
                GenerateMatch(Server1, Day2, scoreboard: new[] { Player1 }),
                GenerateMatch(Server2, Day3, scoreboard: new[] { Player2, Player1 }),
                GenerateMatch(server3, Day4, scoreboard: new[] { Player2 }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(Player1.Name).UniqueServers.Should().Be(2);
            PlayerStatisticStorage.GetStatistics(Player2.Name).UniqueServers.Should().Be(2);
        }
        public async Task AverageScoreboardPercentTest()
        {
            PlayerInfo
                player1 = GeneratePlayer("A"),
                player2 = GeneratePlayer("B"),
                player3 = GeneratePlayer("C"),
                player4 = GeneratePlayer("D");
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            var matches = new[]
            {
                GenerateMatch(Server2, Day1, scoreboard: new[] { player1, player2, player4 }),
                GenerateMatch(Server1, Day2, scoreboard: new[] { player3, player2, player1, player4 }),
                GenerateMatch(Server2, Day3, scoreboard: new[] { player2, player4, player1 }),
                GenerateMatch(Server2, Day4, scoreboard: new[] { player3, player2 }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(player1.Name).AverageScoreboardPercent
            .Should().Be((100.0 + 100.0 / 3 + 0) / 3);
            PlayerStatisticStorage.GetStatistics(player2.Name).AverageScoreboardPercent
            .Should().Be((100.0 / 2 + 100.0 * 2 / 3 + 100.0 + 0) / 4);
            PlayerStatisticStorage.GetStatistics(player3.Name).AverageScoreboardPercent
            .Should().Be((100.0 + 100.0) / 2);
            PlayerStatisticStorage.GetStatistics(player4.Name).AverageScoreboardPercent
            .Should().Be((0.0 + 0.0 + 100.0 / 2) / 3);
        }
示例#4
0
		private void doStart() {
			isAll = true;
			for (int i = 0; i < listBox.Items.Count; i++) {
				if (!listBox.GetItemChecked(i)) { isAll = false; }
			}

			spCount = 0;
			if (!string.IsNullOrEmpty(config.AdminPath) && isAll) {
				Pub.Class.FileDirectory.DirectoryCreate(config.AdminPath + "\\xml\\");
				Pub.Class.FileDirectory.FileDelete(config.AdminPath + "\\xml\\db.aspx");
				FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "<div class='MenuTitlebar' style='top: 12px; left: 12px; width: 168px; height: 25px;' title='数据库管理'><table cellspacing='0' cellpadding='0'><tbody><tr style='width: 185px; height: 25px;'><td class='MenuTitlebarLeft_Head' style='width: 13px;'/><td class='MenuTitlebarMiddle_Head' style='width: 130px;'><div class='MenuTitle_Head' style='width: 130px; height: 25px; line-height: 25px;'>数据库管理</div></td><td class='MenuTitlebarRight_Open_Head' style='width: 25px;'/></tr></tbody></table></div>\n\r<div class='MenuBody_Head' style='border-width: 0px 1px 1px; padding: 9px 0px; overflow: hidden; top: 37px; left: 12px; width: 166px; opacity: 1;'>");
			}
			bool isNull = sbSqlCode.ToString().Trim().IsNullEmpty() ? true : false;
			if (isAll) isNull = false;
			//if (Data.DBType == "SqlServer") sbSqlCode.AppendLine(TableStructureFactory.GetPagerSPCode());
			for (int i = 0; i < listBox.Items.Count; i++) {
				if (listBox.GetItemChecked(i)) {
					listBox.SelectedIndex = i;
					doRun();
				}
			}
			btnStart.Enabled = true;
			if (!string.IsNullOrEmpty(config.AdminPath) && isAll) FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "</div>");

			if (!string.IsNullOrEmpty(config.DALPath) && !isNull) {
				string extFile = Server2.GetMapPath("") + "\\ext\\Sql\\SqlCode.sql";
				string extCode = FileDirectory.FileReadAll(extFile, Encoding.UTF8).ToString();
				Pub.Class.FileDirectory.DirectoryCreate(Server2.GetMapPath("") + "\\SQLCode\\");
				textBox4.Text = sbSqlCode.ToString() + "\r\n" + extCode;
				if (textBox4.Text.Trim().Length > 10) FileDirectory.FileWrite(Server2.GetMapPath("") + "\\SQLCode\\SQLCode" + Rand.RndDateStr() + ".sql", sbSqlCode.ToString() + "\r\n" + extCode);
			}
			this.Text = "Entity Tool [{3}] - {1}连接共有{0}个表{2}".FormatWith(listBox.Items.Count, Data.DBType, spCount > 0 ? ",自动生成{0}个存储过程".FormatWith(spCount) : "", config.TemplateName);
		}
示例#5
0
        // IDisposable Members

        public void Dispose()
        {
            Server1.Dispose();
            Server2.Dispose();
            foreach (var dispo in _disposables)
            {
                dispo.Dispose();
            }
        }
示例#6
0
        public Operation0()
        {
            InitializeComponent();
            mServer = new Server2(SrvrBufHndl);
            mCbMsg  = new UICbMsg();

            mBrd = new ExamBoard();

            bRunning = true;

            tbiSelected = null;
        }
示例#7
0
        public static void Server_app()
        {
            while (true)
            {
                try
                {
                    using (SqlConnection conn = new SqlConnection(strConn))
                    {
                        conn.Open();
                        Server2.Listen(10);

                        Client2 = Server2.Accept();
                        console_command.Showip(Client2);
                        if (Client2.Connected)
                        {
                            DbControll.Del();
                            var cmd = new SqlCommand("select * from Homework", conn);
                            var rdr = cmd.ExecuteReader();
                            while (rdr.Read())
                            {
                                Send(Client2, (string)rdr["Subject"]);

                                //Send(Client2, (string)rdr[1]);

                                Send(Client2, (string)rdr["T_Name"]);

                                Send(Client2, (string)rdr["Contents"]);

                                //Send(Client2, (string)rdr[4]);

                                Send(Client2, (string)rdr["Title"]);

                                Send(Client2, Convert.ToDateTime(rdr["date"]).ToString("dd/MM/yyyy"));
                            }
                            Send(Client2, "EOF");
                            rdr.Close();
                            Client2.Close();
                        }
                    }
                }
                catch (System.Net.Sockets.SocketException socketEx)
                {
                    Console.WriteLine("[Error]:{0}", socketEx.Message);
                }
                catch (System.Exception commonEx)
                {
                    Console.WriteLine("[Error]:{0}", commonEx.Message);
                }
            }
        }
    public async Task RpcInterfaceCanDispose_IDisposable()
    {
        var streams = FullDuplexStream.CreateStreams();

        var clientRpc = JsonRpc.Attach <IDisposableServer2>(streams.Item1);
        var server    = new Server2();

        this.serverRpc = new JsonRpc(streams.Item2);
        this.serverRpc.AddLocalRpcTarget(server);
        this.serverRpc.StartListening();

        Assert.Equal(6, await clientRpc.MultiplyAsync(2, 3));
        clientRpc.Dispose();
        Assert.True(((IJsonRpcClientProxy)clientRpc).JsonRpc.IsDisposed);
    }
示例#9
0
        public async Task PopularServers_ReturnAllServers_IfLessThanCount()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/5"));

            var typeDefinition = new { endpoint = "", name = "", averageMatchesPerDay = 0.0 };
            var expected = new[] { Server1, Server2 }.Select(s => new { endpoint = s.Id, name = s.Name, averageMatchesPerDay = 0.0 });
            var servers = JsonConvert.DeserializeObject <List <JObject> >(response.Response.Content)
                          .Select(value => value.ToObject(typeDefinition.GetType()));

            servers.ShouldBeEquivalentTo(expected);
        }
示例#10
0
        static void Main(string[] args)
        {
            Console.WriteLine("+-+-+-+-+-+-+-+");
            Console.WriteLine("|G|A|T|E|W|A|Y|");
            Console.WriteLine("+-+-+-+-+-+-+-+");
            Console.WriteLine();
            //GatewayServer server = new GatewayServer();
            //server.Start();

            // TEST
            //GatewayLogger.AddMethod("Transfer", "Bank");
            //GatewayLogger.AddMethod("Transfer", "Bank");
            //GatewayLogger.AddMethod("Transfer", "Bank");
            //GatewayLogger.AddMethod("Transfer", "Bank");

            //GatewayLogger.AddMethod("UpdateStatus", "Telenor");
            //GatewayLogger.AddMethod("UpdateStatus", "Telenor");
            //GatewayLogger.AddMethod("UpdateStatus", "Telenor");

            //GatewayLogger.AddMethod("NekaTamo", "VIP");
            //GatewayLogger.AddMethod("NekaTamo", "VIP");

            //GatewayLogger.AddInicijator("Ognjen", "192.168.1.1", 2000);
            //GatewayLogger.AddInicijator("Ognjen", "192.168.1.1", 2000);

            //GatewayLogger.AddInicijator("Sofija", "2000", 2000);
            //GatewayLogger.AddInicijator("Sofija", "2000", 2000);
            //GatewayLogger.AddInicijator("Sofija", "2000", 2000);
            //GatewayLogger.UcitajStatistikuMetoda();
            //GatewayLogger.UcitajStatistikuInicijatora();

            //GatewayLogger.GenerisiIzvestaj();

            Server2 <IGatewayConnection> server = new Server2 <IGatewayConnection>("localhost", Konstante.GATEWAY_PORT.ToString(), "GatewayConnection", typeof(GatewayConnection));

            GatewayLogger.UcitajStatistikuMetoda();
            GatewayLogger.UcitajStatistikuInicijatora();


            Console.ReadKey();
            server.Close();
        }
示例#11
0
        public async Task AverageMatchesPerDayTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            MatchInfo[] matches =
            {
                GenerateMatch(Server1, Day2),
                GenerateMatch(Server1, Day3),
                GenerateMatch(Server2, Day1),
                GenerateMatch(Server2, Day4),
            };
            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).AverageMatchesPerDay.Should().Be(0.5);
        }
        public async Task ModuleReturnsAllServerInfos()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            var response = await Module.ProcessRequest(CreateRequest("", "/servers/info"));

            response.Response.ShouldBeEquivalentTo(new JsonHttpResponse(HttpStatusCode.OK, new[]
            {
                new
                {
                    endpoint = Server1.Id,
                    info     = Server1
                },
                new
                {
                    endpoint = Server2.Id,
                    info     = Server2
                }
            }));
        }
示例#13
0
        public async Task MaximumPopulationTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            MatchInfo[] matches =
            {
                GenerateMatch(Server1, Day2,  "map", new [] { Player1, Player2             }),
                GenerateMatch(Server1, Day3,  "map", new [] { Player1, Player2, GeneratePlayer("A")}),
                GenerateMatch(Server2, Day1,  "map", new [] { Player1, Player2, GeneratePlayer("A"), GeneratePlayer("B")}),
                GenerateMatch(Server2, Day4),
            };
            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).MaximumPopulation.Should().Be(3);
            ServerStatisticStorage.GetStatistics(Server2.Id).MaximumPopulation.Should().Be(4);
        }
示例#14
0
        public async Task PopularServers_ReturnMostPopularServer()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            await StatisticStorage.UpdateMatch(Match2.GetIndex(), Match2.InitPlayers(Match2.EndTime));

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/1"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new[]
            {
                new
                {
                    endpoint             = Server2.Id,
                    name                 = Server2.Name,
                    averageMatchesPerDay = 1.0,
                }
            }));
        }
        public async Task AverageMatchesPerDayTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            var matches = new[]
            {
                GenerateMatch(Server2, new DateTime(2017, 1, 1, 12, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player1, Player2 }),
                GenerateMatch(Server1, new DateTime(2017, 1, 8, 13, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player1 }),
                GenerateMatch(Server2, new DateTime(2017, 1, 2, 14, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player2, Player1 }),
                GenerateMatch(Server2, new DateTime(2017, 1, 1, 15, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player1, Player2 }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(Player1.Name).AverageMatchesPerDay.Should().Be(0.5);
            PlayerStatisticStorage.GetStatistics(Player2.Name).AverageMatchesPerDay.Should().Be(1.5);
        }
        public async Task FavoriteServerTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            var matches = new[]
            {
                GenerateMatch(Server2, Day1, scoreboard: new[] { Player1, Player2 }),
                GenerateMatch(Server2, Day2, scoreboard: new[] { Player1 }),
                GenerateMatch(Server1, Day3, scoreboard: new[] { Player2, Player1 }),
                GenerateMatch(Server1, Day4, scoreboard: new[] { Player2 }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(Player1.Name).FavoriteServer.Should().Be(Server2.Id);
            PlayerStatisticStorage.GetStatistics(Player2.Name).FavoriteServer.Should().Be(Server1.Id);
        }
示例#17
0
        static void Main(string[] args)
        {
            //ovde ucitati informacije o korisnicima i racunima

            //BankDB.BazaKorisnika.Add("admin", new User("admin","admin","admin","0000","20000"));
            Console.WriteLine("+-+-+-+-+");
            Console.WriteLine("|B|A|N|K|");
            Console.WriteLine("+-+-+-+-+");
            Console.WriteLine();
            ucitajKorisnike(BankDB.BazaKorisnika);
            ucitajRacune(BankDB.BazaRacuna);
            Console.WriteLine("Dostupni korisnici: ");
            foreach (User u in BankDB.BazaKorisnika.Values)
            {
                Console.WriteLine(u.Username);
            }


            //BankServer server = new BankServer();
            //server.Start();
            Server2 <IBankConnection> server = new Server2 <IBankConnection>("localhost", Konstante.BANK_PORT.ToString(), "BankConnection", typeof(BankConnetion));

            Console.ReadKey();
        }
示例#18
0
        public static void Run(bool exit = false)
        {
            if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll)
            {
                Pub.Class.FileDirectory.DirectoryCreate(config.AdminPath + "\\xml\\");
                Pub.Class.FileDirectory.FileDelete(config.AdminPath + "\\xml\\db.aspx");
                FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "<div class='MenuTitlebar' style='top: 12px; left: 12px; width: 168px; height: 25px;' title='数据库管理'><table cellspacing='0' cellpadding='0'><tbody><tr style='width: 185px; height: 25px;'><td class='MenuTitlebarLeft_Head' style='width: 13px;'/><td class='MenuTitlebarMiddle_Head' style='width: 130px;'><div class='MenuTitle_Head' style='width: 130px; height: 25px; line-height: 25px;'>数据库管理</div></td><td class='MenuTitlebarRight_Open_Head' style='width: 25px;'/></tr></tbody></table></div>\n\r<div class='MenuBody_Head' style='border-width: 0px 1px 1px; padding: 9px 0px; overflow: hidden; top: 37px; left: 12px; width: 166px; opacity: 1;'>");
            }

            StringBuilder sbSqlCode = new StringBuilder();

            tables.Clear();
            config.OPList = TableStructureFactory.LoadOPList(config, entity => {
                tables.Add((entity.isView ? "* " : "") + entity.Name);
            });
            foreach (string key in tables)
            {
                string tabName = key; bool isView = false;
                if (tabName.IndexOf("* ") == 0)
                {
                    tabName = tabName.Substring(2); isView = true;
                }

                TableOperator to = config.OPList.Where(p => p.Table == tabName).FirstOrDefault();

                string dalCode = string.Empty; string idalCode = string.Empty; string bllCode = string.Empty;
                string sqlCode = string.Empty; string baseCode = string.Empty;

                if (!string.IsNullOrEmpty(config.ModelPath) && to.Entity && config.DesignPattern == "Model-DAL-BLL")
                {
                    string code = TableStructureFactory.GetTableStructCode(config, tabName, config.Project, out idalCode, out dalCode, out bllCode, out sqlCode, isView);
                    Pub.Class.FileDirectory.DirectoryCreate(config.ModelPath + "\\Model\\");
                    Pub.Class.FileDirectory.FileDelete(config.ModelPath + "\\Model\\" + tabName + ".cs");
                    FileDirectory.FileWrite(config.ModelPath + "\\Model\\" + tabName + ".cs", code);
                }
                if (!string.IsNullOrEmpty(config.EntityPath) && to.Entity && config.DesignPattern != "Model-DAL-BLL")
                {
                    string code = TableStructureFactory.GetTableStructCode(config, tabName, config.Project, out baseCode, out sqlCode, isView);
                    Pub.Class.FileDirectory.DirectoryCreate(config.EntityPath + "\\Entity\\");
                    Pub.Class.FileDirectory.FileDelete(config.EntityPath + "\\Entity\\" + tabName + ".cs");
                    FileDirectory.FileWrite(config.EntityPath + "\\Entity\\" + tabName + ".cs", code);
                }

                if (config.DesignPattern == "Model-DAL-BLL" && !string.IsNullOrEmpty(config.DALPath) && to.Entity)
                {
                    Pub.Class.FileDirectory.DirectoryCreate(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\");
                    Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs");

                    Pub.Class.FileDirectory.DirectoryCreate(config.IDALPath + "\\IDAL\\");
                    Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs");

                    if (!string.IsNullOrEmpty(dalCode.Trim()))
                    {
                        FileDirectory.FileWrite(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs", dalCode);
                        FileDirectory.FileWrite(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs", idalCode);
                    }
                    else
                    {
                        Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs");
                        Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs");
                    }

                    Pub.Class.FileDirectory.DirectoryCreate(config.BLLPath + "\\BLL\\");
                    Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs");
                    if (!string.IsNullOrEmpty(bllCode.Trim()))
                    {
                        FileDirectory.FileWrite(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs", bllCode);

                        sbSqlCode.AppendLine(sqlCode);
                    }
                    else
                    {
                        Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs");
                    }
                }
                if (config.DesignPattern != "Model-DAL-BLL" && !string.IsNullOrEmpty(config.FactoryPath) && to.Entity)
                {
                    Pub.Class.FileDirectory.DirectoryCreate(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\");
                    Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs");
                    if (!string.IsNullOrEmpty(baseCode.Trim()))
                    {
                        FileDirectory.FileWrite(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs", baseCode);

                        sbSqlCode.AppendLine(sqlCode);
                    }
                    else
                    {
                        Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs");
                    }
                }
                WriteLog(tabName + " 生成成功!");
            }
            if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll)
            {
                FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "</div>");
            }

            if (!string.IsNullOrEmpty(config.DALPath))
            {
                string extFile = Server2.GetMapPath("") + "\\ext\\Sql\\SqlCode.sql";
                string extCode = FileDirectory.FileReadAll(extFile, Encoding.UTF8).ToString();
                Pub.Class.FileDirectory.DirectoryCreate(Server2.GetMapPath("") + "\\SQLCode\\");
                string code = sbSqlCode.ToString() + "\r\n" + extCode;
                if (code.Trim().Length > 10)
                {
                    FileDirectory.FileWrite(Server2.GetMapPath("") + "\\SQLCode\\SQLCode" + Rand.RndDateStr() + ".sql", sbSqlCode.ToString() + "\r\n" + extCode);
                }
            }
            WriteLog("共 {0} 张表!", tables.Count);
            WriteLog("END");
            Input(exit);
        }
示例#19
0
        static void Main(string[] args)
        {
            Console.WriteLine("+-+-+-+-+-+-+-+-+");
            Console.WriteLine("|O|P|E|R|A|T|E|R|");
            Console.WriteLine("+-+-+-+-+-+-+-+-+");
            Console.WriteLine();
            Client <IGatewayConnection> cli          = new Client <IGatewayConnection>("mbgateway", Konstante.GATEWAY_IP, Konstante.GATEWAY_PORT.ToString(), "GatewayConnection");
            IGatewayConnection          gatewayProxy = cli.GetProxy();
            bool uspesnoUlogovan = false;
            User ulogovanUser    = new User();

            while (!uspesnoUlogovan)
            {
                Console.WriteLine("Username:"******"Password:"******"";
                ConsoleKeyInfo key;

                do
                {
                    key = Console.ReadKey(true);

                    // Backspace Should Not Work
                    if (key.Key != ConsoleKey.Backspace)
                    {
                        pass += key.KeyChar;
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write("\b");
                    }
                }
                // Stops Receving Keys Once Enter is Pressed
                while (key.Key != ConsoleKey.Enter);
                pass = pass.Replace("\r", "");
                string passSifrovano = BitConverter.ToString(Sifrovanje.sifrujCBC(pass, Konstante.ENCRYPTION_KEY));

                ulogovanUser = gatewayProxy.ClientToBankCheckLogin(userSifrovano, passSifrovano, "operater");
                if (ulogovanUser != null)
                {
                    Console.WriteLine();
                    Console.WriteLine("Uspesno logovanje " + ulogovanUser.Username);
                    uspesnoUlogovan = true;
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Neuspesno logovanje");
                    uspesnoUlogovan = false;
                }
            }
            Console.WriteLine("Korisnici koji su na ovom operateru:");
            OperatorDB.operatorName = ulogovanUser.Username;
            ucitajRacune(OperatorDB.operatorName);
            ucitajKorisnike(OperatorDB.operatorName);
            foreach (var item in OperatorDB.BazaKorisnika.Values)
            {
                Console.WriteLine(item.Username);
            }

            //OperatorServer server = new OperatorServer();
            //server.Start();

            Server2 <IOperatorConnection> server = new Server2 <IOperatorConnection>("localhost", Konstante.INITIAL_OPERATER_PORT.ToString(), "OperaterConnection", typeof(OperaterConnection));


            // Javi banci na kom ip-u i portu slusas
            string sifrovanUsername = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, Konstante.ENCRYPTION_KEY));

            if (!gatewayProxy.ClientAndOperatorToBankSetIpAndPort(sifrovanUsername, server.ipAddress, server.connectedPort.ToString()))
            {
                // Ukoliko vec postoji instanca tipa telenora, ugasi aplikaciju ili ponovo loguj itd...
                Environment.Exit(0);
            }

            gatewayProxy.CheckIntoGateway(server.ipAddress, server.connectedPort.ToString(), CertManager.Formatter.ParseName(WindowsIdentity.GetCurrent().Name));

            // Iscitaj iz xml-a



            // Ako je sve proslo ok, uzmi bazu svih racuna i klijenata ciji je operater npr telenor
            //string serializedList = gatewayProxy.OperatorToBankGetOperatorsClients(sifrovanUsername);
            //List<UserIRacun> aktivniKorisnici = ListSerializer.DeserializeString(serializedList);

            //foreach (var item in aktivniKorisnici)
            //{
            //    OperatorDB.BazaRacuna.Add(item.Racun.BrojRacuna,item.Racun);
            //}

            // U novom threadu prodji kroz sve aktivne korisnike i pozovi im sendBill
            Thread sendBillThread = new Thread(() => SendBill(gatewayProxy, sifrovanUsername));

            sendBillThread.Start();

            Console.ReadKey();
            gatewayProxy.OperatorToBankShutdownOperator(ulogovanUser.Username);
        }
示例#20
0
        ///////////////////////////////////////////////////////////////////////////////

        public void SetAsServerSide(Server2 server2, int port = -1)
        {
            _port    = port < 0 ? MyDefaults.SERVER_PORT : port;
            _server2 = server2;
        }
        static void Main(string[] args)
        {
            while (true)
            {
                var         context           = new ZContext();
                Thread      broker1           = new Thread(() => BrokerCreator.Broker(context, broker1AddrRequest, broker1AddrResponse, broker1AddrRequestPush, broker1AddrResponsePull, broker1AddrRequestPub, broker1AddrResponseSub, AddrToBroker2, AddrToBroker3, broker1AddrFromBrokers, brokerIdentity1));
                Thread      broker2           = new Thread(() => BrokerCreator.Broker(context, broker2AddrRequest, broker2AddrResponse, broker2AddrRequestPush, broker2AddrResponsePull, broker2AddrRequestPub, broker2AddrResponseSub, AddrToBroker1, AddrToBroker3, broker2AddrFromBrokers, brokerIdentity2));
                Thread      broker3           = new Thread(() => BrokerCreator.Broker(context, broker3AddrRequest, broker3AddrResponse, broker3AddrRequestPush, broker3AddrResponsePull, broker3AddrRequestPub, broker3AddrResponseSub, AddrToBroker1, AddrToBroker2, broker3AddrFromBrokers, brokerIdentity3));
                ZSocketType socketTypeClient  = ZSocketType.None;
                ZSocketType socketTypeServer  = ZSocketType.None;
                string      AddressforClient  = "";
                string      AddressforServer  = "";
                ZSocketType socketTypeClient2 = ZSocketType.None;
                ZSocketType socketTypeServer2 = ZSocketType.None;
                string      AddressforClient2 = "";
                string      AddressforServer2 = "";
                ZSocketType socketTypeClient3 = ZSocketType.None;
                ZSocketType socketTypeServer3 = ZSocketType.None;
                string      AddressforClient3 = "";
                string      AddressforServer3 = "";
                Thread      Client2           = null;
                Thread      Server2           = null;
                Thread      Client3           = null;
                Thread      Server3           = null;
                Thread      Client            = null;
                Thread      Server            = null;
                string      ClientIdentity    = "Client";
                string      ServerIdentity    = "Server";
                string      ClientIdentity2   = "Client2";
                string      ServerIdentity2   = "Server2";
                string      ClientIdentity3   = "Client3";
                string      ServerIdentity3   = "Server3";
                string      AddrForSub        = "";

                Random random = new Random();

                Console.WriteLine("\nPress number to choose type of clients sockets.");
                Console.WriteLine("1 - REQ-REP");
                Console.WriteLine("2 - PUSH-PULL");
                Console.WriteLine("3 - PUB-SUB");
                Console.WriteLine("4 - All sockets different");
                Console.WriteLine("5 - All sockets REQ-REP");
                Console.WriteLine("6 - All sockets PUSH-PULL");
                Console.WriteLine("7 - All sockets PUB-SUB\n");

                ConsoleKey key2 = Console.ReadKey(true).Key;

                if (key2 == ConsoleKey.D1)
                {
                    socketTypeClient = ZSocketType.REQ;
                    socketTypeServer = ZSocketType.REP;
                    AddressforClient = AddressforClientReq[random.Next(0, AddressforClientReq.Length)];
                    AddressforServer = AddressforServerRep[0];

                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                }
                else if (key2 == ConsoleKey.D2)
                {
                    socketTypeClient = ZSocketType.PUSH;
                    socketTypeServer = ZSocketType.PULL;
                    AddressforClient = AddressforClientPush[random.Next(0, AddressforClientPush.Length)];
                    AddressforServer = AddressforServerPull[0];

                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                }
                else if (key2 == ConsoleKey.D3)
                {
                    int randIndex = random.Next(0, AddressforServerSub.Length);

                    socketTypeClient = ZSocketType.PUB;
                    socketTypeServer = ZSocketType.SUB;
                    AddressforClient = AddressforClientPub[random.Next(0, AddressforClientPub.Length)];
                    AddressforServer = AddressforServerSub[randIndex];
                    AddrForSub       = AddressforClientReq[randIndex];

                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer, socketTypeServer, AddrForSub));
                }
                else if (key2 == ConsoleKey.D4)
                {
                    socketTypeClient  = ZSocketType.REQ;
                    socketTypeServer  = ZSocketType.REP;
                    AddressforClient  = AddressforClientReq[0];
                    AddressforServer  = AddressforServerRep[1];
                    socketTypeClient2 = ZSocketType.PUSH;
                    socketTypeServer2 = ZSocketType.PULL;
                    AddressforClient2 = AddressforClientPush[1];
                    AddressforServer2 = AddressforServerPull[2];
                    socketTypeClient3 = ZSocketType.PUB;
                    socketTypeServer3 = ZSocketType.SUB;
                    AddressforClient3 = AddressforClientPub[2];
                    AddressforServer3 = AddressforServerSub[0];
                    AddrForSub        = AddressforClientReq[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, AddressforServer2));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, ""));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, ""));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, AddrForSub));
                }
                else if (key2 == ConsoleKey.D5)
                {
                    socketTypeClient  = ZSocketType.REQ;
                    socketTypeServer  = ZSocketType.REP;
                    AddressforClient  = AddressforClientReq[0];
                    AddressforServer  = AddressforServerRep[1];
                    socketTypeClient2 = ZSocketType.REQ;
                    socketTypeServer2 = ZSocketType.REP;
                    AddressforClient2 = AddressforClientReq[1];
                    AddressforServer2 = AddressforServerRep[2];
                    socketTypeClient3 = ZSocketType.REQ;
                    socketTypeServer3 = ZSocketType.REP;
                    AddressforClient3 = AddressforClientReq[2];
                    AddressforServer3 = AddressforServerRep[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, AddressforServer2));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, ""));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, AddressforServer3));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, ""));
                }
                else if (key2 == ConsoleKey.D6)
                {
                    socketTypeClient  = ZSocketType.PUSH;
                    socketTypeServer  = ZSocketType.PULL;
                    AddressforClient  = AddressforClientPush[0];
                    AddressforServer  = AddressforServerPull[1];
                    socketTypeClient2 = ZSocketType.PUSH;
                    socketTypeServer2 = ZSocketType.PULL;
                    AddressforClient2 = AddressforClientPush[1];
                    AddressforServer2 = AddressforServerPull[2];
                    socketTypeClient3 = ZSocketType.PUSH;
                    socketTypeServer3 = ZSocketType.PULL;
                    AddressforClient3 = AddressforClientPush[2];
                    AddressforServer3 = AddressforServerPull[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, AddressforServer2));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, ""));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, AddressforServer3));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, ""));
                }
                else if (key2 == ConsoleKey.D7)
                {
                    socketTypeClient  = ZSocketType.PUB;
                    socketTypeServer  = ZSocketType.SUB;
                    AddressforClient  = AddressforClientPub[0];
                    AddressforServer  = AddressforServerSub[1];
                    socketTypeClient2 = ZSocketType.PUB;
                    socketTypeServer2 = ZSocketType.SUB;
                    AddressforClient2 = AddressforClientPub[1];
                    AddressforServer2 = AddressforServerSub[2];
                    socketTypeClient3 = ZSocketType.PUB;
                    socketTypeServer3 = ZSocketType.SUB;
                    AddressforClient3 = AddressforClientPub[2];
                    AddressforServer3 = AddressforServerSub[0];
                    AddrForSub        = AddressforClientReq[1];
                    string AddrForSub2 = AddressforClientReq[2];
                    string AddrForSub3 = AddressforClientReq[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, ""));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, AddrForSub));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, ""));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, AddrForSub2));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, ""));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, AddrForSub3));
                }

                Console.WriteLine("Press number to choose test. Press S to stop.");
                Console.WriteLine("1 - all components active");
                if (key2 == ConsoleKey.D1 || key2 == ConsoleKey.D2 || key2 == ConsoleKey.D3)
                {
                    Console.WriteLine("2 - passive sending client after sending and active receiving client after 5 sec\n");
                }
                else
                {
                    Console.WriteLine("\n");
                }

                ConsoleKey key = Console.ReadKey(true).Key;

                broker1.Start();
                broker2.Start();
                broker3.Start();

                if (key == ConsoleKey.D1)
                {
                    Server.Start();
                    Client.Start();

                    if (AddressforClient2 != "")
                    {
                        Server2.Start();
                        Server3.Start();
                        Client2.Start();
                        Client3.Start();
                    }
                }
                else if (key == ConsoleKey.D2)
                {
                    Client.Start();
                    Thread.Sleep(10 * 1000);
                    Client.Abort();
                    Thread.Sleep(5 * 1000);
                    Server.Start();
                    Thread.Sleep(5 * 1000);
                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Client.Start();
                }

                while (Console.ReadKey(true).Key != ConsoleKey.S)
                {
                    Thread.Sleep(1);
                }
                Client.Abort();
                Server.Abort();
                if (Client2 != null)
                {
                    Client2.Abort();
                    Server2.Abort();
                    Client3.Abort();
                    Server3.Abort();
                }
                broker1.Abort();
                broker2.Abort();
                broker3.Abort();
            }
        }
示例#22
0
        /*
         *
         */
        static void Main(string[] args)
        {
            Console.WriteLine("+-+-+-+-+-+-+");
            Console.WriteLine("|C|L|I|E|N|T|");
            Console.WriteLine("+-+-+-+-+-+-+");
            Console.WriteLine();
            // Prvo konekcija na server radi pristupanja bazi podataka ( gde admin postoji?)
            // Prvo autentifikacija, u zavisnosti od toga gleda se da li je admin ili ne (iz nekog txt-a)
            // ???
            string kljuc = Konstante.ENCRYPTION_KEY;
            Client <IGatewayConnection> cli          = new Client <IGatewayConnection>("mbgateway", Konstante.GATEWAY_IP, Konstante.GATEWAY_PORT.ToString(), "GatewayConnection");
            IGatewayConnection          gatewayProxy = cli.GetProxy();

            Console.WriteLine(">Login");
            User ulogovanUser     = new User();
            bool uspesnoLogovanje = false;

            while (!uspesnoLogovanje)
            {
                Console.WriteLine("Username:"******"Password:"******"";
                ConsoleKeyInfo key;

                do
                {
                    key = Console.ReadKey(true);

                    // Backspace Should Not Work
                    if (key.Key != ConsoleKey.Backspace)
                    {
                        pass += key.KeyChar;
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write("\b");
                    }
                }
                // Stops Receving Keys Once Enter is Pressed
                while (key.Key != ConsoleKey.Enter);
                pass = pass.Replace("\r", "");
                string passSifrovano = BitConverter.ToString(Sifrovanje.sifrujCBC(pass, kljuc));

                ulogovanUser = gatewayProxy.ClientToBankCheckLogin(userSifrovano, passSifrovano, "client");
                if (ulogovanUser != null)
                {
                    uspesnoLogovanje = true;
                }
                else
                {
                    Console.WriteLine("\nNeuspesno logovanje");
                }
            }

            if (ulogovanUser != null)
            {
                string userSifrovanoZaRacun = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, kljuc));

                Console.WriteLine("Uspesno logovanje " + ulogovanUser.Username);
                KlientskiRacun.racun = gatewayProxy.ClientToBankUzmiKlijentskiRacun(userSifrovanoZaRacun);
                if (KlientskiRacun.racun == null)
                {
                    Console.WriteLine("Ne postoji klijentski racun ");
                }
                else
                {
                    Console.WriteLine("Klijentski racun:" + KlientskiRacun.racun.BrojRacuna);
                }

                // podici server za klijenta i javiti banci sa metodomSetIpAndPort na kom portu i ip adresi slusa
                //ClientServer server = new ClientServer();
                //server.Start();
                //string sifrovanUsername = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, Konstante.ENCRYPTION_KEY));
                //gatewayProxy.ClientToBankSetIpAndPortClient(sifrovanUsername, server.ipAddress, server.port.ToString());

                Server2 <IClientConnection> server = new Server2 <IClientConnection>("localhost", Konstante.INITIAL_CLIENT_PORT.ToString(), "ClientConnection", typeof(ClientConnection));
                string sifrovanUsername            = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, Konstante.ENCRYPTION_KEY));
                gatewayProxy.ClientToBankSetIpAndPortClient(sifrovanUsername, server.ipAddress, server.connectedPort.ToString());

                // Javi gatewayu da te doda u listu instanci
                gatewayProxy.CheckIntoGateway(server.ipAddress, server.connectedPort.ToString(), CertManager.Formatter.ParseName(WindowsIdentity.GetCurrent().Name));

                if (ulogovanUser.Uloga == "admin")
                {
                    MeniAdmin(gatewayProxy);
                }
                else if (ulogovanUser.Uloga == "korisnik")
                {
                    MeniKorisnik(gatewayProxy);
                }
            }

            Console.ReadKey();
            gatewayProxy.ClientToBankShutdownClient(ulogovanUser.Username);
        }
示例#23
0
        protected override async Task PutInitialiData()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);
        }