public CardFactory(int wordsCountInOneCard, IShuffler<string> shuffler, ICutter<string> cutter) { if (wordsCountInOneCard <= 0) throw new ArgumentException("Параметр wordsCountInOneCard должен быть больше нуля!"); this.MaxWordsCountInOneCard = wordsCountInOneCard; this.Shuffler = shuffler; this.Cutter = cutter; }
public Bot(int processId, IAsyncRecogniser recogniser, IRepository <TestQuestion> testRepository, IRepository <NumericQuestion> numberRepository, ICutter cutter, IClicker clicker, IReopener reopener) { _process = Process.GetProcesses().FirstOrDefault(p => p.Id == processId); if (_process == null) { Console.WriteLine("Процесс не найден"); throw new Exception(); } _recogniserAsync = recogniser; mode = SyncMode.Async; // Ассинхронный распознаватель _testRepository = testRepository; _numericRepository = numberRepository; _cutter = cutter; _clicker = clicker; _reopener = reopener; }
public ICutter CreateCutter() { ICutter cutter = null; var i = (int)(3 * _random.NextDouble()); switch (i) { case 0: cutter = new Actor(); break; case 1: cutter = new Barber(); break; case 2: cutter = new Butcher(); break; } return(cutter); }
/// <summary> /// Der Anwender wünscht den Schnitt auszuführen. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void cmdRun_Click(object sender, System.EventArgs e) { // Update settings Properties.Settings.Default.Framerate = FrameRateInfo.FindFrameRate(selRate.SelectedIndex).Rate; Properties.Settings.Default.Threshold = udMinimum.Value; Properties.Settings.Default.Save(); // Check selection of page if (selPage.SelectedItem != null) { Properties.Settings.Default.SubtitlePage = (int)selPage.SelectedItem; } // With error handling try { // Load file FileInfo outFile = new FileInfo(saveCut.FileName); // Get the type string suffix = outFile.Extension; // Check if ((null == suffix) || (suffix.Length < 2)) { throw new ApplicationException(Properties.Resources.Error_Format); } // Cut off suffix = suffix.Substring(1); // Load type name string typeName = ConfigurationManager.AppSettings[suffix.ToUpper()]; // Check if ((null == typeName) || (typeName.Length < 1)) { throw new ApplicationException(Properties.Resources.Error_Format); } // Find the type Type cutType = Type.GetType(typeName, true); // Create extractor using (ICutter cutter = (ICutter)Activator.CreateInstance(cutType)) { // Configure cutter.Framerate = FrameRateInfo.FindFrameRate(selRate.SelectedIndex).Rate; cutter.MinDuration = (double)udMinimum.Value; // Check for VCR.NET 3.1 or later ICutter2 cutter31 = cutter as ICutter2; if (null != cutter31) { cutter31.TimeCorrection = (double)udCorrect.Value; } // Position in output file long pos = 0; // Process all cuts foreach (CutElement cut in m_ProjectFile.CutElements) { // Get the core name string coreName = Path.GetFileNameWithoutExtension(cut.VideoFile.FullName); // Append page number if (!ckDVB.Checked) { coreName += "[" + Properties.Settings.Default.SubtitlePage.ToString() + "]"; } // Replace suffix FileInfo ttxFile = new FileInfo(cut.VideoFile.DirectoryName + @"\" + coreName + "." + suffix); // Must exist if (!ttxFile.Exists) { continue; } // Validate if (cut.Start > cut.End) { continue; } // Process cutter.Cut(ttxFile.FullName, cut.Start, cut.End, pos); // Adjust frame counter pos += cut.End - cut.Start + 1; } // Finish cutter.Save(saveCut.FileName); } // Done on success Close(); } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Properties.Resources.Error_Failed); } }
/// <summary> /// 构造函数根,所有其他构造函数都从此进入 /// </summary> /// <param name="socket">核心socket,必须是已经打开的TCP socket</param> /// <param name="eventArgsfactory"> /// <para>获得异步事件对象和回收该对象的方法。</para> /// <para>输入空值会创建默认新建和销毁逻辑.</para></param> /// <param name="byteSegmentLocator"> /// <para>收到数据后创建和定位目标数据片段的定位器。</para> /// <para>输入空值会创建默认创建新数组的逻辑</para> /// </param> /// <param name="byteSegmentLocator"> /// <para>事件容器,负责处理统一的事件相应。</para> /// <para>输入空值会使用静态的默认容器,可以为一组client指定同一个容器进行分流</para> /// </param> public ReactiveTcpClient( Socket socket, ICutter <TPacket> dataCutter, IPacker <TPacket> dataPacker, Func <Disposable <SocketAsyncEventArgs> > eventArgsfactory = null, IByteSegmentLocator byteSegmentLocator = null, ITcpClientEventContainer eventContainer = null ) { //Contract.Requires<ArgumentNullException>(dataCutter != null, "Parameter dataCutter cannot be null."); //Contract.Requires<ArgumentNullException>(dataPacker != null, "Parameter dataPacker cannot be null."); //Contract.Requires<ArgumentNullException>(eventArgsfactory != null, "Parameter eventArgsfactory cannot be null."); //Contract.Requires<ArgumentNullException>(socket != null, "Parameter socket cannot be null."); //Contract.Requires<ArgumentException>(socket.ProtocolType.HasFlag(ProtocolType.Tcp), "Parameter socket should be TCP socket."); //Contract.Requires<ArgumentException>(socket.Connected, "Parameter socket must be open."); //_disposeActionList.Push(() => socket.Dispose()); ExecutionSchedulerPair = new ConcurrentExclusiveSchedulerPair(); _dataCutter = dataCutter; _dataPacker = dataPacker; //默认创建销毁逻辑。 eventArgsfactory = eventArgsfactory ?? new Func <Disposable <SocketAsyncEventArgs> >( () => new Disposable <SocketAsyncEventArgs>( ea => ea.Dispose(), new SocketAsyncEventArgs() ) ); //默认创建新数组逻辑 _byteSegmentLocator = byteSegmentLocator ?? new NewArrayByteSegmentLocator(); //默认事件订阅容器 EventContainer = eventContainer ?? TcpClientEventContainer.DefaultInstance; //创建字段对象 _socket = socket; _disposeActionList.Push(() => _socket.Dispose()); _disposed = false; //_asyncSupport = new ObservableToAsync<TPacket>(); _sendingQueue = new ConcurrentQueue <Tuple <Queue <ArraySegment <byte> >, AsyncCallback, AbortionChecker> >(); _packetReceivedBuffer = new BufferBlock <TPacket>(); _packetReceivedObservable = _packetReceivedBuffer.AsObservable(); _packetReceivedObserver = _packetReceivedBuffer.AsObserver(); _sendLaucherSubject = new Subject <SocketAsyncEventArgs>(); _disposeActionList.Push(() => _sendLaucherSubject.Dispose()); //获得发送的事件参数并且登记销毁 var tokenSend = eventArgsfactory(); _sendEventArgs = tokenSend.StateObject; _disposeActionList.Push( () => { tokenSend.Dispose(); _sendEventArgs = null; }); //获得接收的事件参数并且登记销毁 var tokenReceive = eventArgsfactory(); _receiveEventArgs = tokenReceive.StateObject; _disposeActionList.Push( () => { tokenReceive.Dispose(); _receiveEventArgs = null; }); //设置接收订阅 ConfigReceive(); //设置发送订阅 ConfigSend(); }