Author: jpobst
Date: 2006-12-04 13:13:41 -0500 (Mon, 04 Dec 2006)
New Revision: 68979

Added:
   trunk/moma/MoMA.Analyzer/Definitions/
   trunk/moma/MoMA.Analyzer/Definitions/DefinitionHandler.cs
   trunk/moma/MoMA.Analyzer/Definitions/FileDefinition.cs
Log:
Check-in some missing files.

Added: trunk/moma/MoMA.Analyzer/Definitions/DefinitionHandler.cs
===================================================================
--- trunk/moma/MoMA.Analyzer/Definitions/DefinitionHandler.cs   2006-12-04 
17:44:02 UTC (rev 68978)
+++ trunk/moma/MoMA.Analyzer/Definitions/DefinitionHandler.cs   2006-12-04 
18:13:41 UTC (rev 68979)
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using ICSharpCode.SharpZipLib;
+using ICSharpCode.SharpZipLib.Zip;
+
+namespace MoMA.Analyzer
+{
+       public class DefinitionHandler
+       {
+               public static List<FileDefinition> FindAvailableVersions 
(string path)
+               {
+                       List<FileDefinition> results = new List<FileDefinition> 
();
+               
+                       if (!Directory.Exists (path))
+                               return results;
+                               
+                       foreach (string s in Directory.GetFiles (path, "*.zip"))
+                       {
+                               try {
+                                       FileDefinition fd = 
GetDefinitionFromFile (s);
+                                       
+                                       if (fd != null)
+                                               results.Add (fd);
+                               }
+                               catch {
+                                       // Swallow exceptions, file simply 
won't be available
+                               }
+                       }
+                       
+                       results.Sort ();
+                       return results;
+               }
+               
+               private static FileDefinition GetDefinitionFromFile (string s)
+               {
+                       ZipInputStream zs = new ZipInputStream (File.OpenRead 
(s));
+                       ZipEntry ze;
+                       
+                       while ((ze = zs.GetNextEntry()) != null)
+                       {
+                               if (ze.Name == "version.txt")
+                               {
+                                       StreamReader sr = new StreamReader (zs);
+                                       
+                                       FileDefinition fd = new FileDefinition 
();
+                                       
+                                       fd.Version = sr.ReadLine ();
+                                       fd.Date = DateTime.Parse(sr.ReadLine 
());
+                                       fd.FileName = s;
+                                       
+                                       sr.Close ();
+                                       zs.Close ();
+
+                                       return fd;
+                               }
+                       }
+
+                       return null;
+               }
+               
+               public static void GetDefinitionStreamsFromBundle (string 
bundlePath, out Stream monoTodoDefinitions, out Stream 
notImplementedDefinitions, out Stream missingDefinitions)
+               {
+                       ZipInputStream zs = new ZipInputStream (File.OpenRead 
(bundlePath));
+                       ZipEntry ze;
+
+                       monoTodoDefinitions = null;
+                       notImplementedDefinitions = null;
+                       missingDefinitions = null;
+                       
+                       while ((ze = zs.GetNextEntry ()) != null) {
+                               switch (ze.Name) {
+                                       case "monotodo.txt":
+                                               StreamReader sr = new 
StreamReader (zs);
+                                               string s = sr.ReadToEnd ();
+                                               monoTodoDefinitions = new 
MemoryStream (ASCIIEncoding.ASCII.GetBytes (s));
+                                               break;
+                                       case "exception.txt":
+                                               StreamReader sr2 = new 
StreamReader (zs);
+                                               string s2 = sr2.ReadToEnd ();
+                                               notImplementedDefinitions = new 
MemoryStream (ASCIIEncoding.ASCII.GetBytes (s2));
+                                               break;
+                                       case "missing.txt":
+                                               StreamReader sr3 = new 
StreamReader (zs);
+                                               string s3 = sr3.ReadToEnd ();
+                                               missingDefinitions = new 
MemoryStream (ASCIIEncoding.ASCII.GetBytes (s3));
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+               }
+               
+               public static FileDefinition CheckLatestVersionFromInternet ()
+               {
+                       MoMAWebService.MoMASubmit ws = new 
MoMA.Analyzer.MoMAWebService.MoMASubmit ();
+                       
+                       string result = ws.GetLatestDefinitionsVersion ();
+                       string[] results = result.Split ('|');
+                       
+                       FileDefinition fd = new FileDefinition (results[0], 
results[1], results[2]);
+                       
+                       return fd;
+               }
+       }
+}


Property changes on: trunk/moma/MoMA.Analyzer/Definitions/DefinitionHandler.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/moma/MoMA.Analyzer/Definitions/FileDefinition.cs
===================================================================
--- trunk/moma/MoMA.Analyzer/Definitions/FileDefinition.cs      2006-12-04 
17:44:02 UTC (rev 68978)
+++ trunk/moma/MoMA.Analyzer/Definitions/FileDefinition.cs      2006-12-04 
18:13:41 UTC (rev 68979)
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MoMA.Analyzer
+{
+       public class FileDefinition : IComparable<FileDefinition>
+       {
+               private string version;
+               private DateTime date;
+               private string filename;
+
+               public FileDefinition (string version, string date, string 
filename)
+               {
+                       this.version = version;
+                       this.date = DateTime.Parse(date);
+                       this.filename = filename;
+               }
+               
+               public FileDefinition ()
+               {
+               }
+
+               public string Version
+               {
+                       get { return version; }
+                       set { version = value; }
+               }
+
+               public DateTime Date
+               {
+                       get { return date; }
+                       set { date = value; }
+               }
+
+               public string FileName
+               {
+                       get { return filename; }
+                       set { filename = value; }
+               }
+
+               public override string ToString ()
+               {
+                       return this.version;
+               }
+
+               #region IComparable<DefinitionFile> Members
+               // We want to sort reverse-chronologically, most recent file 
first
+               int IComparable<FileDefinition>.CompareTo (FileDefinition other)
+               {
+                       return date.CompareTo (other.date) * -1;
+               }
+               #endregion
+       }
+}


Property changes on: trunk/moma/MoMA.Analyzer/Definitions/FileDefinition.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to