Exemple #1
0
        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));
        }
Exemple #2
0
 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))
 ;
Exemple #3
0
 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();
Exemple #5
0
 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))
            );
 })));
Exemple #6
0
 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));
Exemple #7
0
 static IObservable <object> Delete(this object instance, ICredentialBearer bearer)
 => Operation.Delete.RestOperation(instance.GetTypeInfo())
 .SelectMany(attribute => attribute.Send(instance, bearer));
Exemple #8
0
 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));
Exemple #9
0
 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);
Exemple #10
0
 public static IObservable <(object o1, IMemberInfo target)> RestPropertiesDefault(this IObjectSpace objectSpace, object o, ICredentialBearer bearer)
 => o.GetType().RestProperties().Where(t => t.attribute.PropertyName != null)
Exemple #11
0
 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());
Exemple #12
0
 static IObservable <object> Update(this object instance, ICredentialBearer bearer)
 => Operation.Update.RestOperation(instance.GetTypeInfo())
 .SelectMany(attribute => attribute.Send(instance, bearer))
 .InvalidateCache(instance, bearer);