Ejemplo n.º 1
0
        public static ScheduleEventList Load(string fileName)
        {
            ScheduleEventList events;

            if (File.Exists(fileName))
            {
                Stream fileStream = File.OpenRead(fileName);
                BinaryFormatter deserializer = new BinaryFormatter();
                events = (ScheduleEventList)deserializer.Deserialize(fileStream);
                events.fileName = fileName;
                fileStream.Close();
            }
            else
            {
                events = new ScheduleEventList(fileName);
            }

            return events;
        }
Ejemplo n.º 2
0
        private void InitializeMyComponent()
        {
            /*
             * Loading settings from file if available
             */
            if (!Directory.Exists(WorkingDirectory))
                Directory.CreateDirectory(WorkingDirectory);
            this.settings = DBExtractorSettings.Load(SettingsFilePath);
            this.events = ScheduleEventList.Load(EventsFilePath);
            //else
            //    this.settings = new DBExtractorSettings(FileName);

            /*
             * Initialize SQL connection helper
             */
            this.sql = new SQLConnectionHelper();
            this.sql.ConnectionEvent += new EventHandler<SQLConnectionEventArgs>(sql_ConnectionEvent);
            this.sql.DisconnectionEvent += new EventHandler<SQLConnectionEventArgs>(sql_DisconnectionEvent);
            this.sql.ServerNamesHasBeenFetched += new EventHandler(sql_ServerNamesHasBeenFetched);
            this.sql.DatabasesHasBeenFetched += new EventHandler(sql_DatabasesHasBeenFetched);
            this.sql.TablesHasBeenFetched += new EventHandler(sql_TablesHasBeenFetched);

            /*
             * Initialize FTP helper
             */
            this.ftp = new FTPHelper();
            this.ftp.ConnectionEvent += new EventHandler<FTPConnectionEventArgs>(ftp_ConnectionEvent);

            /*
             * Service controler handler
             */
            // TODO: Service handler goes here

            /*
             * Store settings
             */
            //this.settings.Save();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start this service.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            LOG("Starting service");

            //LOG("CommonAppData: " + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            LOG("Working dir: " + WorkingDir);
            LOG("Events file: " + EventsFilePath);

            base.OnStart(args);

            this.events = ScheduleEventList.Load(EventsFilePath);
            this.todoEvents = new ScheduleEventList();

            this.mainThread = new Thread(new ThreadStart(MainThread));
            //this.mainThread.Priority = ThreadPriority.BelowNormal;
            this.mainThread.Name = "MainThread";

            this.workerThread = new Thread(new ThreadStart(WorkerThread));
            //this.workerThread.Priority = ThreadPriority.BelowNormal;
            this.workerThread.Name = "WorkerThread";

            this.forever = true;
            this.mainThread.Start();
            this.workerThread.Start();

            LOG("Reading events");
            foreach (ScheduleEvent schedEvent in this.events)
                LOG(" - ScheduleEvent: " + schedEvent.XMLFileName + "(every " + schedEvent.Interval + " minute(s)");

            /*
             * Start all events on the begining
             */
            foreach (ScheduleEvent schedEvent in this.events)
            {
                this.todoEvents.Add(new ScheduleEventWrapper(schedEvent));
            }

            LOG("Service started");
        }