public void Launch(int port)
	{
		_holder = new ServiceHolder(this);
		_holder.Start(new ServiceStartInfo() { Port = port });

		_mailServer = new IMailServerProxy();
		_mailServer.RegisterCallback(this);
		_mailServer.Connect("127.0.0.1", 8090, Context);
	}
Example #2
0
        /// <summary>
        /// Подключает расширение.
        /// </summary>
        protected override void Attach(ExtensionAttachmentContext context, ServiceAttribute attribute)
        {
            // Single instance for all contracts
            var holder = new ServiceHolder(context.Type);

            foreach (var contract in attribute.ContractTypes)
            {
                _publisher.Publish(
                    contract,
                    pub => holder.CreateInstance(_publisher));
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Видите наименование субъекта по которому нужна информация");
                var service = new ServiceHolder(new OSM());

                var address = Console.ReadLine();
                var result  = service.GetPolygons(address);

                Console.WriteLine($"\r\nВсего найдено объектов: {result.Count}");
                foreach (var r in result)
                {
                    Console.WriteLine("\r\n" + r.ObjectName);
                    Console.WriteLine($"Получено полигонов: {r.Polygons.Count}");
                    foreach (var p in r.Polygons.Select((p, i) => new { polygon = p, i }))
                    {
                        var exceptingPoints       = p.polygon.ExceptingPoligons.Sum(ep => ep.Count);
                        var exceptingPointsString = exceptingPoints > 0 ? $" + {exceptingPoints} точек для исключающих областей" : "";
                        Console.WriteLine($"\t{p.i + 1}) всего точек {p.polygon.Instance.Count}" + exceptingPointsString);
                    }
                }

                int key;
                if (result.Count > 0)
                {
                    key = ReadKey("\r\nНажмите 1 для нового поиска, 2 для сохранения результата", new[] { 1, 2 });
                }
                else
                {
                    key = ReadKey("\r\nНажмите 1 для нового поиска", new[] { 1 });
                }

                if (key == 1)
                {
                    Console.Clear();
                    continue;
                }

                var freq     = ReadKey("\r\nУкажите с какой частотой сохранять точки (1 - 9)", new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
                var fileName = ReadFileName();

                SaveResultService.Save(result, fileName, freq);
                Console.WriteLine($"\r\nФайл {fileName}.txt успешно сохранён");

                ReadKey("\r\nНажмите 1 для нового поиска", new[] { 1 });
                Console.Clear();
            }
        }
Example #4
0
        public static void InitServiceClient <ServicePortClient, ServicePort>(this ServiceHolder <ServicePortClient, ServicePort> s, IEnumerable <IChannelController> controllers, BaseOnvifTest test, bool includeAddressController = false)
            where ServicePort : class
            where ServicePortClient : ClientBase <ServicePort>, ServicePort
        {
            bool found = false;

            if (!s.HasAddress)
            {
                s.Retrieve(test.Features);
                test.RunStep(() =>
                {
                    if (!s.HasAddress)
                    {
                        throw new AssertException(string.Format("{0} service not found", s.ServiceName));
                    }
                    else
                    {
                        found = true;
                        test.LogStepEvent(s.Address);
                    }
                },
                             string.Format("Get {0} service address", s.ServiceName), OnvifFaults.NoSuchService, true, true);
                test.DoRequestDelay();
            }

            test.Assert(found,
                        string.Format("{0} service address not found", s.ServiceName),
                        string.Format("Check that the DUT returned {0} service address", s.ServiceName));

            if (found)
            {
                var controller = new EndpointController(new EndpointAddress(s.Address));

                var ctrls = new List <IChannelController>();
                ctrls.Add(controller);
                ctrls.AddRange(controllers);

                Binding binding = test.CreateBinding(includeAddressController, ctrls);

                s.CreateClient(binding, test.AttachSecurity, test.SetupChannel);
            }
        }
Example #5
0
        void InitServiceHolders()
        {
            // door control
            _doorControlServiceHolder = new ServiceHolder <DoorControlPortClient, DoorControlPort>(
                (features) => { return(Client.GetServiceAddress(OnvifService.DOORCONTROL)); },
                (binding, address) => { return(new DoorControlPortClient(binding, address)); },
                "Door Control");

            // user
            //_userServiceHolder = new ServiceHolder<UserPortClient, UserPort>(
            //    (features) => { return Client.GetServiceAddress(OnvifService.USERSERVICE); },
            //    (binding, address) => { return new UserPortClient(binding, address); },
            //    "Users");

            // access control
            _pacsServiceHolder = new ServiceHolder <PACSPortClient, PACSPort>(
                (features) => { return(Client.GetServiceAddress(OnvifService.ACCESSCONTROL)); },
                (binding, address) => { return(new PACSPortClient(binding, address)); },
                "Access Control");
        }
Example #6
0
        public static ServiceHolder <EventPortTypeClient, EventPortType> DefaultInitializer(this IEventService s)
        {
            var deviceService = s as IDeviceService;

            if (null == deviceService)
            {
                s.Test.Assert(false, "The test doesn't implement Device Service", "Implementation issue");
            }

            var client = new ServiceHolder <EventPortTypeClient, EventPortType>(features => deviceService.GetEventServiceAddress(),
                                                                                (binding, address) => new EventPortTypeClient(binding, address),
                                                                                "Event");

            if (null == client.Client)
            {
                client.InitServiceClient(new IChannelController[] { new SoapValidator(EventsSchemasSet.GetInstance()) }, s.Test);
            }

            return(client);
        }
Example #7
0
        void InitServiceClient(ServiceHolder serviceHolder, IEnumerable <IChannelController> controllers)
        {
            bool found = false;

            if (!serviceHolder.HasAddress)
            {
                RunStep(() =>
                {
                    serviceHolder.Retrieve(Features);
                    if (!serviceHolder.HasAddress)
                    {
                        throw new AssertException(string.Format("{0} service not found", serviceHolder.ServiceName));
                    }
                    else
                    {
                        found = true;
                        LogStepEvent(serviceHolder.Address);
                    }
                }, string.Format("Get {0} service address", serviceHolder.ServiceName));
                DoRequestDelay();
            }

            Assert(found,
                   string.Format("{0} service address not found", serviceHolder.ServiceName),
                   string.Format("Check that the DUT returned {0} service address", serviceHolder.ServiceName));

            EndpointController controller = new EndpointController(new EndpointAddress(serviceHolder.Address));

            List <IChannelController> ctrls = new List <IChannelController>();

            ctrls.Add(controller);
            ctrls.AddRange(controllers);

            Binding binding = CreateBinding(
                false,
                ctrls);

            serviceHolder.CreateClient(binding, AttachSecurity, SetupChannel);
        }
	public void Launch(int port)
	{
		_holder = new ServiceHolder(this);
		_holder.Start(new ServiceStartInfo() { Port = port });
	}
Example #9
0
        public bool Execute()
        {
            bool    returnActive;
            Guid    id;
            Version version;

            returnActive = !Guid.TryParse(InterpreterId, out id);

            if (!Version.TryParse(InterpreterVersion, out version))
            {
                if (!returnActive)
                {
                    _log.LogError(
                        "Invalid values for InterpreterId (\"{0}\") and InterpreterVersion (\"{1}\")",
                        InterpreterId,
                        InterpreterVersion
                        );
                    return(false);
                }
            }

            MSBuildProjectInterpreterFactoryProvider provider = null;
            ProjectCollection collection = null;
            Project           project    = null;

            var service = ServiceHolder.Create();

            if (service == null)
            {
                _log.LogError("Unable to obtain interpreter service.");
                return(false);
            }

            try {
                try {
                    project = ProjectCollection.GlobalProjectCollection.GetLoadedProjects(_projectPath).Single();
                } catch (InvalidOperationException) {
                    // Could not get exactly one project matching the path.
                }

                if (project == null)
                {
                    collection = new ProjectCollection();
                    project    = collection.LoadProject(_projectPath);
                }

                var projectHome = PathUtils.GetAbsoluteDirectoryPath(
                    project.DirectoryPath,
                    project.GetPropertyValue("ProjectHome")
                    );

                var searchPath = project.GetPropertyValue("SearchPath");
                if (!string.IsNullOrEmpty(searchPath))
                {
                    SearchPaths = searchPath.Split(';')
                                  .Select(p => PathUtils.GetAbsoluteFilePath(projectHome, p))
                                  .ToArray();
                }
                else
                {
                    SearchPaths = new string[0];
                }

                provider = new MSBuildProjectInterpreterFactoryProvider(service.Service, project);
                try {
                    provider.DiscoverInterpreters();
                } catch (InvalidDataException ex) {
                    _log.LogWarning("Errors while resolving environments: {0}", ex.Message);
                }

                IPythonInterpreterFactory factory = null;
                if (returnActive)
                {
                    factory = provider.ActiveInterpreter;
                }
                else
                {
                    factory = provider.FindInterpreter(id, version);
                }

                if (!provider.IsAvailable(factory))
                {
                    _log.LogError(
                        "The environment '{0}' is not available. Check your project configuration and try again.",
                        factory.Description
                        );
                    return(false);
                }
                else if (factory == service.Service.NoInterpretersValue)
                {
                    _log.LogError(
                        "No Python environments are configured. Please install or configure an environment and try " +
                        "again. See http://go.microsoft.com/fwlink/?LinkID=299429 for information on setting up a " +
                        "Python environment."
                        );
                    return(false);
                }
                else if (factory != null)
                {
                    PrefixPath = PathUtils.EnsureEndSeparator(factory.Configuration.PrefixPath);
                    if (PathUtils.IsSubpathOf(projectHome, PrefixPath))
                    {
                        ProjectRelativePrefixPath = PathUtils.GetRelativeDirectoryPath(projectHome, PrefixPath);
                    }
                    else
                    {
                        ProjectRelativePrefixPath = string.Empty;
                    }
                    InterpreterPath         = factory.Configuration.InterpreterPath;
                    WindowsInterpreterPath  = factory.Configuration.WindowsInterpreterPath;
                    LibraryPath             = PathUtils.EnsureEndSeparator(factory.Configuration.LibraryPath);
                    Architecture            = factory.Configuration.Architecture.ToString();
                    PathEnvironmentVariable = factory.Configuration.PathEnvironmentVariable;
                    Description             = factory.Description;
                    MajorVersion            = factory.Configuration.Version.Major.ToString();
                    MinorVersion            = factory.Configuration.Version.Minor.ToString();

                    return(true);
                }
                else if (returnActive)
                {
                    _log.LogError("Unable to resolve active environment.");
                }
                else
                {
                    _log.LogError("Unable to resolve environment {0} {1}", InterpreterId, InterpreterVersion);
                }
            } catch (Exception ex) {
                _log.LogErrorFromException(ex);
            } finally {
                if (provider != null)
                {
                    provider.Dispose();
                }
                if (collection != null)
                {
                    collection.UnloadAllProjects();
                    collection.Dispose();
                }
                service.Dispose();
            }

            _log.LogError("Unable to resolve environment");
            return(false);
        }
Example #10
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     taskbar = ServiceHolder.GetService <TaskbarService>().NotifyIcon;
 }