コード例 #1
0
        /// <summary>
        /// This method actually performs the work of starting the virtual service
        /// </summary>
        /// <param name="srvItem">The XElement that contains the service information.</param>
        private void StartVirtualService(VirtualServiceBase virService)
        {
            Console.WriteLine("\tStarting Service: " + virService.ServiceName);

            //  Call the service start
            virService.Start();

            //  Create a new service host
            var svcHost = new ServiceHost(virService);
            svcHost.Open(TimeSpan.FromSeconds(5));

            //  Add the service to the hash table
            _virServices.Add(virService.ServiceName, svcHost);

            Console.WriteLine("\tService Started Successfully");
        }
コード例 #2
0
        /// <summary>
        /// This will assign any properties that found in the Services XML file.
        /// </summary>
        /// <param name="virServ">The virtual service object that you are assigning properties</param>
        /// <param name="srvItem">The assembly element that is the root element.</param>
        private void AssignServiceProperties(VirtualServiceBase virServ, XElement srvItem)
        {
            var propQuery = (from props in srvItem.Elements(ServicesXmlConstants.PROPERTIES)
                             select props).Descendants();

            foreach (var propItem in propQuery)
            {
                Trace.WriteLine(String.Format("Property {0}, Value {1}", propItem.Name, propItem.Value));

                //  Get the property item, if the property is found and
                //  it can be written to (not read only) then it will
                //  set the value to the property.
                var propInfo = virServ.GetType().GetProperty(propItem.Name.LocalName);
                if (propInfo != null)
                {
                    if (propInfo.CanWrite)
                        propInfo.SetValue(virServ, Convert.ChangeType(propItem.Value, propInfo.PropertyType) , null);
                }
            }
        }