Exemple #1
0
        protected void OnStart(string[] args)
        {
            try
            {
                KillProcesses();

                for (int s = 0; s < MapServerConfig.ServerCount; s++)
                {
                    MapServerConfig.ServerConfig serverConfig = MapServerConfig.Server(s);

                    if (_startInstances)
                    {
                        _running = true;
                        for (int i = 0; i < serverConfig.Instances.Length; i++)
                        {
                            MapServerConfig.ServerConfig.InstanceConfig instanceConfig = serverConfig.Instances[i];
                            if (instanceConfig == null || instanceConfig.Port <= 0)
                            {
                                continue;
                            }

                            Thread thread = new Thread(new ParameterizedThreadStart(ProcessMonitor));
                            thread.Start(instanceConfig.Port);
                        }
                    }

                    TaskerServiceType serviceType = new TaskerServiceType();
                    serviceType.Init(serverConfig.Port);
                    ServiceHost host = new ServiceHost(/*typeof(Service.TaskerServiceType)*/ serviceType, new Uri("http://localhost:" + serverConfig.Port));

                    try
                    {
                        if (host.Description.Endpoints.Count == 1 &&
                            host.Description.Endpoints[0].Binding is System.ServiceModel.WebHttpBinding)
                        {
                            System.ServiceModel.WebHttpBinding binding = (System.ServiceModel.WebHttpBinding)host.Description.Endpoints[0].Binding;
                            binding.MaxReceivedMessageSize = int.MaxValue;
                        }
                    }
                    catch { }

                    host.Open();

                    Console.WriteLine("Tasker is listening on port " + serverConfig.Port);

                    _hosts.Add(host);
                }
                DeleteImageThread del = new DeleteImageThread();
                _delThread = new Thread(new ThreadStart(del.Run));
                _delThread.Start();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Exception: " + ex.Message + "\n" + ex.StackTrace);
                Console.ResetColor();
            }
        }
Exemple #2
0
        protected override void OnStart(string[] args)
        {
            try
            {
                //XmlDocument doc = new XmlDocument();
                //doc.Load(gView.Framework.system.SystemVariables.ApplicationDirectory + @"\mapServer\Processes.xml");

                bool first = true;
                //foreach (XmlNode procNode in doc.SelectNodes("processes/process[@port]"))
                for (int i = 0; i < MapServerConfig.ServerCount; i++)
                {
                    MapServerConfig.ServerConfig procConfig = MapServerConfig.Server(i);
                    if (procConfig == null)
                    {
                        continue;
                    }

                    if (first)
                    {
                        //RegisterPort(int.Parse(procNode.Attributes["port"].Value));
                        RegisterPort(procConfig.Port);
                        first = false;
                    }
                    else
                    {
                        Process proc = new Process();
                        proc.StartInfo.FileName = gView.Framework.system.SystemVariables.ApplicationDirectory + @"\gView.MapServer.exe";
                        //proc.StartInfo.Arguments = "-port " + procNode.Attributes["port"].Value;
                        proc.StartInfo.Arguments       = "-port " + procConfig.Port;
                        proc.StartInfo.UseShellExecute = false;

                        proc.Start();
                        _procs.Add(proc);
                    }
                }

                DeleteImageThread del = new DeleteImageThread(Functions.outputPath);
                _delThread = new Thread(new ThreadStart(del.Run));
                _delThread.Start();
            }
            catch (Exception ex)
            {
                if (Functions.log_errors)
                {
                    Logger.Log(loggingMethod.error, "Service OnStart: " + ex.Message);
                }
            }
        }
Exemple #3
0
        private void Delete(string filter)
        {
            try
            {
                string last = String.Empty;
                for (int i = 0; i < MapServerConfig.ServerCount; i++)
                {
                    MapServerConfig.ServerConfig procConfig = MapServerConfig.Server(i);
                    if (procConfig == null || procConfig.OutputPath == last)
                    {
                        continue;
                    }
                    last = procConfig.OutputPath;

                    DirectoryInfo di = new DirectoryInfo(procConfig.OutputPath);

                    foreach (FileInfo fi in di.GetFiles(filter))
                    {
                        TimeSpan ts = DateTime.Now - fi.CreationTime;
                        if (ts.TotalMinutes >= MapServerConfig.RemoveInterval)
                        {
                            try
                            {
                                fi.Delete();
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }