コード例 #1
0
        public string CAllApiMethod(GenericAddDto dto, string url, string access_token)
        {
            LogControl logControl = new LogControl();

            string json2        = JsonConvert.SerializeObject(dto, Formatting.Indented);
            var    buffer2      = System.Text.Encoding.UTF8.GetBytes(json2);
            var    byteContent2 = new ByteArrayContent(buffer2);

            byteContent2.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            HttpClient client = _api.Initial();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);

            HttpResponseMessage res = client.PostAsync(url, byteContent2).Result;

            string resposta = "FALHA";

            if (res.IsSuccessStatusCode)
            {
                logControl.Write("Processamento de " + url + " Sucesso");
                resposta = "SUCESSO";
            }
            else
            {
                logControl.Write("Processamento de " + url + " Falha");
                resposta = "FALHA";
            }

            return(resposta);
        }
コード例 #2
0
        public string RegisterProject(string xml)
        {
            IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
            LogControl    logControl          = new LogControl();
            CallApi       api = new CallApi();
            GenericAddDto dto = new GenericAddDto
            {
                Xml = xml
            };

            string user  = request.Headers["Usuario"];
            string senha = request.Headers["Senha"];

            string access_token = api.Login(user, senha).Result;

            if (String.IsNullOrEmpty(access_token))
            {
                logControl.Write("Usuário e senha não conferem");
                return(api.CAllApiMethod(dto, "/project", access_token));
            }
            else
            {
                logControl.Write("Usuário logado");
                return(api.CAllApiMethod(dto, "/project", access_token));
            }
        }
コード例 #3
0
        public string RegisterProject(string xml)
        {
            LogControl    logControl = new LogControl();
            CallApi       api        = new CallApi();
            GenericAddDto dto        = new GenericAddDto
            {
                Xml = xml
            };

            if (Auth != null)
            {
                if (Auth.IsValid())
                {
                    string access_token = api.Login(Auth.Usuario, Auth.Senha).Result;

                    if (String.IsNullOrEmpty(access_token))
                    {
                        logControl.Write("Usuário e senha não conferem");
                        return(api.CAllApiMethod(dto, "/project", access_token));
                    }
                    else
                    {
                        logControl.Write("Usuário logado");
                        return(api.CAllApiMethod(dto, "/project", access_token));
                    }
                }
                else
                {
                    logControl.Write("Usuário e senha informados na requisição não conferem");
                    return("FALHA");
                }
            }
            else
            {
                logControl.Write("Não foram informados usuário e senha no cabeçalho da requisição");
                return("FALHA");
            }
        }