Пример #1
0
        //Писать в БД данные, которые получаем в виде стрктуры данных CrlInfo:
        internal void WriteCrlToDbFromStructure(Crl.CrlInfo crl, string crlPath)
        {
            try
            {
                SQLiteConnection connection = new SQLiteConnection(connectionString);

                connection.Open();

                string q = $"INSERT INTO test(UC, signature, thisUpdate, nextUpdate, crlNumber, linkToCrl) VALUES ('{crl.issuer}',NULL, '{crl.thisTime}', '{crl.updateTime}', 'number', '{crlPath}' )";

                SQLiteCommand query = new SQLiteCommand(q, connection);

                int rezult = query.ExecuteNonQuery();

                if (rezult == 1)
                {
                    Logger.Write($"Запись в БД прошла успешно.");
                }

                connection.Close();
            }
            catch (Exception e)
            {
                Logger.Write(e.Message);
                throw;
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string projectFolderPath = Path.GetFullPath(@"..\..\..\tmp");

            string xmlFolderPath = Path.GetFullPath(@"..\..\..\tmp");

            string crlFolderPath = Path.GetFullPath(@"..\..\..\tmp\crl");

            int numberOfCrlToByDownloaded = 10;

            string mask = "*.crl";

            string dbPath = Path.GetFullPath(@"..\..\..\tmp\CrlCheckTestDb.db");

            string logFilePath = Path.GetFullPath(@"..\..\..\tmp\log.txt");

            Logger.SetPath(logFilePath);

            Db db = new Db(dbPath);

            string query = "default";

            db.CreateTable(query);

            Logger.Write("Start ---------------------------------------------");

            Xml xml = new Xml();

            XmlNodeList crlUrlList = xml.GetXmlFromUrlandSaveAs("http://e-trust.gosuslugi.ru/CA/DownloadTSL?schemaVersion=0", xmlFolderPath);

            Crl crl = new Crl();

            crl.GetNumberOfCrlFromUrlAndSaveToFolder(numberOfCrlToByDownloaded, crlUrlList, crlFolderPath);

            string[] filePaths = Directory.GetFiles(crlFolderPath, mask);

            foreach (string filePath in filePaths)
            {
                Console.WriteLine($"Для загрузки файла {filePath} нажмите любую клавишу...");

                Console.ReadKey();

                string crlPath = filePath;

                if (!(new FileInfo(filePath).Length == 0))
                {
                    Crl.CrlInfo crlInfo = crl.GetCrlInfoAsStructure(crlPath);

                    db.WriteCrlToDbFromStructure(crlInfo, crlPath);
                }
                else
                {
                    Console.WriteLine($"Файл {filePath} пуст!");

                    continue;
                }
            }

            Console.WriteLine("Для завершения нажмите любую клавишу...");

            Console.ReadKey();
        }