1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 using System
.Reflection
;
32 // __________ implementation ____________________________________
34 /** Create and modify a spreadsheet document.
41 public static int Main(String
[] args
)
43 // System.Diagnostics.Debugger.Launch();
44 //get the path to the directory
45 string sLocation
= Assembly
.GetExecutingAssembly().Location
;
46 sLocation
= sLocation
.Substring(0, sLocation
.LastIndexOf('\\'));
47 // Create a reference to the current directory.
48 DirectoryInfo di
= new DirectoryInfo(sLocation
);
49 // Create an array representing the files in the current directory.
50 FileInfo
[] fi
= di
.GetFiles();
52 //For every found dll try to figure out if it contains a
53 //cliversion.Version class
54 foreach (FileInfo fiTemp
in fi
)
56 if (fiTemp
.Extension
!= ".dll"
57 || ! fiTemp
.Name
.StartsWith("version"))
61 Object objVersion
= null;
64 string sName
= fiTemp
.Name
.Substring(0, fiTemp
.Name
.LastIndexOf(".dll"));
65 ass
= Assembly
.Load(sName
);
67 catch (BadImageFormatException
)
73 Console
.WriteLine("#Unexpected Exception");
74 Console
.WriteLine(e
.Message
);
78 //Assembly is loaded, instantiate cliversion.Version
82 objVersion
= ass
.CreateInstance("cliversion.Version");
83 if (objVersion
== null)
85 Console
.WriteLine("#Tested successfully " + fiTemp
.Name
);
86 //Starting the office the second time may fail without this pause
87 System
.Threading
.Thread
.Sleep(2000);
91 TargetInvocationException te
= e
as TargetInvocationException
;
94 FileNotFoundException fe
= e
.InnerException
as FileNotFoundException
;
97 Console
.WriteLine(fiTemp
.Name
+ " did not find " + fe
.FileName
+
98 ". Maybe the " + fe
.FileName
+ " is not installed or does not match the referenced version." +
99 "Original message: " + fe
.Message
+ "\n\n FusionLog: \n" + fe
.FusionLog
);
102 FileLoadException fl
= e
.InnerException
as FileLoadException
;
105 Console
.WriteLine(fiTemp
.Name
+ " could not load " + fl
.FileName
+
106 ". Maybe the version of " + fl
.FileName
+ " does not match the referenced version. " +
107 "Original message: " + fl
.Message
+ "\n\n FusionLog: \n" + fl
.FusionLog
);
111 if (e
.InnerException
!= null)
113 Console
.WriteLine(e
.InnerException
);
116 Console
.WriteLine("#Unexpected Exception");
117 Console
.WriteLine(e
.Message
);
121 //For some unknown reason this program hangs sometimes when started from java. This is
122 //a workaround that makes the problem disappear.
123 System
.Threading
.Thread
.Sleep(1000);