Пример #1
0
        private WSSinkData GetWSSinkDataFromCursor()
        {
            SinkData sinkData = loggingConfigurationView.GetSinkData(ConfigurationName);

            ArgumentValidation.CheckExpectedType(sinkData, typeof(WSSinkData));

            return((WSSinkData)sinkData);
        }
Пример #2
0
        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());
        }
Пример #3
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }
Пример #7
0
        public static ArgumentValidation <string> NotNullOrWhitespace(this ArgumentValidation <string> item)
        {
            if (string.IsNullOrWhiteSpace(item.Value))
            {
                throw new ArgumentNullException(item.ArgumentName);
            }

            return(item);
        }
Пример #8
0
        internal BizUnitTestStepWrapper(ITestStepOM testStep, bool runConcurrently, bool failOnError)
        {
            ArgumentValidation.CheckForNullReference(testStep, "testStep");

            _testStepBuilder = new TestStepBuilder(testStep);
            _runConcurrently = runConcurrently;
            _failOnError     = failOnError;
            _typeName        = testStep.GetType().ToString();
        }
Пример #9
0
        /// <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();
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
        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));
        }
Пример #12
0
        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);
        }
Пример #13
0
        /// <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;
        }
Пример #14
0
        /// <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;
        }
Пример #16
0
        public static ArgumentValidation <T[]> NotEmpty <T>(this ArgumentValidation <T[]> items)
        {
            if (items.Value.Length == 0)
            {
                throw new ArgumentNullException(items.ArgumentName);
            }

            return(items);
        }
Пример #17
0
        /// <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);
        }
Пример #18
0
        /// <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
            }));
        }
Пример #20
0
        /// <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]);
            }
        }
Пример #21
0
        /// <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);
        }
Пример #22
0
        /// <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);
        }
Пример #23
0
 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));
     }
 }
Пример #24
0
        internal BizUnitTestStepWrapper(TestStepBuilder testStepBuilder, bool runConcurrently, bool failOnError)
        {
            ArgumentValidation.CheckForNullReference(testStepBuilder, "testStepBuilder");

            _testStepBuilder = testStepBuilder;
            RunConcurrently  = runConcurrently;
            _failOnError     = failOnError;
            TypeName         = testStepBuilder.TestStepOM.GetType().ToString();
        }
Пример #25
0
        /// <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);
        }
Пример #27
0
        public override void Validate(Context context)
        {
            if (string.IsNullOrEmpty(SubscriptionResultCtxKey))
            {
                SubscriptionResultCtxKey = RedisSubsciptionResultsKeyName;
            }

            ArgumentValidation.CheckForEmptyString(Topic, "Topic");
        }
Пример #28
0
        protected override async Task DoSwitchOn()
        {
            controller = await GpioController.GetDefaultAsync();

            ArgumentValidation.NonNull(controller, nameof(GpioController));
            forwardPin  = OpenPin(ForwardPinNumber);
            backwardPin = OpenPin(BackwardPinNumber);
            ApplyReversedPolarity();
        }
Пример #29
0
        /// <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> >();
        }
Пример #30
0
        internal BizUnitTestStepWrapper(ITestStep testStep, XmlNode stepConfig)
        {
            FailOnError = true;
            ArgumentValidation.CheckForNullReference(testStep, "testStep");
            ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig");

            LoadStepConfig(stepConfig);
            _testStep = testStep;
        }