コード例 #1
0
        //Check if the classes we have available is of type
        public bool MobileDownload(int nMobileID, int nUserID)
        {
            //Webserver running?
            if (_isDisposed)
            {
                return(false);
            }

            try
            {
                _logger.Debug(this.GetType(), "openConnections lock in MobileDownload");

                // record the connection so we can close it if something goes wrong
                lock (_openConnections)
                {
                    //_openConnections.Add(service);
                    for (int i = 0; i < _openConnections.Count(); i++)
                    {
                        IService oService = (IService)_openConnections[i];
                        Type     tType    = oService.GetType();
                        if (tType.IsSubclassOf(typeof(WebSocketBase)))
                        {
                            IServiceWebsocket oServiceWS = (IServiceWebsocket)_openConnections[i];
                            if (oServiceWS.SendMobileDownload(nMobileID, nUserID))
                            {
                                _logger.Information(this.GetType(), "--> Command: MOBILEDOWNLOADCHECK (background)");
                                ArrayList aParameter = new ArrayList();
                                //aParameter.Add("This is a text to look for");
                                oServiceWS.SendCommand("MOBILEDOWNLOADCHECK", aParameter); //Ask mobile to check for downloads
                                return(true);
                            }
                        }
                        //else
                        //    _logger.Error(typeof(WebServer), "Not websocket... This error message should not happend");
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                // do nothing. This will be thrown if the Listener has been stopped
                _logger.Warning(this.GetType(), "Object is already disposed in MobileDownload...");
            }
            catch (Exception ex)
            {
                _logger.Error(this.GetType(), ex);
            }

            return(false);
        }
コード例 #2
0
        //Check if the classes we have available is of type
        public bool SendAllWebsockets(string sCommand, ArrayList aParameters)
        {
            //Webserver running?
            if (_isDisposed)
            {
                return(false);
            }

            try
            {
                _logger.Debug(this.GetType(), "openConnections lock in SendAllWebsockets");

                // record the connection so we can close it if something goes wrong
                lock (_openConnections)
                {
                    //_openConnections.Add(service);
                    for (int i = 0; i < _openConnections.Count(); i++)
                    {
                        IService oService = (IService)_openConnections[i];
                        Type     tType    = oService.GetType();
                        if (tType.IsSubclassOf(typeof(WebSocketBase)))
                        {
                            IServiceWebsocket oServiceWS = (IServiceWebsocket)_openConnections[i];
                            oServiceWS.SendCommand(sCommand, aParameters);
                        }
                        //else
                        //    _logger.Error(typeof(WebServer), "Not websocket... This error message should not happend");
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                // do nothing. This will be thrown if the Listener has been stopped
                _logger.Warning(this.GetType(), "Object is already disposed in SensAllWebsocket...");
            }
            catch (Exception ex)
            {
                _logger.Error(this.GetType(), ex);
            }

            return(true);
        }