예제 #1
0
        /// <summary>
        /// Creates service according to config info
        /// </summary>
        /// <param name="configInfo"></param>
        /// <returns></returns>
        public UserService LoadService(ElementHelper configInfo)
        {
            UserService     service;
            Communicator    communicator;
            IUserRepository repository = new UserRepository();

            if (configInfo.ServerType == "master")
            {
                Sender <BllUser> sender = new Sender <BllUser>();
                communicator = new Communicator(sender);
                service      = new MasterUserService(repository);
            }

            else if (configInfo.ServerType == "slave")
            {
                Receiver <BllUser> receiver = new Receiver <BllUser>(configInfo.IpEndPoint.Address, configInfo.IpEndPoint.Port);
                communicator = new Communicator(receiver);
                service      = new SlaveUserService(repository);
            }
            else
            {
                throw new ArgumentException("Wrong service type!");
            }

            service.Communicator = communicator;

            return(service);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var appSettings = ConfigurationManager.AppSettings;
            var myappSet    = (dynamic)ConfigurationManager.GetSection("Slaves");

            List <KeyValuePair <int, string> > PortsAndHosts = new List <KeyValuePair <int, string> >();

            for (int i = 0; i < Int32.Parse(myappSet["slavesNum"]); i++)
            {
                var temp = myappSet[$"Slave{i}"].Split(' ');
                PortsAndHosts.Add(new KeyValuePair <int, string>(int.Parse(temp[1]), temp[0]));
            }
            var slaveServices = new List <SlaveUserService>();
            int counter       = 0;

            foreach (var slaveSettings in PortsAndHosts)
            {
                var slave = new SlaveUserService(slaveSettings.Value, slaveSettings.Key);
                slaveServices.Add(slave.CreateSlaveServiceInNewDomain($"Slave{counter}"));
                counter++;
            }
            Func <User, bool> searchEngine1 = SearchByPredicate;
            var service = new MasterUserService(PortsAndHosts, ConfigurationManager.AppSettings["pathToXML"]);
            var master  = service.CreateMasterServiceInNewDomain("Master");

            master.Unload();

            Func <User, bool> searchEngine = SearchByPredicate;
            var foundValues  = master.SearchByPredicate(searchEngine);
            var foundValues2 = slaveServices[0].SearchByPredicate(searchEngine);

            Console.ReadKey();
        }
예제 #3
0
        static void Main(string[] args)
        {
            //MasterSlavesConfig masterSlaveConfig = MasterSlavesConfig.GetConfig();

            SlaveUserService slave = new SlaveUserService(new ListStorage());

            slave.OnStart();
            //Console.WriteLine(NetworkHelper.IsPortOpenedWithoutTcp(11000));

            //Console.WriteLine(masterSlaveConfig.Slaves[0].Port);
            //Console.WriteLine(masterSlaveConfig.Slaves[1].Port);
            //Func<User, bool> criteria = user => user.Id == 2;
            //Func<User, bool> criteria = delegate(User user) { return user.Id == 58; };
            //Console.WriteLine(criteria.Method.ToString());
            //Console.WriteLine(criteria.Target);

            while (true)
            {
                Console.WriteLine("Write command:");
                string command = Console.ReadLine();
                switch (command)
                {
                case "stop":
                    slave.OnStop();
                    break;

                case "search":
                    Console.WriteLine(slave.Search(Criterias.ConcreteId));
                    break;

                default:
                    Console.WriteLine("Wrong command");
                    break;
                }
            }
        }