Beispiel #1
0
        static void CSVHeaders(int Standard_Size, string TableName, ref StreamWriter SW)
        {
            int StackPointer = Stack.Add("Import.CSVHeaders");

            HeaderSQL    = $"CREATE TABLE IF NOT EXISTS \"{TableName}\" (";
            HeaderWOType = "(";
            for (int i = 1; i <= Standard_Size; i++)
            {
                HeaderSQL    += "\"" + LDFastArray.Get2D(Data, 1, i) + "\" ";
                HeaderWOType += "\"" + LDFastArray.Get2D(Data, 1, i) + "\"";

                switch (CSV_IsString[(i - 1)])
                {
                case true:
                    HeaderSQL += "TEXT";
                    break;

                case false:
                    HeaderSQL += "INTEGER";
                    break;
                }

                if (i < Standard_Size)
                {
                    HeaderSQL    += ",";
                    HeaderWOType += ",";
                }
            }
            HeaderSQL    += ");\n";
            HeaderWOType += ")";
            SW.WriteLine(HeaderSQL);
            SW.Flush();
            Stack.Exit(StackPointer);
        }
Beispiel #2
0
        static void ArrayToSql(int Standard_Size, string TableName, string Headers, ref StreamWriter SW)
        {
            int StackPointer = Stack.Add("Import.ArrayToSql");

            for (int i = 2; i <= LDFastArray.Size1(Data); i++)
            {
                //This prevent out of bound errors.
                //The Minus one is for the difference in data sets. C# counts from Zero and the LD from one
                if (CSV_Length[(i - 1)] != Standard_Size)
                {
                    continue;
                }

                SW.Write($"INSERT INTO \"{TableName}\" {Headers} VALUES(");
                for (int ii = 1; ii <= LDFastArray.Size2(Data, i); ii++)
                {
                    string Temp = "'" + LDFastArray.Get2D(Data, i, ii).ToString().Replace("'", "''").Replace("\n", " ");
                    if (string.IsNullOrWhiteSpace(Temp))
                    {
                        Temp = "NULL";
                    }

                    if (ii < Standard_Size)
                    {
                        Temp += "',";
                    }

                    if (Temp == "'NULL','")
                    {
                        SW.Write("NULL");
                    }
                    else
                    {
                        SW.Write(Temp);
                    }
                }

                SW.WriteLine("');");
                if (i % CSVInterval == 0)
                {
                    SW.Flush();
                }
            }
            SW.Flush();
            Stack.Exit(StackPointer);
        }
Beispiel #3
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            Primitive shp = Microsoft.SmallBasic.Library.Controls.AddButton("Button", 10, 10);

            LDShapes.ReSize(shp, 100, 100);
            LDShapes.ReSize(shp, 200, 200);

            Primitive xx = LDFastArray.Add();

            LDFastArray.Set(xx, "1 2 3", 24);
            FieldInfo _primitive = typeof(Primitive).GetField("_primitive", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.Instance);
            Primitive aa         = "1 23 45";
            string    bb         = (string)_primitive.GetValue(aa);
            Primitive sb         = "1=1\\=\"hello\"\\;2\\=1\\;3\\=2\\;;2=1\\=3\\;2\\=test\\;3\\=3\\;;";
            Primitive arr        = LDFastArray.CreateFromValues(sb);
            Primitive sb1        = LDFastArray.ToArray(arr);

            Primitive a = LDFastArray.Add();

            LDFastArray.Set2D(a, 2, 5, 10);
            LDFastArray.Set2D(a, 2, 2, 20);
            LDFastArray.Set2D(a, 1, 8, 30);
            LDFastArray.Collapse(a);
            Primitive b = LDFastArray.ToArray(a);

            Primitive img = Microsoft.SmallBasic.Library.ImageList.LoadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/STS120LaunchHiRes-edit1.jpg/153px-STS120LaunchHiRes-edit1.jpg");
            Primitive x1  = LDImage.Copy(img);

            LDImage.EffectCharcoal(x1);



            Primitive image = LDImage.NewImage(100, 100, "Red");

            LDImage.OpenWorkingImage(image);
            Primitive xml  = LDxml.Open("C:\\Users\\Steve\\Documents\\SmallBasic\\steve\\sample.xml");
            Primitive data = LDxml.ToArray();

            LDxml.FromArray(data);
            LDxml.Save("C:\\Users\\Steve\\Documents\\SmallBasic\\steve\\sample1.xml");
            Primitive txt = Microsoft.SmallBasic.Library.File.ReadContents("C:\\Users\\Steve\\Documents\\SmallBasic\\steve\\txt.txt");

            LDSearch.GetProof(txt, "");
            LDSearch.GetWeb("bill gates");
            return;

            //TextWindow.Show();
            //LDTextWindow.SetColours("Pink", "Orange");
            //TextWindow.WriteLine("Hello World");

            LDPhysics.ReadJson("C:\\Users\\Steve\\Documents\\SmallBasic\\steve\\LDPysics.json", 1, "False", "False", 0, 0);

            LDWaveForm.PlayWave(256, 1000, "0=-1;1=1;5=0;");

            Primitive shape = Shapes.AddRectangle(100, 100);

            LDEffect.Bloom(shape, "");
            Program.Delay(1000);

            LDControls.AddDataView(GraphicsWindow.Width, GraphicsWindow.Height, "1=Hello;2=World;");

            //string _urlTemplate = "https://api.flickr.com/services/rest/?sort=interestingness-desc&safe_search=1&license=1,2,3,4,5,6,7&api_key=";
            //string _picUrlTemplate = "http://farm{0}.static.flickr.com/{1}/{2}_{3}.jpg";
            byte[] array = Convert.FromBase64String("MWY5ZmI5ODE4Mjk2NzAwNTgwYmYzMzQwMjc5MzQ2YjY=");
            //_urlTemplate += Encoding.UTF8.GetString(array, 0, array.Length);
            TextWindow.WriteLine(Encoding.UTF8.GetString(array, 0, array.Length));

            Primitive rtb = LDControls.AddRichTextBox(100, 100);

            LDControls.RichTextBoxSetText(rtb, "Hello", "True");
            LDCall.Compile("C:\\Users\\Steve\\Documents\\SmallBasic\\steve\\testinclude.sb");
            Primitive include = LDCall.Include("C:\\Users\\Steve\\Documents\\SmallBasic\\steve\\testinclude.exe");

            TextWindow.WriteLine(include);

            LDUtilities.FixFlickr();//FCClipboard.GetText
            LDCall.CallAsync("SmallBasicLibrary.dll", "Microsoft.SmallBasic.Library", "Flickr", "GetRandomPicture", "Car");

            string      tempFileName = Path.GetTempFileName();
            Stream      stream       = null;
            Stream      stream2      = null;
            WebResponse webResponse  = null;

            try
            {
                string     url        = "https://a75b9da71f50095fc4dc527d860da4427f274b07.googledrive.com/host/0B9s0FFxEQDb6T3VUdEw3QTJDS1E/efecast00.mp3";
                Uri        uri        = new Uri(url);
                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();
                int readCount = stream2.Read(buffer, 0, 16384);
                while (readCount > 0L)
                {
                    stream.Write(buffer, 0, readCount);
                    readCount = stream2.Read(buffer, 0, 16384);
                }
            }
            catch (Exception ex)
            {
                TextWindow.WriteLine(ex.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
                if (stream2 != null)
                {
                    stream2.Close();
                }
                if (webResponse != null)
                {
                    webResponse.Close();
                }
            }

            LDGraphicsWindow.SetFontFromFile("C:\\temp\\04b.ttf");
            TextWindow.Show();
            //Primitive source = "class Evaluator { public static function Eval(expr : String) : String { return eval(expr); } }";
            //LDInline.IncludeJScript(source,"","");
            //Primitive result = LDInline.Call("Eval","5+3");
            //TextWindow.WriteLine(result);

            //TextWindow.Hide();
            Primitive x = LDMath.Evaluate("1e6 + 6/4");
            Primitive y = LDMath.Evaluate2("1e6 + 6/4");

            //TextWindow.Hide();
            TextWindow.WriteLine("HERE " + x + " :" + y);

            LDImage.LoadSVG("C:\\temp\\snowtitle.svg");
            TextWindow.WriteLine(LDNetwork.LAN(1000));

            GraphicsWindow.Show();
            LDText.GetWidth("Hello World");

            Primitive server = LDServer.Start("True");

            LDClient.Connect(server, "True");
            LDClient.SendMessage("Hello1");
            LDClient.SendMessage("World1");
            LDServer.Disconnect("Client1");
            LDClient.Connect(server, "True");
            LDClient.SendMessage("Hello3");
            LDClient.SendMessage("World3");

            GraphicsWindow.Show();
            LDGraphicsWindow.FloodFill(200, 100, "#5588ee");
            //Program.Delay(1000000);
            //Primitive languages = LDTranslate.Languages();
            //Primitive indices = SBArray.GetAllIndices(languages);
            //for (int i = 1; i <= SBArray.GetItemCount(languages); i++)
            //{
            //    TextWindow.WriteLine(indices[i] + " : " + languages[indices[i]]);
            //}
            //Primitive result = LDTranslate.Translate("Hello World", "", "de");
            //TextWindow.WriteLine(result);

            //TextWindow.WriteLine(GraphicsWindow.FontName);
            //GraphicsWindow.DrawText(10, 10, "Hello World");
            //Primitive result = LDGraphicsWindow.SetFontFromFile("C:\\Users\\Public\\Documents\\SmallBasic\\steve\\WWFlakes.ttf");
            //TextWindow.WriteLine(GraphicsWindow.FontName);
            //GraphicsWindow.DrawText(10, 50, "Hello World");

            //PrivateFontCollection fntColl = new PrivateFontCollection();
            //fntColl.AddFontFile("C:\\Users\\Public\\Documents\\SmallBasic\\steve\\WWFlakes.ttf");
            //buttonTest.Font = new Font(fntColl.Families[0], 16, FontStyle.Regular);

            //LDDictionary.GetDefinition("Car");
        }
Beispiel #4
0
        public static void CSV(string FilePath, ref StreamWriter SW)
        {
            int StackPointer = Stack.Add($"Utilities.CSV({FilePath})");

            //TODO Make sure comment's are universal across SQL.Then use them to insert data such as how long it took to generate the SQL and how many rows were skipped if any?
            if (File.Exists(FilePath) == false)
            {
                throw new FileNotFoundException();
            }

            Stopwatch Elappsed = Stopwatch.StartNew();

            Elappsed.Start();

            CSV_Length.Clear();
            CSV_IsString.Clear();

            string Name = Path.GetFileNameWithoutExtension(FilePath).Trim();

            Data = LDFastArray.ReadCSV(FilePath);

            //Calculate Lengths of Data
            for (int i = 1; i <= LDFastArray.Size1(Data); i++)
            {
                CSV_Length.Add(LDFastArray.Size2(Data, i));
            }
            int Standard_Size = CSV_Length.First();

            //Sets IsInteger to true by default
            for (int i = 1; i <= Standard_Size; i++)
            {
                CSV_IsString.Add(true);
            }

            //Tests all Data to see if it is a integer type
            for (int i = 2; i <= Standard_Size; i++)
            {
                //This prevent out of bound errors.
                //The Minus one is for the difference in data sets. C# counts from Zero and the LD from one
                if (CSV_Length[(i - 1)] != Standard_Size)
                {
                    continue;
                }

                for (int ii = 1; ii <= LDFastArray.Size2(Data, i); ii++)
                {
                    if (CSV_IsString[(ii - 1)] == false)
                    {
                        continue;
                    }

                    string Temp = LDFastArray.Get2D(Data, i, ii).ToString().Replace("'", "''").Replace("\n", " ");
                    if (double.TryParse(Temp, out double double2) == true) //Tests a String to see if its a number
                    {
                        CSV_IsString[ii] = false;
                    }
                }
            }

            try
            {
                CSVHeaders(Standard_Size, Name, ref SW);
                ArrayToSql(Standard_Size, Name, HeaderWOType, ref SW);
                LDFastArray.Remove(Data);
                Stack.Exit(StackPointer);
                SW.Close();
                return;
            }
            catch (Exception ex)
            {
                Events.LogMessagePopUp(ex.Message + "\n" + ex.StackTrace, "System", "CSV Conversion Error");
            }

            //Drops The FastArray
            LDFastArray.Remove(Data);
            Stack.Exit(StackPointer);
            SW.Close();
            return;
        }