This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
Archiver.cs
140 lines (129 loc) · 3.73 KB
/
Archiver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// Mono Weekly News Archives Generator
//
// (c) 2003, Jaime Anguiano Olarra (jaime@gnome.org)
//
using System;
using System.IO;
using System.Collections;
public class Archiver {
Queue entries;
ArrayList rssfiles;
Queue descriptions;
StreamWriter writer;
public Archiver ()
{
rssfiles = new ArrayList ();
descriptions = new Queue ();
writer = new StreamWriter ("archives.html");
WriteFile ("archeader");
GetRSSDescriptions ();
GenArchivesCells ();
WriteFile ("contact");
writer.Flush ();
writer.Close ();
writer = null;
GenRSS();
}
public void WriteFile (string file)
{
StreamReader reader = new StreamReader (file);
string line;
while ((line = reader.ReadLine()) != null)
writer.WriteLine (line);
reader.Close ();
reader = null;
}
public void GenArchivesCells ()
{
entries = new Queue ();
rssfiles = new ArrayList ();
DirectoryInfo di = new DirectoryInfo ("archives");
FileInfo[] files = di.GetFiles ();
// We get the RSS files that are available
foreach (FileInfo file in files)
{
string fileName = file.Name;
Console.WriteLine ("File: " + fileName);
if (fileName.EndsWith ("rss")) {
rssfiles.Add (fileName);
Console.WriteLine ("Adding RSS file: " + fileName);
}
}
int ctr = 0;
// We iterate over all the files again.
foreach (FileInfo file in files)
{
string fileName = file.Name;
string rssName = "Not available";
string rssLink = rssName;
// if this is an archived html
if (!fileName.EndsWith ("rss"))
{
// Check if there is a RSS file available
foreach (object obj in rssfiles)
{
string name = obj.ToString();
if (name.StartsWith (fileName.Substring (0, 8)))
{
rssName = name;
rssLink = "<a href=\"archives/" + rssName + "\">" + rssName + "</a>";
}
}
writer.WriteLine ("<tr><td>" + ctr + "</td><td>" + (++ctr).ToString() + "</td><td><a href=\"archives/" + fileName + "\">" + fileName + "</a></td><td>" + rssLink + "</td></tr>");
}
}
}
public void GetRSSDescriptions ()
{
DirectoryInfo di = new DirectoryInfo ("archives");
foreach (FileInfo file in di.GetFiles())
{
if ((file.Name).EndsWith (".mwn.rss"))
{
StreamReader reader = new StreamReader ("archives/" + file.Name);
string line;
while ((line = reader.ReadLine ()) != null)
{
if (line.StartsWith ("1."))
descriptions.Enqueue (line);
}
}
}
}
public void GenRSS ()
{
StreamWriter rsswriter = new StreamWriter ("archives.rss");
rsswriter.WriteLine ("<?xml version=\"1.0\"?>");
rsswriter.WriteLine ("<rss version=\"0.92\">");
rsswriter.WriteLine ("<channel>");
rsswriter.WriteLine ("<title>Mono Weekly News Archives</title>");
rsswriter.WriteLine ("<link>http://monoevo.sf.net/mwn/archives.html</link>");
rsswriter.WriteLine ("<description>Archives of the weekly news from the Mono project: a portable implementation of the .NET Framework</description>");
rsswriter.WriteLine ("<webMaster>jaime@gnome.org</webMaster>");
rsswriter.WriteLine ("<managingEditor>jaime@gnome.org</managingEditor>");
rsswriter.WriteLine ("<pubDate>" + DateTime.Now + "</pubDate>");
string address = "http://monoevo.sf.net/mwn/archives/";
int ctr = 0;
foreach (string s in entries)
{
rsswriter.WriteLine ("<item>");
rsswriter.WriteLine ("<title>" + ++ctr + "</title>");
rsswriter.WriteLine ("<link>" + address + s + "</link>");
rsswriter.WriteLine ("<description>");
for (int i=0; i < descriptions.Count; i++)
{
rsswriter.WriteLine (descriptions.Dequeue() + "||");
}
rsswriter.WriteLine ("</description>");
}
rsswriter.WriteLine ("</channel>\n</rss>");
rsswriter.Flush ();
rsswriter.Close ();
rsswriter = null;
}
public static void Main ()
{
Archiver a = new Archiver ();
}
}