Beispiel #1
0
        public static List <EspecialidadVM> FillCollection(IRootResourceObject list)
        {
            var embeeded = list.Embedded.Count == 0 ? new List <IEmbeddedResourceObject>() : list.Embedded["especialidades"].ToList();
            List <EspecialidadVM> listdto = new List <EspecialidadVM>();

            foreach (var item in embeeded)
            {
                EspecialidadVM especialidad = new EspecialidadVM()
                {
                    id_especialidad   = Int32.Parse(item.State.Values.FirstOrDefault(t => t.Name.Equals("idespecialidad")).Value),
                    desc_especialidad = item.State.Values.FirstOrDefault(t => t.Name.Equals("desc_especialidad")) == null ? string.Empty :
                                        item.State.Values.FirstOrDefault(t => t.Name.Equals("desc_especialidad")).Value,
                    estado = Int32.Parse(item.State.Values.FirstOrDefault(t => t.Name.Equals("idespecialidad")).Value),
                    MyLink = item.Links.First(t => t.Key.Equals("self")).Value.
                             First(d => d.Rel.Equals("self")).Href.ToString(),
                    UpdateLink = item.Links.First(t => t.Key.Equals("update")).Value.
                                 First(d => d.Rel.Equals("update")).Href.ToString(),
                    DeleteLink = item.Links.First(t => t.Key.Equals("delete")).Value.
                                 First(d => d.Rel.Equals("delete")).Href.ToString()
                };
                listdto.Add(especialidad);
            }
            ;
            return(listdto);
        }
Beispiel #2
0
 public static EspecialidadVM Fill(IRootResourceObject resource)
 {
     return(new EspecialidadVM()
     {
         id_especialidad = Int32.Parse(resource.State.Values.FirstOrDefault(t => t.Name.Equals("idespecialidad")).Value),
         desc_especialidad = resource.State.Values.FirstOrDefault(t => t.Name.Equals("desc_especialidad")) == null ? string.Empty :
                             resource.State.Values.FirstOrDefault(t => t.Name.Equals("desc_especialidad")).Value,
         estado = Int32.Parse(resource.State.Values.FirstOrDefault(t => t.Name.Equals("idespecialidad")).Value),
         MyLink = resource.Links.First(t => t.Key.Equals("self")).Value.
                  First(d => d.Rel.Equals("self")).Href.ToString(),
     });
 }
        private void SetRoot(HalHttpClient client, Uri baseAddress, bool refresh)
        {
            try
            {
                if (refresh || (_root == null))
                    client.GetAsync(baseAddress)
                        .ContinueWith(x => _root = x.Result, TaskContinuationOptions.NotOnFaulted)
                        .Wait();

                client.Root = _root;
            }
            catch (AggregateException ex)
            {
                client.Dispose(); // client is unusable ...
                throw new Exception("Could not GET the root response from '" + baseAddress + "'.", ex.InnerExceptions.FirstOrDefault());
            }
        }
Beispiel #4
0
        private async Task <IHalHttpClient> CreateHalHttpClientAsync(HttpClient httpClient, T context, CachingBehavior apiRootCachingBehavior)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }

            var wrapped = new HalHttpClient(HalJsonParser, httpClient);

            try
            {
                Configure(wrapped.Configuration, context);

                var decorated = Decorate(wrapped, context) ?? wrapped;

                switch (apiRootCachingBehavior)
                {
                case CachingBehavior.Never:
                    break;

                case CachingBehavior.PerClient:
                    var apiRootResource = await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false);

                    wrapped.CachedApiRootResource = apiRootResource;
                    break;

                case CachingBehavior.Once:
                    _cachedApiRootResource = _cachedApiRootResource ?? await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false);

                    wrapped.CachedApiRootResource = _cachedApiRootResource;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(apiRootCachingBehavior), apiRootCachingBehavior, null);
                }

                return(decorated);
            }
            catch (Exception)
            {
                wrapped.Dispose();                 // client is unusable ...
                throw;
            }
        }
        private void SetRoot(HalHttpClient client, Uri baseAddress, bool refresh)
        {
            try
            {
                if (refresh || (_root == null))
                {
                    client.GetAsync(baseAddress)
                    .ContinueWith(x => _root = x.Result, TaskContinuationOptions.NotOnFaulted)
                    .Wait();
                }

                client.Root = _root;
            }
            catch (AggregateException ex)
            {
                client.Dispose(); // client is unusable ...
                throw new Exception("Could not GET the root response from '" + baseAddress + "'.", ex.InnerExceptions.FirstOrDefault());
            }
        }
 public HalHttpRequestException(HttpStatusCode statusCode, string reason, IRootResourceObject resource = null)
     : base($"{(int)statusCode} ({reason})")
 {
     StatusCode = statusCode;
     Resource   = resource;
 }
 protected override List <EspecialidadVM> FillCollection(IRootResourceObject list)
 {
     return(EspecialidadBuilder.FillCollection(list));
 }
 protected override EspecialidadVM Fill(IRootResourceObject resource)
 {
     return(EspecialidadBuilder.Fill(resource));
 }
Beispiel #9
0
 protected override List <ModuloVM> FillCollection(IRootResourceObject list)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 protected override ModuloVM Fill(IRootResourceObject resource)
 {
     throw new NotImplementedException();
 }
		private async Task<IHalHttpClient> CreateHalHttpClientAsync(HttpClient httpClient, CachingBehavior apiRootCachingBehavior)
		{
			var wrapped = new HalHttpClient(Parser, httpClient);

			try
			{
				Configure(wrapped.Configuration);

				var decorated = Decorate(wrapped) ?? wrapped;

				switch (apiRootCachingBehavior)
				{
					case CachingBehavior.Never:
						break;
					case CachingBehavior.PerClient:
						var apiRootResource = await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false);
						wrapped.CachedApiRootResource = apiRootResource;
						break;
					case CachingBehavior.Once:
						_cachedApiRootResource = _cachedApiRootResource ?? await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false);
						wrapped.CachedApiRootResource = _cachedApiRootResource;
						break;
					default:
						throw new ArgumentOutOfRangeException(nameof(apiRootCachingBehavior), apiRootCachingBehavior, null);
				}

				return decorated;
			}
			catch (Exception)
			{
				wrapped.Dispose(); // client is unusable ...
				throw;
			}
		}
Beispiel #12
0
 protected abstract VM Fill(IRootResourceObject resource);
Beispiel #13
0
 protected abstract List <VM> FillCollection(IRootResourceObject list);