示例#1
0
 /// <summary>
 /// Service constructor
 /// </summary>
 public ImageService()
 {
     try
     {
         //read params from app config
         eventLog1        = new System.Diagnostics.EventLog();
         eventLog1.Source = ConfigurationManager.AppSettings.Get("SourceName");
         eventLog1.Log    = ConfigurationManager.AppSettings.Get("LogName");
         //initialize members
         this.logging = new LoggingService(this.eventLog1);
         this.logging.MessageRecieved += WriteMessage;
         string output    = ConfigurationManager.AppSettings.Get("OutputDir");
         int    thumbSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"));
         this.modal             = new ImageServiceModal(output, thumbSize);
         this.controller        = new ImageController(this.modal, this.logging);
         this.m_imageServer     = new ImageServer(controller, logging);
         this.controller.Server = m_imageServer;
         int            port    = 8000;
         IClientHandler handler = new ClientHandler(controller, logging);
         ServiceServer = new ServiceServer(logging, handler, port);
         ImageServer.UpdateOnRemovingHandler += ServiceServer.Update;
         this.logging.UpdateLogItems         += ServiceServer.Update;
         ServiceServer.StartServer();
         //TCP server starting
         ITCPClientHandler tcpHandler = new TCPClientHandler(controller, logging);
         ITCPServer        tcpServer  = new TCPServer(7000, logging, tcpHandler);
         tcpServer.StartServer();
     }
     catch (Exception e)
     {
         this.eventLog1.WriteEntry(e.Message, EventLogEntryType.Error);
     }
 }
示例#2
0
        public static void addArticleTest()
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 0;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);
            //ChannelServices.RegisterChannel(channel, false);
            IServiceServer server = (IServiceServer)Activator.GetObject(typeof(IServiceServer), "tcp://localhost:55555/Conference");

            ClientController ctrl = new ClientController(server);

            Article article    = new Article(-1, "myArticle", "this is an article", "this is an article", "YES", 1);
            int     noArticles = ctrl.getAllArticles().Count;

            ctrl.addArticle(article);
            try
            {
                int noArticles2 = ctrl.getAllArticles().Count;
                Assert.AreEqual(noArticles2, noArticles + 1);
                Console.WriteLine("Controller: Test 3 passed");
            }
            catch (AssertFailedException e)
            {
                Console.WriteLine("Controller: Test 3 failed");
            }
        }
示例#3
0
        public static void validateAccountTest()
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 0;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);
            //ChannelServices.RegisterChannel(channel, false);
            IServiceServer server = (IServiceServer)Activator.GetObject(typeof(IServiceServer), "tcp://localhost:55555/Conference");

            ClientController ctrl = new ClientController(server);

            User user   = new User("Caspriac", "Dalia", "dcaspriac", "abc");
            User result = ctrl.validateAccount("dcaspriac", "abc");

            try
            {
                Assert.AreEqual(user.FirstName, result.FirstName);
                Console.WriteLine("Controller: Test 2 passed");
            }
            catch (AssertFailedException e)
            {
                Console.WriteLine("Controller: Test 2 failed");
            }
        }
示例#4
0
        public static void getConferenceIdFromNameTest()
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 0;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);
            //ChannelServices.RegisterChannel(channel, false);
            IServiceServer server = (IServiceServer)Activator.GetObject(typeof(IServiceServer), "tcp://localhost:55555/Conference");

            ClientController ctrl = new ClientController(server);

            int result = ctrl.getConferenceIdFromName("TOTUL DESPRE STIINTE");

            try
            {
                Assert.AreEqual(result, 1);
                Console.WriteLine("Controller: Test 1 passed");
            }catch (AssertFailedException e)
            {
                Console.WriteLine("Controller: Test 1 failed");
            }
        }
示例#5
0
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");

            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            // Set up a timer to trigger every minute.
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 60000; // 60 seconds
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();

            this.s_logger = new LoggingService();
            IImageServiceModal modal     = new ImageServiceModal();
            IImageController   controler = new ImageController(modal, this.s_logger);

            this.s_logger.MessageRecieved += this.OnMessage;
            this.s_server      = new ImageServer(modal, this.s_logger);
            this.serviceServer = new ServiceServer(controler, this.s_logger);
            this.serviceServer.Start();
            this.imgService = new ImageTransferServer(this.s_logger, this.s_server.SavePathes);
            this.imgService.Start();

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }
示例#6
0
        public void Initialize()
        {
            _node = Ros.InitNodeAsync("test", enableLogger: false).Result;

            _serviceServer = _node
                .AdvertiseServiceAsync("add_two_ints", new AddTwoInts(req => new AddTwoInts.Response() {sum = req.a + req.b}))
                .Result;
        }
示例#7
0
        public A4ARepository(IServiceServer server) : base(server)
        {
            var connectionString = SqlTableWithPrimaryKey.GetConnectionString(
                (string)server.GetConfigProperty("DataDirectory", server.BucketId),
                server.BucketId, "A4ARepository");

            underlying = new As.A4ACore.A4ARepository(connectionString);
        }
示例#8
0
        public void Initialize()
        {
            _node = Ros.InitNodeAsync("test", enableLogger: false).Result;

            _serviceServer = _node
                             .AdvertiseServiceAsync("add_two_ints", new AddTwoInts(req => new AddTwoInts.Response()
            {
                sum = req.a + req.b
            }))
                             .Result;
        }
        public Form1(string[] args)
        {
            InitializeComponent();
            label2.Visible = false;
            _pId           = args[0];
            Text           = _pId;
            string myURL = args[1];

            _serverPId = args[2];
            string serverURL = args[3];
            int    mSec      = int.Parse(args[4]);

            if (args.Count() == 6)
            {
                try
                {
                    reader = new StreamReader(args[5]);
                    ReadNextInstruction(reader);
                }
                catch (Exception)
                {
                    Console.WriteLine("Cant read file, check path: " + args[5]);
                }
            }
            _timer = new System.Timers.Timer()
            {
                Interval = mSec, AutoReset = true, Enabled = false
            };
            _timer.Elapsed += Timer_Tick;
            string tmp = Shared.Shared.ParseUrl(URLparts.Port, myURL);

            /* set channel */
            channel = new TcpChannel(int.Parse(tmp));
            ChannelServices.RegisterChannel(channel, false);

            /*set service */
            serviceClient = new ServiceClientWithState(this, _delays);
            RemotingServices.Marshal(serviceClient, Shared.Shared.ParseUrl(URLparts.Link, myURL));

            /* get service */
            server = (IServiceServer)Activator.GetObject(
                typeof(IServiceServer),
                serverURL);
            try
            {
                _delays.SendWithDelay(_serverPId, (Action <string, string>)server.RegisterPlayer, new object[] { _pId, myURL });
            }
            catch
            {
                Console.WriteLine("Cant connect to server");
            }
        }
示例#10
0
        /// <summary>
        /// Service constructor
        /// </summary>
        public ImageService()
        {
            /*
             * InitializeComponent();
             * eventLog1 = new System.Diagnostics.EventLog();
             * eventLog1.Source = "ImageServiceSource";
             * eventLog1.Log = "ImageServiceLog";
             * this.logging = new LoggingService(eventLog1);
             * this.logging.MessageRecieved += WriteToEntry;
             */


            try
            {
                InitializeComponent();
                //read params from app config
                string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
                string logName         = ConfigurationManager.AppSettings.Get("LogName");
                eventLog1 = new System.Diagnostics.EventLog();
                if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
                {
                    System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
                }
                eventLog1.Source = eventSourceName;
                eventLog1.Log    = logName;
                //initialize members
                this.logging = new LoggingService(this.eventLog1);
                this.logging.MessageRecieved += WriteMessage;

                string OutputFolder  = ConfigurationManager.AppSettings.Get("OutputDir");
                int    ThumbnailSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"));

                this.modal = new ImageServiceModal(OutputFolder, ThumbnailSize);

                this.controller        = new ImageController(this.modal, this.logging);
                this.m_imageServer     = new ImageServer(controller, logging);
                this.controller.Server = m_imageServer;
                IClientHandler ch = new ClientHandler(controller, logging);
                imageServiceSrv = new ServiceServer(8000, logging, ch);
                ImageServer.NotifyAllHandlerRemoved += imageServiceSrv.Update;
                this.logging.UpdateLogEntries       += imageServiceSrv.Update;
                imageServiceSrv.Start();
            }
            catch (Exception e)
            {
                this.eventLog1.WriteEntry(e.ToString(), EventLogEntryType.Error);
            }
        }
示例#11
0
        public FuzzyMatcher(IServiceServer server) : base(server)
        {
            L.Trace(
                $"Opened server with bucket {server.BucketId} and data dir - {server.GetConfigProperty("DataDirectory",server.BucketId)}");

            connectionString = SqlTableWithPrimaryKey.GetConnectionString((string)server.GetConfigProperty("DataDirectory", server.BucketId),
                                                                          server.BucketId, "AmlWorker");
            L.Trace($"Initializing Sql - connectionString is {connectionString}");

            using (var connection = newConnection())
            {
                connection.Open();

                if (!SqlTableWithPrimaryKey.TableExists(connection, "FuzzyPhrase"))
                {
                    SqlTableWithPrimaryKey.ExecuteCommandLog(connection, FuzzyPhraseCreate);
                    SqlTableWithPrimaryKey.ExecuteCommandLog(connection, FuzzyTripleCreate);
                    SqlTableWithPrimaryKey.ExecuteCommandLog(connection, FuzzyPhraseToDocument);
                }
            }
        }
示例#12
0
        public AmlRepository(IServiceServer server) : base(server)
        {
            _sqlTableWithPrimaryKey = new SqlTableWithPrimaryKey();

            connectionString = _sqlTableWithPrimaryKey.GetConnectionString(
                (string)server.GetConfigProperty("DataDirectory", server.BucketId),
                server.BucketId, "AmlWorker");

            L.Trace($"Initializing Sql - connectionString is {connectionString}");

            using (var connection = _sqlTableWithPrimaryKey.NewConnection(connectionString))
            {
                if (!_sqlTableWithPrimaryKey.TableExists(connection, partySql))
                {
                    _sqlTableWithPrimaryKey.CreateTable(connection, partySql);
                }

                if (!_sqlTableWithPrimaryKey.TableExists(connection, accountSql))
                {
                    _sqlTableWithPrimaryKey.CreateTable(connection, accountSql);
                }

                if (!_sqlTableWithPrimaryKey.TableExists(connection, "AccountParty"))
                {
                    new SqlTableSimpleLinkages().CreateManyToManyLinkagesTableWithForeignKeyConstraint(connection, "AccountParty",
                                                                                                       "AccountId", "PartyId", "Accounts", "Id");
                }

                if (!_sqlTableWithPrimaryKey.TableExists(connection, "PartyAccount"))
                {
                    new SqlTableSimpleLinkages().CreateManyToManyLinkagesTable(connection, "PartyAccount", "PartyId", "AccountId");
                }

                if (!_sqlTableWithPrimaryKey.TableExists(connection, transactionSql))
                {
                    _sqlTableWithPrimaryKey.CreateTable(connection, transactionSql);
                }
            }
        }
示例#13
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 0;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);
            IServiceServer server = (IServiceServer)Activator.GetObject(typeof(IServiceServer), "tcp://localhost:55555/Conference");

            ClientController ctrl = new ClientController(server);
            //ParticipantForm win = new ParticipantForm(ctrl);
            LoginForm win = new LoginForm(ctrl);

            Application.Run(win);
        }
示例#14
0
 public ClientController(IServiceServer serviceServer)
 {
     this.serviceServer = serviceServer;
     user = null;
 }
示例#15
0
 protected FuzzyMatcherServer(IServiceServer server)
 {
     this.server             = server;
     this.server.OnReceived += OnReceived;
 }
示例#16
0
 protected A4ARepositoryServer(IServiceServer server)
 {
     this.server             = server;
     this.server.OnReceived += OnReceived;
 }
        void Init(string[] args)
        {
            Board           = new Obsticle();
            Board.Corner2.X = 320 + 10;
            Board.Corner2.Y = 280 + 10;
            Board.Corner1.X = 0;
            Board.Corner1.Y = 40;

            _pId = args[0];
            string myURL = args[1];
            int    mSec  = int.Parse(args[2]);

            _maxNumPlayers = int.Parse(args[3]);

            if (args.Length == 6 && args[4].Equals("secondary"))
            {
                PCSurl          = args[5];
                PCS             = (IServicePCS)Activator.GetObject(typeof(IServicePCS), PCSurl);
                _secondary      = true;
                waitFail        = GetGamePrimaryServer;
                _primary_server = (IServiceServer)Activator.GetObject(typeof(IServiceServer), myURL);
                _timer          = new System.Timers.Timer()
                {
                    AutoReset = true, Enabled = false, Interval = 3000
                };
                _timer.Elapsed += Timer_Elapsed_Secondary;
                _timer.Start();
                lock (this)
                {
                    Console.WriteLine("Secondary Server Mode : Waiting for primary server " + _pId + " to fail...");
                    Monitor.Wait(this);
                    //Console.WriteLine("_last size  = " + _last.Length);
                    Console.WriteLine("Primary Server Failed... Taking Control");
                    _game              = (Game)_last[0];
                    _clientsDict       = (Dictionary <string, IServiceClient>)_last[1];
                    _clientsList       = (List <Client>)_last[2];
                    _lastRoundReceived = (Dictionary <string, int>)_last[3];
                    _lastRoundSaved    = (Dictionary <string, int>)_last[4];
                    client_queue       = (Queue)_last[5];

                    // do this to unregister the channel
                    IChannel[] regChannels = ChannelServices.RegisteredChannels;
                    foreach (IChannel ch in regChannels)
                    {
                        Console.WriteLine("CHANNEL : " + ch.ChannelName);
                        if (ch.ChannelName.Equals("tcp"))
                        {
                            ChannelServices.UnregisterChannel(ch);
                        }
                    }
                }
                _timer.Stop();
                _timer.Close();
            }
            waitClients = WaitEnqueuedClients;
            _timer      = new System.Timers.Timer()
            {
                AutoReset = true, Enabled = false, Interval = mSec
            };
            _timer.Elapsed += Timer_Elapsed;
            if (_secondary)
            {
                Console.WriteLine("Starting...");
                _timer.Start();
            }
            waitClients.BeginInvoke(null, null);

            lock (this)
            {
                /* set channel */
                try
                {
                    channel = new TcpChannel(int.Parse(Shared.Shared.ParseUrl(URLparts.Port, myURL)));
                    ChannelServices.RegisterChannel(channel, false);
                    /*set service */
                    serviceServer = new ServiceServer(this, delays);
                    string link = Shared.Shared.ParseUrl(URLparts.Link, myURL);
                    Console.WriteLine("Starting server on " + myURL + ", link: " + link);
                    RemotingServices.Marshal(serviceServer, link);
                }
                catch
                {
                    Console.WriteLine("CATCH!!!! COULD NOT REGISTER SECONDARY SERVER, PRIMARY IS PROBABLY STILL RUNNING");
                }
            }
            if (_secondary)
            {
                string programArguments = _pId + " " + myURL + " " + mSec + " " + _maxNumPlayers;
                PCS.StartSecondaryServer(programArguments);
                _secondary = false;
            }
            while (true)
            {
                Console.ReadLine();
            }
        }