コード例 #1
0
        public void RunHosts()
        {
            // You get one shot at startup.
            Udbus.v4v.v4vConnection connection = TryV4VConnection(Log_io_debug);

            if (connection == null) // If failed to connect to V4V
            {
                // Continue attempting to setup in another thread.
                this.log.Warning("Failed to connect to V4V. Continuing to establish V4V connection in another thread");
                RunHostsInAnotherThread();
            }    // Ends if failed to connect to V4V
            else // Else connected to V4V
            {
                // Try setting up the service connection.
                Udbus.Core.ServiceConnectionParams serviceConnectionParams = TryServiceConnectionParams(connection);

                if (serviceConnectionParams == null) // If failed to set up service connection
                {
                    RunHostsInAnotherThread();
                }    // Ends if failed to set up service connection
                else // Else setup service connection
                {
                    FinishRunHosts(connection, serviceConnectionParams);
                } // Ends else setup service connection
            }     // Ends else connected to V4V
        }
コード例 #2
0
 private void InitFields()
 {
     this.connection = null;
     this.serviceConnectionParams = null;
     this.threadInfo       = default(DbusUtils.VisitorThreadInfo);
     this.threadSignalLoop = null;
     this.hosts            = null;
 }
コード例 #3
0
        private void RunHostsThread()
        {
            log.Info("Setting up running hosts in another thread");
            Udbus.v4v.v4vConnection            connection = null;
            Udbus.Core.ServiceConnectionParams serviceConnectionParams = null;
            DbusHosts.GetV4vConnection(out connection, out serviceConnectionParams, Log_io_debug, this.eventStop, log);

            log.Info("Established service connection");
            FinishRunHosts(connection, serviceConnectionParams);
            log.Info("Finished setting up running hosts in another thread");
        }
コード例 #4
0
        static private Udbus.v4v.v4vConnection KeepTryingToConnectToV4V(Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, System.Threading.ManualResetEvent stop, Udbus.Core.Logging.ILog log)
        {
            Udbus.v4v.v4vConnection connection = TryV4VConnection(io_debug, log);

            while (connection == null && stop.WaitOne(0) == false)
            {
                System.Threading.Thread.Sleep(ConnectionWaitMilliseconds);
                connection = TryV4VConnection(io_debug, log);
            } // Ends while failed to connect to V4V

            return(connection);
        }
コード例 #5
0
        public void StopHosts()
        {
            try
            {
                log.Info("Stopping signals thread...");
                if (this.threadInfo.stop != null)
                {
                    this.threadInfo.stop.Set();
                }

                if (this.serviceConnectionParams != null)
                {
                    Udbus.Core.IStoppable stoppableSignalVisitor = this.serviceConnectionParams.SignalVisitor;
                    stoppableSignalVisitor.Stop = true;
                    this.serviceConnectionParams.SignalConnection.Cancel();
                }

                log.Info("Stopping signals");
                if (this.threadSignalLoop != null)
                {
                    this.threadSignalLoop.Join();
                }
                log.Info("Stopped signals");

                log.Info("Closing hosts...");
                if (this.hosts != null)
                {
                    foreach (System.ServiceModel.ServiceHost host in hosts)
                    {
                        host.Close();
                    }
                }
                log.Info("Disposing hosts...");
            }
            finally
            {
                Udbus.v4v.v4vConnection connectionDispose = this.connection;
                this.InitFields();
                if (connectionDispose != null)
                {
                    log.Info("Disposing connection");
                    connectionDispose.Dispose();
                    log.Info("Disposed connection");
                }
                else
                {
                    log.Info("No connection to dispose");
                }
            }
        }
コード例 #6
0
ファイル: DbusHosts.cs プロジェクト: rneilturner/win-tools
        public static void GetV4vConnection(out Udbus.v4v.v4vConnection connection, out Udbus.Core.ServiceConnectionParams serviceConnectionParams,
            Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, System.Threading.ManualResetEvent stop,
            Udbus.Core.Logging.ILog log)
        {
            connection = null;
            serviceConnectionParams = null;

            while (serviceConnectionParams == null)
            {
                using (Udbus.v4v.v4vConnection connectionTemp = KeepTryingToConnectToV4V(io_debug, stop, log))
                {
                    if (connectionTemp != null) // If got v4v connection
                    {
                        Udbus.v4v.v4vConnection connectionTemp2 = connectionTemp.Release();
                        try
                        {
                            Udbus.Core.ServiceConnectionParams serviceConnectionParamsTemp = TryServiceConnectionParams(connectionTemp2, log);

                            if (serviceConnectionParamsTemp == null) // If failed to create service connection
                            {
                                connectionTemp.Swap(connectionTemp2);

                            } // Ends if failed to create service connection
                            else // Else created service connection
                            {
                                serviceConnectionParams = serviceConnectionParamsTemp;
                                connection = connectionTemp2;

                            } // Ends else created service connection
                        }
                        catch (Exception /*ex*/)
                        {
                            connectionTemp.Swap(connectionTemp2);
                            throw;
                        }

                    } // Ends if got v4v connection
                } // Ends using v4vConnection

                if (serviceConnectionParams == null) // If failed to create connection
                {
                    // Wait a while.
                    System.Threading.Thread.Sleep(ConnectionWaitMilliseconds);

                } // Ends if failed to create connection
            } // Ends while trying to setup service connection
        }
コード例 #7
0
        public static void GetV4vConnection(out Udbus.v4v.v4vConnection connection, out Udbus.Core.ServiceConnectionParams serviceConnectionParams,
                                            Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, System.Threading.ManualResetEvent stop,
                                            Udbus.Core.Logging.ILog log)
        {
            connection = null;
            serviceConnectionParams = null;

            while (serviceConnectionParams == null)
            {
                using (Udbus.v4v.v4vConnection connectionTemp = KeepTryingToConnectToV4V(io_debug, stop, log))
                {
                    if (connectionTemp != null) // If got v4v connection
                    {
                        Udbus.v4v.v4vConnection connectionTemp2 = connectionTemp.Release();
                        try
                        {
                            Udbus.Core.ServiceConnectionParams serviceConnectionParamsTemp = TryServiceConnectionParams(connectionTemp2, log);

                            if (serviceConnectionParamsTemp == null) // If failed to create service connection
                            {
                                connectionTemp.Swap(connectionTemp2);
                            }    // Ends if failed to create service connection
                            else // Else created service connection
                            {
                                serviceConnectionParams = serviceConnectionParamsTemp;
                                connection = connectionTemp2;
                            } // Ends else created service connection
                        }
                        catch (Exception /*ex*/)
                        {
                            connectionTemp.Swap(connectionTemp2);
                            throw;
                        }
                    } // Ends if got v4v connection
                }     // Ends using v4vConnection

                if (serviceConnectionParams == null) // If failed to create connection
                {
                    // Wait a while.
                    System.Threading.Thread.Sleep(ConnectionWaitMilliseconds);
                } // Ends if failed to create connection
            }     // Ends while trying to setup service connection
        }
コード例 #8
0
        static private Udbus.Core.ServiceConnectionParams TryServiceConnectionParams(Udbus.v4v.v4vConnection connection, Udbus.Core.Logging.ILog log)
        {
            Udbus.Core.ServiceConnectionParams result = null;

            try
            {
                Udbus.Core.ServiceConnectionParams create = new Udbus.Core.ServiceConnectionParams(connection);
                result = create;
            }
            catch (Udbus.Serialization.Exceptions.UdbusAuthorisationException authex)
            {
                log.Exception("Authorisation Error creating ServiceConnectionParams. {0}", authex);
            }
            catch (Exception ex)
            {
                log.Exception("Error creating ServiceConnectionParams. {0}", ex);
            }
            return(result);
        }
コード例 #9
0
        static private Udbus.v4v.v4vConnection TryV4VConnection(Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, Udbus.Core.Logging.ILog log)
        {
            Udbus.v4v.v4vConnection result = null;

            try
            {
                Udbus.v4v.v4vConnection create = new Udbus.v4v.v4vConnection(io_debug);
                result = create;
            }
            catch (Udbus.Serialization.Exceptions.TransportFailureException transportEx)
            {
                log.Exception("Failed to create V4V transport. {0}", transportEx);
            }
            catch (Exception ex)
            {
                log.Exception("Error creating V4V transport. {0}", ex);
            }

            return(result);
        }
コード例 #10
0
        private void FinishRunHosts(Udbus.v4v.v4vConnection connection, Udbus.Core.ServiceConnectionParams serviceConnectionParams)
        {
            this.connection = connection;
            this.serviceConnectionParams = serviceConnectionParams;

            log.Info("Connection helloed with name {0} and signalName {1}", serviceConnectionParams.Name, serviceConnectionParams.SignalName);
            System.Uri uriBase = new System.Uri(Udbus.WCF.Constants.BaseAddress);

            new Udbus.WCF.Service.Host.Init.InitHostMakerRegistry();
            new global::XenClientGuestService.wcf.Hosts.Init.InitHostMakerRegistry();
            Udbus.WCF.Service.Host.RegistryDictionaryHolder registry = Udbus.WCF.Service.Host.HostMakerRegistry.RegistryDictionaryClone;

            log.Info("Launching hosts...");

            // Build all hosts including "special" properties host.
            ICollection <Udbus.WCF.Service.Host.ServiceHostCreationData> hostdata = Udbus.WCF.Service.Host.HostMakerRegistry.BuildAllHosts(
                registry.Values
                , new Udbus.WCF.Host.WCFServiceParams(serviceConnectionParams)
                , new Uri[] { uriBase }
                );

            System.ServiceModel.NetNamedPipeBinding namedpipeBinding = new System.ServiceModel.NetNamedPipeBinding();
            System.ServiceModel.Channels.Binding    binding          = namedpipeBinding;
            binding.SendTimeout    = TimeSpan.MaxValue;
            binding.ReceiveTimeout = TimeSpan.MaxValue;

            foreach (Udbus.WCF.Service.Host.ServiceHostCreationData host in hostdata)
            {
                host.Host.AddServiceEndpoint(host.CreationParams.ContractType, binding, host.CreationParams.RelativeName);
            }

            this.hosts = hostdata.Select <Udbus.WCF.Service.Host.ServiceHostCreationData, System.ServiceModel.ServiceHost>(Udbus.WCF.Service.Host.ServiceHostCreationData.DataToHost);
            DbusUtils.RunHosts(hosts);

            this.threadInfo = RunSignalsAsync(out this.threadSignalLoop, serviceConnectionParams);
        }
コード例 #11
0
ファイル: DbusHosts.cs プロジェクト: rneilturner/win-tools
        private static Udbus.v4v.v4vConnection TryV4VConnection(Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, Udbus.Core.Logging.ILog log)
        {
            Udbus.v4v.v4vConnection result = null;

            try
            {
                Udbus.v4v.v4vConnection create = new Udbus.v4v.v4vConnection(io_debug);
                result = create;
            }
            catch (Udbus.Serialization.Exceptions.TransportFailureException transportEx)
            {
                log.Exception("Failed to create V4V transport. {0}", transportEx);
            }
            catch (Exception ex)
            {
                log.Exception("Error creating V4V transport. {0}", ex);
            }

            return result;
        }
コード例 #12
0
 static void Testv4vGetProperty()
 {
     using (Udbus.v4v.v4vConnection connection = new Udbus.v4v.v4vConnection(Console_io_debug))
     {
         TestDbusGetProperty(connection);
         Console.WriteLine("About to Dispose");
     }
     Console.WriteLine("Press <ENTER> to end connection");
     Console.ReadLine();
 }
コード例 #13
0
 static void Testv4v()
 {
     using (Udbus.v4v.v4vConnection connection = new Udbus.v4v.v4vConnection(Console_io_debug))
     {
         TestDbusCalls(connection);
         Console.WriteLine("About to Dispose");
     }
 }
コード例 #14
0
ファイル: DbusHosts.cs プロジェクト: rneilturner/win-tools
 private void InitFields()
 {
     this.connection = null;
     this.serviceConnectionParams = null;
     this.threadInfo = default(DbusUtils.VisitorThreadInfo);
     this.threadSignalLoop = null;
     this.hosts = null;
 }
コード例 #15
0
ファイル: DbusHosts.cs プロジェクト: rneilturner/win-tools
        private void FinishRunHosts(Udbus.v4v.v4vConnection connection, Udbus.Core.ServiceConnectionParams serviceConnectionParams)
        {
            this.connection = connection;
            this.serviceConnectionParams = serviceConnectionParams;

            log.Info("Connection helloed with name {0} and signalName {1}", serviceConnectionParams.Name, serviceConnectionParams.SignalName);
            System.Uri uriBase = new System.Uri(Udbus.WCF.Constants.BaseAddress);

            new Udbus.WCF.Service.Host.Init.InitHostMakerRegistry();
            new global::XenClientGuestService.wcf.Hosts.Init.InitHostMakerRegistry();
            Udbus.WCF.Service.Host.RegistryDictionaryHolder registry = Udbus.WCF.Service.Host.HostMakerRegistry.RegistryDictionaryClone;

            log.Info("Launching hosts...");

            // Build all hosts including "special" properties host.
            ICollection<Udbus.WCF.Service.Host.ServiceHostCreationData> hostdata = Udbus.WCF.Service.Host.HostMakerRegistry.BuildAllHosts(
                registry.Values
                , new Udbus.WCF.Host.WCFServiceParams(serviceConnectionParams)
                , new Uri[] { uriBase }
            );

            System.ServiceModel.NetNamedPipeBinding namedpipeBinding = new System.ServiceModel.NetNamedPipeBinding();
            System.ServiceModel.Channels.Binding binding = namedpipeBinding;
            binding.SendTimeout = TimeSpan.MaxValue;
            binding.ReceiveTimeout = TimeSpan.MaxValue;

            foreach (Udbus.WCF.Service.Host.ServiceHostCreationData host in hostdata)
            {
                host.Host.AddServiceEndpoint(host.CreationParams.ContractType, binding, host.CreationParams.RelativeName);
            }

            this.hosts = hostdata.Select<Udbus.WCF.Service.Host.ServiceHostCreationData, System.ServiceModel.ServiceHost>(Udbus.WCF.Service.Host.ServiceHostCreationData.DataToHost);
            DbusUtils.RunHosts(hosts);

            this.threadInfo = RunSignalsAsync(out this.threadSignalLoop, serviceConnectionParams);
        }
コード例 #16
0
 private Udbus.Core.ServiceConnectionParams TryServiceConnectionParams(Udbus.v4v.v4vConnection connection)
 {
     return(TryServiceConnectionParams(connection, this.log));
 }
コード例 #17
0
ファイル: DbusHosts.cs プロジェクト: rneilturner/win-tools
        private static Udbus.v4v.v4vConnection KeepTryingToConnectToV4V(Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, System.Threading.ManualResetEvent stop, Udbus.Core.Logging.ILog log)
        {
            Udbus.v4v.v4vConnection connection = TryV4VConnection(io_debug, log);

            while (connection == null && stop.WaitOne(0) == false)
            {
                System.Threading.Thread.Sleep(ConnectionWaitMilliseconds);
                connection = TryV4VConnection(io_debug, log);

            } // Ends while failed to connect to V4V

            return connection;
        }