5 // Chris J Breisch (cjbreisch@altavista.net)
6 // Joerg Rosenkranz (JoergR@voelcker.com)
8 // (C) 2002 Chris J Breisch
9 // (C) 2004 Joerg Rosenkranz
13 // Copyright (c) 2002-2003 Mainsoft Corporation.
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Reflection;
38 using System.Collections;
39 using System.Diagnostics;
40 //using Windows.Drawing;
41 //using System.Windows.Forms;
43 using Microsoft.VisualBasic.CompilerServices;
45 namespace Microsoft.VisualBasic {
46 [Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute]
47 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Auto)]
48 sealed public class Interaction {
54 public static System.Int32 Shell (System.String Pathname,
55 [System.Runtime.InteropServices.Optional]
56 [System.ComponentModel.DefaultValue(2)] Microsoft.VisualBasic.AppWinStyle Style,
57 [System.Runtime.InteropServices.Optional]
58 [System.ComponentModel.DefaultValue(false)] System.Boolean Wait,
59 [System.Runtime.InteropServices.Optional]
60 [System.ComponentModel.DefaultValue(-1)] System.Int32 Timeout)
62 Process prcs = new Process();
64 ProcessWindowStyle PWinStyle = 0;
66 case AppWinStyle.Hide:
67 PWinStyle = ProcessWindowStyle.Hidden;
69 case AppWinStyle.NormalFocus:
70 PWinStyle = ProcessWindowStyle.Normal;
72 case AppWinStyle.MinimizedFocus:
73 PWinStyle = ProcessWindowStyle.Minimized;
75 case AppWinStyle.MaximizedFocus:
76 PWinStyle = ProcessWindowStyle.Maximized;
78 case AppWinStyle.NormalNoFocus:
79 PWinStyle = ProcessWindowStyle.Normal; //ToDo: no focus is not set
81 case AppWinStyle.MinimizedNoFocus:
82 PWinStyle = ProcessWindowStyle.Minimized; //ToDo: no focus is not set
86 prcs.StartInfo.FileName = Pathname;
87 prcs.StartInfo.WindowStyle = PWinStyle;
98 prcs.WaitForExit(Timeout);
105 catch (System.ComponentModel.Win32Exception e){
106 throw new System.IO.FileNotFoundException (
107 Utils.GetResourceString(53));
112 public static void AppActivate (System.Int32 ProcessId)
114 throw new NotImplementedException ();
118 public static void AppActivate (System.String Title)
120 throw new NotImplementedException ();
124 public static System.String InputBox (System.String Prompt, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue("")] System.String Title, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue("")] System.String DefaultResponse, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int32 XPos, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int32 YPos)
126 throw new NotImplementedException ();
129 public static System.Object IIf (System.Boolean Expression, System.Object TruePart, System.Object FalsePart)
131 return Expression ? TruePart : FalsePart;
134 public static System.String Partition (System.Int64 number, System.Int64 start, System.Int64 stop, System.Int64 interval)
137 String startStr = "";
138 long startNumber = 0;
143 throw new ArgumentException(
144 Utils.GetResourceString("Argument_InvalidValue1", "Start"));
146 throw new ArgumentException(
147 Utils.GetResourceString("Argument_InvalidValue1", "Stop"));
149 throw new ArgumentException(
150 Utils.GetResourceString("Argument_InvalidValue1", "Interval"));
153 endNumber = start - 1;
156 startNumber = stop + 1;
159 startNumber = number;
164 while (endNumber < number)
165 endNumber += interval;
166 startNumber = endNumber - interval + 1;
168 if (endNumber > stop)
170 if (startNumber < start)
176 startStr = startNumber.ToString();
177 stopStr = endNumber.ToString();
179 if (stopStr.Length > startStr.Length)
180 spacesCount = stopStr.Length;
182 spacesCount = startStr.Length;
184 return startStr.PadLeft(spacesCount) + ":" + stopStr.PadRight(spacesCount);
187 public static System.Object Switch (params System.Object[] VarExpr)
195 counter = VarExpr.Length;
198 if (counter % 2 != 0)
199 throw new ArgumentException(
200 Utils.GetResourceString("Argument_InvalidValue1", "VarExpr"));
203 if((bool)VarExpr[index])
204 return VarExpr[index + 1];
206 counter = counter - 2;
214 public static void DeleteSetting (System.String AppName, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.String Section, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.String Key)
216 throw new NotImplementedException ();
220 public static System.String[,] GetAllSettings (System.String AppName, System.String Section)
222 throw new NotImplementedException ();
226 public static System.String GetSetting (System.String AppName, System.String Section, System.String Key, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue("")] System.String Default)
228 throw new NotImplementedException ();
232 public static void SaveSetting (System.String AppName, System.String Section, System.String Key, System.String Setting)
234 throw new NotImplementedException ();
238 public static System.Object CreateObject (System.String ProgId, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue("")] System.String ServerName)
240 throw new NotImplementedException ();
244 public static System.Object GetObject ([System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.String PathName, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.String Class)
246 throw new NotImplementedException ();
250 public static Object CallByName (Object objRef, String name, CallType userCallType, Object[] args)
252 Object retVal = null;
253 Type[] argsType = null;
256 if(args != null && args.Length != 0) {
257 argsType = new Type[args.Length];
259 for(int i = 0; i < args.Length; i++)
260 argsType[i] = args[i].GetType();
263 Type objType = objRef.GetType();
267 MethodInfo methodInfo = null;
269 if(userCallType == CallType.Method) {
270 Console.WriteLine("Method");
271 methodInfo = objType.GetMethod(name, argsType);
273 else if(userCallType == CallType.Get) {
274 Console.WriteLine("GetMethod");
275 methodInfo = objType.GetProperty(name).GetGetMethod();
277 else if(userCallType == CallType.Set) {
279 Console.WriteLine("SetMethod");
280 methodInfo = objType.GetProperty(name).GetSetMethod();
283 return methodInfo.Invoke(objRef, args);
286 catch (Exception exp)
288 throw new ArgumentException();
294 public static System.Object Choose (System.Double Index, System.Object[] Choice)
298 i = (int) Math.Round(Conversion.Fix(Index) - 1.0);
300 throw new ArgumentException(Utils.GetResourceString("Argument_RankEQOne1", "Choice"));
302 if(i < 0 || i > Choice.GetUpperBound(0))
309 public static System.String Environ (System.Int32 Expression)
314 // Console.WriteLine("Coming Here"+Expression);
316 IDictionary envVars = Environment.GetEnvironmentVariables();
318 foreach(DictionaryEntry de in envVars) {
319 if(++index == Expression) {
320 if( (object) de.Value == null)
323 return String.Concat(de.Key, "=" , de.Value);
326 // Console.WriteLine("Exiting the loop");
332 public static System.String Environ (System.String Expression)
335 if (Expression == null) {
336 e = ExceptionUtils.VbMakeExceptionEx(5, Utils.GetResourceString("Argument_InvalidValue1", Expression));
340 string var = Environment.GetEnvironmentVariable (Expression);
341 return var != null ? var : "";
344 public static void Beep ()
346 Console.WriteLine("\a");
350 public static System.String Command ()
352 string [] args = Environment.GetCommandLineArgs ();
354 if (args != null && args.Length > 1) {
355 return string.Join (" ", args, 2, args.Length - 1);
362 public static Microsoft.VisualBasic.MsgBoxResult MsgBox (System.Object Prompt,
363 [System.Runtime.InteropServices.Optional]
364 [System.ComponentModel.DefaultValue(0)]
365 Microsoft.VisualBasic.MsgBoxStyle Buttons,
366 [System.Runtime.InteropServices.Optional]
367 [System.ComponentModel.DefaultValue(null)] System.Object Title)
369 throw new NotImplementedException ();
370 /* //MessageButtons msgBoxButtons = 0;
371 MessageBoxIcon msgBoxIcon = 0;
372 MessageBoxDefaultButton msgBoxDefaultButton = 0;
373 MessageBoxOptions msgBoxOptions = 0;
376 int IconsMask = MsgBoxStyle.Critical | MsgBoxStyle.Question | MsgBoxStyle.Exclamation | MsgBoxStyle.Information;
378 int ButtonsMask = MsgBoxStyle.OKOnly |MsgBoxStyle.OKCancel | MsgBoxStyle.AbortRetryIgnore |
379 MsgBoxStyle.YesNoCancel |
380 MsgBoxStyle.YesNo | MsgBoxStyle.RetryCancel;
382 int DefaultButtonMask = MsgBoxStyle.DeafultButton1 | MsgBoxStyle.DefaultButton2 |
383 MsgBoxStyle.DefaultButton3;
385 int OptionsMask = MsgBoxStyle.MsgBoxRight | MsgBoxStyle.MsgBoxRtlReading;
388 switch(Buttons & IconMask) {
389 case MsgBoxStyle.OKOnly:
390 msgBoxButtons = MessageBoxButtons.OK;
393 case MsgBoxStyle.OKCancel:
394 msgBoxButtons = MessageBoxButtons.OK;
397 case MsgBoxStyle.AbortRetryIgnore:
398 msgBoxButtons = MessageBoxButtons.OKCancel;
401 case MsgBoxStyle.YesNoCancel:
402 msgBoxButtons = MessageBoxButtons.YesNoCancel;
405 case MsgBoxStyle.YesNo:
406 msgBoxButtons = MessageBoxButtons.YesNo;
409 case MsgBoxStyle.RetryCancel:
410 msgBoxButtons = MessageBoxButtons.RetryCancel;
420 switch(Buttons & IconMask) {
422 case MsgBoxStyle.Critical:
423 msgBoxIcon = MessageBoxIcon.Error;
426 case MsgBoxStyle.Question:
427 msgBoxIcon = MessageBoxIcon.Question;
430 case MsgBoxStyle.Exclamation:
431 msgBoxIcon = MessageBoxIcon.Exclamation;
434 case MsgBoxStyle.Information:
435 msgBoxIcon = MessageBoxIcon.Information;
443 switch(Buttons & DefaultButtonMask) {
444 case MsgBoxStyle.DefaultButton1:
445 msgBoxDefaultButton = MessageBoxDefaultButton.Button1;
447 case MsgBoxStyle.DefaultButton2:
448 msgBoxDefaultButton = MessageBoxDefaultButton.Button2;
450 case MsgBoxStyle.DefaultButton3:
451 msgBoxDefaultButton = MessageBoxDefaultButton.Button3;
458 switch(Buttons & OptionsMask) {