private string GetId(object entity) { string id; if (generateEntityIdOnTheClient.TryGetIdFromInstance(entity, out id) == false) { id = generateEntityIdOnTheClient.GenerateDocumentKeyForStorage(entity); generateEntityIdOnTheClient.TrySetIdentity(entity, id); //set Id property if it was null } return(id); }
private void NotifySubscribers(BlittableJsonReaderObject curDoc, out long lastReceivedEtag) { BlittableJsonReaderObject metadata; string id; if (curDoc.TryGet(Constants.Metadata.Key, out metadata) == false) { throw new InvalidOperationException("Document must have a metadata"); } if (metadata.TryGet(Constants.Metadata.Id, out id) == false) { throw new InvalidOperationException("Document must have an id"); } if (metadata.TryGet(Constants.Metadata.Etag, out lastReceivedEtag) == false) { throw new InvalidOperationException("Document must have an ETag"); } T instance; if (typeof(T) == typeof(BlittableJsonReaderObject)) { instance = (T)(object)curDoc; } else { instance = (T)EntityToBlittable.ConvertToEntity(typeof(T), id, curDoc, _conventions); } if (string.IsNullOrEmpty(id) == false) { _generateEntityIdOnTheClient.TrySetIdentity(instance, id); } foreach (var subscriber in _subscribers) { _proccessingCts.Token.ThrowIfCancellationRequested(); try { subscriber.OnNext(instance); } catch (Exception ex) { Logger.WarnException( string.Format( "Subscription #{0}. Subscriber threw an exception", _options.SubscriptionId), ex); if (_options.IgnoreSubscribersErrors == false) { IsErroredBecauseOfSubscriber = true; LastSubscriberException = ex; try { subscriber.OnError(ex); } catch (Exception) { // can happen if a subscriber doesn't have an onError handler - just ignore it } break; } } } }