Ejemplo n.º 1
0
        protected Output(SerializationInfo info, StreamingContext context)
        {
            try
            {
                ColorTransformerConfigs = (IList <ColorTransformerConfig>)info.GetValue("ColorTransformerConfigs", typeof(IList <ColorTransformerConfig>));
            }
            catch (SerializationException)
            {
            }

            string pluginName = info.GetString("OutputPluginName");

            if (!string.IsNullOrEmpty(pluginName))
            {
                IOutputPlugin outputPlugin = OutputPlugins.GetOutputPlugin(pluginName);
                if (outputPlugin == null)
                {
                    throw new SerializationException(string.Format("Error while deserializing: Output plugin {0} not found", pluginName));
                }

                IOutputInfo outputInfo = outputPlugin.GetNewOutputInfo();
                outputInfo.Deserialize((Dictionary <string, string>)info.GetValue("OutputInfoDictionary", typeof(Dictionary <string, string>)));

                OutputInfo = outputInfo;
            }
        }
Ejemplo n.º 2
0
        public IOutputPlugin AddOutputPlugin(Type pluginType)
        {
            IOutputPlugin plugin = Activator.CreateInstance(pluginType, new object[] { Table.Database.AddTable(), Logger, Runtime }) as IOutputPlugin;

            this.OutputPlugins.Add(plugin);
            SaveToStorage(() => this.OutputPlugins, this.OutputPlugins);
            return(plugin);
        }
        private void btnUp_Click(object sender, EventArgs e)
        {
            IOutputPlugin itemToMove    = lbSelected.SelectedItem as IOutputPlugin;
            int           selectedIndex = lbSelected.SelectedIndex;

            _profile.OutputPlugins.RemoveAt(selectedIndex);
            _profile.OutputPlugins.Insert(selectedIndex - 1, itemToMove);

            lbSelected.SelectedIndex = selectedIndex - 1;
            PluginsChanged();
        }
Ejemplo n.º 4
0
        public static IOutputPlugin GetOutputPlugin(string pluginName)
        {
            IOutputPlugin toReturn = AvailablePlugins.SingleOrDefault(x => x.Name == pluginName);

            if (toReturn == null)
            {
                throw new Exception(string.Format("Output plugin {0} not found", pluginName));
            }

            return(toReturn);
        }
        public bool Post(DeletePluginRequest request)
        {
            PluginResponse response = new PluginResponse();
            Profile        profile  = (from p in Program.Runtime.Setup.Profiles
                                       where p.Id == request.ProfileId
                                       select p).FirstOrDefault();

            if (request.Id == 0)
            {
                return(true);
            }

            bool updated = false;

            switch (request.PluginType)
            {
            case 4:
                IPostProcessPlugin postProcessPlugin = profile.PostProcessPlugins.Where(l => l.Id == request.Id).FirstOrDefault() as IPostProcessPlugin;
                if (postProcessPlugin != null)
                {
                    profile.PostProcessPlugins.Remove(postProcessPlugin);
                    updated = true;
                }
                break;

            case 5:
                IPreOutputPlugin preOutputPlugin = profile.PreOutputPlugins.Where(l => l.Id == request.Id).FirstOrDefault() as IPreOutputPlugin;
                if (preOutputPlugin != null)
                {
                    profile.PreOutputPlugins.Remove(preOutputPlugin);
                    updated = true;
                }
                break;

            case 6:
                IOutputPlugin outputPlugin = profile.OutputPlugins.Where(l => l.Id == request.Id).FirstOrDefault() as IOutputPlugin;
                if (outputPlugin != null)
                {
                    profile.OutputPlugins.Remove(outputPlugin);
                    updated = true;
                }
                break;

            default:
                break;
            }
            if (updated)
            {
                Program.Runtime.Save();
            }
            return(true);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Trys to get a configured Output Plugin (no specific ordering),
 /// failing that it will attempt to create a new Output Plugin from the available types (no specific ordering)
 /// </summary>
 /// <returns>A list with one Output Plugin</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public SerializableInterfaceList<IOutputPlugin> DefaultOutputPlugins()
 {
     SerializableInterfaceList<IOutputPlugin> outputPlugins = new SerializableInterfaceList<IOutputPlugin>();
     Type type = AvailableOutputPlugins.FirstOrDefault();
     if (type == null)
     {
         AfterglowRuntime.Logger.Fatal("No IOutputPlugin's have been loaded, please check the install and try again");
     }
     else
     {
         IOutputPlugin plugin = Activator.CreateInstance(type) as IOutputPlugin;
         plugin.Id = this.GetNewId<IOutputPlugin>();
         outputPlugins.Add(plugin);
     }
     return outputPlugins;
 }
Ejemplo n.º 7
0
        public TransferResult Transfer(IInputPlugin inputPlugin, IOutputPlugin outputPlugin)
        {
            _log.InfoFormat("Transfer started");
            try
            {
                int counter = 0;
                while (true)
                {
                    try
                    {
                        _log.Info("Reading next item from input plugin");
                        if (!inputPlugin.Read(out IDictionary <string, object> item))
                        {
                            break;
                        }

                        _log.Info("Writing item to output plugin");
                        outputPlugin.Write(item);
                        counter++;
                    }
                    catch (Exception itemEx) when(!_stopOnItemError)
                    {
                        _log.Warn(itemEx);
                    }
                }
                TransferResult success = new TransferResult {
                    Id = 1, Text = "Success", ItemsTransfered = counter
                };
                _log.InfoFormat("Items transfered successfully");
                _log.Debug(success.Text + "--> Number of items transfered: " + success.ItemsTransfered);
                return(success);
            }
            catch (Exception e)
            {
                TransferResult notCompleted = new TransferResult {
                    Id = 2, Text = "Transfer not completed" + e.Message, ItemsTransfered = 0
                };
                _log.InfoFormat("Items transfered not successfully");
                _log.Debug(notCompleted.Text + "--> Number of items transfered: " + notCompleted.ItemsTransfered);
                return(notCompleted);
            }
            finally
            {
                _log.InfoFormat("Items transfer ended");
                _log.Debug("Disposing resources");
            }
        }
        private ObservableCollection <IOutputPlugin> GetLookupValues()
        {
            PropertyInfo         prop            = _profile.GetType().GetProperties().Where(p => p.Name == "OutputPlugins").FirstOrDefault();
            ConfigTableAttribute configAttribute = Attribute.GetCustomAttribute(prop, typeof(ConfigTableAttribute)) as ConfigTableAttribute;

            Type pluginType   = _profile.GetType();
            Type propertyType = prop.PropertyType;

            IEnumerable <Type> availableValues = null;

            if (configAttribute.RetrieveValuesFrom != null)
            {
                var member = pluginType.GetMember(configAttribute.RetrieveValuesFrom);
                if (member.Length > 0)
                {
                    if (member[0].MemberType == MemberTypes.Method)
                    {
                        MethodInfo mi = pluginType.GetMethod(configAttribute.RetrieveValuesFrom);

                        var propertyValue = mi.Invoke(_profile, null);

                        availableValues = propertyValue as IEnumerable <Type>;
                    }
                }
            }

            ObservableCollection <IOutputPlugin> result = new ObservableCollection <IOutputPlugin>();

            foreach (Type item in availableValues)
            {
                IOutputPlugin plugin = Activator.CreateInstance(item) as IOutputPlugin;
                result.Add(plugin);
            }

            return(result);
        }
Ejemplo n.º 9
0
 public ExecutionStage(BuildState buildState, BuildStatus buildStatus, IOutputPlugin outputPlugin)
 {
     BuildState = buildState;
     BuildStatus = buildStatus;
     OutputPlugin = outputPlugin;
 }
Ejemplo n.º 10
0
        private void ApplyConfig(AmbiLightConfig config)
        {
            if (_screenCaptureService != null)
            {
                _screenCaptureService.Dispose();
            }

            _screenCaptureService = _screenCaptureServiceProvider.Provide(true);

            List <IOutputPlugin> plugins = OutputPlugins.GetAvailablePlugins();

            List <ScreenRegionOutput> regions = config.RegionsToOutput;

            if (_regionConfigurations != null)
            {
                foreach (RegionConfiguration regionConfiguration in _regionConfigurations)
                {
                    regionConfiguration.Dispose();
                }
            }

            _regionConfigurations = new List <RegionConfiguration>();

            var regionConfigId = 0;

            foreach (ScreenRegionOutput region in regions)
            {
                var regionConfig = new RegionConfiguration(regionConfigId++)
                {
                    ScreenRegion          = region.ScreenRegion,
                    ColorAveragingService = _colorAveragingServiceProvider.Provide(region.ColorAveragingConfig),
                    OutputConfigs         = new List <OutputConfiguration>()
                };

                var outputId = 0;

                foreach (Output output in region.Outputs)
                {
                    IOutputInfo   outputInfo = output.OutputInfo;
                    IOutputPlugin plugin     = plugins.FirstOrDefault(y => y.Name == outputInfo.PluginName);
                    if (plugin == null)
                    {
                        throw new InvalidOperationException(string.Format("Missing OutputPlugin {0}", outputInfo.PluginName));
                    }

                    OutputService outputService = _regionConfigurations.SelectMany(x => x.OutputConfigs).Select(x => x.OutputService).FirstOrDefault(x => x.IsReusableFor(outputInfo)) ?? plugin.GetNewOutputService();

                    outputService.Initialize(outputInfo);

                    IList <ColorTransformerConfig> colorTransformerConfigs = output.ColorTransformerConfigs;

                    if (colorTransformerConfigs == null)
                    {
                        colorTransformerConfigs = new List <ColorTransformerConfig>
                        {
                            new ColorTransformerConfig
                            {
                                Type   = typeof(HysteresisColorTransformer),
                                Config = new Dictionary <string, object>
                                {
                                    { "hysteresis", "0.01" }
                                }
                            },
                            new ColorTransformerConfig
                            {
                                Type   = typeof(BrightnessColorTransformer),
                                Config = new Dictionary <string, object>
                                {
                                    { "factorR", "1" },
                                    { "factorG", "1" },
                                    { "factorB", "0.9" }
                                }
                            },
                            //new ColorTransformerConfig
                            //{
                            //	Type = typeof (GammaColorTransformer),
                            //	Config = new Dictionary<string, object>
                            //	{
                            //		{"gammaR", "1"},
                            //		{"gammaG", "1.2"},
                            //		{"gammaB", "1.2"}
                            //	}
                            //},
                            new ColorTransformerConfig
                            {
                                Type   = typeof(ThresholdColorTransformer),
                                Config = new Dictionary <string, object>
                                {
                                    { "threshold", "0.01" }
                                }
                            }
                        };
                    }

                    var outputConfig = new OutputConfiguration(regionConfig.Id, outputId++)
                    {
                        ColorTransformerContexts = colorTransformerConfigs.Select(x => new ColorTransformerContext(x)).ToList(),
                        OutputService            = outputService,
                        ResendIntervalFunc       = outputService.GetResendInterval,
                        OutputInfo = outputInfo
                    };

                    regionConfig.OutputConfigs.Add(outputConfig);
                }

                _regionConfigurations.Add(regionConfig);
            }

            _screenRegions = _regionConfigurations.Select(x => x.ScreenRegion).ToList();
        }
Ejemplo n.º 11
0
 public void RemoveOutputPlugin(IOutputPlugin plugin)
 {
     this.OutputPlugins.Remove(plugin);
     SaveToStorage(() => this.OutputPlugins, this.OutputPlugins);
 }
Ejemplo n.º 12
0
        private void ProcessWorker(Queue<KeyValuePair<string, string>> taskQueue, IEnumerable<IProcessingPlugin> processingPlugins, IOutputPlugin outputPlugin, AsyncOperation asyncOp)
        {
            var imageProcessingManagerTaskContext = new ImageProcessingManagerTaskContext(taskQueue, asyncOp.UserSuppliedState);
            imageProcessingManagerTaskContext.TotalTaskCount = taskQueue.Count;

            lock ((userStateToTaskContext as ICollection).SyncRoot)
            {
                userStateToTaskContext[asyncOp.UserSuppliedState] = imageProcessingManagerTaskContext;
            }

            while (imageProcessingManagerTaskContext.TaskQueue.Count > 0)
            {
                imageProcessingManagerTaskContext.Semaphore.WaitOne();

                if (IsTaskCancelled(asyncOp.UserSuppliedState))
                {
                    break;
                }
                else
                {
                    var task = taskQueue.Dequeue();
                    asyncOp.Post(processAsyncStateChangedDelegate, new ProcessStateChangedEventArgs(asyncOp.UserSuppliedState, task.Key, "处理中"));
                    object userState = Guid.NewGuid();
                    lock ((imageProcessorUserStateToUserState as ICollection).SyncRoot)
                    {
                        imageProcessorUserStateToUserState[userState] = asyncOp.UserSuppliedState;
                    }
                    lock ((imageProcessorUserStateToInput as ICollection).SyncRoot)
                    {
                        imageProcessorUserStateToInput[userState] = task.Key;
                    }
                    lock (imageProcessingManagerTaskContext.CurrentProcessingPluginUserStates)
                    {
                        imageProcessingManagerTaskContext.CurrentProcessingPluginUserStates.Add(userState);
                    }
                    imageProcessor.ProcessAsync(task, processingPlugins, outputPlugin, userState);
                }
            }
            while (imageProcessingManagerTaskContext.CurrentProcessingPluginUserStates.Count > 0)
            {
                imageProcessingManagerTaskContext.Semaphore.WaitOne();
            }
            bool cancelled = IsTaskCancelled(asyncOp.UserSuppliedState);
            asyncOp.PostOperationCompleted(processAsyncCompletedDelegate, new AsyncCompletedEventArgs(null, cancelled, asyncOp.UserSuppliedState));
        }
Ejemplo n.º 13
0
 private void comboBoxOutputType_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (currentOutputPlugin != null)
     {
         currentOutputPlugin.Dispose();
     }
     currentOutputType = comboBoxOutputType.Text;
     currentOutputPlugin = Activator.CreateInstance(comboBoxItemToOutputPluginType[currentOutputType]) as IOutputPlugin;
     if (currentOutputPlugin.ConfigForm == null)
     {
         buttonOutputOption.Enabled = false;
     }
     else
     {
         buttonOutputOption.Enabled = true;
     }
 }
Ejemplo n.º 14
0
        public void ProcessAsync(IDictionary<string, string> tasks, IEnumerable<IProcessingPlugin> processingPlugins, IOutputPlugin outputPlugin, object userState)
        {
            if (IsTaskCancelled(userState))
            {
                ProcessProgressForm processProgressForm = null;
                try
                {
                    AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(userState);
                    processProgressForm = new ProcessProgressForm(userState);
                    processProgressForm.CancelProcess += processingProgressForm_CancelProcessDelegate;
                    processProgressForm.AddListViewItems(tasks.Keys);

                    lock ((userStateToLifetime as ICollection).SyncRoot)
                    {
                        userStateToLifetime[userState] = asyncOp;
                    }

                    lock ((userStateToProcessProgressForm as ICollection).SyncRoot)
                    {
                        userStateToProcessProgressForm[userState] = processProgressForm;
                    }

                    processWorkerDelegate.BeginInvoke(new Queue<KeyValuePair<string, string>>(tasks), processingPlugins, outputPlugin, asyncOp, null, null);
                    processProgressForm.ShowDialog();
                }
                finally
                {
                    if (processProgressForm != null)
                    {
                        processProgressForm.Dispose();
                    }
                }
            }
            else
            {
                throw new ArgumentException("用户状态已存在。", "userState");
            }
        }
Ejemplo n.º 15
0
 public void RemoveOutputPlugin(IOutputPlugin plugin)
 {
     this.OutputPlugins.Remove(plugin);
     SaveToStorage(() => this.OutputPlugins, this.OutputPlugins);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// 异步工作线程。
        /// </summary>
        /// <param name="task">输入路径到输出路径</param>
        /// <param name="processingPlugins">处理插件</param>
        /// <param name="outputPlugin">输出插件</param>
        /// <param name="asyncOp">跟踪异步操作的生存期。</param>
        private void ProcessWorker(KeyValuePair<string, string> task, IEnumerable<IProcessingPlugin> processingPlugins, IOutputPlugin outputPlugin, AsyncOperation asyncOp)
        {
            // 创建处理任务上下文对象。
            ImageProcessorTaskContext imageProcessorTaskContext = new ImageProcessorTaskContext();
            imageProcessorTaskContext.TotalProcedureCount = processingPlugins.Count() + 2;

            // 为 ProcessingPlugin 添加事件处理方法。
            foreach (var processingPlugin in processingPlugins)
            {
                // ! 重要,保证多任务处理事件唯一,也许以后可能有更好的方法。
                lock (processingPlugin)
                {
                    processingPlugin.ProcessProgressChanged -= processingPlugin_ProcessProgressChangedDelegate;
                    processingPlugin.ProcessCompleted -= getBitmapCompletedDelegate;
                    processingPlugin.ProcessProgressChanged += processingPlugin_ProcessProgressChangedDelegate;
                    processingPlugin.ProcessCompleted += getBitmapCompletedDelegate;
                }
                imageProcessorTaskContext.ProcessingPluginQueue.Enqueue(processingPlugin);
            }

            // 添加到对应关系中。
            lock ((userStateToTaskContext as ICollection).SyncRoot)
            {
                userStateToTaskContext[asyncOp.UserSuppliedState] = imageProcessorTaskContext;
            }

            // 创建 UserState 对象。
            object userState = Guid.NewGuid();

            // 添加到对应关系中。
            lock ((taskUserStateToUserState as ICollection).SyncRoot)
            {
                taskUserStateToUserState[userState] = asyncOp.UserSuppliedState;
            }

            // 开始获取 Bitmap。
            getBitmapManager.GetBitmapAsync(task.Key, userState);

            while (imageProcessorTaskContext.ProcessingPluginQueue.Count > 0)
            {
                // 等待上步操作完成。
                imageProcessorTaskContext.AutoResetEvent.WaitOne();

                if (IsTaskCancelled(asyncOp.UserSuppliedState) || imageProcessorTaskContext.Error != null)
                {
                    break;
                }
                else
                {
                    IProcessingPlugin processingPlugin = imageProcessorTaskContext.ProcessingPluginQueue.Dequeue();
                    userState = Guid.NewGuid();
                    imageProcessorTaskContext.CurrentProcessingPlugin = processingPlugin;
                    imageProcessorTaskContext.CurrentProcessingPluginUserState = userState;

                    lock ((taskUserStateToUserState as ICollection).SyncRoot)
                    {
                        taskUserStateToUserState[userState] = asyncOp.UserSuppliedState;
                    }
                    processingPlugin.ProcessAsync(imageProcessorTaskContext.Bitmap, userState);
                }
            }

            if (!IsTaskCancelled(asyncOp.UserSuppliedState) && imageProcessorTaskContext.Error == null)
            {
                // 等待最后处理完成。
                imageProcessorTaskContext.AutoResetEvent.WaitOne();

                // 输出。
                outputPlugin.Output(imageProcessorTaskContext.Bitmap, task.Value);
            }

            bool cancelled = IsTaskCancelled(asyncOp.UserSuppliedState);
            lock ((userStateToLifetime as ICollection).SyncRoot)
            {
                userStateToLifetime.Remove(asyncOp.UserSuppliedState);
            }
            asyncOp.PostOperationCompleted(processAsyncCompletedDelegate, new AsyncCompletedEventArgs(imageProcessorTaskContext.Error, cancelled, asyncOp.UserSuppliedState));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 异步处理图像。
 /// </summary>
 /// <param name="bitmap">要处理的图像</param>
 /// <param name="userState">用户状态</param>
 public void ProcessAsync(KeyValuePair<string, string> task, IEnumerable<IProcessingPlugin> processingPlugins, IOutputPlugin outputPlugin, object userState)
 {
     if (IsTaskCancelled(userState))
     {
         AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(userState);
         lock ((userStateToLifetime as ICollection).SyncRoot)
         {
             userStateToLifetime[userState] = asyncOp;
         }
         processWorkerDelegate.BeginInvoke(task, processingPlugins, outputPlugin, asyncOp, null, null);
     }
     else
     {
         throw new ArgumentException("用户状态已存在。", "userState");
     }
 }
Ejemplo n.º 18
0
 public Match(string patternString, IOutputPlugin output)
 {
     pattern = CreateMatchPattern(patternString);
     this.output = output;
 }