public int Compare(IClientResource x, IClientResource y)
 {
     if (x is InterlocutorResourceViewModel && y is RoomResourceViewModel)
     {
         return -1;
     }
     if (x is RoomResourceViewModel && y is InterlocutorResourceViewModel)
     {
         return 1;
     }
     if (x is InterlocutorResourceViewModel && y is InterlocutorResourceViewModel)
     {
         return CompareInterlocutors((InterlocutorResourceViewModel)x, (InterlocutorResourceViewModel)y);
     }
     if (x is RoomResourceViewModel && y is RoomResourceViewModel)
     {
         return CompareRooms((RoomResourceViewModel)x, (RoomResourceViewModel)y);
     }
     if (x is NullClientResource)
     {
         return 1;
     }
     if (y is NullClientResource)
     {
         return -1;
     }
     throw new NotImplementedException();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientResource"/> class.
 /// </summary>
 /// <param name="clientResource">The client resource.</param>
 public ClientResource(IClientResource clientResource)
 {
     this.Path     = clientResource.Path;
     this.Priority = clientResource.Priority;
     this.Targets  = clientResource.Targets;
     this.Type     = clientResource.Type;
 }
Example #3
0
 public string GetName(IClientResource resource)
 {
     if (resource is RoomResourceViewModel)
     {
         return ((RoomResourceViewModel) resource).Room.Name;
     }
     if (resource is InterlocutorResourceViewModel)
     {
         return ((InterlocutorResourceViewModel) resource).Interlocutor.Name;
     }
     return null;
 }
Example #4
0
 public FilterResult Apply(IClientResource clientResource)
 {
     var interlocutorNode = clientResource as InterlocutorResourceViewModel;
     if (interlocutorNode == null)
     {
         return FilterResult.Accepted;
     }
     if (!ShowOffline)
     {
         var context = SessionModel.GetInterlocutorContext(interlocutorNode.Interlocutor);
         if (context.State == ContactState.Offline)
         {
             return FilterResult.Rejected;
         }
     }
     return FilterResult.Accepted;
 }
        public static TOriginal Unwrap <TOriginal>(this IClientResource wrapped)
            where TOriginal : class, IClientResource
        {
            var er = wrapped as IExtendedResourceProxy;

            if (er == null)
            {
                throw new ArgumentException("Can only unwrap a wrapped resource.", nameof(wrapped));
            }
            var unwrapped = er.WrappedResource as TOriginal;

            if (unwrapped == null)
            {
                throw new ArgumentException("Unable to unwrap to type " + typeof(TOriginal), nameof(wrapped));
            }
            return(unwrapped);
        }
Example #6
0
        public FilterResult Apply(IClientResource clientResource)
        {
            var name = GetName(clientResource);

            if (name == null)
            {
                return FilterResult.Rejected;
            }

            if (string.IsNullOrEmpty(_querySource.SearchQuery))
            {
                return FilterResult.Rejected;
            }

            var index = name.IndexOf(_querySource.SearchQuery, StringComparison.OrdinalIgnoreCase);
            if (index == -1)
            {
                return FilterResult.Rejected;
            }
            return FilterResult.Accepted;
        }
Example #7
0
 private void AddResource(IClientResource targetResource)
 {
     if (ActiveResources.Contains(_nullResource))
     {
         ActiveResources.Remove(_nullResource);
     }
     var position = Position(ActiveResources, targetResource);
     ActiveResources.Insert(position, targetResource);
 }
 public virtual void Delete(IClientResource resource)
 {
     throw new NotImplementedException();
 }
 public static bool IsTransient(this IClientResource resource)
 {
     return(resource is IPostForm);
 }
 public static bool IsPersisted(this IClientResource resource)
 {
     return(!IsTransient(resource));
 }
        public static bool IsLoaded(this IClientResource resource)
        {
            var lazyProxy = resource as ILazyProxy;

            return(lazyProxy == null || lazyProxy.IsLoaded);
        }
Example #12
0
 private int Compare(IClientResource x, IClientResource y)
 {
     var xName = GetName(x);
     var yName = GetName(y);
     if (xName == null || yName == null)
     {
         return 0;
     }
     var xMeasure = NameMeasure(xName);
     var yMeasure = NameMeasure(yName);
     if (xMeasure != yMeasure)
     {
         return xMeasure > yMeasure ? 1 : -1;
     }
     return 0;
 }
Example #13
0
 private int Position(IEnumerable<IClientResource> resources, IClientResource target)
 {
     if (resources.Contains(target))
     {
         return OrderedResources(resources)
                 .TakeWhile(resource => resource != target).Count();
     }
     var concat = resources.Concat(new[]
     {
             target
     });
     return OrderedResources(concat).TakeWhile(resource => resource != target).Count();
 }
Example #14
0
 public ClientRepository(IPomonaClient client, string uri, IEnumerable results, IClientResource parent)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     Client       = client;
     Uri          = uri;
     this.results = results as IEnumerable <TResource> ?? (results != null ? results.Cast <TResource>() : null);
 }
Example #15
0
 private bool IsAccepted(IClientResource clientResource)
 {
     return _resourceFilter.Apply(clientResource) == FilterResult.Accepted;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientResourceAttribute"/> class.
 /// </summary>
 /// <param name="clientResource">The client resource.</param>
 public ClientResourceAttribute(IClientResource clientResource)
 {
     this.ClientResource = new ClientResource(clientResource);
 }
Example #17
0
 public ChildResourceRepository(IPomonaClient client, string uri, IEnumerable results, IClientResource parent)
     : base(client, uri, results, parent)
 {
     this.parent = parent;
 }
Example #18
0
 private void RegisterResource(IClientResource resource)
 {
     _registeredResources.Add(resource);
     resource.StartListen();
     resource.Subscribe(this);
     if (IsAccepted(resource))
     {
         AddResource(resource);
     }
 }
Example #19
0
 private void UnRegisterResource(IClientResource resource)
 {
     if (resource == null)
     {
         return;
     }
     resource.StopListen();
     _registeredResources.Remove(resource);
     if (ActiveResources.Contains(resource))
     {
         RemoveResource(resource);
     }
 }
Example #20
0
 private void RemoveResource(IClientResource resource)
 {
     ActiveResources.Remove(resource);
     if (ActiveResources.Count == 0)
     {
         ActiveResources.Add(_nullResource);
     }
 }