public async Task <V> GetAsync(string key, IKeyValueSource <V> provider, ProviderDefaultValueHandling defaultValueHandling = ProviderDefaultValueHandling.Throw) { Contract.NotNullOrEmpty(key, nameof(key)); Contract.NotNull(provider, nameof(provider)); var item = await this.cacheProvider.GetAsync(key); if (item == default(V)) { var providerItem = await provider.GetAsync(key); bool hasValue = providerItem != default(V); if (!hasValue && defaultValueHandling == ProviderDefaultValueHandling.Throw) { throw new KeyNotFoundException(String.Format("Could not find value for '{0}' in the provider", key)); } item = providerItem; if (hasValue || defaultValueHandling == ProviderDefaultValueHandling.Store) { await this.cacheProvider.SetAsync(key, providerItem); } } return(item); }
/// <summary> /// Modifies conflict relation between two items /// </summary> protected override void SetConflictedItems(IKeyValueSource row1, IKeyValueSource row2, bool p) { BatchMoveToResourcesToolGrid grid = (row1 as DataGridViewRow).DataGridView as BatchMoveToResourcesToolGrid; object dest1 = (row1 as DataGridViewRow).Cells[grid.DestinationColumnName].Value; object dest2 = (row2 as DataGridViewRow).Cells[grid.DestinationColumnName].Value; // items are in conflict only if their destination files are the same p = p && (dest1 == null || dest2 == null || dest1.ToString() == dest2.ToString()); base.SetConflictedItems(row1, row2, p); }
public async Task LoadFromProviderAsync(IKeyValueSource <V> provider, bool flush = true) { Contract.NotNull(provider, nameof(provider)); if (flush && !this.cacheProvider.SupportsFlushing) { throw new NotSupportedException("The provider does not support flushing the cache"); } var items = await provider.GetAllAsync(); await this.cacheProvider.SetAsync(items, flush : flush); }
/// <summary> /// Validates if new key is a valid identifier of specified language, with respect to specified policy /// </summary> public void TryAdd(string oldKey, string newKey, IKeyValueSource item, ResXProjectItem resxItem, LANGUAGE?language) { if (item == null) { throw new ArgumentNullException("item"); } if (resxItem != null) { if (language == null && resxItem != null) { language = resxItem.DesignerLanguage; } if (!language.HasValue) { throw new InvalidOperationException("Cannot determine file language."); } bool empty = string.IsNullOrEmpty(newKey); // new key is empty bool validIdentifier = newKey.IsValidIdentifier(language.Value); // new key is valid identifier of the language bool hasOwnDesigner = (resxItem.DesignerItem != null || resxItem.HasImplicitDesignerFile) && !resxItem.IsCultureSpecific(); // ResX file has own designer file bool identifierError = false; switch (SettingsObject.Instance.BadKeyNamePolicy) { case BAD_KEY_NAME_POLICY.IGNORE_COMPLETELY: identifierError = empty; // only empty keys are reported as an error break; case BAD_KEY_NAME_POLICY.IGNORE_ON_NO_DESIGNER: identifierError = empty || (!validIdentifier && hasOwnDesigner); // empty keys and invalid identifiers in own designers are reported break; case BAD_KEY_NAME_POLICY.WARN_ALWAYS: identifierError = empty || !validIdentifier; // all kinds of invalid identifiers are reported break; } item.ErrorMessages.Remove(string.Format(KeyIsNotValidIdentifierErrorMessageFormat, oldKey)); if (identifierError) { item.ErrorMessages.Add(string.Format(KeyIsNotValidIdentifierErrorMessageFormat, newKey)); } else { item.ErrorMessages.Remove(string.Format(KeyIsNotValidIdentifierErrorMessageFormat, newKey)); } } TryAdd(oldKey, newKey, item); }
/// <summary> /// Initializes a new instance of the DefaultKeyValueConsumer class /// </summary> /// <param name="source">the source KeyValueSource object that provides raw-key-value data</param> /// <param name="columnMode">the column-mode of this consumer</param> /// <param name="config">the Key-Value configuration used to configure this consumer</param> public DefaultKeyValueConsumer(IKeyValueSource source, ColumnNameMode columnMode, KeyValueConfiguration config) : base(source, config?.VirtualColumns ?? new ConstConfigurationCollection()) { if (columnMode == ColumnNameMode.FromConfig && (config?.Columns?.Count ?? 0) == 0) { throw new ArgumentException("Columns required when the ColumnMode is set to 'FromConfig'!", nameof(config)); } this.columnMode = columnMode; this.config = config; if (config != null) { tableName = config.TableName; } }
/// <summary> /// Initializes a new instance of the DefaultKeyValueConsumer class /// </summary> /// <param name="source">the source KeyValueSource object that provides raw-key-value data</param> /// <param name="columnMode">the column-mode of this consumer</param> /// <param name="tableName">the table that is used to register the data of this consumer</param> public DefaultKeyValueConsumer( IKeyValueSource source, ColumnNameMode columnMode, string tableName) : this(source, columnMode, (KeyValueConfiguration)null) { this.tableName = tableName; }