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;
44 using DefaultParameterValueAttribute = Microsoft.VisualBasic.CompilerServices.__DefaultParameterValueAttribute;
47 //using Windows.Drawing;
48 //using System.Windows.Forms;
50 namespace Microsoft.VisualBasic {
52 [StructLayoutAttribute(LayoutKind.Auto)]
53 sealed public class Interaction {
55 private Interaction (){}
62 public static int Shell (string Pathname,
63 [Optional, __DefaultParameterValue(2)] AppWinStyle Style,
64 [Optional, DefaultParameterValue(false)] bool Wait,
65 [Optional, DefaultParameterValue(-1)] int Timeout)
67 Process prcs = new Process();
69 ProcessWindowStyle PWinStyle = 0;
71 case AppWinStyle.Hide:
72 PWinStyle = ProcessWindowStyle.Hidden;
74 case AppWinStyle.NormalFocus:
75 PWinStyle = ProcessWindowStyle.Normal;
77 case AppWinStyle.MinimizedFocus:
78 PWinStyle = ProcessWindowStyle.Minimized;
80 case AppWinStyle.MaximizedFocus:
81 PWinStyle = ProcessWindowStyle.Maximized;
83 case AppWinStyle.NormalNoFocus:
84 PWinStyle = ProcessWindowStyle.Normal; //ToDo: no focus is not set
86 case AppWinStyle.MinimizedNoFocus:
87 PWinStyle = ProcessWindowStyle.Minimized; //ToDo: no focus is not set
91 prcs.StartInfo.FileName = Pathname;
92 prcs.StartInfo.WindowStyle = PWinStyle;
103 prcs.WaitForExit(Timeout);
110 catch (System.ComponentModel.Win32Exception e){
111 throw new System.IO.FileNotFoundException (
112 Utils.GetResourceString(53));
117 public static void AppActivate (System.Int32 ProcessId)
119 throw new NotImplementedException ();
123 public static void AppActivate (System.String Title)
125 throw new NotImplementedException ();
129 public static System.String InputBox (System.String Prompt,
130 [Optional, DefaultParameterValue("")] System.String Title,
131 [Optional, DefaultParameterValue("")] System.String DefaultResponse,
132 [Optional, DefaultParameterValue(-1)] System.Int32 XPos,
133 [Optional, DefaultParameterValue(-1)] System.Int32 YPos)
135 throw new NotImplementedException ();
138 public static System.Object IIf (System.Boolean Expression, System.Object TruePart, System.Object FalsePart)
140 return Expression ? TruePart : FalsePart;
143 public static System.String Partition (System.Int64 number, System.Int64 start, System.Int64 stop, System.Int64 interval)
146 String startStr = "";
147 long startNumber = 0;
152 throw new ArgumentException(
153 Utils.GetResourceString("Argument_InvalidValue1", "Start"));
155 throw new ArgumentException(
156 Utils.GetResourceString("Argument_InvalidValue1", "Stop"));
158 throw new ArgumentException(
159 Utils.GetResourceString("Argument_InvalidValue1", "Interval"));
162 endNumber = start - 1;
165 startNumber = stop + 1;
168 startNumber = number;
173 while (endNumber < number)
174 endNumber += interval;
175 startNumber = endNumber - interval + 1;
177 if (endNumber > stop)
179 if (startNumber < start)
185 startStr = startNumber.ToString();
186 stopStr = endNumber.ToString();
188 if (stopStr.Length > startStr.Length)
189 spacesCount = stopStr.Length;
191 spacesCount = startStr.Length;
193 return startStr.PadLeft(spacesCount) + ":" + stopStr.PadRight(spacesCount);
196 public static System.Object Switch (params System.Object[] VarExpr)
204 counter = VarExpr.Length;
207 if (counter % 2 != 0)
208 throw new ArgumentException(
209 Utils.GetResourceString("Argument_InvalidValue1", "VarExpr"));
212 if((bool)VarExpr[index])
213 return VarExpr[index + 1];
215 counter = counter - 2;
223 public static void DeleteSetting (System.String AppName,
224 [Optional, DefaultParameterValue(null)] System.String Section,
225 [Optional, DefaultParameterValue(null)] System.String Key)
227 throw new NotImplementedException ();
231 public static System.String[,] GetAllSettings (System.String AppName, System.String Section)
233 throw new NotImplementedException ();
237 public static System.String GetSetting (System.String AppName,
238 System.String Section,
240 [Optional, DefaultParameterValue("")] System.String Default)
242 throw new NotImplementedException ();
246 public static void SaveSetting (System.String AppName, System.String Section, System.String Key, System.String Setting)
248 throw new NotImplementedException ();
252 public static System.Object CreateObject (System.String ProgId,
253 [Optional, DefaultParameterValue("")] System.String ServerName)
255 throw new NotImplementedException ();
259 public static System.Object GetObject ([Optional, DefaultParameterValue(null)] System.String PathName,
260 [Optional, DefaultParameterValue(null)] System.String Class)
262 throw new NotImplementedException ();
266 public static Object CallByName (Object objRef, String name, CallType userCallType, params Object[] args)
268 Type[] argsType = null;
269 if (userCallType != CallType.Method &&
270 userCallType != CallType.Get &&
271 userCallType != CallType.Set &&
272 userCallType != CallType.Let)
273 throw new ArgumentException (Utils.GetResourceString("Argument_InvalidValue1", "CallType"));
276 argsType = new Type[args.Length];
278 for(int i = 0; i < args.Length; i++)
279 argsType[i] = args[i].GetType();
282 argsType = new Type[0];*/
284 Type objType = objRef.GetType();
288 MethodInfo methodInfo = null;
290 if(userCallType == CallType.Method) {
291 //Console.WriteLine("Method");
292 methodInfo = objType.GetMethod(name, argsType);
294 else if(userCallType == CallType.Get) {
295 //Console.WriteLine("GetMethod");
296 methodInfo = objType.GetProperty(name).GetGetMethod();
298 else if(userCallType == CallType.Set) {
300 //Console.WriteLine("SetMethod");
301 methodInfo = objType.GetProperty(name).GetSetMethod();
304 return methodInfo.Invoke(objRef, args);
307 catch (Exception exp)
309 throw new ArgumentException();
315 public static System.Object Choose (System.Double Index, params System.Object[] Choice)
319 i = (int) Math.Round(Conversion.Fix(Index) - 1.0);
321 throw new ArgumentException(Utils.GetResourceString("Argument_RankEQOne1", "Choice"));
323 if(i < 0 || i > Choice.GetUpperBound(0))
330 public static System.String Environ (System.Int32 Expression)
334 // Console.WriteLine("Coming Here"+Expression);
336 IDictionary envVars = Environment.GetEnvironmentVariables();
338 foreach(DictionaryEntry de in envVars) {
339 if(++index == Expression) {
340 if( (object) de.Value == null)
343 return String.Concat(de.Key, "=" , de.Value);
346 // Console.WriteLine("Exiting the loop");
352 public static System.String Environ (System.String Expression)
355 if (Expression == null) {
356 e = ExceptionUtils.VbMakeExceptionEx(5, Utils.GetResourceString("Argument_InvalidValue1", Expression));
360 string var = Environment.GetEnvironmentVariable (Expression);
361 return var != null ? var : "";
364 public static void Beep ()
366 Console.WriteLine("\a");
370 public static System.String Command ()
372 string [] args = Environment.GetCommandLineArgs ();
374 if (args != null && args.Length > 1) {
375 return string.Join (" ", args, 1, args.Length - 1);
382 public static MsgBoxResult MsgBox (object Prompt,
383 [Optional, __DefaultParameterValue(0)]MsgBoxStyle Buttons,
384 [Optional, DefaultParameterValue(null)] object Title)
386 throw new NotImplementedException ();
387 /* //MessageButtons msgBoxButtons = 0;
388 MessageBoxIcon msgBoxIcon = 0;
389 MessageBoxDefaultButton msgBoxDefaultButton = 0;
390 MessageBoxOptions msgBoxOptions = 0;
393 int IconsMask = MsgBoxStyle.Critical | MsgBoxStyle.Question | MsgBoxStyle.Exclamation | MsgBoxStyle.Information;
395 int ButtonsMask = MsgBoxStyle.OKOnly |MsgBoxStyle.OKCancel | MsgBoxStyle.AbortRetryIgnore |
396 MsgBoxStyle.YesNoCancel |
397 MsgBoxStyle.YesNo | MsgBoxStyle.RetryCancel;
399 int DefaultButtonMask = MsgBoxStyle.DeafultButton1 | MsgBoxStyle.DefaultButton2 |
400 MsgBoxStyle.DefaultButton3;
402 int OptionsMask = MsgBoxStyle.MsgBoxRight | MsgBoxStyle.MsgBoxRtlReading;
405 switch(Buttons & IconMask) {
406 case MsgBoxStyle.OKOnly:
407 msgBoxButtons = MessageBoxButtons.OK;
410 case MsgBoxStyle.OKCancel:
411 msgBoxButtons = MessageBoxButtons.OK;
414 case MsgBoxStyle.AbortRetryIgnore:
415 msgBoxButtons = MessageBoxButtons.OKCancel;
418 case MsgBoxStyle.YesNoCancel:
419 msgBoxButtons = MessageBoxButtons.YesNoCancel;
422 case MsgBoxStyle.YesNo:
423 msgBoxButtons = MessageBoxButtons.YesNo;
426 case MsgBoxStyle.RetryCancel:
427 msgBoxButtons = MessageBoxButtons.RetryCancel;
437 switch(Buttons & IconMask) {
439 case MsgBoxStyle.Critical:
440 msgBoxIcon = MessageBoxIcon.Error;
443 case MsgBoxStyle.Question:
444 msgBoxIcon = MessageBoxIcon.Question;
447 case MsgBoxStyle.Exclamation:
448 msgBoxIcon = MessageBoxIcon.Exclamation;
451 case MsgBoxStyle.Information:
452 msgBoxIcon = MessageBoxIcon.Information;
460 switch(Buttons & DefaultButtonMask) {
461 case MsgBoxStyle.DefaultButton1:
462 msgBoxDefaultButton = MessageBoxDefaultButton.Button1;
464 case MsgBoxStyle.DefaultButton2:
465 msgBoxDefaultButton = MessageBoxDefaultButton.Button2;
467 case MsgBoxStyle.DefaultButton3:
468 msgBoxDefaultButton = MessageBoxDefaultButton.Button3;
475 switch(Buttons & OptionsMask) {