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 System.Runtime.InteropServices;
41 using Microsoft.VisualBasic.CompilerServices;
43 //using Windows.Drawing;
44 //using System.Windows.Forms;
46 namespace Microsoft.VisualBasic {
48 [StructLayoutAttribute(LayoutKind.Auto)]
49 sealed public class Interaction {
51 private Interaction (){}
58 public static System.Int32 Shell (System.String Pathname,
59 [Optional, __DefaultArgumentValue(2)] AppWinStyle Style,
60 [Optional, __DefaultArgumentValue(false)] System.Boolean Wait,
61 [Optional, __DefaultArgumentValue(-1)] System.Int32 Timeout)
63 Process prcs = new Process();
65 ProcessWindowStyle PWinStyle = 0;
67 case AppWinStyle.Hide:
68 PWinStyle = ProcessWindowStyle.Hidden;
70 case AppWinStyle.NormalFocus:
71 PWinStyle = ProcessWindowStyle.Normal;
73 case AppWinStyle.MinimizedFocus:
74 PWinStyle = ProcessWindowStyle.Minimized;
76 case AppWinStyle.MaximizedFocus:
77 PWinStyle = ProcessWindowStyle.Maximized;
79 case AppWinStyle.NormalNoFocus:
80 PWinStyle = ProcessWindowStyle.Normal; //ToDo: no focus is not set
82 case AppWinStyle.MinimizedNoFocus:
83 PWinStyle = ProcessWindowStyle.Minimized; //ToDo: no focus is not set
87 prcs.StartInfo.FileName = Pathname;
88 prcs.StartInfo.WindowStyle = PWinStyle;
99 prcs.WaitForExit(Timeout);
106 catch (System.ComponentModel.Win32Exception e){
107 throw new System.IO.FileNotFoundException (
108 Utils.GetResourceString(53));
113 public static void AppActivate (System.Int32 ProcessId)
115 throw new NotImplementedException ();
119 public static void AppActivate (System.String Title)
121 throw new NotImplementedException ();
125 public static System.String InputBox (System.String Prompt,
126 [Optional, __DefaultArgumentValue("")] System.String Title,
127 [Optional, __DefaultArgumentValue("")] System.String DefaultResponse,
128 [Optional, __DefaultArgumentValue(-1)] System.Int32 XPos,
129 [Optional, __DefaultArgumentValue(-1)] System.Int32 YPos)
131 throw new NotImplementedException ();
134 public static System.Object IIf (System.Boolean Expression, System.Object TruePart, System.Object FalsePart)
136 return Expression ? TruePart : FalsePart;
139 public static System.String Partition (System.Int64 number, System.Int64 start, System.Int64 stop, System.Int64 interval)
142 String startStr = "";
143 long startNumber = 0;
148 throw new ArgumentException(
149 Utils.GetResourceString("Argument_InvalidValue1", "Start"));
151 throw new ArgumentException(
152 Utils.GetResourceString("Argument_InvalidValue1", "Stop"));
154 throw new ArgumentException(
155 Utils.GetResourceString("Argument_InvalidValue1", "Interval"));
158 endNumber = start - 1;
161 startNumber = stop + 1;
164 startNumber = number;
169 while (endNumber < number)
170 endNumber += interval;
171 startNumber = endNumber - interval + 1;
173 if (endNumber > stop)
175 if (startNumber < start)
181 startStr = startNumber.ToString();
182 stopStr = endNumber.ToString();
184 if (stopStr.Length > startStr.Length)
185 spacesCount = stopStr.Length;
187 spacesCount = startStr.Length;
189 return startStr.PadLeft(spacesCount) + ":" + stopStr.PadRight(spacesCount);
192 public static System.Object Switch (params System.Object[] VarExpr)
200 counter = VarExpr.Length;
203 if (counter % 2 != 0)
204 throw new ArgumentException(
205 Utils.GetResourceString("Argument_InvalidValue1", "VarExpr"));
208 if((bool)VarExpr[index])
209 return VarExpr[index + 1];
211 counter = counter - 2;
219 public static void DeleteSetting (System.String AppName,
220 [Optional, __DefaultArgumentValue(null)] System.String Section,
221 [Optional, __DefaultArgumentValue(null)] System.String Key)
223 throw new NotImplementedException ();
227 public static System.String[,] GetAllSettings (System.String AppName, System.String Section)
229 throw new NotImplementedException ();
233 public static System.String GetSetting (System.String AppName,
234 System.String Section,
236 [Optional, __DefaultArgumentValue("")] System.String Default)
238 throw new NotImplementedException ();
242 public static void SaveSetting (System.String AppName, System.String Section, System.String Key, System.String Setting)
244 throw new NotImplementedException ();
248 public static System.Object CreateObject (System.String ProgId,
249 [Optional, __DefaultArgumentValue("")] System.String ServerName)
251 throw new NotImplementedException ();
255 public static System.Object GetObject ([Optional, __DefaultArgumentValue(null)] System.String PathName,
256 [Optional, __DefaultArgumentValue(null)] System.String Class)
258 throw new NotImplementedException ();
262 public static Object CallByName (Object objRef, String name, CallType userCallType, Object[] args)
264 Object retVal = null;
265 Type[] argsType = null;
268 if(args != null && args.Length != 0) {
269 argsType = new Type[args.Length];
271 for(int i = 0; i < args.Length; i++)
272 argsType[i] = args[i].GetType();
275 argsType = new Type[0];*/
277 Type objType = objRef.GetType();
281 MethodInfo methodInfo = null;
283 if(userCallType == CallType.Method) {
284 Console.WriteLine("Method");
285 methodInfo = objType.GetMethod(name, argsType);
287 else if(userCallType == CallType.Get) {
288 Console.WriteLine("GetMethod");
289 methodInfo = objType.GetProperty(name).GetGetMethod();
291 else if(userCallType == CallType.Set) {
293 Console.WriteLine("SetMethod");
294 methodInfo = objType.GetProperty(name).GetSetMethod();
297 return methodInfo.Invoke(objRef, args);
300 catch (Exception exp)
302 throw new ArgumentException();
308 public static System.Object Choose (System.Double Index, System.Object[] Choice)
312 i = (int) Math.Round(Conversion.Fix(Index) - 1.0);
314 throw new ArgumentException(Utils.GetResourceString("Argument_RankEQOne1", "Choice"));
316 if(i < 0 || i > Choice.GetUpperBound(0))
323 public static System.String Environ (System.Int32 Expression)
328 // Console.WriteLine("Coming Here"+Expression);
330 IDictionary envVars = Environment.GetEnvironmentVariables();
332 foreach(DictionaryEntry de in envVars) {
333 if(++index == Expression) {
334 if( (object) de.Value == null)
337 return String.Concat(de.Key, "=" , de.Value);
340 // Console.WriteLine("Exiting the loop");
346 public static System.String Environ (System.String Expression)
349 if (Expression == null) {
350 e = ExceptionUtils.VbMakeExceptionEx(5, Utils.GetResourceString("Argument_InvalidValue1", Expression));
354 string var = Environment.GetEnvironmentVariable (Expression);
355 return var != null ? var : "";
358 public static void Beep ()
360 Console.WriteLine("\a");
364 public static System.String Command ()
366 string [] args = Environment.GetCommandLineArgs ();
368 if (args != null && args.Length > 1) {
369 return string.Join (" ", args, 1, args.Length - 1);
376 public static MsgBoxResult MsgBox (System.Object Prompt,
377 [Optional, __DefaultArgumentValue(0)]MsgBoxStyle Buttons,
378 [Optional, __DefaultArgumentValue(null)] System.Object Title)
380 throw new NotImplementedException ();
381 /* //MessageButtons msgBoxButtons = 0;
382 MessageBoxIcon msgBoxIcon = 0;
383 MessageBoxDefaultButton msgBoxDefaultButton = 0;
384 MessageBoxOptions msgBoxOptions = 0;
387 int IconsMask = MsgBoxStyle.Critical | MsgBoxStyle.Question | MsgBoxStyle.Exclamation | MsgBoxStyle.Information;
389 int ButtonsMask = MsgBoxStyle.OKOnly |MsgBoxStyle.OKCancel | MsgBoxStyle.AbortRetryIgnore |
390 MsgBoxStyle.YesNoCancel |
391 MsgBoxStyle.YesNo | MsgBoxStyle.RetryCancel;
393 int DefaultButtonMask = MsgBoxStyle.DeafultButton1 | MsgBoxStyle.DefaultButton2 |
394 MsgBoxStyle.DefaultButton3;
396 int OptionsMask = MsgBoxStyle.MsgBoxRight | MsgBoxStyle.MsgBoxRtlReading;
399 switch(Buttons & IconMask) {
400 case MsgBoxStyle.OKOnly:
401 msgBoxButtons = MessageBoxButtons.OK;
404 case MsgBoxStyle.OKCancel:
405 msgBoxButtons = MessageBoxButtons.OK;
408 case MsgBoxStyle.AbortRetryIgnore:
409 msgBoxButtons = MessageBoxButtons.OKCancel;
412 case MsgBoxStyle.YesNoCancel:
413 msgBoxButtons = MessageBoxButtons.YesNoCancel;
416 case MsgBoxStyle.YesNo:
417 msgBoxButtons = MessageBoxButtons.YesNo;
420 case MsgBoxStyle.RetryCancel:
421 msgBoxButtons = MessageBoxButtons.RetryCancel;
431 switch(Buttons & IconMask) {
433 case MsgBoxStyle.Critical:
434 msgBoxIcon = MessageBoxIcon.Error;
437 case MsgBoxStyle.Question:
438 msgBoxIcon = MessageBoxIcon.Question;
441 case MsgBoxStyle.Exclamation:
442 msgBoxIcon = MessageBoxIcon.Exclamation;
445 case MsgBoxStyle.Information:
446 msgBoxIcon = MessageBoxIcon.Information;
454 switch(Buttons & DefaultButtonMask) {
455 case MsgBoxStyle.DefaultButton1:
456 msgBoxDefaultButton = MessageBoxDefaultButton.Button1;
458 case MsgBoxStyle.DefaultButton2:
459 msgBoxDefaultButton = MessageBoxDefaultButton.Button2;
461 case MsgBoxStyle.DefaultButton3:
462 msgBoxDefaultButton = MessageBoxDefaultButton.Button3;
469 switch(Buttons & OptionsMask) {