internal static IObservable <object> Send(this IRestAttribute attribute, object instance, ICredentialBearer user, string requestUrl = null, Func <string, object[]> deserializeResponse = null) { // var user = ((ICredentialBearer) SecuritySystem.CurrentUser); requestUrl ??= attribute.RequestUrl(instance); var url = $"{user.BaseAddress}{requestUrl}"; var pollInterval = attribute.PollInterval > 0?TimeSpan.FromSeconds(attribute.PollInterval) :(TimeSpan?)null; return(attribute.HttpMethod().Send(url, instance, user.Key, user.Secret, deserializeResponse, pollInterval) .HandleAttributeErrors(url, instance, attribute.HandleErrors)); }
public static IObservable <object> RestPropertyDependent(this IObservable <object[]> source, IObjectSpace objectSpace, Type objectType, ICredentialBearer bearer) => source.ConcatIgnored(objects => objectSpace.RestPropertyDependentName(objectType, objects)) .ConcatIgnored(objects => objects.RestPropertyDependentReadOnly(objectType, bearer)) ;
private static IObservable <object> RestPropertyDependentReadOnly(this object[] objects, Type objectTpe, ICredentialBearer bearer) => objectTpe.RestDependentMembersByReadOnly() .SelectMany(t => objects.ToObservable(Scheduler.Immediate) .SelectMany(o => t.attribute.Send(t.info.MemberType.CreateInstance(), bearer, t.attribute.RequestUrl(o)) .Do(o1 => t.info.SetValue(o, o1))));
public static IObservable <object> RestPropertyDependent(this IObservable <object> source, IObjectSpace objectSpace, Type objectType, ICredentialBearer bearer) => source.BufferUntilCompleted().ConcatIgnored(objects => objectSpace.RestPropertyDependentName(objectType, objects)) .ConcatIgnored(objects => objects.RestPropertyDependentReadOnly(objectType, bearer)) .SelectMany();
public static IObservable <object> ReactiveCollectionsFetch(this IObservable <object> source, ICredentialBearer bearer) => source.MergeIgnored(o => o.GetType().ReactiveCollectionMembers() .SelectMany(t => ((DynamicCollection)t.info.GetValue(o)).WhenFetchObjects() .SelectMany(t2 => { var realType = t.info.MemberType.RealType(); return(t.attribute.Send(realType.CreateInstance(), bearer, t.attribute.RequestUrl(o), realType.DeserializeResponse(t2.sender.ObjectSpace)) .BufferUntilCompleted() .Do(objects => t2.sender.AddObjects(objects, true)) ); })));
private static IObservable <object> CommitingRestCall(this IObjectSpace objectSpace, object o, IObservable <object> crudSource, ICredentialBearer bearer) => o.GetTypeInfo().Members.Where(info => info.MemberType == typeof(bool) && info.FindAttributes <RestOperationAttribute>().Any()) .ToObservable(Scheduler.Immediate) .SelectMany(info => info.FindAttributes <RestOperationAttribute>()).Where(attribute => { var isObjectFitForCriteria = objectSpace.IsObjectFitForCriteria(o, CriteriaOperator.Parse(attribute.Criteria)); return(isObjectFitForCriteria.HasValue && isObjectFitForCriteria.Value); }) .SelectMany(attribute => attribute.Send(o, bearer)) .Concat(Observable.Defer(() => crudSource));
static IObservable <object> Delete(this object instance, ICredentialBearer bearer) => Operation.Delete.RestOperation(instance.GetTypeInfo()) .SelectMany(attribute => attribute.Send(instance, bearer));
public static IObservable <object> Get(this IObjectSpace objectSpace, Type type, ICredentialBearer bearer) => Operation.Get.RestOperation(type.ToTypeInfo()) .SelectMany(attribute => attribute.Send(type.CreateInstance(), bearer).Link(objectSpace));
public static IObservable <object> Commit(this IObjectSpace objectSpace, object o, ICredentialBearer bearer) => objectSpace.IsNewObject(o) ? o.Create(bearer) : objectSpace.IsDeletedObject(o) ? o.Delete(bearer) : objectSpace.CommitingRestCall(o, o.Update(bearer), bearer);
public static IObservable <(object o1, IMemberInfo target)> RestPropertiesDefault(this IObjectSpace objectSpace, object o, ICredentialBearer bearer) => o.GetType().RestProperties().Where(t => t.attribute.PropertyName != null)
static IObservable <T> InvalidateCache <T>(this IObservable <T> source, object instance, ICredentialBearer bearer) => source.Merge(Operation.Get.RestOperation(instance.GetTypeInfo()) .Do(attribute => RestService.CacheStorage.TryRemove($"{bearer.BaseAddress}{attribute.RequestUrl(instance)}", out _)) .Cast <T>().IgnoreElements());
static IObservable <object> Update(this object instance, ICredentialBearer bearer) => Operation.Update.RestOperation(instance.GetTypeInfo()) .SelectMany(attribute => attribute.Send(instance, bearer)) .InvalidateCache(instance, bearer);