示例#1
0
        /**
         * Añade el tercero que se le pasa como parámetro a la anotación que también se le
         * pasa como parámetro
         */
        private static bool addTercero(Anotacion anotacion, Tercero tercero, bool isProvider)
        {
            Uri uri = null;
            if (isProvider)
            {
                uri = new Uri(anotacion.links[2].href);
            }
            else
            {
                uri = new Uri(anotacion.links[3].href);
            }

            var request = new HttpRequestMessage()
            {
                RequestUri = uri,
                Method = HttpMethod.Post
            };
            request.Headers.Add("X-Gestiona-Access-Token", accessToken);
            request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(tercero));
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.gestiona.thirdparty");
            HttpResponseMessage response = httpClient.SendAsync(request).Result;

            if (response.StatusCode == HttpStatusCode.Created)
            {
                return true;
            }
            else if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                throw new System.InvalidOperationException("Error al añadir tercero: no tiene autorización " + response.ReasonPhrase);
            }
            else
            {
                throw new System.InvalidOperationException("Error al añadir tercero: " + response.StatusCode);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                httpClient = new HttpClient();
                httpClient.BaseAddress = new Uri(serverURL);

                // Obtenemos los Bookmarks de los recursos de la API, para a partir
                // de ellos empezar a 'navegar' haciendo las peticiones.
                getRecursos();

                // Creamos un token de acceso, al crearlo estará en estado
                // 'pendiente de autorizar' a la espera de que nos logueemos con un
                // usuario y lo autoricemos
                if (token == null)
                    token = createToken();

                // Comprobamos el estado del token
                while (tokenAutorizado == false)
                    tokenAutorizado = comprobarToken(token);

                Console.WriteLine("============================== LOGIN CORRECTO ==============================");

                // Obtenemos la oficina de registro en la que queremos crear la
                // anotación
                OficinaRegistro or = getOficinaRegistro("RC");

                // Creamos el tercero y el solicitante a añadir en las anotaciones
                Tercero tercero = new Tercero();
                tercero.nif = "33333333T";
                tercero.name = "Tercero-CSharp-03";
                tercero.relation = "INVOLVED";
                tercero.address = "address";
                tercero.zone = "zone";
                tercero.country = "España";
                tercero.province = "Zaragoza";
                tercero.zipCode = "50009";
                tercero.notificationChannel = "PAPER";
                tercero.personType = "JURIDICAL";

                Tercero provider = new Tercero();
                provider.nif = "44444444P";
                provider.name = "Tercero-CSharp-04";
                provider.address = "address";
                provider.zone = "zone";
                provider.country = "España";
                provider.province = "Zaragoza";
                provider.zipCode = "50012";
                provider.notificationChannel = "PAPER";
                provider.personType = "JURIDICAL";

                for (int i = 0; i < 3; i++)
                {
                    // Creamos la anotación
                    Anotacion anotacion = new Anotacion();
                    anotacion.incomeType = "PRESENTIAL";
                    anotacion.shortDescription = "API prueba rendimiento";
                    anotacion.classification = "REQUERIMENT";
                    anotacion.longDescription = "Aqui van las observaciones de la anotacíon";
                    anotacion.originCode = "C0D-O4161N";
                    anotacion = crearAnotacion(or.links[1].href, anotacion);

                    // Añadirmos el solicitante y el tercero
                    addTercero(anotacion, provider, true);
                    addTercero(anotacion, tercero, false);

                    // Subimos un documento a la anotación
                    String upload = crearUpload();
                    bool subido = subirFichero(upload, "C:/Users/eedevadmin/Downloads/a.pdf");
                    addFileToAnotacion(anotacion, upload, "documentoPrueba");

                    // Finalizamos la anotación
                    finalizarAnotacion(anotacion);
                }

                Console.WriteLine("Pulse una tecla para continuar...");
                Console.ReadLine();
            }
            finally
            {
                if (httpClient != null)
                    httpClient = null;
            }
        }