Exemple #1
0
        /// <summary>
        /// standard log new file each time
        /// </summary>
        /// <param name="s"></param>
        public static void ToFileNew(string s)
        {
            StreamWriter SW;

            SW = File.CreateText(File3);
            SW.WriteLine(s);
            SW.Flush();
            SW.Close();
        }
Exemple #2
0
        /// <summary>
        /// standard log with time stamp
        /// </summary>
        /// <param name="s"></param>
        public static void ToFileTime(string s)
        {
            StreamWriter SW;

            SW = File.AppendText(File2);
            SW.WriteLine(DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond.ToString() + "\t : " + s);
            SW.Flush();
            SW.Close();
        }
Exemple #3
0
        /// <summary>
        /// DataTable to new file each time
        /// </summary>
        /// <param name="aDBTable"></param>
        public static void TableToFileNew(DataTable aDBTable)
        {
            int[] aWidths;
            aWidths = new Int32[aDBTable.Columns.Count];

            //widths
            for (int j = 0; j < aDBTable.Columns.Count; j++)
            {
                aWidths[j] = 0;
                if (aDBTable.Columns[j].Caption.Length >= aWidths[j])
                {
                    aWidths[j] = aDBTable.Columns[j].Caption.Length + 1;
                }

                for (int i = 0; i < aDBTable.Rows.Count; i++)
                {
                    if (aDBTable.Rows[i].ItemArray[j].ToString().Length >= aWidths[j])
                    {
                        aWidths[j] = aDBTable.Rows[i].ItemArray[j].ToString().Length + 1;
                    }
                }
            }

            StreamWriter SW;

            SW = File.CreateText(File4);

            //captions
            for (int j = 0; j < aDBTable.Columns.Count; j++)
            {
                SW.Write(aDBTable.Columns[j].Caption);
                SW.Write(Util.GetNSpaces(aWidths[j] - aDBTable.Columns[j].Caption.Length));
            }
            SW.WriteLine("");
            for (int j = 0; j < aDBTable.Columns.Count; j++)
            {
                for (int i = 0; i < aWidths[j]; i++)
                {
                    SW.Write("-");
                }
            }
            SW.WriteLine("");

            //data
            for (int i = 0; i < aDBTable.Rows.Count; i++)
            {
                for (int j = 0; j < aDBTable.Columns.Count; j++)
                {
                    SW.Write(aDBTable.Rows[i].ItemArray[j].ToString());
                    SW.Write(Util.GetNSpaces(aWidths[j] - aDBTable.Rows[i].ItemArray[j].ToString().Length));
                }
                SW.WriteLine("");
            }
            SW.Flush();
            SW.Close();
        }
Exemple #4
0
 /// <summary>
 /// standard log
 /// </summary>
 /// <param name="s"></param>
 public static void ToFileAppend(string s)
 {
     lock (_lock)
     {
         StreamWriter SW;
         SW = File.AppendText(File1);
         SW.Write(s);
         SW.Flush();
         SW.Close();
     }
 }
Exemple #5
0
 /// <summary>
 /// standard log
 /// </summary>
 /// <param name="s"></param>
 public static void ToFile(string s, string filename)
 {
     lock (_lock)
     {
         StreamWriter SW;
         SW = File.AppendText(filename);
         SW.WriteLine(s);
         SW.Flush();
         SW.Close();
     }
 }
Exemple #6
0
        public void WriteResponse(String [] Response)
        {
            StreamWriter SW;

            SW = File.CreateText(Application.StartupPath + "\\" + responseFile);
            //MessageBox.Show(Application.StartupPath + "\\" + responseFile);
            for (int i = 0; i < Response.Length; i++)
            {
                string [] values = Response[i].Split('=');
                switch (values[0])
                {
                case "ResponseDescription":
                    SW.WriteLine("RESULT=SUCCESS");
                    break;

                case "CardType":
                    SW.WriteLine("ACCOUNTTYPE=" + values[1]);
                    break;

                case "ExpDate":
                    SW.WriteLine("EXPIRTATION=" + values[1]);
                    break;

                case "TransactionID":
                    SW.WriteLine("XCTRANSACTIONID=" + values[1]);
                    break;

                case "TransactionType":
                    if (values[1] == "CreditSaleTransaction")
                    {
                        SW.WriteLine("XCTRANSACTIONID=Purchase");
                    }

                    if (values[1] == "CreditVoidTransaction")
                    {
                        SW.WriteLine("XCTRANSACTIONID=VOID");
                    }

                    if (values[1] == "CreditReturnTransaction")
                    {
                        SW.WriteLine("XCTRANSACTIONID=Refund");
                    }
                    break;

                default:
                    SW.WriteLine(values[0] + "=" + values[1]);
                    break;
                }
            }
            SW.Flush();
            SW.Close();
            Application.Exit();
        }
Exemple #7
0
 public static void AppendToFile(String teks, String Path)
 {
     try
     {
         StreamWriter SW;
         SW = System.IO.File.AppendText(Path);
         SW.WriteLine(teks);
         SW.Flush();
         //Console.WriteLine("Text Appended Successfully");
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception: " + e.Message);
     }
     finally
     {
         //Console.WriteLine("Executing finally block.");
     }
 }
 public void Close()
 {
     if (this.OutputFormat != "")
     {
         if (!this.BatchProcessingDone)
         {
             foreach (Feature backloggedFeature in FeatureQ)
             {
                 ProcessFeature(backloggedFeature);
             }
         }
     }
     this.OutputOutliers();
     if (this.OutputFormat == "CSV")
     {
         foreach (System.IO.StreamWriter SW in this.StreamWriters.Values)
         {
             SW.Flush();
             SW.Close();
         }
     }
 }
Exemple #9
0
        public static void PerformUpdate(bool oldrevision)
        {
            try
            {
                StreamWriter SW;
                if (!Server.mono)
                {
                    if (!File.Exists("Update.bat"))
                    {
                        SW = new StreamWriter(File.Create("Update.bat"));
                    }
                    else
                    {
                        if (File.ReadAllLines("Update.bat")[0] != "::Version 3")
                        {
                            SW = new StreamWriter(File.Create("Update.bat"));
                        }
                        else
                        {
                            SW = new StreamWriter(File.Create("Update_generated.bat"));
                        }
                    }
                    SW.WriteLine("::Version 3");
                    SW.WriteLine("TASKKILL /pid %2 /F");
                    SW.WriteLine("if exist MCForge_.dll.backup (erase MCForge_.dll.backup)");
                    SW.WriteLine("if exist MCForge_.dll (rename MCForge_.dll MCForge_.dll.backup)");
                    SW.WriteLine("if exist MCForge.new (rename MCForge.new MCForge_.dll)");
                    SW.WriteLine("start MCForge.exe");
                }
                else
                {
                    if (!File.Exists("Update.sh"))
                    {
                        SW = new StreamWriter(File.Create("Update.sh"));
                    }
                    else
                    {
                        if (File.ReadAllLines("Update.sh")[0] != "#Version 2")
                        {
                            SW = new StreamWriter(File.Create("Update.sh"));
                        }
                        else
                        {
                            SW = new StreamWriter(File.Create("Update_generated.sh"));
                        }
                    }
                    SW.WriteLine("#Version 2");
                    SW.WriteLine("#!/bin/bash");
                    SW.WriteLine("kill $2");
                    SW.WriteLine("rm MCForge_.dll.backup");
                    SW.WriteLine("mv MCForge_.dll MCForge.dll_.backup");
                    SW.WriteLine("wget " + DLLLocation);
                    SW.WriteLine("mono MCForge.exe");
                }

                SW.Flush(); SW.Close(); SW.Dispose();

                string  filelocation = "";
                string  verscheck    = "";
                Process proc         = Process.GetCurrentProcess();
                string  assemblyname = proc.ProcessName + ".exe";
                if (!oldrevision)
                {
                    WebClient client = new WebClient();
                    Server.selectedrevision = client.DownloadString(ServerSettings.CurrentVersionFile);
                    client.Dispose();
                }
                verscheck = Server.selectedrevision.TrimStart('r');
                int vers = int.Parse(verscheck.Split('.')[0]);
                if (oldrevision)
                {
                    filelocation = (ServerSettings.ArchivePath + Server.selectedrevision + ".exe");
                }
                if (!oldrevision)
                {
                    filelocation = (DLLLocation);
                }
                WebClient Client = new WebClient();
                Client.DownloadFile(filelocation, "MCLawl.new");
                Client.DownloadFile(ServerSettings.ChangelogLocation, "extra/Changelog.txt");

                // Its possible there are no levels or players loaded yet
                // Only save them if they exist, otherwise we fail-whale
                if (Server.levels != null && Server.levels.Any())
                {
                    foreach (Level l in Server.levels)
                    {
                        l.Save();
                    }
                }

                if (Player.players != null && Player.players.Any())
                {
                    foreach (Player pl in Player.players)
                    {
                        pl.save();
                    }
                }

                string fileName;
                if (!Server.mono)
                {
                    fileName = "Update.bat";
                }
                else
                {
                    fileName = "Update.sh";
                }

                try
                {
                    if (MCForge.Gui.Window.thisWindow.notifyIcon1 != null)
                    {
                        MCForge.Gui.Window.thisWindow.notifyIcon1.Icon    = null;
                        MCForge.Gui.Window.thisWindow.notifyIcon1.Visible = false;
                    }
                }
                catch { }

                Process p = Process.Start(fileName, "main " + System.Diagnostics.Process.GetCurrentProcess().Id.ToString());
                p.WaitForExit();
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Exemple #10
0
        public static void PerformUpdate(bool oldrevision)
        {
            try
            {
                StreamWriter SW;
                if (!Server.mono)
                {
                    if (!File.Exists("Update.bat"))
                    {
                        SW = new StreamWriter(File.Create("Update.bat"));
                    }
                    else
                    {
                        if (File.ReadAllLines("Update.bat")[0] != "::Version 3")
                        {
                            SW = new StreamWriter(File.Create("Update.bat"));
                        }
                        else
                        {
                            SW = new StreamWriter(File.Create("Update_generated.bat"));
                        }
                    }
                    SW.WriteLine("::Version 3");
                    SW.WriteLine("TASKKILL /pid %2 /F");
                    SW.WriteLine("if exist MCSong_.dll.backup (erase MCSong_.dll.backup)");
                    SW.WriteLine("if exist MCSong_.dll (rename MCSong_.dll MCSong_.dll.backup)");
                    SW.WriteLine("if exist MCSong.new (rename MCSong.new MCSong_.dll)");
                    SW.WriteLine("start MCSong.exe");
                }
                else
                {
                    if (!File.Exists("Update.sh"))
                    {
                        SW = new StreamWriter(File.Create("Update.sh"));
                    }
                    else
                    {
                        if (File.ReadAllLines("Update.sh")[0] != "#Version 2")
                        {
                            SW = new StreamWriter(File.Create("Update.sh"));
                        }
                        else
                        {
                            SW = new StreamWriter(File.Create("Update_generated.sh"));
                        }
                    }
                    SW.WriteLine("#Version 2");
                    SW.WriteLine("#!/bin/bash");
                    SW.WriteLine("kill $2");
                    SW.WriteLine("rm MCSong_.dll.backup");
                    SW.WriteLine("mv MCSong_.dll MCSong.dll_.backup");
                    SW.WriteLine("wget http://updates.mcsong.x10.mx/MCSong_.dll");
                    SW.WriteLine("mono MCSong.exe");
                }

                SW.Flush(); SW.Close(); SW.Dispose();

                string  filelocation = "";
                string  verscheck    = "";
                Process proc         = Process.GetCurrentProcess();
                string  assemblyname = proc.ProcessName + ".exe";
                if (!oldrevision)
                {
                    WebClient client = new WebClient();
                    Server.selectedrevision = client.DownloadString("http://updates.mcsong.x10.mx/curversion.txt");
                    client.Dispose();
                }
                verscheck = Server.selectedrevision.TrimStart('r');
                int vers = int.Parse(verscheck.Split('.')[0]);
                if (oldrevision)
                {
                    filelocation = ("http://updates.mcsong.x10.mx/archives/exe/" + Server.selectedrevision + ".exe");
                }
                if (!oldrevision)
                {
                    filelocation = ("http://updates.mcsong.x10.mx/MCSong_.dll");
                }
                WebClient Client = new WebClient();
                Client.DownloadFile(filelocation, "MCSong.new");
                Client.DownloadFile("http://updates.mcsong.x10.mx/changelog.txt", "extra/Changelog.txt");
                foreach (Level l in Server.levels)
                {
                    l.Save();
                }
                foreach (Player pl in Player.players)
                {
                    pl.save();
                }

                string fileName;
                if (!Server.mono)
                {
                    fileName = "Update.bat";
                }
                else
                {
                    fileName = "Update.sh";
                }

                try
                {
                    if (MCSong.Gui.Window.thisWindow.notifyIcon1 != null)
                    {
                        MCSong.Gui.Window.thisWindow.notifyIcon1.Icon    = null;
                        MCSong.Gui.Window.thisWindow.notifyIcon1.Visible = false;
                    }
                }
                catch { }

                Process p = Process.Start(fileName, "main " + System.Diagnostics.Process.GetCurrentProcess().Id.ToString());
                p.WaitForExit();
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Exemple #11
0
        public void addPoint(Player p, string foundPath, string additional = "", string extra = "10", string more = "2")
        {
            string[] allLines;
            try { allLines = File.ReadAllLines("bots/" + foundPath); }
            catch { allLines = new string[1]; }

            StreamWriter SW;

            try
            {
                if (!File.Exists("bots/" + foundPath))
                {
                    Player.SendMessage(p, "Created new bot AI: &b" + foundPath);
                    SW = new StreamWriter(File.Create("bots/" + foundPath));
                    SW.WriteLine("#Version 2");
                }
                else if (allLines[0] != "#Version 2")
                {
                    Player.SendMessage(p, "File found is out-of-date. Overwriting");
                    SW = new StreamWriter(File.Create("bots/" + foundPath));
                    SW.WriteLine("#Version 2");
                }
                else
                {
                    Player.SendMessage(p, "Appended to bot AI: &b" + foundPath);
                    SW = new StreamWriter("bots/" + foundPath, true);
                }
            }
            catch { Player.SendMessage(p, "An error occurred when accessing the files. You may need to delete it."); return; }

            try
            {
                switch (additional.ToLower())
                {
                case "":
                case "walk":
                    SW.WriteLine("walk " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
                    break;

                case "teleport":
                case "tp":
                    SW.WriteLine("teleport " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
                    break;

                case "wait":
                    SW.WriteLine("wait " + int.Parse(extra)); break;

                case "nod":
                    SW.WriteLine("nod " + int.Parse(extra) + " " + int.Parse(more)); break;

                case "speed":
                    SW.WriteLine("speed " + int.Parse(extra)); break;

                case "remove":
                    SW.WriteLine("remove"); break;

                case "reset":
                    SW.WriteLine("reset"); break;

                case "spin":
                    SW.WriteLine("spin " + int.Parse(extra) + " " + int.Parse(more)); break;

                case "reverse":
                    for (int i = allLines.Length - 1; i > 0; i--)
                    {
                        if (allLines[i][0] != '#' && allLines[i] != "")
                        {
                            SW.WriteLine(allLines[i]);
                        }
                    }
                    break;

                case "linkscript":
                    if (extra != "10")
                    {
                        SW.WriteLine("linkscript " + extra);
                    }
                    else
                    {
                        Player.SendMessage(p, "Linkscript requires a script as a parameter");
                    }
                    break;

                case "jump":
                    SW.WriteLine("jump"); break;

                default:
                    Player.SendMessage(p, "Could not find \"" + additional + "\""); break;
                }

                SW.Flush();
                SW.Close();
                SW.Dispose();
            }
            catch { Player.SendMessage(p, "Invalid parameter"); SW.Close(); }
        }
Exemple #12
0
        public void addPoint(Player p, string foundPath, string additional = "", string extra = "10", string more = "2")
        {
            string[] allLines;
            try { allLines = File.ReadAllLines("bots/" + foundPath); }
            catch { allLines = new string[1]; }

            StreamWriter SW;

            try
            {
                if (!File.Exists("bots/" + foundPath))
                {
                    Player.SendMessage(p, "Cree une nouvelle IA de bot: &b" + foundPath);
                    SW = new StreamWriter(File.Create("bots/" + foundPath));
                    SW.WriteLine("#Version 2");
                }
                else if (allLines[0] != "#Version 2")
                {
                    Player.SendMessage(p, "Le fichier trouver est depacer. Reecriture");
                    SW = new StreamWriter(File.Create("bots/" + foundPath));
                    SW.WriteLine("#Version 2");
                }
                else
                {
                    Player.SendMessage(p, "Apprentissage a l'IA: &b" + foundPath);
                    SW = new StreamWriter("bots/" + foundPath, true);
                }
            }
            catch { Player.SendMessage(p, "Une erreur s'est produite lors de l'acces aux fichiers. Vous devez le supprimer."); return; }

            try
            {
                switch (additional.ToLower())
                {
                case "":
                case "walk":
                    SW.WriteLine("walk " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
                    break;

                case "teleport":
                case "tp":
                    SW.WriteLine("teleport " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
                    break;

                case "wait":
                    SW.WriteLine("wait " + int.Parse(extra)); break;

                case "nod":
                    SW.WriteLine("nod " + int.Parse(extra) + " " + int.Parse(more)); break;

                case "speed":
                    SW.WriteLine("speed " + int.Parse(extra)); break;

                case "remove":
                    SW.WriteLine("remove"); break;

                case "reset":
                    SW.WriteLine("reset"); break;

                case "spin":
                    SW.WriteLine("spin " + int.Parse(extra) + " " + int.Parse(more)); break;

                case "reverse":
                    for (int i = allLines.Length - 1; i > 0; i--)
                    {
                        if (allLines[i][0] != '#' && allLines[i] != "")
                        {
                            SW.WriteLine(allLines[i]);
                        }
                    }
                    break;

                case "linkscript":
                    if (extra != "10")
                    {
                        SW.WriteLine("linkscript " + extra);
                    }
                    else
                    {
                        Player.SendMessage(p, "Linkscript necessite un script comme paramètre");
                    }
                    break;

                case "jump":
                    SW.WriteLine("jump"); break;

                default:
                    Player.SendMessage(p, "Could not find \"" + additional + "\""); break;
                }

                SW.Flush();
                SW.Close();
                SW.Dispose();
            }
            catch { Player.SendMessage(p, "parametre invalide"); SW.Close(); }
        }