public static EBPrimitive CopyFile(EBPrimitive sourceFilePath, EBPrimitive destinationFilePath) { File.LastError = ""; string text = Environment.ExpandEnvironmentVariables(sourceFilePath); string text2 = Environment.ExpandEnvironmentVariables(destinationFilePath); if (!System.IO.File.Exists(text)) { File.LastError = "Source file doesn't exist."; return "FAILED"; } if (Directory.Exists(text2) || text2[text2.Length - 1] == '\\') { text2 = Path.Combine(text2, Path.GetFileName(text)); } try { string directoryName = Path.GetDirectoryName(text2); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } System.IO.File.Copy(text, text2, true); return "SUCCESS"; } catch (Exception ex) { File.LastError = ex.Message; } return "FAILED"; }
public static EBPrimitive InvokeStaticMethod(EBPrimitive typeName, EBPrimitive methodName, EBPrimitive argumentsStackName) { EBPrimitive result; try { Type type = Type.GetType(typeName); MethodInfo method = type.GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public); int num = Stack.GetCount(argumentsStackName); ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length == num) { List<object> list = new List<object>(); for (int i = num - 1; i >= 0; i--) { list[i] = Stack.PopValue(argumentsStackName); } result = new EBPrimitive(method.Invoke(null, list.ToArray())); } else { result = "ERROR"; } } catch { result = "ERROR"; } return result; }
public static EBPrimitive InvokeInstanceMethod(EBPrimitive instanceId, EBPrimitive methodName, EBPrimitive argumentsStackName) { EBPrimitive result; try { object obj = Platform._objectMap[instanceId]; MethodInfo method = obj.GetType().GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public); int num = Stack.GetCount(argumentsStackName); ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length == num) { List<object> list = new List<object>(); for (int i = num - 1; i >= 0; i--) { list[i] = Stack.PopValue(argumentsStackName); } result = new EBPrimitive(method.Invoke(obj, list.ToArray())); } else { result = "ERROR"; } } catch { result = "ERROR"; } return result; }
public static EBPrimitive GetWebPageContents(EBPrimitive url) { if (url.IsEmpty) { return url; } return Network.GetWebPageContents(url); }
public static EBPrimitive GetCharacterCode(EBPrimitive character) { if (character.IsEmpty) { return 0; } return (int)character[0]; }
public static void RemoveValue(EBPrimitive arrayName, EBPrimitive index) { Dictionary<EBPrimitive, EBPrimitive> array = Array.GetArray(arrayName); if (array != null) { array.Remove(index); } }
public static EBPrimitive GetWidthOfImage(EBPrimitive imageName) { BitmapSource image = ImageList.GetBitmap(imageName); if (image == null) { return 0; } return (EBPrimitive)GraphicsWindow.InvokeWithReturn(() => image.PixelWidth); }
public static EBPrimitive ConvertToLowerCase(EBPrimitive _text) { string text = _text; if (text=="") { return text; } return text.ToLower(CultureInfo.CurrentUICulture); }
public static EBPrimitive ConvertToUpperCase(EBPrimitive _text) { string text = _text.ToString(); if (text=="") { return text; } return text.ToUpper(CultureInfo.InvariantCulture); }
public static void SetWallPaper(EBPrimitive fileOrUrl) { if (fileOrUrl.IsEmpty) { return; } string lpvParam = Desktop.ConvertToBitmap(fileOrUrl); NativeHelper.SystemParametersInfo(20, 0, lpvParam, 3); }
internal static Dictionary<EBPrimitive, EBPrimitive> GetArray(EBPrimitive arrayName) { Dictionary<EBPrimitive, EBPrimitive> result; if (Array._arrayMap.TryGetValue(arrayName, out result)) { return result; } return null; }
public static EBPrimitive GetArgument(EBPrimitive index) { int num = index; if (num >= 1 && num < Program.args.Length) { return new EBPrimitive(Program.args[num]); } return new EBPrimitive(""); }
public static EBPrimitive GetLength(EBPrimitive ptext) { string text = ptext.ToString(); if (text == "") { return 0; } return text.Length; }
public static EBPrimitive LoadImage(EBPrimitive fileNameOrUrl) { if (fileNameOrUrl.IsEmpty) { return ""; } string text = Shapes.GenerateNewName("ImageList"); ImageList._savedImages[text] = ImageList.LoadImageFromFile(fileNameOrUrl); return text; }
public static EBPrimitive EndsWith(EBPrimitive _text, EBPrimitive _subText) { string text = _text.ToString(); string subText = _subText.ToString(); if (text == "" || subText == "") { return false; } return text.EndsWith(subText, StringComparison.CurrentCulture); }
internal static BitmapSource GetBitmap(EBPrimitive imageName) { BitmapSource bitmapSource = null; if (!imageName.IsEmpty) { ImageList._savedImages.TryGetValue(imageName, out bitmapSource); } if (bitmapSource == null) { bitmapSource = ImageList.LoadImageFromFile(imageName); } return bitmapSource; }
public static EBPrimitive GetIndexOf(EBPrimitive _text, EBPrimitive _subText) { string text = _text; string subText = _subText; if (text=="") { return 0; } if (subText=="") { return 0; } return text.IndexOf(subText) + 1; }
public static void SetValue(EBPrimitive arrayName, EBPrimitive index, EBPrimitive value) { if (arrayName.IsEmpty) { return; } Dictionary<EBPrimitive, EBPrimitive> dictionary; if (!Array._arrayMap.TryGetValue(arrayName, out dictionary)) { dictionary = new Dictionary<EBPrimitive, EBPrimitive>(); Array._arrayMap[arrayName] = dictionary; } dictionary[index] = value; }
public static EBPrimitive GetValue(EBPrimitive arrayName, EBPrimitive index) { Dictionary<EBPrimitive, EBPrimitive> array = Array.GetArray(arrayName); if (array == null) { return ""; } EBPrimitive result; if (array.TryGetValue(index, out result)) { return result; } return ""; }
public static EBPrimitive GetRandomPicture(EBPrimitive tag) { Random random = new Random((int)DateTime.Now.Ticks); if (tag == Flickr._cachedTag && Flickr._cachedTagDocument != null && Flickr._cachedTagDocumentHitCount < 10) { Flickr._cachedTagDocumentHitCount++; return Flickr.GetRandomPhotoNodeUrl(Flickr._cachedTagDocument); } string url = string.Format("{0}&method=flickr.photos.search&per_page=50&tags={1}&page={2}", Flickr._urlTemplate, tag, random.Next(10) + 1); Thread.Sleep(1000); Flickr._cachedTag = tag; Flickr._cachedTagDocument = RestHelper.GetContents(url); Flickr._cachedTagDocumentHitCount = 0; return Flickr.GetRandomPhotoNodeUrl(Flickr._cachedTagDocument); }
public static EBPrimitive CreateDirectory(EBPrimitive directoryPath) { File.LastError = ""; Environment.ExpandEnvironmentVariables(directoryPath); try { Directory.CreateDirectory(directoryPath); return "SUCCESS"; } catch (Exception ex) { File.LastError = ex.Message; } return "FAILED"; }
public static EBPrimitive AddLine(EBPrimitive x1, EBPrimitive y1, EBPrimitive x2, EBPrimitive y2) { string name = Shapes.GenerateNewName("Line"); GraphicsWindow.Invoke(delegate { Line line = new Line(); GraphicsWindow.AddShape(name, line); line.X1 = x1; line.Y1 = y1; line.X2 = x2; line.Y2 = y2; line.Stroke = GraphicsWindow._pen.Brush; line.StrokeThickness = GraphicsWindow._pen.Thickness; }); return name; }
public static EBPrimitive CreateInstance(EBPrimitive typeName) { EBPrimitive result; try { Type type = Type.GetType(typeName); object value = Activator.CreateInstance(type); string text = Platform.GenerateNewName("Instance"); Platform._objectMap[text] = value; result = text; } catch { result = "ERROR"; } return result; }
internal static EBPrimitive GetLocalFile(EBPrimitive fileNameOrUrl) { if (fileNameOrUrl.IsEmpty) { return fileNameOrUrl; } Uri uri; if (!Uri.TryCreate(fileNameOrUrl, UriKind.RelativeOrAbsolute, out uri) || !uri.IsAbsoluteUri) { return fileNameOrUrl; } if (uri.Scheme.ToLower(CultureInfo.InvariantCulture) == "file") { return fileNameOrUrl; } return Network.DownloadFile(fileNameOrUrl); }
public static EBPrimitive DownloadFile(EBPrimitive url) { if (url.IsEmpty) { return url; } string tempFileName = Path.GetTempFileName(); Stream stream = null; Stream stream2 = null; WebResponse webResponse = null; try { WebRequest webRequest = WebRequest.Create(url); webResponse = webRequest.GetResponse(); stream = System.IO.File.Open(tempFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); byte[] buffer = new byte[16384]; long num = webResponse.ContentLength; stream2 = webResponse.GetResponseStream(); while (num > 0L) { int num2 = stream2.Read(buffer, 0, 16384); stream.Write(buffer, 0, num2); num -= (long)num2; } } catch (Exception) { return ""; } finally { if (stream != null) { stream.Close(); } if (stream2 != null) { stream2.Close(); } if (webResponse != null) { webResponse.Close(); } } return tempFileName; }
public static EBPrimitive AddButton(EBPrimitive caption, EBPrimitive left, EBPrimitive top) { string name = Shapes.GenerateNewName("Button"); GraphicsWindow.Invoke(delegate { Button button = new Button { Content = caption, Padding = new Thickness(4.0) }; Canvas.SetLeft(button, left); Canvas.SetTop(button, top); button.Click += new RoutedEventHandler(Controls.OnButtonClicked); GraphicsWindow.AddControl(name, button); }); return name; }
public static EBPrimitive AppendContents(EBPrimitive filePath, EBPrimitive contents) { File.LastError = ""; Environment.ExpandEnvironmentVariables(filePath); try { using (StreamWriter streamWriter = new StreamWriter(filePath, true)) { streamWriter.WriteLine((string)contents); } return "SUCCESS"; } catch (Exception ex) { File.LastError = ex.Message; } return "FAILED"; }
public static EBPrimitive AddRectangle(EBPrimitive width, EBPrimitive height) { string name = Shapes.GenerateNewName("Rectangle"); GraphicsWindow.Invoke(delegate { GraphicsWindow.VerifyAccess(); Rectangle shape = new Rectangle { Width = width, Height = height, Fill = GraphicsWindow._fillBrush, Stroke = GraphicsWindow._pen.Brush, StrokeThickness = GraphicsWindow._pen.Thickness }; GraphicsWindow.AddShape(name, shape); }); return name; }
internal static BitmapImage LoadImageFromFile(EBPrimitive fileNameOrUrl) { EBPrimitive localFileName = Network.GetLocalFile(fileNameOrUrl); return (BitmapImage)SmallBasicApplication.InvokeWithReturn(delegate { object result; try { BitmapImage bitmapImage = new BitmapImage(new Uri(localFileName)); result = bitmapImage; } catch (Exception) { result = null; } return result; }); }
public static EBPrimitive AddImage(EBPrimitive imageName) { string name = Shapes.GenerateNewName("Image"); GraphicsWindow.Invoke(delegate { Image image = new Image(); BitmapSource bitmap = ImageList.GetBitmap(imageName); if (bitmap != null) { image.Source = bitmap; if (bitmap.PixelWidth != 0 && bitmap.PixelHeight != 0) { image.Width = (double)bitmap.PixelWidth; image.Height = (double)bitmap.PixelHeight; } GraphicsWindow.AddShape(name, image); } }); return name; }