Advertisement
Guest User

Генерация списка литературы 2

a guest
May 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp21
  9. {
  10.     class Program
  11.     {
  12.  
  13.         static Random rnd = new Random();
  14.         static void Main(string[] args)
  15.         {
  16.             List<string> lines = new List<string>();
  17.             string inputPath = @"INPUT_DIRECTORY\urls.txt";
  18.             string outputPath = @"OUTPUT_DIRECTORY\MySources.xml";
  19.             using (StreamReader sr = new StreamReader(inputPath))
  20.             {
  21.                 string line;
  22.                 while ((line = sr.ReadLine()) != null)
  23.                 {
  24.                     lines.Add(line);
  25.                 }
  26.             }
  27.  
  28.             string xml = "";
  29.             int counter = 1;
  30.             for (int i = 0; i < lines.Count; i += 2)
  31.             {
  32.                 string URL = lines.ElementAt(i);
  33.                 string Title = lines.ElementAt(i + 1);
  34.                 Uri uri = new Uri(URL);
  35.                 string InternetSiteTitle = uri.Host;
  36.                 string Year = "2019";
  37.                 string YearAccessed = "2019";
  38.                 var month = rnd.Next(4, 6);
  39.                 string MonthAccessed = month.ToString();
  40.                 int start, end;
  41.                 if (month == 4)
  42.                 {
  43.                     start = 1;
  44.                     end = 29;
  45.                 }
  46.                 else
  47.                 {
  48.                     start = 1;
  49.                     end = 19;
  50.                 }
  51.  
  52.                 var day = rnd.Next(start, end);
  53.                 string DayAccessed = day.ToString();
  54.  
  55.  
  56.                 string Tag = "SomeTag" + counter;
  57.  
  58.                 string xmlNode = $"<b:Source> <b:Tag>{Tag}</b:Tag> <b:SourceType>InternetSite</b:SourceType> <b:Guid>" + "{044F29E4-974C-42F2-9B2D-DA1E893E51AD}" + $"</b:Guid> <b:Title>{Title}</b:Title> <b:InternetSiteTitle>{InternetSiteTitle}</b:InternetSiteTitle> <b:Year>{Year}</b:Year> <b:YearAccessed>{YearAccessed}</b:YearAccessed> <b:MonthAccessed>{MonthAccessed}</b:MonthAccessed> <b:DayAccessed>{DayAccessed}</b:DayAccessed> <b:URL>{URL}</b:URL> </b:Source>";
  59.                 xml += xmlNode;
  60.                 if (counter % 3 == 0)
  61.                 {
  62.                     xml = "<b:Sources SelectedStyle=\"\" xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\" xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\"> " + xml + " </b:Sources>";
  63.                     outputPath = $@"C:\Users\zgame\Desktop\src2\MySources{counter}.xml";
  64.                     using (StreamWriter sr = new StreamWriter(outputPath))
  65.                     {
  66.                         sr.Write(xml);
  67.                     }
  68.                     xml = "";
  69.                 }
  70.                 counter++;
  71.  
  72.             }
  73.             outputPath = @"C:\Users\zgame\Desktop\MySources.xml";
  74.             xml = "<b:Sources SelectedStyle=\"\" xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\" xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\"> " + xml + " </b:Sources>";
  75.  
  76.             using (StreamWriter sr = new StreamWriter(outputPath))
  77.             {
  78.                 sr.Write(xml);
  79.             }
  80.             Console.WriteLine("Success");
  81.             Console.ReadKey();
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement