private static string getFilter(Primitive extension) { string filter = ""; if (((string)extension).Contains("|")) { filter = extension; } else if (SBArray.IsArray(extension)) { Primitive indices = SBArray.GetAllIndices(extension); int count = SBArray.GetItemCount(indices); string types = ""; for (int i = 1; i <= count; i++) { types += "*." + extension[indices[i]]; if (i < count) { types += ";"; } } filter = "File Type (" + types + ") |" + types; } else { filter = "File Type (*." + extension + ") |*." + extension; } return(filter); }
public void SetData(Primitive data) { Primitive indices = SBArray.GetAllIndices(data); Count = SBArray.GetItemCount(indices); string index; double value; Values.Clear(); Labels.Clear(); Total = 0; Min = 0; Max = -double.MaxValue; for (int i = 1; i <= Count; i++) { index = indices[i]; value = data[index]; Labels.Add(index); Total += value; Min = System.Math.Min(Min, value); Max = System.Math.Max(Max, value); Values.Add(value); } Update(); }
/// <summary> /// Set a list of files to the clipboard. /// </summary> /// <param name="fileList">An array (or single file) of file names (full path).</param> /// <returns>"SUCCESS" or "FAILED".</returns> public static Primitive SetFileList(Primitive fileList) { try { CB_files = new StringCollection(); if (SBArray.IsArray(fileList)) { Primitive indices = SBArray.GetAllIndices(fileList); for (int i = 1; i <= SBArray.GetItemCount(indices); i++) { CB_files.Add(fileList[indices[i]]); } } else { CB_files.Add(fileList); } Thread thread = new Thread(CB_SetFileList); thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA thread.Start(); thread.Join(); //Wait for the thread to end return("SUCCESS"); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return("FAILED"); } }
/// <summary> /// Compress files to a zip archive. /// </summary> /// <param name="zipFile">The zip archive file to create.</param> /// <param name="files"> /// An array of files to append to the zip archive. /// A single file or directory may also be set. /// Any directories will be recursively added to the zip. /// Any white space in files or directories will be replaced with "_". /// </param> /// <returns>An error message or "".</returns> public static Primitive Zip(Primitive zipFile, Primitive files) { try { using (Package zip = ZipPackage.Open(zipFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (SBArray.IsArray(files)) { Primitive indices = SBArray.GetAllIndices(files); int count = SBArray.GetItemCount(indices); for (int i = 1; i <= count; i++) { AddToArchive(zip, files[indices[i]], ""); } } else { AddToArchive(zip, files, ""); } zip.Close(); } return(""); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(Utilities.GetCurrentMethod() + " " + ex.Message); } }
private void buttonBlueTooth_Click(object sender, EventArgs e) { Primitive encodings = LDBlueTooth.GetEncodings(); for (int i = 1; i <= SBArray.GetItemCount(encodings); i++) { TextWindow.WriteLine(encodings[i]); } Primitive status = LDBlueTooth.Initialise(); if (status) { Primitive devices = LDBlueTooth.GetDevices(); for (int i = 1; i <= SBArray.GetItemCount(devices); i++) { TextWindow.WriteLine(devices[i]); } } else { TextWindow.WriteLine(LDBlueTooth.LastError); } while (true) { Program.Delay(100); } }
/// <summary> /// Remove a file (or directory with all sub files) from an existing zip archive. /// </summary> /// <param name="zipFile">The zip archive to remove a file from.</param> /// <param name="files"> /// An array of files to remove from the zip archive. /// A single file or directory may also be deleted. /// Any directories will be recursively removed from the zip. /// </param> /// <returns>An error message or "".</returns> public static Primitive Remove(Primitive zipFile, Primitive files) { try { using (ZipFile zip = ZipFile.Read(zipFile)) { if (SBArray.IsArray(files)) { Primitive indices = SBArray.GetAllIndices(files); int count = SBArray.GetItemCount(indices); for (int i = 1; i <= count; i++) { RemoveFromArchive(zip, files[indices[i]]); } } else { RemoveFromArchive(zip, files); } zip.Save(); } return(""); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(Utilities.GetCurrentMethod() + " " + ex.Message); } }
/// <summary> /// Split a variable into an array delimiated by a separator. /// </summary> /// <param name="text">A text string to split.</param> /// <param name="separator">A separator string (e.g. " "), or an array of separator strings.</param> /// <returns>A result array of deliminated texts.</returns> public static Primitive Split(Primitive text, Primitive separator) { try { string[] separators; if (SBArray.IsArray(separator)) { int count = SBArray.GetItemCount(separator); separators = new string[count]; Primitive indices = SBArray.GetAllIndices(separator); for (int i = 0; i < count; i++) { separators[i] = separator[indices[i + 1]]; } } else { separators = new string[] { separator }; } string[] splitText = ((string)text).Split(separators, System.StringSplitOptions.RemoveEmptyEntries); string result = ""; for (int i = 0; i < splitText.Length; i++) { result += (i + 1).ToString() + "=" + Utilities.ArrayParse(splitText[i]) + ";"; } return(Utilities.CreateArrayMap(result)); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
private void buttonCommPort_Click(object sender, EventArgs e) { Primitive ports = LDCommPort.AvailablePorts(); for (int i = 1; i <= SBArray.GetItemCount(ports); i++) { TextWindow.WriteLine(ports[i]); } LDCommPort.OpenPort(ports[1], 100); }
/// <summary> /// Delete temporary sound files. /// </summary> public static void CleanTemp() { for (int i = 1; i <= SBArray.GetItemCount(sounds); i++) { if (System.IO.File.Exists(sounds[i])) { Utilities.ClearMediaPlayer(sounds[i]); System.IO.File.Delete(sounds[i]); } } }
private static string _PlayHarmonics(double frequency, double duration, Primitive harmonics) { try { Initialise(); int sampleCount = (int)(waveFormat.SamplesPerSecond / frequency); // buffer description SoundBufferDescription soundBufferDescription = new SoundBufferDescription(); soundBufferDescription.Format = waveFormat; soundBufferDescription.Flags = BufferFlags.Defer | BufferFlags.ControlVolume | BufferFlags.ControlPan; soundBufferDescription.SizeInBytes = sampleCount * waveFormat.BlockAlignment; SecondarySoundBuffer secondarySoundBuffer = new SecondarySoundBuffer(directSound, soundBufferDescription); secondarySoundBuffer.Pan = pan; secondarySoundBuffer.Volume = volume; short[] rawsamples = new short[sampleCount]; double frac, value; Primitive indices = SBArray.GetAllIndices(harmonics); int count = SBArray.GetItemCount(harmonics); for (int i = 0; i < sampleCount; i++) { frac = i / (double)sampleCount; value = System.Math.Sin(2.0 * System.Math.PI * frac); for (int j = 1; j <= count; j++) { double harmonic = indices[j]; value += harmonics[harmonic] * System.Math.Sin(2.0 * System.Math.PI * harmonic * frac); } rawsamples[i] = (short)(amplitude * value); } secondarySoundBuffer.Write(rawsamples, 0, LockFlags.EntireBuffer); string name = NextName(); Buffer buffer = new Buffer(name, secondarySoundBuffer, frequency, duration); buffers.Add(buffer); Thread thread = new Thread(new ParameterizedThreadStart(DoPlay)); thread.Start(buffer); if (!bAsync) { thread.Join(); } return(name); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
private void buttonDialogs_Click(object sender, EventArgs e) { int i; GraphicsWindow.Show(); Primitive items = ""; Primitive images = ""; for (i = 1; i <= 5; i++) { items[i] = "Item " + i; images[i] = "C:\temp\test.jpg"; } LDDialogs.AddRightClickMenu(items, images); TextWindow.WriteLine(System.Windows.Media.RenderCapability.Tier >> 16); Primitive a1 = LDArray.Create(1000); Shapes.AddEllipse(50, 50); FormPropertyGrid grid = new FormPropertyGrid(); grid.Display("_mainCanvas"); Primitive properties = grid.GetProperties("_mainCanvas"); for (i = 1; i <= SBArray.GetItemCount(properties); i++) { TextWindow.WriteLine(properties[i]); } grid.SetProperty("_mainCanvas.Children.Ellipse1.Opacity", 0.5); Primitive font = LDDialogs.Font(""); Primitive font2 = LDDialogs.Font(font); Primitive fileName = LDDialogs.OpenFile("Small Basic File (*.sb) |*.sb", ""); LDUtilities.Version(); GraphicsWindow.Show(); TextWindow.WriteLine(LDDialogs.Calendar(LDDateTime.Add(LDDateTime.Now(), 7))); //Now + 7 days //LDUtilities.PauseUpdates(); LDDialogs.Wait("Please wait for a few seconds while I draw something...", LDColours.SetOpacity(LDColours.Violet, 200)); double start = Clock.ElapsedMilliseconds; i = 1; while (Clock.ElapsedMilliseconds < start + 5000) { Primitive ball = Shapes.AddEllipse(20, 20); Shapes.Move(ball, SBMath.GetRandomNumber(GraphicsWindow.Width) - 10, SBMath.GetRandomNumber(GraphicsWindow.Height) - 10); LDDialogs.ToolTip(ball, "Ball " + i++); SBProgram.Delay(100); } //LDUtilities.ResumeUpdates(); LDDialogs.EndWait(); }
private void buttonSpeech_Click(object sender, EventArgs e) { TextWindow.WriteLine(LDSpeech.Volume); TextWindow.WriteLine(LDSpeech.Speed); Primitive voices = LDSpeech.Voices(); LDSpeech.Speed = -2; LDSpeech.Volume = 50; for (int i = 1; i <= SBArray.GetItemCount(voices); i++) { LDSpeech.Voice = voices[i]; LDSpeech.Speak("Available voice " + i + " " + LDSpeech.Voice); } }
private static void fromArray(Primitive array) { if (SBArray.GetItemCount(array) != 1) { throw new Exception("Array node should have 1 array element"); } Primitive indices = SBArray.GetAllIndices(array); Primitive content = array[indices[1]]; XmlElement newNode = xmlDoc.doc.CreateElement(indices[1]); if (null == xmlDoc.node) { xmlDoc.node = xmlDoc.doc.AppendChild(newNode); XmlDeclaration xmldecl = xmlDoc.doc.CreateXmlDeclaration("1.0", "UTF-8", null); xmlDoc.doc.InsertBefore(xmldecl, xmlDoc.doc.DocumentElement); } else { xmlDoc.node = xmlDoc.node.AppendChild(newNode); } Primitive attributes = content["Attributes"]; indices = SBArray.GetAllIndices(attributes); for (int i = 1; i <= SBArray.GetItemCount(indices); i++) { string index = indices[i]; XmlAttribute attrib = xmlDoc.doc.CreateAttribute(index); attrib.Value = attributes[index]; xmlDoc.node.Attributes.Append(attrib); } Primitive data = content["Data"]; xmlDoc.node.InnerText = data; Primitive children = content["Children"]; for (int i = 1; i <= SBArray.GetItemCount(children); i++) { fromArray(children[i]); xmlDoc.node = xmlDoc.node.ParentNode; } }
public static ContextMenu getMenu(Dictionary <string, BitmapSource> _savedImages, Primitive items, Primitive images, int iconSize) { BitmapSource img; ContextMenu menu = new ContextMenu(); int itemCount = SBArray.GetItemCount(items); Primitive itemIndices = SBArray.GetAllIndices(items); for (int i = 1; i <= itemCount; i++) { string itemText = items[itemIndices[i]]; string imageName = images[itemIndices[i]]; // Add the item MenuItem menuItem = new MenuItem(); menuItem.Header = itemText; menuItem.Click += new RoutedEventHandler(_MenuClickEvent); menuItem.Tag = (string)(itemIndices[i]); // Creates the item image. if (imageName != "") { if (!_savedImages.TryGetValue(imageName, out img)) { imageName = ImageList.LoadImage(imageName); _savedImages.TryGetValue(imageName, out img); } if (null != img) { System.Windows.Controls.Image image = new System.Windows.Controls.Image(); image.Source = img; if (iconSize > 0) { Bitmap dImg = FastPixel.GetBitmap(img); System.Drawing.Image.GetThumbnailImageAbort dummyCallback = new System.Drawing.Image.GetThumbnailImageAbort(LDWebCam.ResizeAbort); dImg = (Bitmap)dImg.GetThumbnailImage(iconSize, iconSize, dummyCallback, IntPtr.Zero); image.Source = FastPixel.GetBitmapImage(dImg); } menuItem.Icon = image; } } menu.Items.Add(menuItem); } if (menu.Items.Count == 0) { return(null); } return(menu); }
/// <summary> /// Add a new node. /// The current node is unchanged, it is not updated to be the new node. /// </summary> /// <param name="name">The new node element name.</param> /// <param name="attributes">An array of attributes (values indexed by attribute name) for the new node or "".</param> /// <param name="text">Inner text for the new node or "".</param> /// <param name="location">Where the node is inserted. /// "Append" - insert at the end of current node's child nodes. /// "Prepend" - insert at the start of current node's child nodes. /// "Before" - insert before the current node. /// "After" - insert after the current node.</param> /// <returns>"SUCCESS" or "FAILED".</returns> public static Primitive AddNode(Primitive name, Primitive attributes, Primitive text, Primitive location) { try { if (null == xmlDoc) { return("FAILED"); } XmlElement newNode = xmlDoc.doc.CreateElement(name); Primitive indices = SBArray.GetAllIndices(attributes); for (int i = 1; i <= SBArray.GetItemCount(indices); i++) { string index = indices[i]; XmlAttribute attrib = xmlDoc.doc.CreateAttribute(index); attrib.Value = attributes[index]; newNode.Attributes.Append(attrib); } newNode.InnerText = text; switch (((string)location).ToLower()) { case "append": xmlDoc.node.AppendChild(newNode); break; case "prepend": xmlDoc.node.PrependChild(newNode); break; case "after": xmlDoc.node.ParentNode.InsertAfter(newNode, xmlDoc.node); break; case "before": xmlDoc.node.ParentNode.InsertBefore(newNode, xmlDoc.node); break; } return("SUCCESS"); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return("FAILED"); }
/// <summary> /// Interpolate a 1D data array to find the value of x(y). /// /// The values of y should be monotonically increasing with x. /// </summary> /// <param name="array">The array to interpolate (array[x]=y).</param> /// <param name="y">The value of y (may be an array of y values).</param> /// <returns>The interpolated value x or an array of x values.</returns> public static Primitive InterpolateX(Primitive array, Primitive y) { formData(array); if (SBArray.GetItemCount(y) == 0) { return(interpolateX(y)); } else { setPoints(y); string result = ""; for (int i = 0; i < points.Count; i++) { result += (i + 1).ToString() + "=" + interpolateX(points[i]).ToString(CultureInfo.InvariantCulture) + ";"; } return(Utilities.CreateArrayMap(result)); } }
private static Object[] GetArguments(Primitive args, MethodInfo methodInfo) { Object[] arguments = new Object[] { }; if (SBArray.IsArray(args)) { Primitive indices = SBArray.GetAllIndices(args); int count = SBArray.GetItemCount(indices); arguments = new Object[count]; for (int i = 1; i <= count; i++) { arguments[i - 1] = ObjectCast(args[indices[i]], methodInfo.GetParameters()[i - 1].ParameterType); } } else if (args != "") { arguments = new Object[1]; arguments[0] = ObjectCast(args, methodInfo.GetParameters()[0].ParameterType); } return(arguments); }
private void buttonWeather_Click(object sender, EventArgs e) { GraphicsWindow.Show(); LDControls.AddBrowser(200, 200, "http://smallbasic.com"); string result = LDNetwork.HighScore("MyGame", "Steve", 1000); TextWindow.WriteLine(result); Primitive forecast = LDWeather.Forecast("Rhodes"); for (int i = 1; i <= SBArray.GetItemCount(forecast); i++) { TextWindow.WriteLine(forecast[i]); } TextWindow.WriteLine(LDWeather.Location); TextWindow.WriteLine(LDWeather.Conditions); TextWindow.WriteLine(LDWeather.TempC); TextWindow.WriteLine(LDWeather.TempF); TextWindow.WriteLine(LDWeather.WindDirection); TextWindow.WriteLine(LDWeather.WindSpeed); TextWindow.WriteLine(LDWeather.Humidity); }
/// <summary> /// Write to the IO-Warrior device. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <param name="channel">The channel to write to (indexed from 0).</param> /// <param name="data">An array of bytes to send [0 to 255]. /// The array size should be ReportSize for channel 0 and SpecialReportSize for channel 1. /// See GetReportSize and GetSpecialReportSize.</param> /// <returns>The number of bytes successfully written.</returns> public static Primitive Write(Primitive id, Primitive channel, Primitive data) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(0); } int length = SBArray.GetItemCount(data); byte[] buffer = new byte[length]; for (int i = 0; i < length; i++) { buffer[i] = (byte)data[i + 1]; } return((int)device.Write((uint)channel, buffer, (uint)length)); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(0); }
private void buttonCSV_Click(object sender, EventArgs e) { LDFile.CSVplaceholder = " "; Primitive data = LDFile.ReadCSVTransposed("C:\\temp\\testfile2.csv"); TextWindow.WriteLine("Read"); LDFile.WriteCSV("C:\\temp\\testfile2-1.csv", data); TextWindow.WriteLine("Write"); data = LDFile.ReadCSV("C:\\temp\\testfile2-1.csv"); TextWindow.WriteLine("Read"); Primitive dataA = SBArray.GetAllIndices(data); for (int i = 1; i <= SBArray.GetItemCount(dataA); i++) { Primitive dataB = SBArray.GetAllIndices(data[dataA[i]]); for (int j = 1; j <= SBArray.GetItemCount(dataB); j++) { TextWindow.WriteLine(dataA[i] + "," + dataB[j] + " : " + data[dataA[i]][dataB[j]]); } } }
private static string AddFigure(eFigure figure, double width, double height, Primitive[] properties) { Type GraphicsWindowType = typeof(GraphicsWindow); Type ShapesType = typeof(Shapes); Canvas _mainCanvas; Dictionary <string, UIElement> _objectsMap; string shapeName; try { ExtractDll(); MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); method.Invoke(null, new object[] { }); method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); shapeName = method.Invoke(null, new object[] { "Figure" }).ToString(); _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null); _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null); InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate { try { switch (figure) { case eFigure.ARC: { Arc shape = new Arc(); shape.Name = shapeName; shape.Width = width; shape.Height = height; _objectsMap[shapeName] = shape; _mainCanvas.Children.Add(shape); shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor)); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor)); shape.StrokeThickness = GraphicsWindow.PenWidth; shape.StartAngle = properties[0]; shape.EndAngle = properties[1]; shape.ArcThickness = properties[2]; shape.ArcThicknessUnit = Microsoft.Expression.Media.UnitType.Pixel; } break; case eFigure.BLOCKARROW: { BlockArrow shape = new BlockArrow(); shape.Name = shapeName; shape.Width = width; shape.Height = height; _objectsMap[shapeName] = shape; _mainCanvas.Children.Add(shape); shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor)); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor)); shape.StrokeThickness = GraphicsWindow.PenWidth; shape.ArrowBodySize = properties[0]; shape.ArrowheadAngle = properties[1]; switch (((string)properties[2]).ToLower()) { case "up": shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Up; break; case "down": shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Down; break; case "left": shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Left; break; case "right": shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Right; break; } } break; case eFigure.REGULARPOLYGON: { RegularPolygon shape = new RegularPolygon(); shape.Name = shapeName; shape.Width = width; shape.Height = height; _objectsMap[shapeName] = shape; _mainCanvas.Children.Add(shape); shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor)); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor)); shape.StrokeThickness = GraphicsWindow.PenWidth; shape.PointCount = properties[0]; shape.InnerRadius = properties[1]; } break; case eFigure.CALLOUT: { Callout shape = new Callout(); shape.Name = shapeName; shape.Width = width; shape.Height = height; _objectsMap[shapeName] = shape; _mainCanvas.Children.Add(shape); shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor)); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor)); shape.StrokeThickness = GraphicsWindow.PenWidth; shape.FontFamily = new FontFamily(GraphicsWindow.FontName); shape.FontSize = GraphicsWindow.FontSize; shape.FontStyle = GraphicsWindow.FontItalic ? FontStyles.Italic : FontStyles.Normal; shape.FontWeight = GraphicsWindow.FontBold ? FontWeights.Bold : FontWeights.Normal; shape.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor)); shape.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor)); shape.Content = properties[0]; switch (((string)properties[1]).ToLower()) { case "cloud": shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Cloud; break; case "oval": shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Oval; break; case "rectangle": shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Rectangle; break; case "roundedrectangle": shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.RoundedRectangle; break; } Primitive anchor = properties[2]; Point point = new Point(0, 1.25); if (SBArray.GetItemCount(anchor) == 2) { Primitive indices = SBArray.GetAllIndices(anchor); point.X = anchor[indices[1]]; point.Y = anchor[indices[2]]; } shape.AnchorPoint = point; } break; case eFigure.LINEARROW: { LineArrow shape = new LineArrow(); shape.Name = shapeName; shape.Width = width; shape.Height = height; _objectsMap[shapeName] = shape; _mainCanvas.Children.Add(shape); shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor)); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor)); shape.StrokeThickness = GraphicsWindow.PenWidth; shape.ArrowSize = properties[0]; shape.BendAmount = properties[1]; switch (((string)properties[2]).ToLower()) { case "none": shape.StartArrow = Microsoft.Expression.Media.ArrowType.NoArrow; break; case "arrow": shape.StartArrow = Microsoft.Expression.Media.ArrowType.Arrow; break; case "open": shape.StartArrow = Microsoft.Expression.Media.ArrowType.OpenArrow; break; case "oval": shape.StartArrow = Microsoft.Expression.Media.ArrowType.OvalArrow; break; case "stealth": shape.StartArrow = Microsoft.Expression.Media.ArrowType.StealthArrow; break; } switch (((string)properties[3]).ToLower()) { case "none": shape.EndArrow = Microsoft.Expression.Media.ArrowType.NoArrow; break; case "arrow": shape.EndArrow = Microsoft.Expression.Media.ArrowType.Arrow; break; case "open": shape.EndArrow = Microsoft.Expression.Media.ArrowType.OpenArrow; break; case "oval": shape.EndArrow = Microsoft.Expression.Media.ArrowType.OvalArrow; break; case "stealth": shape.EndArrow = Microsoft.Expression.Media.ArrowType.StealthArrow; break; } switch (((string)properties[4]).ToLower()) { case "bottomleft": shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomLeft; break; case "bottomright": shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomRight; break; case "topleft": shape.StartCorner = Microsoft.Expression.Media.CornerType.TopLeft; break; case "topright": shape.StartCorner = Microsoft.Expression.Media.CornerType.TopRight; break; } } break; } return(shapeName); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }); return(FastThread.InvokeWithReturn(ret).ToString()); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
private static string _PlayWave(double frequency, double duration, Primitive waveform) { try { Initialise(); int sampleCount = (int)(waveFormat.SamplesPerSecond / frequency); // buffer description SoundBufferDescription soundBufferDescription = new SoundBufferDescription(); soundBufferDescription.Format = waveFormat; soundBufferDescription.Flags = BufferFlags.Defer | BufferFlags.ControlVolume | BufferFlags.ControlPan; soundBufferDescription.SizeInBytes = sampleCount * waveFormat.BlockAlignment; SecondarySoundBuffer secondarySoundBuffer = new SecondarySoundBuffer(directSound, soundBufferDescription); secondarySoundBuffer.Pan = pan; secondarySoundBuffer.Volume = volume; short[] rawsamples = new short[sampleCount]; double frac, value; Primitive indices = SBArray.GetAllIndices(waveform); int count = SBArray.GetItemCount(waveform); double interval = indices[count] - indices[1]; double[] timeFrac = new double[count]; double[] timeValue = new double[count]; for (int i = 1; i <= count; i++) //Normalise to interval 1; { timeFrac[i - 1] = (indices[i] - indices[1]) / interval; timeValue[i - 1] = waveform[indices[i]]; } for (int i = 0; i < sampleCount; i++) { frac = i / (double)sampleCount; frac = frac - (int)frac; for (int j = 0; j < count - 1; j++) { if (frac >= timeFrac[j] && frac <= timeFrac[j + 1]) { value = timeValue[j] + (timeValue[j + 1] - timeValue[j]) * (frac - timeFrac[j]) / (timeFrac[j + 1] - timeFrac[j]); rawsamples[i] = (short)(amplitude * value); break; } } } secondarySoundBuffer.Write(rawsamples, 0, LockFlags.EntireBuffer); string name = NextName(); Buffer buffer = new Buffer(name, secondarySoundBuffer, frequency, duration); buffers.Add(buffer); Thread thread = new Thread(new ParameterizedThreadStart(DoPlay)); thread.Start(buffer); if (!bAsync) { thread.Join(); } return(name); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
private static string _PlayDX7(Primitive channels) { try { Initialise(); int i, iServo; double duration = 0.0225; int sampleCount = (int)(duration * waveFormat.SamplesPerSecond); // buffer description SoundBufferDescription soundBufferDescription = new SoundBufferDescription(); soundBufferDescription.Format = waveFormat; soundBufferDescription.Flags = BufferFlags.Defer | BufferFlags.ControlVolume | BufferFlags.ControlPan; soundBufferDescription.SizeInBytes = sampleCount * waveFormat.BlockAlignment; SecondarySoundBuffer secondarySoundBuffer = new SecondarySoundBuffer(directSound, soundBufferDescription); secondarySoundBuffer.Pan = pan; secondarySoundBuffer.Volume = volume; short[] rawsamples = new short[sampleCount]; int stopSamples = (int)(0.0004 * waveFormat.SamplesPerSecond); List <int> servoSamples = new List <int>(); Primitive indices = SBArray.GetAllIndices(channels); int servoCount = SBArray.GetItemCount(indices); for (iServo = 1; iServo <= servoCount; iServo++) { servoSamples.Add((int)((0.0007 + 0.0008 * channels[indices[iServo]]) * waveFormat.SamplesPerSecond)); } //Lead-in int leading = sampleCount - (servoCount + 1) * stopSamples - servoSamples.Sum(); int sample = 0; for (i = 0; i < leading; i++) { rawsamples[sample++] = 0; } //Servos for (i = 0; i < stopSamples; i++) { rawsamples[sample++] = (short)(-amplitude); } for (iServo = 0; iServo < servoCount; iServo++) { for (i = 0; i < servoSamples[iServo]; i++) { rawsamples[sample++] = amplitude; } for (i = 0; i < stopSamples; i++) { rawsamples[sample++] = (short)(-amplitude); } } secondarySoundBuffer.Write(rawsamples, 0, LockFlags.EntireBuffer); string name = NextName(); Buffer buffer = new Buffer(name, secondarySoundBuffer, 0, -1); buffers.Add(buffer); Thread thread = new Thread(new ParameterizedThreadStart(DoPlay)); thread.Start(buffer); if (!bAsync) { thread.Join(); } return(name); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(""); } }
/// <summary> /// Call any extension method asynchronously. /// See example LDCallAsync. /// If dll, extension, obj and arguments are all "", then method may be a subroutine in your SmallBasic program. /// </summary> /// <param name="dll">The extension dll (e.g. "LitDev.dll" or "SmallBasicLibrary.dll").</param> /// <param name="extension">The extension namespace (usually the same as the dll name, e.g. "LitDev" or "MicroSoft.SmallBasic.Library" for SmallBasicLibrary.dll).</param> /// <param name="obj">The extension object name.</param> /// <param name="method">The extension method name.</param> /// <param name="arguments">An array of arguments or "" for none. A single argument doesn't have to be in an array.</param> /// <returns>"PENDING" or an error message on failure.</returns> public static Primitive CallAsync(Primitive dll, Primitive extension, Primitive obj, Primitive method, Primitive arguments) { try { Type type; string callName = ""; if (dll == "" && extension == "" && obj == "" && arguments == "") { type = mainModule; } else { string path = Path.GetDirectoryName(entryAssembly.Location) + "\\" + dll; if (!System.IO.File.Exists(path)) { return(dll + " dll not found"); } Assembly assembly = Assembly.LoadFrom(path); type = assembly.GetType(extension + "." + obj, false, true); if (null == type) { return(extension + "." + obj + " extension not found"); } callName += extension + "." + obj + "."; } MethodInfo methodInfo = type.GetMethod((string)method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); if (null == methodInfo) { return(method + " method not found"); } int numArgs = 0; Object[] args = null; callName += method + "("; if (SBArray.IsArray(arguments)) { numArgs = SBArray.GetItemCount(arguments); args = new Object[numArgs]; Primitive indices = SBArray.GetAllIndices(arguments); for (int i = 1; i <= numArgs; i++) { args[i - 1] = arguments[indices[i]]; callName += arguments[indices[i]]; if (i < numArgs) { callName += ","; } } } else if (arguments != "") { args = new Object[1] { arguments }; callName += arguments; } callName += ")"; Thread thread = new Thread(new ParameterizedThreadStart(DoCall)); thread.Start(new Object[] { methodInfo, args, callName }); //while (!thread.IsAlive) Thread.Sleep(1); //delay to let async call get started return("PENDING"); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return(ex.Message); } }
private static bool isCondition() { string varName = FormDebug.conditionName.ToLower(); Primitive varValue = FormDebug.conditionValue; varValue = Text.ConvertToLowerCase(varValue); if (varName == "" || varValue == "") { return(false); } try { if (applicationThread.ThreadState != System.Threading.ThreadState.Running) { applicationThread.Suspend(); } StackTrace stackTrace = new StackTrace(applicationThread, false); StackFrame frame = stackTrace.GetFrame(stackTrace.FrameCount - 1); MethodBase method = frame.GetMethod(); Type type = method.DeclaringType; FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic); for (int i = 0; i < fields.Length; i++) { Primitive var = (Primitive)(fields[i].GetValue(null)); var = Text.ConvertToLowerCase(var); int pos = varName.IndexOf("["); string variable = pos < 0 ? varName : varName.Substring(0, pos); if (fields[i].Name.ToLower() == variable) { string arrayName = fields[i].Name.ToLower(); if (SBArray.IsArray(var)) { Primitive Indices1 = SBArray.GetAllIndices(var); for (int j = 1; j <= SBArray.GetItemCount(Indices1); j++) { Primitive var1 = var[Indices1[j]]; arrayName = ((string)(fields[i].Name + "[" + Indices1[j] + "]")).ToLower(); if (SBArray.IsArray(var1)) { Primitive Indices2 = SBArray.GetAllIndices(var1); for (int k = 1; k <= SBArray.GetItemCount(Indices2); k++) { Primitive var2 = var1[Indices2[k]]; arrayName = ((string)(fields[i].Name + "[" + Indices1[j] + "]" + "[" + Indices2[k] + "]")).ToLower(); if (SBArray.IsArray(var2)) { Primitive Indices3 = SBArray.GetAllIndices(var2); for (int l = 1; l <= SBArray.GetItemCount(Indices3); l++) { Primitive var3 = var2[Indices3[l]]; arrayName = ((string)(fields[i].Name + "[" + Indices1[j] + "]" + "[" + Indices2[k] + "]" + "[" + Indices3[l] + "]")).ToLower(); if (arrayName.StartsWith(varName) && checkCondition(var3, varValue)) { return(true); } } } else { if (arrayName.StartsWith(varName) && checkCondition(var2, varValue)) { return(true); } } } } else { if (arrayName.StartsWith(varName) && checkCondition(var1, varValue)) { return(true); } } } } else { if (checkCondition(var, varValue)) { return(true); } } } } return(false); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); if (Utilities.bShowErrors) { TextWindow.WriteLine("ThreadState " + applicationThread.ThreadState.ToString()); } return(false); } }
public void SetEffect_Delegate() { try { int i = 0; eEffect effect = (eEffect)data[i++]; Primitive properties = (Primitive)data[i++]; UIElement obj = (UIElement)data[i++]; switch (effect) { case eEffect.NONE: obj.Effect = null; break; case eEffect.DROPSHADOW: obj.Effect = new DropShadowEffect(); if (SBArray.ContainsIndex(properties, "BlurRadius")) { obj.Effect.SetValue(DropShadowEffect.BlurRadiusProperty, (double)properties["BlurRadius"]); } if (SBArray.ContainsIndex(properties, "Color")) { obj.Effect.SetValue(DropShadowEffect.ColorProperty, (Color)ColorConverter.ConvertFromString(properties["Color"])); } if (SBArray.ContainsIndex(properties, "Direction")) { obj.Effect.SetValue(DropShadowEffect.DirectionProperty, (double)properties["Direction"]); } if (SBArray.ContainsIndex(properties, "Opacity")) { obj.Effect.SetValue(DropShadowEffect.OpacityProperty, (double)properties["Opacity"]); } if (SBArray.ContainsIndex(properties, "ShadowDepth")) { obj.Effect.SetValue(DropShadowEffect.ShadowDepthProperty, (double)properties["ShadowDepth"]); } break; case eEffect.BLUR: obj.Effect = new BlurEffect(); if (SBArray.ContainsIndex(properties, "KernelType")) { string value = properties["KernelType"]; obj.Effect.SetValue(BlurEffect.KernelTypeProperty, value.ToLower() == "box" ? KernelType.Box : KernelType.Gaussian); } if (SBArray.ContainsIndex(properties, "Radius")) { obj.Effect.SetValue(BlurEffect.RadiusProperty, (double)properties["Radius"]); } break; case eEffect.BLOOM: obj.Effect = new BloomEffect(); if (SBArray.ContainsIndex(properties, "BaseIntensity")) { obj.Effect.SetValue(BloomEffect.BaseIntensityProperty, (double)properties["BaseIntensity"]); } if (SBArray.ContainsIndex(properties, "BaseSaturation")) { obj.Effect.SetValue(BloomEffect.BaseSaturationProperty, (double)properties["BaseSaturation"]); } if (SBArray.ContainsIndex(properties, "BloomIntensity")) { obj.Effect.SetValue(BloomEffect.BloomIntensityProperty, (double)properties["BloomIntensity"]); } if (SBArray.ContainsIndex(properties, "BloomSaturation")) { obj.Effect.SetValue(BloomEffect.BloomSaturationProperty, (double)properties["BloomSaturation"]); } if (SBArray.ContainsIndex(properties, "Threshold")) { obj.Effect.SetValue(BloomEffect.ThresholdProperty, (double)properties["Threshold"]); } break; case eEffect.COLORTONE: obj.Effect = new ColorToneEffect(); if (SBArray.ContainsIndex(properties, "DarkColor")) { obj.Effect.SetValue(ColorToneEffect.DarkColorProperty, (Color)ColorConverter.ConvertFromString(properties["DarkColor"])); } if (SBArray.ContainsIndex(properties, "Desaturation")) { obj.Effect.SetValue(ColorToneEffect.DesaturationProperty, (double)properties["Desaturation"]); } if (SBArray.ContainsIndex(properties, "LightColor")) { obj.Effect.SetValue(ColorToneEffect.LightColorProperty, (Color)ColorConverter.ConvertFromString(properties["LightColor"])); } if (SBArray.ContainsIndex(properties, "ToneAmount")) { obj.Effect.SetValue(ColorToneEffect.ToneAmountProperty, (double)properties["ToneAmount"]); } break; case eEffect.EMBOSSED: obj.Effect = new EmbossedEffect(); if (SBArray.ContainsIndex(properties, "Amount")) { obj.Effect.SetValue(EmbossedEffect.AmountProperty, (double)properties["Amount"]); } if (SBArray.ContainsIndex(properties, "Color")) { obj.Effect.SetValue(EmbossedEffect.ColorProperty, (Color)ColorConverter.ConvertFromString(properties["Color"])); } if (SBArray.ContainsIndex(properties, "Height")) { obj.Effect.SetValue(EmbossedEffect.HeightProperty, (double)properties["Height"]); } break; case eEffect.MAGNIFY: obj.Effect = new MagnifyEffect(); if (SBArray.ContainsIndex(properties, "Amount")) { obj.Effect.SetValue(MagnifyEffect.AmountProperty, (double)properties["Amount"]); } if (SBArray.ContainsIndex(properties, "Center")) { Primitive center = properties["Center"]; Point point = new Point(0.5, 0.5); if (SBArray.GetItemCount(center) == 2) { Primitive indices = SBArray.GetAllIndices(center); point.X = center[indices[1]]; point.Y = center[indices[2]]; } obj.Effect.SetValue(MagnifyEffect.CenterProperty, point); } if (SBArray.ContainsIndex(properties, "InnerRadius")) { obj.Effect.SetValue(MagnifyEffect.InnerRadiusProperty, (double)properties["InnerRadius"]); } if (SBArray.ContainsIndex(properties, "OuterRadius")) { obj.Effect.SetValue(MagnifyEffect.OuterRadiusProperty, (double)properties["OuterRadius"]); } break; case eEffect.MONOCHROME: obj.Effect = new MonochromeEffect(); if (SBArray.ContainsIndex(properties, "Color")) { obj.Effect.SetValue(MonochromeEffect.ColorProperty, (Color)ColorConverter.ConvertFromString(properties["Color"])); } break; case eEffect.PIXELATE: obj.Effect = new PixelateEffect(); if (SBArray.ContainsIndex(properties, "Pixelation")) { obj.Effect.SetValue(PixelateEffect.PixelationProperty, (double)properties["Pixelation"]); } break; case eEffect.RIPPLE: obj.Effect = new RippleEffect(); if (SBArray.ContainsIndex(properties, "Center")) { Primitive center = properties["Center"]; Point point = new Point(0.5, 0.5); if (SBArray.GetItemCount(center) == 2) { Primitive indices = SBArray.GetAllIndices(center); point.X = center[indices[1]]; point.Y = center[indices[2]]; } obj.Effect.SetValue(RippleEffect.CenterProperty, point); } if (SBArray.ContainsIndex(properties, "Frequency")) { obj.Effect.SetValue(RippleEffect.FrequencyProperty, (double)properties["Frequency"]); } if (SBArray.ContainsIndex(properties, "Magnitude")) { obj.Effect.SetValue(RippleEffect.MagnitudeProperty, (double)properties["Magnitude"]); } if (SBArray.ContainsIndex(properties, "Phase")) { obj.Effect.SetValue(RippleEffect.PhaseProperty, (double)properties["Phase"]); } break; case eEffect.SHARPEN: obj.Effect = new SharpenEffect(); if (SBArray.ContainsIndex(properties, "Amount")) { obj.Effect.SetValue(SharpenEffect.AmountProperty, (double)properties["Amount"]); } if (SBArray.ContainsIndex(properties, "Height")) { obj.Effect.SetValue(SharpenEffect.HeightProperty, (double)properties["Height"]); } break; case eEffect.SWIRL: obj.Effect = new SwirlEffect(); if (SBArray.ContainsIndex(properties, "AngleFrequency")) { obj.Effect.SetValue(SwirlEffect.AngleFrequencyProperty, (double)properties["AngleFrequency"]); } if (SBArray.ContainsIndex(properties, "Center")) { Primitive center = properties["Center"]; Point point = new Point(0.5, 0.5); if (SBArray.GetItemCount(center) == 2) { Primitive indices = SBArray.GetAllIndices(center); point.X = center[indices[1]]; point.Y = center[indices[2]]; } obj.Effect.SetValue(SwirlEffect.CenterProperty, point); } if (SBArray.ContainsIndex(properties, "TwistAmount")) { obj.Effect.SetValue(SwirlEffect.TwistAmountProperty, (double)properties["TwistAmount"]); } break; } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
private void buttonSortStatistics_Click(object sender, EventArgs e) { Primitive array = ""; for (int i = 1; i <= 100; i++) { array[i] = SBMath.GetRandomNumber(100); } LDSort.CaseSensitive = "False"; array[1] = "FB"; array[2] = "fb"; array[4] = "c"; array[3] = "C"; Primitive result = LDSort.ByValue(array); for (int i = 1; i <= SBArray.GetItemCount(result); i++) { TextWindow.WriteLine(i + " : " + result[i]); } TextWindow.WriteLine(""); result = LDStatistics.SetArray(array); for (int i = 1; i <= SBArray.GetItemCount(result); i++) { TextWindow.WriteLine(i + " : " + result[i]); } TextWindow.WriteLine(""); TextWindow.WriteLine(LDStatistics.Count); TextWindow.WriteLine(LDStatistics.Mean); TextWindow.WriteLine(LDStatistics.Median); TextWindow.WriteLine(LDStatistics.Mode); TextWindow.WriteLine(LDStatistics.SDev); TextWindow.WriteLine(LDStatistics.PDev); TextWindow.WriteLine(LDStatistics.HarmonicMean); TextWindow.WriteLine(LDStatistics.GeometricMean); TextWindow.WriteLine(LDStatistics.Min); TextWindow.WriteLine(LDStatistics.Max); Primitive graph = LDGraph.AddGraph(0, 0, GraphicsWindow.Width, GraphicsWindow.Height, "Probability Distribution", "Value", "Probability"); //Primitive data = LDStatistics.DistNormal(4, 0.5, 101); //Primitive data = LDStatistics.DistUniform(3, 6, 101); //Primitive data = LDStatistics.DistTriangular(3, 6, 101); Primitive data = LDStatistics.DistBinomial(20, 0.5); LDGraph.AddSeriesLine(graph, "PDF", data, "Red"); LDGraph.AddSeriesLine(graph, "CDF", LDStatistics.Integrate(data), "Blue"); LDGraph.AddSeriesLine(graph, "Derivative", LDStatistics.Differentiate(data), "Green"); LDUtilities.Icon = "C:\\Users\\Public\\Pictures\\fractal-1.jpg"; array = ""; for (int i = 1; i <= 1000; i++) { array[i] = SBMath.GetRandomNumber(999) / 1000.0; } Primitive dist = LDStatistics.InterpolateX(LDStatistics.Integrate(data), array); Primitive freq = LDStatistics.Frequency(dist, 50, "True"); LDGraph.AddSeriesHistogram(graph, "Generated", freq, "Black"); LDStatistics.SetArray(dist); TextWindow.WriteLine(LDStatistics.Mean); TextWindow.WriteLine(LDStatistics.SDev); Primitive A = LDArray.Create(3); Primitive index = LDArray.Create(3); LDArray.SetValue(A, 1, 5); LDArray.SetValue(A, 2, 3); LDArray.SetValue(A, 3, 1); LDArray.SortIndex(A, index); }
private void AddVariables(StackTrace stackTrace) { StackFrame frame = stackTrace.GetFrame(stackTrace.FrameCount - 1); MethodBase method = frame.GetMethod(); Type type = method.DeclaringType; FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic); List <varSort> fieldsSort = new List <varSort>(); for (int i = 0; i < fields.Length; i++) { fieldsSort.Add(new varSort(i, fields[i].Name)); } fieldsSort.Sort(); // 3D array is enough (could make it infinite but messy the way the tree is defined) foreach (varSort variable in fieldsSort) { int i = variable.I; Primitive var = (Primitive)fields[i].GetValue(null); if (SBArray.IsArray(var)) { treeView1.Nodes[1].Nodes.Add(variable.Name).Tag = new vars(i, new string[] { }); Primitive Indices = SBArray.GetAllIndices(var); for (int j = 1; j <= SBArray.GetItemCount(Indices); j++) { Primitive var1 = var[Indices[j]]; if (SBArray.IsArray(var1)) { treeView1.Nodes[1].Nodes[treeView1.Nodes[1].Nodes.Count - 1].Nodes.Add(Indices[j]).Tag = new vars(i, new string[] { Indices[j] }); Primitive Indices1 = SBArray.GetAllIndices(var1); for (int k = 1; k <= SBArray.GetItemCount(Indices1); k++) { Primitive var2 = var1[Indices1[k]]; if (SBArray.IsArray(var2)) { treeView1.Nodes[1].Nodes[treeView1.Nodes[1].Nodes.Count - 1].Nodes[j - 1].Nodes.Add(Indices1[k]).Tag = new vars(i, new string[] { Indices[j], Indices1[k] }); Primitive Indices2 = SBArray.GetAllIndices(var2); for (int l = 1; l <= SBArray.GetItemCount(Indices2); l++) { Primitive var3 = var2[Indices2[l]]; treeView1.Nodes[1].Nodes[treeView1.Nodes[1].Nodes.Count - 1].Nodes[j - 1].Nodes[k - 1].Nodes.Add(Indices2[l] + " : " + var3).Tag = new vars(i, new string[] { Indices[j], Indices1[k], Indices2[l] }); } } else { treeView1.Nodes[1].Nodes[treeView1.Nodes[1].Nodes.Count - 1].Nodes[j - 1].Nodes.Add(Indices1[k] + " : " + var2).Tag = new vars(i, new string[] { Indices[j], Indices1[k] }); } } } else { treeView1.Nodes[1].Nodes[treeView1.Nodes[1].Nodes.Count - 1].Nodes.Add(Indices[j] + " : " + var1).Tag = new vars(i, new string[] { Indices[j] }); } } } else { treeView1.Nodes[0].Nodes.Add(variable.Name + " : " + var).Tag = new vars(i, new string[] { }); } } }
private static CompilerParameters SetReferences(Primitive assemblies, string dllName, bool bJS = false) { CompilerParameters compilerParams = new CompilerParameters(); compilerParams.TreatWarningsAsErrors = false; compilerParams.GenerateExecutable = false; if (!bJS) { compilerParams.CompilerOptions = "/optimize"; } if (dllName.Length == 0) { compilerParams.GenerateInMemory = true; } else { compilerParams.GenerateInMemory = false; if (!dllName.EndsWith(".dll")) { dllName += ".dll"; } compilerParams.OutputAssembly = dllName; if (!bJS) { compilerParams.CompilerOptions += " /doc:" + '"' + Path.ChangeExtension(dllName, ".xml") + '"'; } } loadedAssemblies.Clear(); AddReferences(Assembly.GetExecutingAssembly(), compilerParams); if (!bJS) { foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { AddReferences(assembly, compilerParams); } } if (SBArray.IsArray(assemblies)) { Primitive indices = SBArray.GetAllIndices(assemblies); for (int i = 1; i <= SBArray.GetItemCount(indices); i++) { try { AddReference(Assembly.ReflectionOnlyLoadFrom(assemblies[indices[i]]), compilerParams); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } } } else if (assemblies != "") { try { AddReference(Assembly.ReflectionOnlyLoadFrom(assemblies), compilerParams); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } } if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\Resources")) { string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\Resources"); foreach (string file in files) { compilerParams.EmbeddedResources.Add(file); } } return(compilerParams); }