Esempio n. 1
0
        /// <summary>
        /// Замена параметров запроса
        /// </summary>
        /// <param name="parameterAksiok">Модель с параметрами АКСИОК</param>
        /// <param name="typeId">Ун типа</param>
        /// <param name="productId">Ун продукта</param>
        /// <param name="modelDocumentTypeId">Ун документа типа</param>
        /// <param name="modelDocumentId">Ун документа</param>
        /// <returns></returns>
        private ModelParametersAksiok GenerateParametersAksiok(ModelParametersAksiok parameterAksiok, int typeId = 0, int productId = 0, int modelDocumentTypeId = 0, int modelDocumentId = 0)
        {
            ModelParametersAksiok model = new ModelParametersAksiok();

            model.IndexExecute     = parameterAksiok.IndexExecute;
            model.UrlAksiok        = parameterAksiok.UrlAksiok;
            model.ModelUpdateSql   = parameterAksiok.ModelUpdateSql;
            model.ParametersAksiok = parameterAksiok.ParametersAksiok.Replace("{Date}", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"))
                                     .Replace("{typeId}", typeId.ToString())
                                     .Replace("{productId}", productId.ToString())
                                     .Replace("{modelDocumentTypeId}", modelDocumentTypeId.ToString())
                                     .Replace("{modelDocumentId}", modelDocumentId.ToString());
            return(model);
        }
Esempio n. 2
0
        /// <summary>
        /// Запрос в Аксиок получения моделей
        /// </summary>
        /// <typeparam name="T">Тип возвращаемого параметра</typeparam>
        /// <param name="parameterAksiok">Параметры АКСИОК</param>
        /// <param name="idType">Ун типа </param>
        /// <param name="idProduct">Ун продукта</param>
        /// <returns></returns>
        private DataAksiokFullSchemes <T> PostAksiok <T>(ModelParametersAksiok parameterAksiok, int idType = 0, int idProduct = 0)
        {
            DataAksiokFullSchemes <T> dataModelServerAksiok = new DataAksiokFullSchemes <T>();

            DatesBytes              = Encoding.UTF8.GetBytes(parameterAksiok.ParametersAksiok);
            Request                 = (HttpWebRequest)WebRequest.Create(parameterAksiok.UrlAksiok);
            Request.Accept          = "*/*";
            Request.KeepAlive       = true;
            Request.Credentials     = MyCache;
            Request.CookieContainer = Сookies;
            Request.Host            = "aksiok.dpc.tax.nalog.ru";
            Request.UserAgent       = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36";
            Request.ContentType     = "application/json";
            Request.Headers.Add("Accept-Encoding", "gzip, deflate, br");
            Request.Headers.Add("Accept-Language", "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7");
            Request.Headers.Add("X-Requested-With", "XMLHttpRequest");
            Request.Headers.Add("Origin", "https://aksiok.dpc.tax.nalog.ru/");
            Request.Headers.Add("sec-ch-ua", "Not A;Brand\";v=\"99\", \"Chromium\"; v=\"96\", \"Google Chrome\"; v=\"96\"");
            Request.Headers.Add("sec-ch-ua-mobile", "?0");
            Request.Headers.Add("sec-ch-ua-platform", "Windows");
            Request.Headers.Add("Sec-Fetch-Dest", "empty");
            Request.Headers.Add("Sec-Fetch-Mode", "cors");
            Request.Headers.Add("Sec-Fetch-Site", "same-origin");
            Request.Method        = "POST";
            Request.ContentLength = DatesBytes.Length;
            using (var stream = Request.GetRequestStream())
            {
                stream.Write(DatesBytes, 0, DatesBytes.Length);
            }
            Response = (HttpWebResponse)Request.GetResponse();
            Сookies.Add(Response.Cookies);
            if (Response.StatusCode == HttpStatusCode.OK)
            {
                using (var receiveStream = Response.GetResponseStream())
                {
                    var readStream = String.IsNullOrWhiteSpace(Response.CharacterSet)
                        ? new StreamReader(receiveStream ?? throw new InvalidOperationException())
                        : new StreamReader(receiveStream ?? throw new InvalidOperationException(), Encoding.GetEncoding(Response.CharacterSet));
                    string data = readStream.ReadToEnd();
                    dataModelServerAksiok = Newtonsoft.Json.JsonConvert.DeserializeObject <DataAksiokFullSchemes <T> >(data);
                    if (parameterAksiok.ModelUpdateSql != null)
                    {
                        AksiokAddAndUpdateObjectDb.AddAndUpdateFullLoadAksiok(dataModelServerAksiok.Data, parameterAksiok.ModelUpdateSql, idType, idProduct);
                    }
                }
            }
            return(dataModelServerAksiok);
        }