Exemplo n.º 1
0
        //this function is called when the service begins.
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
            //creating logging service to send messages to the log
            this.ils = new LoggingService();
            //every time the logger receives a message MessageRecieved is invoked and onmsg function in this class is called
            this.ils.MessageRecieved += this.OnMsg;
            string outputDir     = ReadAppConfig.ReadSetting("OutPutDir");
            int    thumbnailSize = ReadAppConfig.ReadThumbnailSize("ThumbnailSize");

            if (thumbnailSize == -1) //in case of failed conversion to an int
            {
                thumbnailSize = 120;
                eventLog1.WriteEntry("warning: parsing failed, sets thumbnailsize to 120");
            }
            else
            {
                eventLog1.WriteEntry("Thumbnail size has been read successfuly");
            }
            //creating image model (thumbail size should be taken from app.config file)
            this.modal = new ImageServiceModal(outputDir, thumbnailSize);
            eventLog1.WriteEntry("output dir is: " + outputDir);
            //creating the controller and the server.
            this.controller    = new ImageController(modal, ils);
            this.server        = new ImageServer(this.controller, this.ils);
            this.server.Close += OnServerClose;
            this.controller.addServer(this.server);
            this.cServer              = new ComunicationServer(8000, this.controller);
            this.ils.MessageRecieved += delegate(object sender, MessageRecievedEventArgs e)
            {
                string[] logArgs = { e.Status.ToString(), e.Message };
                this.cServer.SendCommandToAllClients((int)CommandsEnum.LogCommand, logArgs);
            };

            this.cServer.Start();
            ITCPHandler tcpClientHandler = new TCPHandler(controller, ils);
            ITCPServer  tcpServer        = new TCPServer(8001, ils, tcpClientHandler);

            tcpServer.Start();
            this.imageServer = new TCPServer(8001, ils, new TCPHandler(this.controller, ils));
            this.imageServer.Start();
        }
Exemplo n.º 2
0
        public string Execute(string[] args, out bool result)
        {
            ConfigFileData cfd = new ConfigFileData();

            try
            {
                cfd.OutputDir    = ReadAppConfig.ReadSetting("OutPutDir");
                cfd.SourceDir    = ReadAppConfig.readAppSettings("ImageServiceSource");
                cfd.LogName      = ReadAppConfig.readAppSettings("ImageServiceLog");
                cfd.ThumnailSize = ReadAppConfig.ReadThumbnailSize("ThumbnailSize");
                cfd.InputDirs    = ReadAppConfig.ReadSetting("Handlers").Split(';');
                result           = true;
                return(JsonConvertor.ConvertToJson(cfd));
            }
            catch
            {
                result = false;
                return("problem occured");
            }
        }