コード例 #1
0
ファイル: PusherService.cs プロジェクト: rwakelam/Flow
        public PusherService(PusherCollection config)
        {
            // Create and configure the watchers.
            _watchers = new List<PushableEventWatcher>();
            foreach (PusherElement pusherConfig in config)
            {
                try
                {
                    PushableEventWatcher watcher = new PushableEventWatcher(
                        pusherConfig.SourcePath, pusherConfig.TargetPath, pusherConfig.Pattern,
                        pusherConfig.Attributes);//config more like folder mapping? would be same for cleaner
                    _watchers.Add(watcher);
                    watcher.OnPushable += new PushableEventWatcher.OnPushableEventHandler(OnPushableEvent);

                    //_Logger.Subscribe(pushDelegator);
                    //string synchroniserCreatedMessage = String.Format(SynchroniserCreatedMessage,
                    //    pusherConfig.Name, pusherConfig.TargetPath,
                    //    pusherConfig.SourcePath, pusherConfig.Pattern,
                    //    pusherConfig.Attributes);
                    //eventLog.WriteEntry(synchroniserCreatedMessage, EventLogEntryType.Information);
                    }
                catch (Exception ex)
                {
                    //eventLog.WriteEntry(string.Format(SynchronsierNotCreatedMessage, pusherConfig.Name, ex.Message),
                    //    EventLogEntryType.Error);
                }

            }
        }
コード例 #2
0
 private void OnPushRequired(PushableEventWatcher.PushRequiredEventArgs e)
 {
     lock (_filePushTasks)
     {
         if (_filePushTasks.ContainsKey(e.SourcePath))
         {
             return;
         }
         _filePushTasks.Add(e.SourcePath, e.TargetPath);
     }
 }
コード例 #3
0
        // NOTE:: For this to fire, CanHandlePowerEvent needs to be enabled on ServiceBase.
        //protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
        //{
        //    eventLog.WriteEntry(String.Format(PowerEventDetectedMessage, Enum.GetName(typeof(PowerBroadcastStatus), powerStatus)), EventLogEntryType.Information);
        //    if (_Mode == Mode.Power)
        //    {
        //         switch (powerStatus)
        //        {
        //            case PowerBroadcastStatus.ResumeSuspend:
        //                Pull();
        //                break;
        //            case PowerBroadcastStatus.Suspend:
        //                Push();
        //                break;
        //        }
        //    }
        //    return true;
        //}
        // NOTE:: For this to fire, CanHandleShutdown needs to be enabled on ServiceBase.
        //protected override void OnShutdown()
        //{
        //    Push();
        //}
        protected override void OnStart(string[] args)
        {
            // Apply the configuration.
            ServiceSection serviceConfig = (ServiceSection)ConfigurationManager.GetSection(ConfigurationSectionName);
            if (serviceConfig == null)
            {
                throw new ConfigurationErrorsException(String.Format(ConfigurationNotFoundMessage, ConfigurationSectionName));
            }
            //_Mode = serviceConfig.Mode;
            //if (_Mode == Mode.Timer)
            //{
            //    _Timer.Interval = TimeSpan.FromMinutes(serviceConfig.TimerInterval).TotalMilliseconds;
            //}
            //string serviceConfiguredMessage = String.Format(ServiceConfiguredMessage, _Mode, serviceConfig.TimerInterval);
            //eventLog.WriteEntry(serviceConfiguredMessage, EventLogEntryType.Information);
            //SubscriptionLevel loggingLevel = (SubscriptionLevel)Enum.Parse(typeof(SubscriptionLevel), serviceConfig.LoggingLevel);

            // Create the Directory push delegators.
            _pushDelegators = new Dictionary<string, PushableEventWatcher>();
               // _Logger = new Logger(this, serviceConfig.LoggingLevel);
            if (serviceConfig.Pushers != null)
            {
                foreach (PusherElement pusherConfig in serviceConfig.Pushers)
                {
                    try
                    {
                        PushableEventWatcher pushDelegator = new PushableEventWatcher(
                            pusherConfig.SourcePath,
                            pusherConfig.TargetPath,
                            pusherConfig.Pattern,
                            pusherConfig.Attributes);
                        _pushDelegators.Add(pusherConfig.Name, pushDelegator);
                        pushDelegator.OnPushable += new PushableEventWatcher.OnPushableEventHandler(OnPushRequired);

                        //_Logger.Subscribe(pushDelegator);
                        string synchroniserCreatedMessage = String.Format(SynchroniserCreatedMessage,
                            pusherConfig.Name, pusherConfig.TargetPath,
                            pusherConfig.SourcePath, pusherConfig.Pattern,
                            pusherConfig.Attributes);
                        eventLog.WriteEntry(synchroniserCreatedMessage, EventLogEntryType.Information);
                    }
                    catch (Exception ex)
                    {
                        eventLog.WriteEntry(string.Format(SynchronsierNotCreatedMessage, pusherConfig.Name, ex.Message),
                            EventLogEntryType.Error);
                    }
                }
            }

            // Kick off a pull, but in a new thread so that the start method can still return in a timely fashion.
               // new Thread(Pull).Start();

            // Start the refresh mechanism.
            switch(_Mode)
            {
                //case Mode.Power:
                //    break;
                case Mode.Timer:
                    _Timer.Start();
                    break;
            }
        }