示例#1
0
        public void TakePictureTask(TaskServer server, string taskName)
        {
            if (!settings.Enabled)
            {
                return;
            }

            var now = DateTime.Now;
            string dirName = now.ToString("yyyyMMdd");
            string dirPath = Path.Combine(PicDir, dirName);
            string fileName = now.ToString("yyyyMMdd_HHmm") + ".jpg";
            string filePath = Path.Combine(PicDir, dirName, fileName);
            string thName = now.ToString("yyyyMMdd_HHmm") + "_th.jpg";
            string thPath = Path.Combine(PicDir, dirName, thName);

            Log.Trace.TraceEvent(TraceEventType.Information, 0,
                "[{0}] Take a picture: {1}", taskName, filePath);

            Directory.CreateDirectory(dirPath);
            var p = Process.Start("raspistill",
                string.Format(@"-o ""{0}"" -w {1} -h {2} -th {3}",
                    filePath, ImgW, ImgH, ThumOption));
            p.WaitForExit();
            Log.Trace.TraceEvent(TraceEventType.Information, 0,
                "[{0}] Result: {1}", taskName, p.ExitCode);

            // Create thumb
            var image = Image.FromFile(filePath);
            var thumb = image.GetThumbnailImage(ThumbX, ThumbY, null, IntPtr.Zero);
            thumb.Save(thPath, ImageFormat.Jpeg);
        }
示例#2
0
        public void UpdateTask(TaskServer server, string taskName)
        {
            if (!settings.Enabled)
            {
                Log.Trace.TraceEvent(TraceEventType.Information, 0,
                    "[{0}] DDNS update is disabled, skip", taskName);
                return;
            }

            const string Uri = "http://www.mydns.jp/login.html";
            const int TimeoutSec = 10;

            var client = new HttpClient();
            client.Timeout = TimeSpan.FromSeconds(TimeoutSec);
            byte[] byteArray = Encoding.ASCII.GetBytes(
                string.Format("{0}:{1}", settings.User, settings.Pass));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                "Basic", Convert.ToBase64String(byteArray));

            Task<HttpResponseMessage> task = client.GetAsync(Uri, server.CancelToken);
            task.Wait(server.CancelToken);
            if (task.Result.StatusCode == HttpStatusCode.OK)
            {
                Log.Trace.TraceEvent(TraceEventType.Information, 0,
                    "[{0}] DDNS update succeeded", taskName);
            }
            else
            {
                Log.Trace.TraceEvent(TraceEventType.Warning, 0,
                    "[{0}] DDNS update failed", taskName);
            }
        }
示例#3
0
        public string GetTaskXml(long taskId)
        {
            Debug.Assert(_callback != null);
            TaskServer task = (TaskServer)_tasks.Tasks.TaskById(taskId);

            if (task != null)
            {
                return(task.ToProxyXml());
            }
            return(null);
        }
示例#4
0
        public void updateIpAddr(TaskServer server, string taskName)
        {
            const string Uri = "http://inet-ip.info";
            const string UserAgent = "curl";
            const int TimeoutSec = 10;

            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent);
            httpClient.Timeout = TimeSpan.FromSeconds(TimeoutSec);

            Task<string> task = httpClient.GetStringAsync(Uri);
            task.Wait(server.CancelToken);

            string ipAddr = task.Result.Trim();
            Log.Trace.TraceEvent(TraceEventType.Information, 0,
                "[{0}] IP addr: {1}", taskName, ipAddr);
            TwitterManager.UpdateProfileLocation(string.Format("http://{0}/", ipAddr));
        }
示例#5
0
        public int Run()
        {
            LOG.Info("Starting server");
            TimedReferenceController.SetMode(CacheType.PERMANENT);

            if (Config.Services == null)
            {
                LOG.Warn("No services found in the configuration file, exiting");
                return(1);
            }

            if (!Directory.Exists(Config.GameLocation))
            {
                LOG.Fatal("The directory specified as gameLocation in config.json does not exist");
                return(1);
            }

            Directory.CreateDirectory(Config.SimNFS);
            Directory.CreateDirectory(Path.Combine(Config.SimNFS, "Lots/"));
            Directory.CreateDirectory(Path.Combine(Config.SimNFS, "Objects/"));

            Content.Model.AbstractTextureRef.ImageFetchFunction = Utils.SoftwareImageLoader.SoftImageFetch;

            //TODO: Some content preloading
            LOG.Info("Scanning content");
            Content.Content.Init(Config.GameLocation, Content.ContentMode.SERVER);
            Kernel.Bind <Content.Content>().ToConstant(Content.Content.Get());
            VMContext.InitVMConfig();
            Kernel.Bind <MemoryCache>().ToConstant(new MemoryCache("fso_server"));

            LOG.Info("Loading domain logic");
            Kernel.Load <ServerDomainModule>();

            Servers     = new List <AbstractServer>();
            CityServers = new List <CityServer>();
            Kernel.Bind <IServerNFSProvider>().ToConstant(new ServerNFSProvider(Config.SimNFS));

            if (Config.Services.UserApi != null &&
                Config.Services.UserApi.Enabled)
            {
                var childKernel = new ChildKernel(
                    Kernel
                    );
                var api = new UserApi(Config, childKernel);
                ActiveUApiServer = api;
                Servers.Add(api);
                api.OnRequestShutdown       += RequestedShutdown;
                api.OnBroadcastMessage      += BroadcastMessage;
                api.OnRequestUserDisconnect += RequestedUserDisconnect;
                api.OnRequestMailNotify     += RequestedMailNotify;
            }

            foreach (var cityServer in Config.Services.Cities)
            {
                /**
                 * Need to create a kernel for each city server as there is some data they do not share
                 */
                var childKernel = new ChildKernel(
                    Kernel,
                    new ShardDataServiceModule(Config.SimNFS),
                    new CityServerModule()
                    );

                var city = childKernel.Get <CityServer>(new ConstructorArgument("config", cityServer));
                CityServers.Add(city);
                Servers.Add(city);
            }

            foreach (var lotServer in Config.Services.Lots)
            {
                if (lotServer.SimNFS == null)
                {
                    lotServer.SimNFS = Config.SimNFS;
                }
                var childKernel = new ChildKernel(
                    Kernel,
                    new LotServerModule()
                    );

                Servers.Add(
                    childKernel.Get <LotServer>(new ConstructorArgument("config", lotServer))
                    );
            }

            if (Config.Services.Tasks != null &&
                Config.Services.Tasks.Enabled)
            {
                var childKernel = new ChildKernel(
                    Kernel,
                    new TaskEngineModule()
                    );

                childKernel.Bind <TaskServerConfiguration>().ToConstant(Config.Services.Tasks);
                childKernel.Bind <TaskTuning>().ToConstant(Config.Services.Tasks.Tuning);

                var tasks = childKernel.Get <TaskServer>(new ConstructorArgument("config", Config.Services.Tasks));
                Servers.Add(tasks);
                ActiveTaskServer = tasks;
                Server.Servers.Tasks.Domain.ShutdownTask.ShutdownHook = RequestedShutdown;
            }

            foreach (var server in Servers)
            {
                server.OnInternalShutdown += ServerInternalShutdown;
            }

            Running = true;

            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
            AppDomain.CurrentDomain.ProcessExit  += CurrentDomain_ProcessExit;

            /*
             * NetworkDebugger debugInterface = null;
             *
             * if (Options.Debug)
             * {
             *  debugInterface = new NetworkDebugger(Kernel);
             *  foreach (AbstractServer server in Servers)
             *  {
             *      server.AttachDebugger(debugInterface);
             *  }
             * }
             */

            LOG.Info("Starting services");
            foreach (AbstractServer server in Servers)
            {
                server.Start();
            }

            HostPool.Start();

            //Hacky reference to maek sure the assembly is included
            FSO.Common.DatabaseService.Model.LoadAvatarByIDRequest x;

            /*if (debugInterface != null)
             * {
             *  Application.EnableVisualStyles();
             *  Application.Run(debugInterface);
             * }
             * else*/
            {
                while (Running)
                {
                    Thread.Sleep(1000);
                    lock (Servers)
                    {
                        if (Servers.Count == 0)
                        {
                            LOG.Info("All servers shut down, shutting down program...");

                            Kernel.Get <IGluonHostPool>().Stop();

                            /*var domain = AppDomain.CreateDomain("RebootApp");
                             *
                             * var assembly = "FSO.Server.Updater, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
                             * var type = "FSO.Server.Updater.Program";
                             *
                             * var updater = typeof(FSO.Server.Updater.Program);
                             *
                             * domain.CreateInstance(assembly, type);
                             * AppDomain.Unload(AppDomain.CurrentDomain);*/
                            return(2 + (int)ShutdownMode);
                        }
                    }
                }
            }
            return(1);
        }
示例#6
0
        public void UploadPictureTask(TaskServer server, string taskName)
        {
            string[] files = Directory.GetFiles(TweetDir, "*.jpg");
            if (files.Length > 0)
            {
                Array.Sort(files);
                string upfile = files[0];

                Log.Trace.TraceEvent(TraceEventType.Information, 0,
                    "[{0}] Upload: {1}", taskName, upfile);
                TwitterManager.UpdateWithImage(Path.GetFileName(upfile), upfile);

                // delete if succeeded
                File.Delete(upfile);
            }
            else {
                Log.Trace.TraceEvent(TraceEventType.Information, 0,
                    "[{0}] No upload files", taskName);
            }
        }
示例#7
0
        public void Run()
        {
            switch (arguments.Type)
            {
            //case "plugins":
            //    var plugin = new TaskPlugin(crmServiceClient, currentDirectory, arguments);
            //    plugin.Run();
            //    break;
            //case "workflows":
            //    var workflow = new TaskWorkflow(crmServiceClient, currentDirectory, arguments);
            //    workflow.Run();
            //    break;
            case "webresources":
                var webresource = new TaskWebResource(crmServiceClient, currentDirectory, arguments);
                webresource.Run();
                break;

            //case "dataproviders":
            //    var dataprovider = new TaskDataProvider(crmServiceClient, currentDirectory, arguments);
            //    dataprovider.Run();
            //    break;
            case "solutionpackagers":
                var solutionpackager = new TaskSolutionPackager(crmServiceClient, currentDirectory, arguments);
                solutionpackager.Run();
                break;

            case "generators":
                var generator = new TaskGenerator(crmServiceClient, currentDirectory, arguments);
                generator.Run();
                break;

            case "proxytypes":
                var proxytype = new TaskProxyType(crmServiceClient, currentDirectory, arguments);
                proxytype.Run();
                break;

            case "downloadwebresources":
                var downloadwebresource = new TaskDownloadWebResource(crmServiceClient, currentDirectory, arguments);
                downloadwebresource.Run();
                break;

            case "downloadreports":
                var downloadreport = new TaskDownloadReport(crmServiceClient, currentDirectory, arguments);
                downloadreport.Run();
                break;

            //case "initialize":
            //    var initialize = new TaskInitialize(crmServiceClient, currentDirectory, arguments);
            //    initialize.Run();
            //    break;
            //case "portals":
            //    var portal = new TaskPortal(crmServiceClient, currentDirectory, arguments);
            //    portal.Run();
            //    break;
            case "datasources":
                var datasource = new TaskDataSource(crmServiceClient, currentDirectory, arguments);
                datasource.Run();
                break;

            case "servers":
            case "plugins":
            case "workflows":
            case "dataproviders":
                var server = new TaskServer(crmServiceClient, currentDirectory, arguments);
                server.Run();
                break;

            default:
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, "Type: ", CliLog.ColorRed, arguments.Type, CliLog.ColorGreen, " not support");
                CliLog.WriteLine(CliLog.ColorWhite, "|");
                break;
            }
        }