private void AddField(BulkFieldKey key, string value, Func <Stream> blob = null, bool isBlob = false, string name = null, Action <BulkField> postProcessor = null) { if (value == null && !isBlob) { return; } BulkField field = null; if (key.Language == null && !key.Version.HasValue) { field = new SharedBulkField(this, key.FieldId, value, blob, isBlob, name); _fields.Add(key, field); } else if (key.Language != null && !key.Version.HasValue) { field = new UnversionedBulkField(this, key.FieldId, key.Language, value, blob, isBlob, name); _fields.Add(key, field); } else if (key.Language == null && key.Version.HasValue) { throw new ArgumentException("You cannot add a language specific field without a version."); } else { field = new VersionedBulkField(this, key.FieldId, key.Language, key.Version.Value, value, blob, isBlob, name); _fields.Add(key, field); } postProcessor?.Invoke(field); }
/// <summary> /// Tries to add the field, returns false if the field with name and version already exists. /// </summary> public bool TryAddField(Guid id, string value, Func <Stream> blob = null, bool isBlob = false, string language = null, int?version = null, string name = null, Action <BulkField> postProcessor = null) { if (string.IsNullOrWhiteSpace(language)) { language = null; } var key = new BulkFieldKey(id, language, version); if (_fields.ContainsKey(key)) { return(false); } AddField(key, value, blob, isBlob, name, postProcessor); return(true); }
private bool Equals(BulkFieldKey other) { return(FieldId.Equals(other.FieldId) && string.Equals(Language, other.Language, StringComparison.OrdinalIgnoreCase) && Version == other.Version); }