public CaptchaOptions(string options) { var items = StringHelper.ParseOptions(options); Path = items[CaptchaOptionNames.Path] ?? CaptchaOptionDefaults.Path; MinTimeout = TimeSpan.FromSeconds(NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.MinTimeout, CaptchaOptionDefaults.MinTimeout)); MaxTimeout = TimeSpan.FromSeconds(NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.MaxTimeout, CaptchaOptionDefaults.MaxTimeout)); VaryByCacheLifetime = TimeSpan.FromSeconds(NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.VaryByCacheLifetime, CaptchaOptionDefaults.VaryByCacheLifetime)); ChallengeQueryKey = items[CaptchaOptionNames.ChallengeQueryKey] ?? CaptchaOptionDefaults.ChallengeQueryKey; ValidationStateKey = items[CaptchaOptionNames.ValidationStateKey] ?? CaptchaOptionDefaults.ValidationStateKey; Width = NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.Width, CaptchaOptionDefaults.Width); Height = NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.Height, CaptchaOptionDefaults.Height); Items = items; }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public object ConvertFromString(string value) { object result = Activator.CreateInstance <T>(); NameValueCollectionHelper.SetNameValueCollection(ref result, NameValueCollectionHelper.Parse(value)); return(result); }
public DefaultTuringNumberProvider(CaptchaOptions options) { var items = options.Items; m_characterGroup = items[CaptchaOptionNames.Chars] ?? CaptchaOptionDefaults.Chars; m_max = NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.MaxChars, CaptchaOptionDefaults.MaxChars); m_min = NameValueCollectionHelper.ConvertToInt32(items, CaptchaOptionNames.MinChars, m_max); }
public DistributedOptions(string options) { var items = StringHelper.ParseOptions(options); ClientAccessTimeout = NameValueCollectionHelper.ConvertToInt32(items, "client access timeout", 100); IdlePoolSize = NameValueCollectionHelper.ConvertToInt32(items, "idle pool size", 16); IdleLeaseTime = NameValueCollectionHelper.ConvertToInt32(items, "idle lease time", 10 * 1000); IdleAccessTimeout = NameValueCollectionHelper.ConvertToInt32(items, "idle access timeout", 100); }
public ProtocolOptions(string options) { var items = StringHelper.ParseOptions(options); BufferSize = NameValueCollectionHelper.ConvertToInt32(items, "buffer size", 1024); NoReply = NameValueCollectionHelper.ConvertToBoolean(items, "no reply", false); PoolAccessTimeout = NameValueCollectionHelper.ConvertToInt32(items, "pool access timeout", 100); MaxPoolSize = NameValueCollectionHelper.ConvertToInt32(items, "max pool size", 16); }
public static void HasKey_Collection_IsNull() { // Arrange // Act Assert.Throws <ArgumentNullException>(() => NameValueCollectionHelper.HasKey(null, "x")); // Assert }
public SymmetricAlgorithmOptions(string options) { var items = StringHelper.ParseOptions(options); Name = items["name"] ?? "Default"; MaxPoolSize = NameValueCollectionHelper.ConvertToInt32(items, "max pool size", 16); PoolAccessTimeout = NameValueCollectionHelper.ConvertToInt32(items, "pool access timeout", 100); PoolWaitTimeout = NameValueCollectionHelper.ConvertToInt32(items, "pool wait timeout", 250); }
public RetryOptions(string options, string prefix) { var items = StringHelper.ParseOptions(options); MaxRetryCount = NameValueCollectionHelper.ConvertToInt32(items, String.Concat(prefix, " max retry count").TrimStart(), 0); RetryTimeout = NameValueCollectionHelper.ConvertToInt32(items, String.Concat(prefix, " retry timeout").TrimStart(), 0); RetryDelay = NameValueCollectionHelper.ConvertToInt32(items, String.Concat(prefix, " retry delay").TrimStart(), 0); RetryFails = NameValueCollectionHelper.ConvertToBoolean(items, String.Concat(prefix, " retry fails").TrimStart(), false); }
public static void ConvertToBoolean() { // Arrange var collection = new NameValueCollection(); collection.Add("x", "true"); // Act var result = NameValueCollectionHelper.ConvertToBoolean(collection, "x"); // Assert Assert.Equal(true, result); }
public static void ConvertToInt32_Required(string value) { // Arrange var collection = new NameValueCollection(); collection.Add("x", value); // Act Assert.Throws <ArgumentException>(() => NameValueCollectionHelper.ConvertToInt32(collection, "x")); // Assert }
public static void ConvertToInt32_Default(string value) { // Arrange var collection = new NameValueCollection(); collection.Add("x", value); // Act var result = NameValueCollectionHelper.ConvertToInt32(collection, "x", 100); // Assert Assert.Equal(100, result); }
public static void ConvertToInt32() { // Arrange var collection = new NameValueCollection(); collection.Add("x", "100"); // Act var result = NameValueCollectionHelper.ConvertToInt32(collection, "x"); // Assert Assert.Equal(100, result); }
public static void HasKey(string key, bool expected) { // Arrange var collection = new NameValueCollection(); collection.Add("x", "1"); collection.Add("y", "2"); collection.Add(null, "3"); // Act var result = NameValueCollectionHelper.HasKey(collection, key); // Assert Assert.Equal(expected, result); Assert.Equal(expected, collection[key] != null); }
/// <summary> /// Attempts to convert to a DoubleDataSourceItemInfo from the given object. /// </summary> /// <returns> /// The DoubleDataSourceItemInfo which was constructed. /// </returns> /// <exception cref="NotSupportedException"> /// A NotSupportedException is thrown if the example object is null or is not a valid type /// which can be converted to a DoubleDataSourceItemInfo. /// </exception> /// <param name="context"> The ITypeDescriptorContext for this call. </param> /// <param name="culture"> The requested CultureInfo. Note that conversion uses "en-US" rather than this parameter. </param> /// <param name="value"> The object to convert to an instance of DoubleDataSourceItemInfo. </param> public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value) { if (value is null) { throw GetConvertFromException(null); } var source = value as string; if (source is not null) { object result = Activator.CreateInstance <T>(); NameValueCollectionHelper.SetNameValueCollection(ref result, NameValueCollectionHelper.Parse(source)); return(result); } return(base.ConvertFrom(context, culture, value)); }
public ConnectionOptions(string options) { var items = StringHelper.ParseOptions(options); Name = items["name"] ?? "Default"; Server = items["server"] ?? IpNumberHelper.Localhost; Port = NameValueCollectionHelper.ConvertToInt32(items, "port"); DnsTimeout = NameValueCollectionHelper.ConvertToInt32(items, "dns timeout", 250); ConnectTimeout = NameValueCollectionHelper.ConvertToInt32(items, "connect timeout", 250); SendTimeout = NameValueCollectionHelper.ConvertToInt32(items, "send timeout", 250); SendBufferSize = NameValueCollectionHelper.ConvertToInt32(items, "send buffer size", 8 * 1024); ReceiveTimeout = NameValueCollectionHelper.ConvertToInt32(items, "receive timeout", 250); ReceiveBufferSize = NameValueCollectionHelper.ConvertToInt32(items, "receive buffer size", 8 * 1024); MaxPoolSize = NameValueCollectionHelper.ConvertToInt32(items, "max pool size", 16); PoolAccessTimeout = NameValueCollectionHelper.ConvertToInt32(items, "pool access timeout", 100); PoolWaitTimeout = NameValueCollectionHelper.ConvertToInt32(items, "pool wait timeout", 250); IdleTimeout = NameValueCollectionHelper.ConvertToInt32(items, "idle timeout", 30 * 1000); LeaseTimeout = NameValueCollectionHelper.ConvertToInt32(items, "lease timeout", 15 * 60 * 1000); FullName = String.Format(CultureInfo.InvariantCulture, "Name={0}, Server={1}:{2}", Name, Server, Port); }
// During startup these methods are called in this order: // -LaunchSuspended // -ResumeProcess // -Attach - Triggered by Attach int IDebugEngineLaunch2.LaunchSuspended(string aPszServer, IDebugPort2 aPort, string aDebugInfo , string aArgs, string aDir, string aEnv, string aOptions, enum_LAUNCH_FLAGS aLaunchFlags , uint aStdInputHandle, uint aStdOutputHandle, uint hStdError, IDebugEventCallback2 aAD7Callback , out IDebugProcess2 oProcess) { // Launches a process by means of the debug engine. // Normally, Visual Studio launches a program using the IDebugPortEx2::LaunchSuspended method and then attaches the debugger // to the suspended program. However, there are circumstances in which the debug engine may need to launch a program // (for example, if the debug engine is part of an interpreter and the program being debugged is an interpreted language), // in which case Visual Studio uses the IDebugEngineLaunch2::LaunchSuspended method // The IDebugEngineLaunch2::ResumeProcess method is called to start the process after the process has been successfully launched in a suspended state. oProcess = null; try { mEngineCallback = new EngineCallback(this, aAD7Callback); var xDebugInfo = new NameValueCollection(); NameValueCollectionHelper.LoadFromString(xDebugInfo, aDebugInfo); //TODO: In the future we might support command line args for kernel etc //string xCmdLine = EngineUtils.BuildCommandLine(exe, args); //var processLaunchInfo = new ProcessLaunchInfo(exe, xCmdLine, dir, env, options, launchFlags, hStdInput, hStdOutput, hStdError); AD7EngineCreateEvent.Send(this); oProcess = mProcess = new AD7Process(xDebugInfo, mEngineCallback, this, aPort); // We only support one process, so just use its ID for the program ID mProgramID = mProcess.ID; //AD7ThreadCreateEvent.Send(this, xProcess.Thread); mModule = new AD7Module(); mProgNode = new AD7ProgramNode(mProcess.PhysID); } catch (NotSupportedException) { return(VSConstants.S_FALSE); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } return(VSConstants.S_OK); }
public static void PerformanceCounterExceptionHandler() { // Arrange var handler = new PerformanceCounterExceptionHandler() { Counters = new[] { @"\Memory\Pages/sec", @"\PhysicalDisk(_Total)\Avg. Disk Queue Length", @"\Processor(_Total)\% Processor Time" } }; var ex = new InvalidOperationException(); // Act var result = handler.HandleException(ex); // Assert Assert.False(result); var counters = (NameValueCollection)ex.Data["Performance Counters"]; Assert.Equal(3, counters.Count); Assert.True(handler.Counters.All(name => NameValueCollectionHelper.HasKey(counters, name))); }
public DefaultVaryByCustomProvider(CaptchaOptions options) : this(NameValueCollectionHelper.ConvertToInt32(options.Items, CaptchaOptionNames.MaxVaryCacheSize, CaptchaOptionDefaults.MaxVaryCacheSize)) { }
public ConsoleOutLoggerFactoryAdapter(System.Collections.Specialized.NameValueCollection properties) : this(NameValueCollectionHelper.ToCommonLoggingCollection(properties)) { }
public string ConvertToString(object value) { return (NameValueCollectionHelper.GetNameValueCollectionString( NameValueCollectionHelper.GetNameValueCollection(value))); }
public static int ConvertToInt32(this NameValueCollection collection, string paramName, int defaultValue) { return(NameValueCollectionHelper.ConvertToInt32(collection, paramName, defaultValue)); }
public static bool ConvertToBoolean(this NameValueCollection collection, string paramName, bool defaultValue) { return(NameValueCollectionHelper.ConvertToBoolean(collection, paramName, defaultValue)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="context"></param> /// <returns></returns> public override bool CanConvertToString(object value, IValueSerializerContext context) { return(NameValueCollectionHelper.CanGetNameValueCollection(value)); }
public static Type ConvertToType(this NameValueCollection collection, string paramName, Type defaultValue) { return(NameValueCollectionHelper.ConvertToType(collection, paramName, defaultValue)); }
public static IEnumerable <KeyValuePair <string, string> > AllPairs(this NameValueCollection collection) { return(NameValueCollectionHelper.AllPairs(collection)); }
public static bool HasKey(this NameValueCollection collection, string key) { return(NameValueCollectionHelper.HasKey(collection, key)); }
public JpegImageCodecInfo(CaptchaOptions options) : this(NameValueCollectionHelper.ConvertToInt32(options.Items, CaptchaOptionNames.EncoderQuality, CaptchaOptionDefaults.EncoderQuality)) { }
public CaptchaInstrumentationProvider(CaptchaOptions options) : this(options.Items[CaptchaOptionNames.InstrumentationCategory] ?? CaptchaOptionDefaults.InstrumentationCategory, options.Items[CaptchaOptionNames.InstrumentationInstanceNameSuffix] ?? options.Path, NameValueCollectionHelper.ConvertToBoolean(options.Items, CaptchaOptionNames.InstrumentationEnabled, CaptchaOptionDefaults.InstrumentationEnabled)) { }