Example #1
0
 private void RemoveEventHandlerNotifications(IServiceHandler serviceHandler)
 {
     serviceHandler.ReadCompleteNotification  -= ReadCompleteNotification;
     serviceHandler.WriteCompleteNotification -= WriteCompleteNotification;
     serviceHandler.CloseEventNotification    -= CloseEventNotification;
     serviceHandler.ErrorNotification         -= ErrorNotification;
 }
Example #2
0
 private void SetupEventHandlerNotifications(IServiceHandler serviceHandler)
 {
     serviceHandler.ReadCompleteNotification  += ReadCompleteNotification;
     serviceHandler.WriteCompleteNotification += WriteCompleteNotification;
     serviceHandler.CloseEventNotification    += CloseEventNotification;
     serviceHandler.ErrorNotification         += ErrorNotification;
 }
        /**
         * 初始化Handler实例
         * @throws EisException
         */
        private void initHandler()
        {
            String className = config.getProperty(ConfigConstants.PROVIDER_HANDLER_CLASSNAME);

            try {
                if (handler == null)
                {
                    //动态创建此类对象下面这样写就行了
                    //Type t = Type.GetType(“TestSpace.TestClass”);
                    //Object[] constructParms = new object[] {“hello”}; //构造器参数
                    //TestClass obj = (TestClass)Activator.CreateInstance(t,constructParms);

                    //如果类的构造器是无参数的,就调用这个
                    //TestClass obj = (TestClass)Activator.CreateInstance(t);


                    Type t = Type.GetType(className);
                    this.handler = (IServiceHandler)Activator.CreateInstance(t);


                    //this.handler = (IServiceHandler)Class.forName(className).newInstance();
                }
            } catch (Exception e) {
                StringBuilder sb = new StringBuilder().Append("class(").Append(className).Append(") initialization failed!");
                LogUtil.Error(sb.ToString(), e);
                sb = null;
                throw new EisException(e);
            }
        }
 public void setServiceHandler(IServiceHandler serviceHandler)
 {
     if (this.handler == null)
     {
         this.handler = serviceHandler;
     }
 }
Example #5
0
        private void Open(UdpTestType testType, EndPoint bindEndPoint, EndPoint connectEndPoint)
        {
            switch (testType)
            {
            case UdpTestType.BROADCAST:
            {
                serviceHandler = new UdpBroadcast_ServiceHandler(this.reactor, bindEndPoint, connectEndPoint);
                break;
            }

            case UdpTestType.MULTICAST:
            {
                serviceHandler = new UdpMulticast_ServiceHandler(this.reactor, bindEndPoint, connectEndPoint, false, 4);
                break;
            }

            case UdpTestType.P2P:
            {
                serviceHandler = new UdpP2P_ServiceHandler(this.reactor, bindEndPoint, connectEndPoint);
                break;
            }

            default:
                break;
            }

            SetupEventHandlerNotifications(serviceHandler);
            serviceHandler.Open();
        }
Example #6
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         IserviceHandler = new ServiceHandler();
         if (validateAddress() && validateContactDetails() && validateClientDetails())
         {
             ClientDetail clientDetails = new ClientDetail
             {
                 IdNumber = long.Parse(txtIdNumber.Text),
                 Name     = txtName.Text,
                 Gender   = cmbGender.Text,
                 Surname  = txtSurname.Text,
                 Id       = Guid.NewGuid()
             };
             var saved = IserviceHandler.SaveClientData(clientDetails);
             if (saved)
             {
                 _ClientId = clientDetails.Id;
                 SaveAddressDetails(clientDetails.Id);
                 SaveContactDetails(clientDetails.Id);
             }
         }
         else
         {
             MessageBox.Show("All fields are required!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception ex)
     {
         _rttLogger.WriteToLog(LogType.Fatal, ex.Message);
         throw;
     }
 }
Example #7
0
        public Login(IServiceHandler serviceHandler, User maybeAUser)
        {
            InitializeComponent();

            userToLogin   = maybeAUser;
            userManager   = serviceHandler.GetUserManagementService();
            loggerService = serviceHandler.GetLoggingService();
        }
        public BaseController()
        {
            serviceHandler = ServiceFactory.ServiceFactory.GetImplementation();

            sessionHandler        = serviceHandler.GetSessionService();
            authenticationService = serviceHandler.GetAuthenticationService();
            userManagementService = serviceHandler.GetUserManagementService();
        }
Example #9
0
        private void ReadCompleteNotification(IServiceHandler serviceHandler)
        {
            var str = System.Text.Encoding.UTF8.GetString(serviceHandler.ReadData);

            log.InfoFormat("Message from {0} : {1} --- {2}", ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(),
                           ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(), str);
            socketEvent?.Invoke(SocketEventType.ReadCompleteEvent);
        }
Example #10
0
 public static ServiceProvider getInstance(IServiceHandler serviceHandler)
 {
     if (sp == null)
     {
         sp = new ServiceProvider(serviceHandler);
     }
     return(sp);
 }
Example #11
0
 private void CloseEventNotification(IServiceHandler serviceHandler)
 {
     log.InfoFormat("Connection to {0} : {1} closed and removed from connector list.",
                    ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(),
                    ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString());
     RemoveEventHandlerNotifications(serviceHandler);
     connectionList.Remove(serviceHandler);
     socketEvent?.Invoke(SocketEventType.CloseEvent);
 }
Example #12
0
        private void ReadCompleteNotification(IServiceHandler serviceHandler)
        {
            //             byte[] dataType = new byte[4];
            //             byte[] data = new byte[serviceHandler.ReadData.Length - 4];
            //             Buffer.BlockCopy(serviceHandler.ReadData, 0, dataType, 0, 4);
            //             Buffer.BlockCopy(serviceHandler.ReadData, 4, data, 0, serviceHandler.ReadData.Length - 4);
            //             var integer_serializer = MessagePackSerializer.Get<int>(); // added msg pack deserialiser
            //             var deserializedDataType = integer_serializer.UnpackSingleObject(dataType);
            //             switch(deserializedDataType)
            //             {
            //                 case 0:
            //                     var clock_serializer = MessagePackSerializer.Get<double>();
            //                     break;
            //                 case 1:
            //                     var date_serializer = MessagePackSerializer.Get<Array<int, 6>>();
            //                     break;
            //                 default:
            //                     break;
            //             }

            var rawObject = Unpacking.UnpackObject(serviceHandler.ReadData);

            if (rawObject.Value.IsArray)
            {
                log.InfoFormat("Is Array ? {0}", rawObject.Value.IsArray);
                var        arrayObject = rawObject.Value.AsList();
                List <int> dateList    = new List <int>();
                foreach (var obj in arrayObject)
                {
                    dateList.Add(obj.AsInt32());
//                     log.InfoFormat("Container at {0} is of type {1}",
//                         arrayObject.IndexOf(obj),
//                         obj.UnderlyingType);
                }

                string listAsString = string.Join(", ", dateList.ToArray());
                log.InfoFormat("Array contains [{0}]", listAsString);
            }
            else if (rawObject.Value.UnderlyingType == typeof(double))
            {
                var double_serializer = MessagePackSerializer.Get <double>();
                var deserialized      = double_serializer.UnpackSingleObject(serviceHandler.ReadData);
                log.InfoFormat("Message received on {0} : {1} --- {2}  : Type is {3}",
                               ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(),
                               ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(),
                               deserialized,
                               rawObject.Value.UnderlyingType);
            }


            //log.InfoFormat("Message received on {0} : {1} --- {2}", ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(),
            //                                                    ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(), deserialized);
            //var str = System.Text.Encoding.UTF8.GetString(serviceHandler.ReadData);
//             log.InfoFormat("Message received on {0} : {1} --- {2}", ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(),
//                                                                 ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(), str);
            socketEvent?.Invoke(SocketEventType.ReadCompleteEvent);
        }
Example #13
0
        static void Main()
        {
            IServiceHandler serviceHandler = ServiceFactory.ServiceFactory.GetImplementation();


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(MainMenu.CreateInstance(serviceHandler));
        }
 public ImporterControl(IServiceHandler serviceHandler, User loggedUser)
 {
     InitializeComponent();
     formatService     = serviceHandler.GetFormatManagementService();
     styleClassService = serviceHandler.GetStyleClassManagementService();
     styleService      = serviceHandler.GetStyleManagementService();
     loggerService     = serviceHandler.GetLoggingService();
     importingUser     = loggedUser;
 }
        private MainMenu(IServiceHandler aServiceHandler)
        {
            InitializeComponent();
            loggedUser     = new User();
            serviceHandler = aServiceHandler;

            HideAllMenus();
            DisplayLogin();
        }
Example #16
0
 private void ErrorNotification(IServiceHandler serviceHandler, Exception ex)
 {
     log.InfoFormat("Connection to {0} : {1} closed due to error: {2}",
                    ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(),
                    ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(),
                    ex.Message);
     RemoveEventHandlerNotifications(serviceHandler);
     socketEvent?.Invoke(SocketEventType.CloseEvent);
 }
        private void AcceptNotification()
        {
            IServiceHandler connection = acceptor.ServiceHandler;

            SetupEventHandlerNotifications(connection);
            connectionList.Add(connection);
            log.InfoFormat("Connection to {0} : {1} added to acceptor list.",
                           ((IPEndPoint)connection.RemoteURI).Address.ToString(),
                           ((IPEndPoint)connection.RemoteURI).Port.ToString());
            socketEvent?.Invoke(SocketEventType.AcceptEvent);
        }
Example #18
0
 public static IServiceProvider getInstance(IServiceHandler serviceHandler, String alt)
 {
     lock (syncRoot)
     {
         if (null == provider)
         {
             provider = new BaseServiceProvider(serviceHandler, alt);
         }
     }
     return(provider);
 }
Example #19
0
 private static void EnsureQueue(IServiceHandler handler)
 {
     if (!_registeredHandlerUrls.ContainsKey(handler.QueueName))
     {
         var createQueueRequest = new CreateQueueRequest();
         createQueueRequest.QueueName = handler.QueueName;
         var createQueueResponse = SqsClient.CreateQueue(createQueueRequest);
         var queueUrl            = createQueueResponse.CreateQueueResult.QueueUrl;
         _registeredHandlerUrls[handler.QueueName] = queueUrl;
     }
     handler.QueueUrl = _registeredHandlerUrls[handler.QueueName];
 }
Example #20
0
 private static void EnsureQueue(IServiceHandler handler)
 {
     if (!_registeredHandlerUrls.ContainsKey(handler.QueueName))
     {
         var createQueueRequest = new CreateQueueRequest();
         createQueueRequest.QueueName = handler.QueueName;
         var createQueueResponse = SqsClient.CreateQueue(createQueueRequest);
         var queueUrl = createQueueResponse.CreateQueueResult.QueueUrl;
         _registeredHandlerUrls[handler.QueueName] = queueUrl;
     }
     handler.QueueUrl = _registeredHandlerUrls[handler.QueueName];
 }
        public ManageFormats(IServiceHandler serviceHandler, User loggedUser)
        {
            InitializeComponent();

            formatManager     = serviceHandler.GetFormatManagementService();
            styleClassManager = serviceHandler.GetStyleClassManagementService();
            styleManager      = serviceHandler.GetStyleManagementService();

            administrator = loggedUser;

            LoadFormatsAndStyleClasses();
        }
Example #22
0
 private void ConnectNotification(IServiceHandler serviceHandler, ConnectionResult result)
 {
     serviceHandler.ConnectionNotification -= ConnectNotification;
     if (result == ConnectionResult.SUCCESS)
     {
         SetupEventHandlerNotifications(serviceHandler);
         connectionList.Add(serviceHandler);
         socketEvent?.Invoke(SocketEventType.ConnectionEvent);
     }
     else
     {
         socketEvent?.Invoke(SocketEventType.ConnectionError);
     }
 }
Example #23
0
 public void GetAllClients()
 {
     try
     {
         IserviceHandler = new ServiceHandler();
         var clients = IserviceHandler.GetAllClients();
         dgvClients.DataSource  = clients;
         tcClient.SelectedIndex = 1;
     }
     catch (Exception ex)
     {
         _rttLogger.WriteToLog(LogType.Fatal, ex.Message);
         throw;
     }
 }
 private void ActivateServiceHandler(IServiceHandler serviceHandler)
 {
     if (serviceHandler.Handle.UserSocket.Connected)
     {
         log.Info("ServiceHandler connected.");
         serviceHandler.Open();
         AcceptNotification?.Invoke();
     }
     else
     {
         log.Warn("ServiceHandler not connected.");
         serviceHandler.Dispose();
         serviceHandler = null;
     }
 }
Example #25
0
        public void StartListening(object state)
        {
            _handler = state as IServiceHandler;

            if (_handler != null)
            {
                _sqsClient = AwsFacade.GetSqsClient();

                Console.WriteLine("*");
                Console.WriteLine("Listening for messages on Queue: {0} with URL: {1}", _handler.QueueName, _handler.QueueUrl);
                Console.WriteLine("*");

                while (true)
                {
                    ReceiveMessage();
                    Thread.Sleep(ReceiveMessageWaitMilliseconds);
                }
            }
        }
        public void StartListening(object state)
        {
            _handler = state as IServiceHandler;

            if (_handler != null)
            {
                _sqsClient = AwsFacade.GetSqsClient();

                Console.WriteLine("*");
                Console.WriteLine("Listening for messages on Queue: {0} with URL: {1}", _handler.QueueName, _handler.QueueUrl);
                Console.WriteLine("*");

                while (true)
                {
                    ReceiveMessage();
                    Thread.Sleep(ReceiveMessageWaitMilliseconds);
                }
            }
        }
Example #27
0
        private ServiceProvider(IServiceHandler serviceHandler)
        {
            //加入主MQ队列管理器监控
            ProviderList.Add(new BaseServiceProvider(serviceHandler));

            //加入备份MQ队列管理器监控
            Properties config    = CacheManager.getInstance().getConfig();
            String     AltConfig = config.getProperty(ConfigConstants.ALTERNATIVE_PROVIDER_CONFIG);

            if (AltConfig != null && !"".Equals(AltConfig.Trim()))
            {
                String[] alts = AltConfig.Split(char.Parse(ConfigConstants.ALTERNATIVE_CONFIG_SPLIT));
                foreach (String alt in alts)
                {
                    ProviderList.Add(new BaseServiceProvider(serviceHandler, alt));
                }
            }

            init();
        }
Example #28
0
 public void SaveContactDetails(Guid clientId)
 {
     try
     {
         IserviceHandler = new ServiceHandler();
         ContactDetails details = new ContactDetails
         {
             ClientId = clientId,
             Number   = txtNumber.Text,
             Type     = cmbType.Text
         };
         var savedContactDetails = IserviceHandler.SaveContactData(details);
         bindGrid();
     }
     catch (Exception ex)
     {
         _rttLogger.WriteToLog(LogType.Fatal, ex.Message);
         throw;
     }
 }
 protected virtual void Complete(IServiceHandler handler, ConnectionResult result)
 {
     if (connectionMap.ContainsKey(handler.Handle))
     {
         IServiceHandler serviceHandler = connectionMap[handler.Handle];
         reactor.RemoveHandler(serviceHandler, EventType.CONNECT_EVENT);
         serviceHandler.ConnectionNotification -= Complete;
         connectionMap.Remove(handler.Handle);
         if (result == ConnectionResult.SUCCESS)
         {
             log.Info("Socket Address {0} connected. Removed from Reactor and Connection map", ((IPEndPoint)handler.Handle.RemoteEndPoint).ToString());
             ActivateServiceHandler(serviceHandler);
         }
         else
         {
             this.Dispose();
         }
     }
     else
     {
         log.Warn("Connection map does not contain handle for address {0}", ((IPEndPoint)handler.Handle.RemoteEndPoint).ToString());
     }
 }
 protected virtual void ConnectServiceHandler(IServiceHandler serviceHandler,
                                              EndPoint remoteAddress, Connection_Mode mode)
 {
     try
     {
         serviceHandler.Handle.Connect(remoteAddress);
         ActivateServiceHandler(serviceHandler);
     }
     catch (SocketException ex)
     {
         if (ex.SocketErrorCode == SocketError.WouldBlock && mode == Connection_Mode.ASYNC)
         {
             reactor.RegisterHandler(serviceHandler, EventType.CONNECT_EVENT);
             serviceHandler.ConnectionNotification += Complete;
             connectionMap[serviceHandler.Handle]   = serviceHandler;
         }
         else
         {
             log.Error(ex, String.Format("Connector Socket Error has occurred with WSAError - {0}", ex.SocketErrorCode.ToString()));
             serviceHandler?.Dispose();
         }
     }
 }
Example #31
0
 public void SaveAddressDetails(Guid clientId)
 {
     try
     {
         IserviceHandler = new ServiceHandler();
         AddressDetails details = new AddressDetails
         {
             StreetAddressLine1 = txtStreetAddress.Text,
             PostalCode         = txtPostalCode.Text,
             City               = txtCity.Text,
             Province           = cmbProvince.Text,
             ClientId           = clientId,
             StreetAddressLine2 = txtSurburb.Text
         };
         var savedAddressDetails = IserviceHandler.SaveAddressData(details);
         bindGrid();
     }
     catch (Exception ex)
     {
         _rttLogger.WriteToLog(LogType.Fatal, ex.Message);
         throw;
     }
 }
Example #32
0
        /// <summary>
        /// handles a request to the service server
        /// </summary>
        /// <param name="context">http context</param>
        protected override void HandleRequest(HttpListenerContext context)
        {
            string path = HttpExtensions.GetRelativePath(context.Request.Url.AbsoluteUri, Prefixes);

            if (!ignorelogginpaths.Contains(path))
            {
                OnRequestPath(path, context.Request?.RemoteEndPoint?.ToString());
            }

            if (ProcessRequest(context, path))
            {
                return;
            }

            if (context.Request.HttpMethod == "OPTIONS")
            {
                OnResponse(context, default(T));
            }
            else
            {
                IServiceHandler <T> handler = GetService(path);
                if (handler == null)
                {
                    throw new ServiceServerException($"Service handler for '{path}' not found");
                }

                T response;
                try {
                    response = handler.HandleRequest(context);
                }
                catch (Exception e) {
                    throw new ServiceServerException("Error handling request", e);
                }
                OnResponse(context, response);
            }
        }
Example #33
0
 public TimerHost(IServiceHandler serviceHandler)
 {
     this.serviceHandler = serviceHandler;
 }
Example #34
0
 private static void ListenForMessages(IServiceHandler handler)
 {
     var listener = new MessageListener();
     ThreadPool.QueueUserWorkItem(new WaitCallback(listener.StartListening), handler);
 }
Example #35
0
 public TimerHost(double interval, IServiceHandler serviceHandler)
     : base(interval)
 {
     this.serviceHandler = serviceHandler;
 }
Example #36
0
 public DataExtract(IEnvironmentHandler envHandler, IIisHandler iisHandler, IServiceHandler serHandler)
 {
     this.envHandler = envHandler;
     this.iisHandler = iisHandler;
     this.serHandler = serHandler;
 }
Example #37
0
 public ScheduleHost(double interval, DateTime startTime, DateIntervalType intervalType, int intervalValue, ILogService logService, IServiceHandler serviceHandler)
     : base(interval, startTime, intervalType, intervalValue, logService)
 {
     this.serviceHandler = serviceHandler;
 }