2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 using System
.Reflection
;
23 // __________ implementation ____________________________________
25 /** Create and modify a spreadsheet document.
32 public static int Main(String
[] args
)
34 // System.Diagnostics.Debugger.Launch();
35 //get the path to the directory
36 string sLocation
= Assembly
.GetExecutingAssembly().Location
;
37 sLocation
= sLocation
.Substring(0, sLocation
.LastIndexOf('\\'));
38 // Create a reference to the current directory.
39 DirectoryInfo di
= new DirectoryInfo(sLocation
);
40 // Create an array representing the files in the current directory.
41 FileInfo
[] fi
= di
.GetFiles();
43 //For every found dll try to figure out if it contains a
44 //cliversion.Version class
45 foreach (FileInfo fiTemp
in fi
)
47 if (fiTemp
.Extension
!= ".dll"
48 || ! fiTemp
.Name
.StartsWith("version"))
52 Object objVersion
= null;
55 string sName
= fiTemp
.Name
.Substring(0, fiTemp
.Name
.LastIndexOf(".dll"));
56 ass
= Assembly
.Load(sName
);
58 catch (BadImageFormatException
)
64 Console
.WriteLine("#Unexpected Exception");
65 Console
.WriteLine(e
.Message
);
69 //Assembly is loaded, instantiate cliversion.Version
73 objVersion
= ass
.CreateInstance("cliversion.Version");
74 if (objVersion
== null)
76 Console
.WriteLine("#Tested successfully " + fiTemp
.Name
);
77 //Starting the office the second time may fail without this pause
78 System
.Threading
.Thread
.Sleep(2000);
82 TargetInvocationException te
= e
as TargetInvocationException
;
85 FileNotFoundException fe
= e
.InnerException
as FileNotFoundException
;
88 Console
.WriteLine(fiTemp
.Name
+ " did not find " + fe
.FileName
+
89 ". Maybe the " + fe
.FileName
+ " is not installed or does not match the referenced version." +
90 "Original message: " + fe
.Message
+ "\n\n FusionLog: \n" + fe
.FusionLog
);
93 FileLoadException fl
= e
.InnerException
as FileLoadException
;
96 Console
.WriteLine(fiTemp
.Name
+ " could not load " + fl
.FileName
+
97 ". Maybe the version of " + fl
.FileName
+ " does not match the referenced version. " +
98 "Original message: " + fl
.Message
+ "\n\n FusionLog: \n" + fl
.FusionLog
);
102 if (e
.InnerException
!= null)
104 Console
.WriteLine(e
.InnerException
);
107 Console
.WriteLine("#Unexpected Exception");
108 Console
.WriteLine(e
.Message
);
112 //For some unknown reason this program hangs sometimes when started from java. This is
113 //a workaround that makes the problem disappear.
114 System
.Threading
.Thread
.Sleep(1000);