/*public ProtokollerInstance()
        {
            ProtokollerConfiguration.Load(false);
            this.akConfig = ProtokollerConfiguration.ActualConfigInstance;            
        }*/

        public void Start(bool StartedAsService)
        {

            //Remoting Server für Benachrichtigung an Client das neue Daten da sind
            /*remotingServer = new RemotingServer();
            remotingServer.Start();*/

            if (akConfig.UseWebserver)
            {
                AspxVirtualRoot webServer = new AspxVirtualRoot(akConfig.WebserverPort);
                webServer.Configure("/", System.IO.Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "web"));
            }

            if (akConfig.UseWCFService)
            {
                var serverName = "ProtocolService";
                var addressWeb = new Uri("http://localhost:" + akConfig.WCFServicePort + "/");

                wcfWebService = new WebServiceHost(this /*.GetType()*/, new Uri[] { addressWeb });

                wcfWebService.AddServiceEndpoint(typeof(IProtocolService), new BasicHttpBinding(), serverName);
                wcfWebService.AddServiceEndpoint(typeof(IPolicyRetriever), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());

                wcfWebService.Open();
            }

            context = SynchronizationContext.Current;

            Logging.LogText("Protokoller gestartet", Logging.LogLevel.Information);
            EstablishConnections();
            OpenStoragesAndCreateTriggers(true, StartedAsService);

            synTimer = new Timer(synchronizePLCTimes, null, 0, 60000);            
        }
Exemplo n.º 2
0
        /**
         * This method will be called when a client/browser makes a request. We will pass on
         * required information to the hosting API from this method
         */
        private void ContextReceivedCallback(IAsyncResult asyncResult)
        {
            //Check if listener is listening other wise return
            if (!m_HttpListener.IsListening)
            {
                return;
            }

            //Get the context
            HttpListenerContext listenerContext = m_HttpListener.EndGetContext(asyncResult);

            //Lets get the Listener listening for the next request
            m_HttpListener.BeginGetContext(new AsyncCallback(ContextReceivedCallback), null);

            //If No AspNetEngine was configured, just respond with 404
            if (m_AspNetEngine == null)
            {
                listenerContext.Response.StatusCode = 404;
                listenerContext.Response.Close();
                return;
            }

            //Retrieve the URL requested
            String pageRequested = listenerContext.Request.Url.LocalPath;

            //Remove the "/alias"  from the begining page request as we just need to
            //pass the file and the query out to the Application Host
            pageRequested = AspxVirtualRoot.RemoveAliasFromRequest(pageRequested, m_AspNetEngine.VirtualAlias);

            //Prepare the DataHolder object that will be passed on for processing
            AspxRequestInfo dataHolder = AspxNetEngine.PrepareAspxRequestInfoObject(listenerContext);;

            //Look for Client Certificate if it has any
            if (listenerContext.Request.IsSecureConnection)
            {
                dataHolder.m_ClientCertificate = listenerContext.Request.GetClientCertificate();
                Console.WriteLine("Client certificate received.");
            }

            try
            {
                //Pass the request to the Hosted application
                m_AspNetEngine.ExecutingAppDomain.ProcessRequest(pageRequested, listenerContext.Request.Url.Query.Replace("?", ""), dataHolder);
            }
            catch (AspxException aspxException)
            {
                //Error occured.Log it and move on
                Console.WriteLine(aspxException);
            }

            Console.WriteLine(listenerContext.Request.Url.LocalPath + "...   " +
                              listenerContext.Response.StatusCode + " " + listenerContext.Response.StatusDescription);

            //Finally close the response or else the client will time out
            listenerContext.Response.Close();
        }
        public void Dispose()
        {
            Logging.LogText("Protokoller gestopt", Logging.LogLevel.Information);
            if (myReEstablishConnectionsThreads != null)
                foreach (var myReEstablishConnectionsThread in myReEstablishConnectionsThreads)
                {
                    myReEstablishConnectionsThread.Abort();
                }

            if (webServer != null)
            {
                webServer.StopListener();
                webServer.Dispose();
                webServer = null;
            }

            if (wcfWebService != null)
            {
                wcfWebService.Close();
                wcfWebService = null;
            }

            foreach (var disposable in myDisposables)
            {
                disposable.Dispose();
            }

            foreach (object conn in ConnectionList.Values)
            {
                if (conn is PLCConnection)
                    ((PLCConnection)conn).Dispose();
                else if (conn is TCPFunctionsAsync)
                    ((TCPFunctionsAsync)conn).Dispose();
            }

            foreach (IDBInterface dbInterface in DatabaseInterfaces.Values)
            {
                dbInterface.Close();
            }

            if (synTimer != null)
                synTimer.Dispose();
        }