Пример #1
0
        public void Start()
        {
            if (CurrentProfile == null)
            {
                throw new InvalidOperationException("No profile has been selected");
            }

            CurrentProfile.Validate();

            if (!_active)
            {
                _active       = true;
                _mainLoopTask = new Task(MainLoop);
                _mainLoopTask.Start();
            }
        }
Пример #2
0
        /// <summary>
        /// Start running the current profile
        /// </summary>
        public void Start()
        {
            Stop();
            Logger.Info("Starting...");

            bool profileJustSet = false;

            if (this.CurrentProfile == null)
            {
                this.CurrentProfile = (from p in this.Setup.Profiles
                                       where p.Id == this.Setup.CurrentProfileId
                                       select p).FirstOrDefault();
                profileJustSet = true;
            }

            if (this.CurrentProfile == null)
            {
                CurrentProfile = this.Setup.Profiles.FirstOrDefault();
                profileJustSet = true;
            }

            if (CurrentProfile == null)
            {
                Logger.Error("No profile has been selected");
                return;
            }
            else
            {
                //Reset current profile incase there has been any setting changes
                if (!profileJustSet)
                {
                    this.CurrentProfile = (from p in this.Setup.Profiles
                                           where p.Id == this.CurrentProfile.Id
                                           select p).First();
                }

                CurrentProfile.Validate();

                if (!Active)
                {
                    Active = true;

                    // Prepare light data buffer
                    _nextLightData = new LightData(CurrentProfile.LightSetupPlugin.Lights.Count);
                    _prevLightData = new LightData(CurrentProfile.LightSetupPlugin.Lights.Count);;

                    // Start all plugins
                    CurrentProfile.CapturePlugin.Start();
                    CurrentProfile.ColourExtractionPlugin.Start();
                    CurrentProfile.PostProcessPlugins.ToList().ForEach(p => p.Start());
                    CurrentProfile.PreOutputPlugins.ToList().ForEach(p => p.Start());

                    string errorMessage   = String.Empty;
                    int    outputFailures = 0;
                    List <IOutputPlugin> outputPluginsInError = new List <IOutputPlugin>();
                    foreach (IOutputPlugin outputPlugin in CurrentProfile.OutputPlugins)
                    {
                        if (!outputPlugin.TryStart())
                        {
                            outputFailures++;
                            outputPluginsInError.Add(outputPlugin);
                        }
                    }

                    //If all output plugins are in error then stop
                    if (outputFailures == CurrentProfile.OutputPlugins.Count())
                    {
                        Stop();
                    }
                    else
                    {
                        //Remove plugins in error and allow other plugins to continue to run
                        outputPluginsInError.ForEach(o => this.CurrentProfile.OutputPlugins.Remove(o));

                        // Commence capture and output threads
                        _captureLoopTask = Task.Factory.StartNew(CaptureLoop);
                        _outputLoopTask  = Task.Factory.StartNew(OutputLoop);
                    }
                }
            }
        }