public void GetCode(CodeFormat format, TextWriter writer) { IOutputProvider output; switch (format) { case CodeFormat.Disassemble: output = OutputFactory.GetDisassembleOutputProvider(); break; case CodeFormat.ControlFlowDecompile: output = OutputFactory.GetDecompileCFOutputProvider(); break; case CodeFormat.FullDecompile: output = OutputFactory.GetDecompileFullOutputProvider(); break; case CodeFormat.FullDecompileAnnotate: output = OutputFactory.GetDecompileFullAnnotateOutputProvider(); break; case CodeFormat.CodePath: output = OutputFactory.GetCodePathOutputProvider(); break; case CodeFormat.Variables: output = OutputFactory.GetVariablesOutputProvider(); break; case CodeFormat.ScruffDecompile: output = OutputFactory.GetScruffDecompileOutputProvider(); break; case CodeFormat.ScruffHeader: output = OutputFactory.GetScruffHeaderOutputProvider(); break; default: throw new ArgumentOutOfRangeException("format"); } output.Process(_file, writer); }
/// <summary> /// Transmits an IR code asynchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount"> /// Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times). /// </param> /// <param name="inactivityWaitTime"> /// Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter. /// </param> /// <param name="userState"> /// An optional user state object that will be passed to the /// TransmitCompleted event. /// </param> public void TransmitAsync( string irCode, CodeFormat codeFormat, int repeatCount, TimeSpan inactivityWaitTime, object userState) { CheckDisposed(); if (null == irCode) { throw new ArgumentNullException("irCode", "irCode cannot be null"); } if (0 == irCode.Length) { throw new ArgumentException("irCode", "irCode cannot be empty"); } if (repeatCount < 0) { throw new ArgumentOutOfRangeException("repeatCount", "repeatCount cannot be negative"); } if (inactivityWaitTime < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("inactivityWaitTime", "inactivityWaitTime cannot be less than TimeSpan.Zero"); } var transmitState = new TransmitState(irCode, codeFormat, repeatCount, Convert.ToInt32(inactivityWaitTime.TotalMilliseconds), userState); if (false == ThreadPool.QueueUserWorkItem(DoTransmit, transmitState)) { throw new ApplicationException("Unable to QueueUserWorkItem"); } }
/// <summary> /// Learns an IR code asynchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="forcedFrequency">The frequency to use in learning.</param> /// <param name="userState"> /// An optional user state object that will be passed to the /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel(). /// </param> public void LearnAsync(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, uint forcedFrequency, object userState) { CheckDisposed(); if (LearnCodeModifier.ForceFrequency == learnCodeFormat) { if (0 == forcedFrequency) { throw new ArgumentException("forcedFrequency", "forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency"); } } else { if (0 != forcedFrequency) { throw new ArgumentException("forcedFrequency", "forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency"); } } object learnStatesKey = null == userState ? this : userState; var learnState = new LearnState(codeFormat, learnCodeFormat, forcedFrequency, userState); _learnStates[learnStatesKey] = learnState; if (false == ThreadPool.QueueUserWorkItem(DoLearn, learnState)) { throw new ApplicationException("Unable to QueueUserWorkItem"); } }
public void ToPascalSingleLetters() { Assert.AreEqual("HelloThereBuddyL", CodeFormat.ToPascalCase("Hello there buddy l")); Assert.AreEqual("HelloThereBuddyL", CodeFormat.ToPascalCase("Hello there buddy L")); Assert.AreEqual("HelloThereABuddyL", CodeFormat.ToPascalCase("Hello there a buddy L")); Assert.AreEqual("ABuddyLeeIsABuddyNDeed", CodeFormat.ToPascalCase("a buddy Lee is a buddy n deed")); }
/// <summary> /// GetNextCode /// </summary> /// <returns></returns> public String GetNextCode(string EntityName) { string returnCode = string.Empty; try { CodeFormat codeFormat = eCollabroDbContext.Repository <CodeFormat>().Query().Get().Where(cf => cf.EntityName.Equals(EntityName)).FirstOrDefault(); lock (codeFormat) { codeFormat.CurrentSeed += 1; eCollabroDbContext.Save(); int genCodeLength = (codeFormat.Prefix.Trim() + codeFormat.Seprator.Trim() + codeFormat.CurrentSeed.ToString() + codeFormat.Seprator.Trim() + codeFormat.Suffix.Trim()).Length; int shortLength = codeFormat.Codelength.Value - genCodeLength; string zero = string.Empty; for (int i = 0; i < shortLength; i++) { zero = zero + "0"; } returnCode = (!String.IsNullOrEmpty(codeFormat.Suffix)) ? (codeFormat.Prefix + codeFormat.Seprator + zero + codeFormat.CurrentSeed.ToString() + codeFormat.Seprator + codeFormat.Suffix) : (codeFormat.Prefix + codeFormat.Seprator + zero + codeFormat.CurrentSeed.ToString()); } } catch (Exception ex) { if (!HandleError(ex)) { throw; } } return(returnCode); }
public void ToPascalSpecialPuncuation() { Assert.AreEqual("Bahai", CodeFormat.ToPascalCase("Baha'i")); Assert.AreEqual("RegionalBaháíCouncil", CodeFormat.ToPascalCase("Regional Bahá'í Council")); Assert.AreEqual("HuqúqulláhBoard", CodeFormat.ToPascalCase("Huqúq'u'lláh Board")); Assert.AreEqual("ChuukTruk", CodeFormat.ToPascalCase("Chuuk (truk)")); }
/// <summary> /// Transmits an IR code synchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount"> /// Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times). /// </param> /// <param name="inactivityWaitTime"> /// Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter. /// </param> public void Transmit( string irCode, CodeFormat codeFormat, int repeatCount, TimeSpan inactivityWaitTime) { CheckDisposed(); if (null == irCode) { throw new ArgumentNullException("irCode", "irCode cannot be null"); } if (0 == irCode.Length) { throw new ArgumentException("irCode", "irCode cannot be empty"); } if (repeatCount < 0) { throw new ArgumentOutOfRangeException("repeatCount", "repeatCount cannot be negative"); } if (inactivityWaitTime < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("inactivityWaitTime", "inactivityWaitTime cannot be less than TimeSpan.Zero"); } using (var evt = new ManualResetEvent(false)) { TransmitIr(irCode, codeFormat, repeatCount, Convert.ToInt32(inactivityWaitTime.TotalMilliseconds), evt); evt.WaitOne(); } }
static void CreateWindow() { CodeFormat window = (CodeFormat)EditorWindow.GetWindow(typeof(CodeFormat)); window.Init(); window.Show(); }
private static void OutputCode(ScriptFile file, CodeFormat format, TextWriter writer) { writer.WriteLine("// Generated by Scruff v" + Version + ", (c) 2008, aru."); writer.WriteLine("// This disassembly/decompilation is licensed for research purposes only."); writer.WriteLine(); file.GetCode(format, writer); }
public Task LearnAsync(CodeFormat? codeFormat = null, LearnCodeModifier? learnCodeModifier = null, uint? forcedFrequency = null, object userState = null) { _waitHandle.WaitOne(); return _learner.LearnAsync(codeFormat, learnCodeModifier, forcedFrequency, userState); }
public void Learn(CodeFormat? codeFormat = null, LearnCodeModifier? learnCodeFormat = null, uint? forcedFrequency = null, TimeSpan? timeout = null) { _waitHandle.WaitOne(); _learner.Learn(codeFormat, learnCodeFormat, forcedFrequency, timeout); }
public LearnHelper(Driver driver, CodeFormat defaultCodeFormat = CodeFormat.Pronto, LearnCodeModifier defaultLearnCodeModifier = LearnCodeModifier.Default) : base(driver) { SetUpLearner(driver, defaultCodeFormat, defaultLearnCodeModifier); SetUpReceiver(driver); }
public void ToPascalWithMultipleSpaces() { Assert.AreEqual("TelevisionAdvertisement", CodeFormat.ToPascalCase("Television Advertisement")); Assert.AreEqual("TelevisionAdvertisement", CodeFormat.ToPascalCase("Television Advertisement")); Assert.AreEqual("TelevisionAdvertisementMaterial", CodeFormat.ToPascalCase("Television Advertisement Material")); Assert.AreEqual("TelevisionAdvertisementMaterial", CodeFormat.ToPascalCase("Television Advertisement material")); Assert.AreEqual("TelevisionAdvertisementMaterial", CodeFormat.ToPascalCase("Television advertisement Material")); }
public Learner(Driver driver, CodeFormat defaultCodeFormat = CodeFormat.Pronto, LearnCodeModifier defaultLearnCodeModifier = LearnCodeModifier.Default) : base(driver) { _defaultLearnCodeFormat = defaultCodeFormat; _defaultLearnCodeModifier = defaultLearnCodeModifier; }
/// <summary> /// Transmits an IR code asynchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount"> /// Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times). /// </param> /// <param name="inactivityWaitTime"> /// Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter. /// </param> public void TransmitAsync( string irCode, CodeFormat codeFormat, int repeatCount, TimeSpan inactivityWaitTime) { CheckDisposed(); TransmitAsync(irCode, codeFormat, repeatCount, inactivityWaitTime, null); }
/// <summary> /// Creates an instance of the Transmitter class that can be used to transmit IR codes. /// </summary> /// <param name="defaultEmitter">The emitter to transmit the IR code with</param> /// <param name="defaultCodeFormat">The format of the IR code.</param> /// <param name="defaultRepeatCount">Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).</param> /// <param name="defaultInactivityWaitTime">Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.</param> /// <remarks>This class should be disposed if using this constructor.</remarks> public Transmitter(Emitter defaultEmitter = Emitter.All, CodeFormat defaultCodeFormat = CodeFormat.Pronto, int defaultRepeatCount = 1, int defaultInactivityWaitTime = 0) { _defaultEmitter = defaultEmitter; _defaultCodeFormat = defaultCodeFormat; _defaultRepeatCount = defaultRepeatCount; _defaultInactivityWaitTime = defaultInactivityWaitTime; }
internal LearnState(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, uint forcedFrequency, object userState) { _codeFormat = codeFormat; _learnCodeFormat = learnCodeFormat; _forcedFrequency = forcedFrequency; _userState = userState; _abort = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32))); Marshal.WriteInt32(_abort, 0); }
internal TransmitState(string irCode, CodeFormat codeFormat, int repeatCount, int inactivityWaitTime, object userState) { _irCode = irCode; _codeFormat = codeFormat; _repeatCount = repeatCount; _inactivityWaitTime = inactivityWaitTime; _userState = userState; _evt = new ManualResetEvent(false); }
public string GetCode(CodeFormat format) { var sb = new StringBuilder(); var sw = new StringWriter(sb); GetCode(format, sw); sw.Close(); return(sb.ToString()); }
public string GetCode(CodeFormat format) { var sb = new StringBuilder(); var sw = new StringWriter(sb); GetCode(format, sw); sw.Close(); return sb.ToString(); }
private void TransmitIr(string irCode, CodeFormat codeFormat, int repeatCount, int inactivityWaitTime, ManualResetEvent evt) { if (false == UUIRTTransmitIR( _hDrvHandle, irCode, (int)codeFormat, repeatCount, inactivityWaitTime, null == evt ? IntPtr.Zero : evt.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, IntPtr.Zero)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public override void AddCode(string file, CodeFormat format = CodeFormat.Cs) { string fileContend = File.ReadAllText(file); var code = fileContend.Split('\n').ToList(); Builder.AppendLine(); Builder.AppendLine(format == CodeFormat.Cs ? "<pre lang=\"cs\">" : "<pre lang=\"xml\">"); var minIndent = code.Min(GetIndent); foreach (var item in code.Skip(code.First() == "\r" ? 1 : 0)) { NormalizeIndent(System.Net.WebUtility.HtmlEncode(item), minIndent); } Builder.AppendLine("</pre>"); Builder.AppendLine(); }
public override void AddCode(string file, string section, CodeFormat format = CodeFormat.Cs) { string fileContend = File.ReadAllText(file); var code = ExtractFromString(fileContend, "// " + section, "// End" + section).SelectMany(p => p.Split('\n')).ToList(); Builder.AppendLine(); Builder.AppendLine(format == CodeFormat.Cs ? ".. sourcecode:: csharp" : ".. sourcecode:: xml"); Builder.AppendLine(); var minIndent = code.Min(GetIndent); var enumerable = code.SkipWhile(string.IsNullOrWhiteSpace); foreach (var item in enumerable) { NormalizeIndent(item, minIndent); } Builder.AppendLine(); }
public override void AddCode(string file, CodeFormat format = CodeFormat.Cs) { string fileContend = File.ReadAllText(file); var code = fileContend.Split('\n').ToList(); Builder.AppendLine(); Builder.AppendLine(format == CodeFormat.Cs ? ".. sourcecode:: csharp" : ".. sourcecode:: xml"); Builder.AppendLine(); var minIndent = code.Min(GetIndent); var enumerable = code.SkipWhile(string.IsNullOrWhiteSpace); foreach (var item in enumerable) { NormalizeIndent(item, minIndent); } Builder.AppendLine(); }
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="forcedFrequency">The frequency to use in learning.</param> /// <param name="timeout">The timeout after which to abort learning if it has not completed.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, uint forcedFrequency, TimeSpan timeout) { CheckDisposed(); if (timeout < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("timeout", "timeout cannot be negative"); } using (var results = new SyncLearnResults()) { LearnCompleted += ManagedWrapper_LearnCompleted; try { LearnAsync(codeFormat, learnCodeFormat, forcedFrequency, results); if (TimeSpan.Zero == timeout) { results.WaitEvent.WaitOne(); return(results.LearnCompletedEventArgs.Code); } else if (results.WaitEvent.WaitOne(timeout, false)) { if (null != results.LearnCompletedEventArgs.Error) { throw results.LearnCompletedEventArgs.Error; } else if (results.LearnCompletedEventArgs.Cancelled) { return(null); } return(results.LearnCompletedEventArgs.Code); } else { LearnAsyncCancel(results); return(null); } } finally { LearnCompleted -= ManagedWrapper_LearnCompleted; } } }
public string Format(string value, CodeFormat codeFormat) { string code = value; try { if ((codeFormat & CodeFormat.Trim) == CodeFormat.Trim) { code = code.Trim(); } if ((codeFormat & CodeFormat.WithoutNumberSeparator) == CodeFormat.WithoutNumberSeparator) { code = code.Replace(NUMBER_SEPARATOR, ""); } if ((codeFormat & CodeFormat.WithoutDigit) == CodeFormat.WithoutDigit) { string digit = value.Trim().Substring(value.Length - 2, 2); code = code.Substring(0, code.LastIndexOf(digit)); codeFormat |= CodeFormat.WithoutDigitSeparator; } if ((codeFormat & CodeFormat.WithoutDigitSeparator) == CodeFormat.WithoutDigitSeparator) { code = code.Replace(DIGIT_SEPARATOR, ""); } } catch { throw; } return(code); }
/// <summary> /// Learns an IR code asynchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="forcedFrequency">The frequency to use in learning.</param> /// <param name="userState">An optional user state object that will be passed to the /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().</param> public void LearnAsync(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, uint forcedFrequency, object userState) { CheckDisposed(); if (LearnCodeModifier.ForceFrequency == learnCodeFormat) { if (0 == forcedFrequency) { throw new ArgumentException("forcedFrequency", "forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency"); } } else { if (0 != forcedFrequency) { throw new ArgumentException("forcedFrequency", "forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency"); } } object learnStatesKey = null == userState ? this : userState; LearnState learnState = new LearnState(codeFormat, learnCodeFormat, forcedFrequency, userState); _learnStates[learnStatesKey] = learnState; if (false == ThreadPool.QueueUserWorkItem(new WaitCallback(DoLearn), learnState)) { throw new ApplicationException("Unable to QueueUserWorkItem"); } }
/// <summary> /// Learns an IR code asynchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeModifier">The modifier used for the code format.</param> /// <param name="forcedFrequency">The frequency to use in learning.</param> /// <param name="userState">An optional user state object that will be passed to the /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().</param> public Task<string> LearnAsync( CodeFormat? codeFormat = null, LearnCodeModifier? learnCodeModifier = null, uint? forcedFrequency = null, object userState = null) { CheckDisposed(); if (learnCodeModifier == LearnCodeModifier.ForceFrequency) { if (forcedFrequency == 0) { throw new ArgumentException("forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency", "forcedFrequency"); } } else { if (forcedFrequency != null && forcedFrequency != 0) { throw new ArgumentException("forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency", "forcedFrequency"); } } object learnStatesKey = userState ?? this; var cancellationSource = new CancellationTokenSource(); var learnState = new LearnState( codeFormat ?? _defaultLearnCodeFormat, learnCodeModifier ?? _defaultLearnCodeModifier, cancellationSource, forcedFrequency ?? 0, userState); _learnStates[learnStatesKey] = learnState; var learnTask = Task<string>.Factory.StartNew(LearnInternal, learnState, cancellationSource.Token); learnTask.ContinueWith(t => { try { var temp = LearnCompleted; if (temp != null) { temp(this, new LearnCompletedEventArgs(t.Exception, learnState.WasAborted, t.Result, learnState.UserState)); } } finally { learnState.Dispose(); learnStatesKey = null == learnState.UserState ? this : t.AsyncState; _learnStates[learnStatesKey] = null; } }); return learnTask; }
private void SetUpLearner(Driver driver, CodeFormat defaultCodeFormat, LearnCodeModifier defaultLearnCodeModifier) { _learner = driver == null ? new Learner(defaultCodeFormat, defaultLearnCodeModifier) : new Learner(driver, defaultCodeFormat, defaultLearnCodeModifier); _learner.LearnCompleted += OnLearnComplete; }
public abstract void AddCode(string file, CodeFormat format = CodeFormat.Cs);
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn(CodeFormat codeFormat) { CheckDisposed(); return(Learn(codeFormat, _defaultLearnCodeModifier, TimeSpan.Zero)); }
/// <summary> /// Transmits an IR code synchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount">Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).</param> /// <param name="inactivityWaitTime">Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.</param> /// <param name="emitter">The emitter to transmit the IR code with</param> public void Transmit( string irCode, Emitter? emitter = null, CodeFormat? codeFormat = null, int? repeatCount = null, int? inactivityWaitTime = null) { CheckDisposed(); var task = Task.Factory.StartNew(() => TransmitInternal(irCode, codeFormat, repeatCount, inactivityWaitTime, emitter)); try { task.Wait(); } catch (Exception ex) { throw ex.GetBaseException(); } }
/// <summary> /// Transmits an IR code asynchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount">Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).</param> /// <param name="inactivityWaitTime">Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.</param> /// <param name="userState">An optional user state object that will be passed to the /// TransmitCompleted event.</param> public void TransmitAsync( string irCode, CodeFormat codeFormat, int repeatCount, TimeSpan inactivityWaitTime, object userState) { CheckDisposed(); if (null == irCode) { throw new ArgumentNullException("irCode", "irCode cannot be null"); } if (0 == irCode.Length) { throw new ArgumentException("irCode", "irCode cannot be empty"); } if (repeatCount < 0) { throw new ArgumentOutOfRangeException("repeatCount", "repeatCount cannot be negative"); } if (inactivityWaitTime < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("inactivityWaitTime", "inactivityWaitTime cannot be less than TimeSpan.Zero"); } TransmitState transmitState = new TransmitState(irCode, codeFormat, repeatCount, Convert.ToInt32(inactivityWaitTime.TotalMilliseconds), userState); if (false == ThreadPool.QueueUserWorkItem(new WaitCallback(DoTransmit), transmitState)) { throw new ApplicationException("Unable to QueueUserWorkItem"); } }
public static string CodeFromString(string str, CodeFormat outputFormat) { string ret = null; switch (outputFormat) { case CodeFormat.DEFAULT: ret = CodeFromString(str); break; case CodeFormat.YAHOO: ret = CodeFromString(str); if (ret.EndsWith(".HK") && ret[0] == '0') ret = ret.Substring(1); break; } return ret; }
public LearnHelper(CodeFormat defaultCodeFormat = CodeFormat.Pronto, LearnCodeModifier defaultLearnCodeModifier = LearnCodeModifier.Default) { SetUpLearner(null, defaultCodeFormat, defaultLearnCodeModifier); SetUpReceiver(); }
/// <summary> /// Learns an IR code asynchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> public void LearnAsync(CodeFormat codeFormat) { CheckDisposed(); LearnAsync(codeFormat, _defaultLearnCodeModifier, null); }
/// <summary> /// Learns an IR code asynchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="userState"> /// An optional user state object that will be passed to the /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel(). /// </param> public void LearnAsync(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, object userState) { CheckDisposed(); LearnAsync(codeFormat, learnCodeFormat, 0, userState); }
private void TransmitInternal( string irCode, CodeFormat? codeFormat, int? repeatCount, int? inactivityWaitTime, Emitter? emitter) { //This is kind of hackish... codeFormat = codeFormat ?? _defaultCodeFormat; repeatCount = repeatCount ?? _defaultRepeatCount; inactivityWaitTime = inactivityWaitTime ?? _defaultInactivityWaitTime; emitter = emitter ?? _defaultEmitter; if (irCode == null) { throw new ArgumentNullException("irCode", "irCode cannot be null"); } if (irCode.Length == 0) { throw new ArgumentException("irCode", "irCode cannot be empty"); } if (repeatCount < 0) { throw new ArgumentOutOfRangeException("repeatCount", "repeatCount cannot be negative"); } if (inactivityWaitTime < 0) { throw new ArgumentOutOfRangeException("inactivityWaitTime", "inactivityWaitTime cannot be less than TimeSpan.Zero"); } using (var evt = new ManualResetEvent(false)) { if (false == UUIRTTransmitIR( DriverHandle, emitter.Value.GetZoneForEmitter() + irCode, (int)codeFormat.Value, repeatCount.Value, inactivityWaitTime.Value, evt.Handle, IntPtr.Zero, IntPtr.Zero)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } evt.WaitOne(); } }
/// <summary> /// Transmits an IR code asynchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount">Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).</param> /// <param name="inactivityWaitTime">Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.</param> /// <param name="emitter">The emitter to transmit the IR code with</param> /// <param name="userState">An optional user state object that will be passed to the /// TransmitCompleted event.</param> public Task TransmitAsync( string irCode, object userState = null, Emitter? emitter = null, CodeFormat? codeFormat = null, int? repeatCount = null, int? inactivityWaitTime = null) { CheckDisposed(); var task = Task.Factory .StartNew(() => TransmitInternal(irCode, codeFormat, repeatCount, inactivityWaitTime, emitter)); task.ContinueWith(t => { var temp = TransmitCompleted; if (null != temp) { temp(this, new TransmitCompletedEventArgs(t.Exception, userState)); } }); return task; }
/// <summary> /// Transmits an IR code synchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount">Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).</param> /// <param name="inactivityWaitTime">Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.</param> public void Transmit( string irCode, CodeFormat codeFormat, int repeatCount, TimeSpan inactivityWaitTime) { CheckDisposed(); if (null == irCode) { throw new ArgumentNullException("irCode", "irCode cannot be null"); } if (0 == irCode.Length) { throw new ArgumentException("irCode", "irCode cannot be empty"); } if (repeatCount < 0) { throw new ArgumentOutOfRangeException("repeatCount", "repeatCount cannot be negative"); } if (inactivityWaitTime < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("inactivityWaitTime", "inactivityWaitTime cannot be less than TimeSpan.Zero"); } using (ManualResetEvent evt = new ManualResetEvent(false)) { TransmitIr(irCode, codeFormat, repeatCount, Convert.ToInt32(inactivityWaitTime.TotalMilliseconds), evt); evt.WaitOne(); } }
/// <summary> /// Transmits an IR code asynchronously. /// </summary> /// <param name="irCode">The IR code to transmit.</param> /// <param name="codeFormat">The format of the IR code.</param> /// <param name="repeatCount">Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).</param> /// <param name="inactivityWaitTime">Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.</param> public void TransmitAsync( string irCode, CodeFormat codeFormat, int repeatCount, TimeSpan inactivityWaitTime) { CheckDisposed(); TransmitAsync(irCode, codeFormat, repeatCount, inactivityWaitTime, null); }
private void TransmitIr(string irCode, CodeFormat codeFormat, int repeatCount, int inactivityWaitTime, ManualResetEvent evt) { if (false == UUIRTTransmitIR( _hDrvHandle, irCode, (int) codeFormat, repeatCount, inactivityWaitTime, null == evt ? IntPtr.Zero : evt.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, IntPtr.Zero)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public CodeFormatOptions(string param, CodeFormat format, string description) { Param = param; Format = format; Description = description; }
private static void TestLearn(Controller mc, CodeFormat learnFormat, LearnCodeModifier learnCodeModifier) { learnCompletedEventArgs = null; Console.WriteLine("<Press x to abort Learn>"); mc.Learning += new UsbUirt.Controller.LearningEventHandler(mc_Learning); mc.LearnCompleted += new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted); try { try { mc.LearnAsync(learnFormat, learnCodeModifier, learnCompletedEventArgs); } catch(Exception ex) { Console.WriteLine("*** ERROR calling LearnAsync! ***"); throw; } while (learnCompletedEventArgs == null) { string s = Console.ReadLine(); if (s.Length != 0 && s[0] == 'x') { if (learnCompletedEventArgs == null) { Console.WriteLine("Calling LearnAsyncCancel..."); mc.LearnAsyncCancel(learnCompletedEventArgs); Thread.Sleep(1000); break; } } else { Console.WriteLine("<Press x to abort Learn>"); } } if (learnCompletedEventArgs != null && learnCompletedEventArgs.Cancelled == false && learnCompletedEventArgs.Error == null) { irCode = learnCompletedEventArgs.Code; Console.WriteLine("...Done...IRCode = {0}", irCode); transmitFormat = learnFormat; } } finally { mc.Learning -= new UsbUirt.Controller.LearningEventHandler(mc_Learning); mc.LearnCompleted -= new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted); } }
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn(CodeFormat codeFormat) { CheckDisposed(); return Learn(codeFormat, _defaultLearnCodeModifier, TimeSpan.Zero); }
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="timeout">The timeout after which to abort learning if it has not completed.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, TimeSpan timeout) { CheckDisposed(); return(Learn(codeFormat, learnCodeFormat, 0, timeout)); }
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="timeout">The timeout after which to abort learning if it has not completed.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, TimeSpan timeout) { CheckDisposed(); return Learn(codeFormat, learnCodeFormat, 0, timeout); }
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="forcedFrequency">The frequency to use in learning.</param> /// <param name="timeout">The timeout after which to abort learning if it has not completed.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, uint forcedFrequency, TimeSpan timeout) { CheckDisposed(); if (timeout < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("timeout", "timeout cannot be negative"); } using (SyncLearnResults results = new SyncLearnResults()) { this.LearnCompleted += new LearnCompletedEventHandler(ManagedWrapper_LearnCompleted); try { LearnAsync(codeFormat, learnCodeFormat, forcedFrequency, results); if (TimeSpan.Zero == timeout) { results.WaitEvent.WaitOne(); return results.LearnCompletedEventArgs.Code; } else if (results.WaitEvent.WaitOne(timeout, false)) { if (null != results.LearnCompletedEventArgs.Error) { throw results.LearnCompletedEventArgs.Error; } else if (false != results.LearnCompletedEventArgs.Cancelled) { return null; } return results.LearnCompletedEventArgs.Code; } else { LearnAsyncCancel(results); return null; } } finally { this.LearnCompleted -= new LearnCompletedEventHandler(ManagedWrapper_LearnCompleted); } } }
/// <summary> /// Learns an IR code asynchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="userState">An optional user state object that will be passed to the /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().</param> public void LearnAsync(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, object userState) { CheckDisposed(); LearnAsync(codeFormat, learnCodeFormat, 0, userState); }
public Learner(CodeFormat defaultCodeFormat = CodeFormat.Pronto, LearnCodeModifier defaultLearnCodeModifier = LearnCodeModifier.Default) { _defaultLearnCodeFormat = defaultCodeFormat; _defaultLearnCodeModifier = defaultLearnCodeModifier; }
/// <summary> /// Learns an IR code synchronously. /// </summary> /// <param name="codeFormat">The format of the IR code to use in learning.</param> /// <param name="learnCodeFormat">The modifier used for the code format.</param> /// <param name="forcedFrequency">The frequency to use in learning.</param> /// <param name="timeout">The timeout after which to abort learning if it has not completed.</param> /// <returns>The IR code that was learned, or null if learning failed.</returns> public string Learn( CodeFormat? codeFormat = null, LearnCodeModifier? learnCodeFormat = null, uint? forcedFrequency = null, TimeSpan? timeout = null) { CheckDisposed(); timeout = timeout ?? TimeSpan.Zero; if (timeout < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("timeout", "timeout cannot be negative"); } var learnTask = LearnAsync(codeFormat, learnCodeFormat, forcedFrequency); if (TimeSpan.Zero == timeout) { return learnTask.Result; } if (learnTask.Wait(timeout.Value)) { if (learnTask.Exception != null) { throw learnTask.Exception; } if (learnTask.IsCanceled) { return null; } return learnTask.Result; } LearnAsyncCancel(); return null; }