private WSSinkData GetWSSinkDataFromCursor() { SinkData sinkData = loggingConfigurationView.GetSinkData(ConfigurationName); ArgumentValidation.CheckExpectedType(sinkData, typeof(WSSinkData)); return((WSSinkData)sinkData); }
public async Task <IEnumerable <AutoCompleteText> > ExtractAutoCompleteValuesAsync(IOspSession session, string ckId, string attributeName, string regexFilterValue, int takeCount) { ArgumentValidation.ValidateString(nameof(ckId), ckId); ArgumentValidation.ValidateString(nameof(attributeName), attributeName); ArgumentValidation.ValidateString(nameof(regexFilterValue), regexFilterValue); var entityCacheItem = GetEntityCacheItem(ckId); if (entityCacheItem == null) { throw new InvalidCkIdException($"Construction Kit Id '{ckId}' is invalid."); } if (!entityCacheItem.Attributes.Keys.Contains(attributeName)) { throw new InvalidAttributeException( $"Attribute '{attributeName}' does not exist at type '{ckId}'"); } var match = new BsonDocument { { "$match", new BsonDocument { { $"attributes.{attributeName.ToCamelCase()}", new BsonDocument { { "$regex", regexFilterValue } } } } } }; var sortByCount = new BsonDocument { { "$sortByCount", $"$attributes.{attributeName.ToCamelCase()}" } }; var limit = new BsonDocument { { "$limit", takeCount } }; var collection = _databaseContext.GetRtCollection <RtEntity>(entityCacheItem.CkId); var result = collection.Aggregate(session, PipelineDefinition <RtEntity, AutoCompleteText> .Create(match, sortByCount, limit)); return(await result.ToListAsync()); }
/// <summary> /// <para>Gets the registered <see cref="IMenuContainerService"/>.</para> /// </summary> /// <param name="serviceProvider"> /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para> /// </param> /// <returns>The registered <see cref="IMenuContainerService"/>.</returns> public static IMenuContainerService GetMenuContainerService(IServiceProvider serviceProvider) { ArgumentValidation.CheckForNullReference(serviceProvider, "serviceProvider"); IMenuContainerService menuService = serviceProvider.GetService(typeof(IMenuContainerService)) as IMenuContainerService; Debug.Assert(menuService != null, "Could not get the IMenuContainerService"); return(menuService); }
/// <summary> /// Wraps <see cref="ResolveFieldContextExtensions.GetArgument{TType}"/> to validate the resulting argument instance. /// Uses <see cref="IValidator.ValidateAsync(ValidationContext,CancellationToken)"/> to perform validation. /// If a <see cref="ValidationException"/> it will be converted <see cref="ExecutionError"/>s by a field middleware. /// </summary> public static async Task <TArgument> GetValidatedArgumentAsync <TArgument>(this IResolveFieldContext context, string name, TArgument defaultValue = default) { Guard.AgainstNull(context, nameof(context)); var argument = context.GetArgument(name, defaultValue); var validatorCache = context.GetCache(); await ArgumentValidation.ValidateAsync(validatorCache, typeof(TArgument), argument, context.UserContext); return(argument); }
/// <summary> /// <para>Gets the registered <see cref="IUIService"/>.</para> /// </summary> /// <param name="serviceProvider"> /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para> /// </param> /// <returns>The registered <see cref="IUIService"/>.</returns> public static IUIService GetUIService(IServiceProvider serviceProvider) { ArgumentValidation.CheckForNullReference(serviceProvider, "serviceProvider"); IUIService uiService = serviceProvider.GetService(typeof(IUIService)) as IUIService; Debug.Assert(uiService != null, "Could not get the IUIService"); return(uiService); }
/// <summary> /// Wraps <see cref="ResolveFieldContextExtensions.GetArgument{TType}"/> to validate the resulting argument instance. /// Uses <see cref="IValidator.Validate(IValidationContext)"/> to perform validation. /// If a <see cref="ValidationException"/> occurs it will be converted to <see cref="ExecutionError"/>s by a field middleware. /// </summary> public static object GetValidatedArgument(this IResolveFieldContext context, Type argumentType, string name, object?defaultValue = null) { Guard.AgainstNull(context, nameof(context)); var argument = context.GetArgument(argumentType, name, defaultValue); var validatorCache = context.GetCache(); ArgumentValidation.Validate(validatorCache, argumentType, argument, context.UserContext, context.Schema as IServiceProvider); return(argument); }
public static ArgumentValidation <string> NotNullOrWhitespace(this ArgumentValidation <string> item) { if (string.IsNullOrWhiteSpace(item.Value)) { throw new ArgumentNullException(item.ArgumentName); } return(item); }
internal BizUnitTestStepWrapper(ITestStepOM testStep, bool runConcurrently, bool failOnError) { ArgumentValidation.CheckForNullReference(testStep, "testStep"); _testStepBuilder = new TestStepBuilder(testStep); _runConcurrently = runConcurrently; _failOnError = failOnError; _typeName = testStep.GetType().ToString(); }
/// <summary> /// Instantiates a new Simulation object from the GroundFrame.SQL database /// </summary> /// <param name="ID">The ID of the Simulation record to be retreived</param> /// <param name="SQLConnector">The GFSqlConnector to the GroundFrame.SQL database</param> public Simulation(int ID, GFSqlConnector SQLConnector) { //Validate arguments ArgumentValidation.ValidateSQLConnector(SQLConnector, Globals.UserSettings.GetCultureInfo()); this._ID = ID; this._SQLConnector = new GFSqlConnector(SQLConnector); //Instantiates a copy of the SQLConnector object so prevent conflicts on Connections, Commands and DataReaders this.GetSimulationFromSQLDBByID(); }
/// <summary> /// Instantiates a new Location Node object from the GroundFrame.SQL database /// </summary> /// <param name="ID">The ID of the location record to be retreived</param> /// <param name="SQLConnector">The GFSqlConnector to the GroundFrame.SQL database</param> /// <param name="LoadPathEdges">A flag to indicate whether the Path Edges should be loaded from the GroundFrame.SQL database</param> public LocationNode(int ID, GFSqlConnector SQLConnector, bool LoadPathEdges) { //Validate Arguments ArgumentValidation.ValidateSQLConnector(SQLConnector, Globals.UserSettings.GetCultureInfo()); this._ID = ID; this._SQLConnector = new GFSqlConnector(SQLConnector); //Instantiates a copy of the SQLConnector object so prevent conflicts on Connections, Commands and DataReaders this.GetLocationNodeFromSQLDBByID(LoadPathEdges); }
public virtual bool Update(T obj, object primaryKeyValue, DbTransaction trans = null) { ArgumentValidation.CheckForNullReference(obj, "传入的对象obj为空"); Debug.WriteLine("Update(T obj, object primaryKeyValue, DbTransaction trans = null)"); OperationLogOfUpdate(obj, primaryKeyValue, trans); Hashtable hash = GetHashByEntity(obj); return(Update(primaryKeyValue, hash, trans)); }
private async Task <WeatherDataRoot> ProcessCityWeatherDataQuery(City city, ExcludeParameter excludeParameter, MetricSystem metricSystem) { string relativeUrlWithQueryParams = BuildRelativeCityUrl(ArgumentValidation.ThrowIfNull(city, nameof(city)), excludeParameter, metricSystem); Uri fullUrl; string rawWeatherData; try { fullUrl = new Uri(_darkSkyForecastBaseUrl, relativeUrlWithQueryParams); rawWeatherData = await _weatherDataRetriever.FetchWeatherData(fullUrl); } catch (UriFormatException ex) { Logger.Error("The retrieved DarkSky Forecast Request URL used has invalid format.", ex); throw ex; } catch (HttpRequestException ex) { Logger.Error("The DarkSky Forecast Request failed due to an underlying issue e.g. network connectivity.", ex); throw ex; } catch (ArgumentOutOfRangeException ex) { Logger.Error("The DarkSky Forecast Base URL processing was unsuccessful.", ex); throw ex; } catch (ArgumentNullException ex) { Logger.Error("The DarkSky Forecast Base URL was null.", ex); throw ex; } if (Logger.IsInfoEnabled) { Logger.Info($"Successful weather data retrieval for {city.Name} from URL: {fullUrl}"); } WeatherDataRoot weatherDataForCity; try { weatherDataForCity = ParseWeatherDataFromStringResult(rawWeatherData); } catch (ArgumentNullException ex) { weatherDataForCity = null; Logger.Error("JSON parser had to work on a null raw response.", ex); throw ex; } if (weatherDataForCity != null) { weatherDataForCity.CityName = city.Name; } return(weatherDataForCity); }
/// <summary> /// <para>Initializes a new instance of the <see cref="ConfigurationFactory"/> class with the factory name and a <see cref="ConfigurationContext"/>.</para> /// </summary> /// <param name="factoryName"> /// <para>The name of the factory.</para> /// </param> /// <param name="configurationContext"> /// <para>A <see cref="ConfigurationContext"/> object</para> /// </param> protected ConfigurationFactory(string factoryName, ConfigurationContext configurationContext) { ArgumentValidation.CheckForNullReference(configurationContext, "configurationContext"); ArgumentValidation.CheckForNullReference(factoryName, "providerName"); ArgumentValidation.CheckForEmptyString(factoryName, "factoryName"); this.configurationContext = configurationContext; this.factoryName = factoryName; }
/// <summary> /// <para>Initializes this provider to the correct state and context used by the factory creating it.</para> /// </summary> /// <param name="configurationView"> /// <para>The cursor to use to get the data specific for the transformer.</para> /// </param> /// <exception cref="ArgumentException"> /// <para><paramref name="configurationView"/> must be of type <see cref="RuntimeConfigurationView"/>.</para> /// </exception> /// <exception cref="ArgumentNullException"> /// <para><paramref name="configurationView"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para> /// </exception> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationCursor"); ArgumentValidation.CheckExpectedType(configurationView, typeof(RuntimeConfigurationView)); RuntimeConfigurationView runtimeConfigurationView = (RuntimeConfigurationView)configurationView; types = runtimeConfigurationView.GetXmlIncludeTypes(CurrentSectionName); }
internal RefactorRenameDialog(EFNormalizableItem objectToRename) { ArgumentValidation.CheckForNullReference(objectToRename, "objectToRename"); InitializeComponent(); _objectToRename = objectToRename; this.newNameTextBox.Text = objectToRename.Name.Value; this.Loaded += OnLoaded; }
public static ArgumentValidation <T[]> NotEmpty <T>(this ArgumentValidation <T[]> items) { if (items.Value.Length == 0) { throw new ArgumentNullException(items.ArgumentName); } return(items); }
/// <summary> /// <para>Gets the registered <see cref="IConfigurationErrorLogService"/>.</para> /// </summary> /// <param name="serviceProvider"> /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para> /// </param> /// <returns> /// <para>The registered <see cref="IConfigurationErrorLogService"/>.</para> /// </returns> public static IConfigurationErrorLogService GetConfigurationErrorService(IServiceProvider serviceProvider) { ArgumentValidation.CheckForNullReference(serviceProvider, "serviceProvider"); IConfigurationErrorLogService errorLogService = serviceProvider.GetService(typeof(IConfigurationErrorLogService)) as IConfigurationErrorLogService; Debug.Assert(errorLogService != null, "Could not get the IConfigurationErrorLogService"); return(errorLogService); }
/// <summary> /// Get the language service registed for passed in file extension. /// </summary> /// <param name="fileExtension">This is the file extension for which you want to get language service for it.</param> /// <returns>Registed language service for this file extension. If nothing is registed, null will be returned.</returns> internal Guid GetLanguageService(string fileExtension) { ArgumentValidation.CheckForEmptyString(fileExtension, "fileExtension"); var languageServiceID = Guid.Empty; _languageServices.TryGetValue(fileExtension, out languageServiceID); return(languageServiceID); }
public IAggregateFluent <TDocument> Aggregate(IOspSession session) { ArgumentValidation.Validate(nameof(session), session); return(_documentCollection.Aggregate(((IOspSessionInternal)session).SessionHandle, new AggregateOptions { AllowDiskUse = true })); }
/// <summary> /// Gets a string previously saved on the context. /// </summary> /// <param name="key">The name of the key for the object to get.</param> /// <returns>string value</returns> /// /// <remarks> /// The following example demonstrates how to get a string value from the context: /// /// <code escaped="true"> /// string fileName = context.GetValue("FILE_NAME"); /// </code> /// /// </remarks> public string GetValue(string key) { ArgumentValidation.CheckForNullReference(key, "key"); lock (_context.SyncRoot) { return((string)_context[key]); } }
/// <summary> /// Create a preview temp file, so we can open it to get TextLines buffer /// </summary> /// <param name="fileExtension"></param> /// <returns></returns> private static string CreatePreviewTempFile(string fileExtension) { ArgumentValidation.CheckForEmptyString(fileExtension, "fileExtension"); string tempFileName = null; FileUtils.CreateUniqueFilename("vstdRefactoring", fileExtension, out tempFileName); return(tempFileName); }
/// <summary> /// <para>Create an <see cref="ODP10CommandWrapper"/> for a SQL query.</para> /// </summary> /// <param name="query"><para>The text of the query.</para></param> /// <returns><para>The <see cref="ODP10CommandWrapper"/> for the SQL query.</para></returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="query"/> can not be <see langword="null"/> (Nothing in Visual Basic).</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><paramref name="query"/> hast not been initialized.</para> /// </exception> public override DBCommandWrapper GetSqlStringCommandWrapper(string query) { ArgumentValidation.CheckForNullReference(query, "query"); ArgumentValidation.CheckForEmptyString(query, "query"); ODP10CommandWrapper wrapper = new ODP10CommandWrapper(query, CommandType.Text, ParameterToken); return(wrapper); }
public override void Validate(Context context) { ArgumentValidation.CheckForEmptyString(DirectoryPath, "DirectoryPath"); ArgumentValidation.CheckForEmptyString(SearchPattern, "SearchPattern"); if (ExpectedNumberOfFiles < 1) { throw new ArgumentException(string.Format("ExpectedNumberOfFiles should be greater than zero, but was set to: {0}", ExpectedNumberOfFiles)); } }
internal BizUnitTestStepWrapper(TestStepBuilder testStepBuilder, bool runConcurrently, bool failOnError) { ArgumentValidation.CheckForNullReference(testStepBuilder, "testStepBuilder"); _testStepBuilder = testStepBuilder; RunConcurrently = runConcurrently; _failOnError = failOnError; TypeName = testStepBuilder.TestStepOM.GetType().ToString(); }
/// <summary> /// Gets an object previously saved to the context . /// </summary> /// <param name="key">The name of the key for the object to get.</param> /// <returns>object</returns> /// /// <remarks> /// The following example demonstrates how to get an object from the context: /// /// <code escaped="true"> /// object fileName = context.GetObject("FILE_NAME"); /// </code> /// /// </remarks> public object GetObject(string key) { ArgumentValidation.CheckForNullReference(key, "key"); lock (_context.SyncRoot) { return(_context[key]); } }
/// <summary> /// Wraps <see cref="ResolveFieldContextExtensions.GetArgument{TType}"/> to validate the resulting argument instance. /// Uses <see cref="IValidator.ValidateAsync(ValidationContext,CancellationToken)"/> to perform validation. /// If a <see cref="ValidationException"/> it will be converted <see cref="ExecutionError"/>s by a field middleware. /// </summary> public static async Task <object> GetValidatedArgumentAsync(this IResolveFieldContext context, Type argumentType, string name, object?defaultValue = null) { Guard.AgainstNull(context, nameof(context)); var argument = context.GetArgument(argumentType, name, defaultValue); var validatorCache = context.GetCache(); await ArgumentValidation.ValidateAsync(validatorCache, argumentType, argument, context.UserContext); return(argument); }
public override void Validate(Context context) { if (string.IsNullOrEmpty(SubscriptionResultCtxKey)) { SubscriptionResultCtxKey = RedisSubsciptionResultsKeyName; } ArgumentValidation.CheckForEmptyString(Topic, "Topic"); }
protected override async Task DoSwitchOn() { controller = await GpioController.GetDefaultAsync(); ArgumentValidation.NonNull(controller, nameof(GpioController)); forwardPin = OpenPin(ForwardPinNumber); backwardPin = OpenPin(BackwardPinNumber); ApplyReversedPolarity(); }
/// <summary> /// Create FileChange associated with file and project /// </summary> /// <param name="fileName">Full path to the file being changed</param> /// <param name="projectName">Name of the project the file belongs to</param> public FileChange(string fileName, string projectName) { ArgumentValidation.CheckForEmptyString(fileName, "fileName"); ArgumentValidation.CheckForNullReference(projectName, "projectName"); _filename = fileName; ProjectName = projectName; _changeList = new Dictionary <RefactoringPreviewGroup, HashSet <ChangeProposal> >(); }
internal BizUnitTestStepWrapper(ITestStep testStep, XmlNode stepConfig) { FailOnError = true; ArgumentValidation.CheckForNullReference(testStep, "testStep"); ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig"); LoadStepConfig(stepConfig); _testStep = testStep; }