コード例 #1
0
 static void session_BeforeImReceived(AccSession session, IAccImSession imSession, IAccParticipant sender, IAccIm im)
 {
     throw new NotImplementedException();
 }
コード例 #2
0
 static void session_BeforeImSend(AccSession session, IAccImSession imSession, IAccParticipant recipient, IAccIm im)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
        static void session_OnImReceived(AccSession session, IAccImSession imSession, IAccParticipant sender, IAccIm im)
        {
            //convert IM to a String
            String strReceive = im.GetConvertedText(MIME_TYPE);

            //get timestamp
            String time = im.get_Property(AccImProp.AccImProp_Timestamp).ToString();

            time = time.Substring(time.IndexOf(":") - 2).Trim();

            //get if this is an auto-response
            if (Enum.GetName(typeof(AccImFlags), im.get_Property((AccImProp)AccImFlags.AccImFlags_AutoResponse)) == AccImFlags.AccImFlags_AutoResponse.ToString())
            {
                //add users sn and auto-response to the front of the text
                strReceive = "<font color=\"red\">AUTO RESPONSE FROM " + sender.Name + " (" + time + ")</font>: " + strReceive;
            }
            else
            {
                //add the users sn to the front of the text
                strReceive = "<font color=\"red\">" + sender.Name + " (" + time + ")</font>: " + strReceive;
            }

            //raise the event
            if (InstantMessageReceived != null)
            {
                InstantMessageReceived.Invoke(sender.Name, strReceive, imSession);
            }
        }
コード例 #4
0
 static void session_OnImSendResult(AccSession session, IAccImSession imSession, IAccParticipant recipient, IAccIm im, AccResult hr)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
        private void s_OnImReceived(AccSession session, IAccImSession piImSession, IAccParticipant piSender, IAccIm piIm)
        {
            try
            {
                if (piSender.Name.ToLower().Equals("aim") || piSender.Name.ToLower().Equals("buddybulletin"))
                {
                    return;
                }

                string text = piIm.GetConvertedText("text/plain").Trim();
                Console.WriteLine("<*{0}*> {1}", piSender.Name, text);

                string[] @params = text.Split(' ');
                if (@params.Length == 1 && @params[0].ToLower().Equals("help"))
                {
                    piImSession.SendIm(session.CreateIm("\r\nThe purpose of this bot is to compile and run C++/C#/PHP/Perl/Python/Java code for you.\r\nTo use it, send a file/multiple files containing source code and type \"run language files\" without the quotes, where language is one of php/csh/cpp/java/python/perl"
                        + " and files is a space delimited list of files or a single file.\r\nNote: You may only send files of extensions *.cpp, *.cs, *.h, *.hpp, *.php, *.java, *.py, *.pl or folders containing such files.\r\n\r\nExample for C#: Upload a file named Main.cs and type run csh Main.cs\r\n\r\nExample for JAVA: Upload a folder named test (we're assuming Class1 and Class2 are in package test), containing Class1.java and Class2.java, and Class1.java contains a \"main\" method.\r\nNow type run java test/Class1.java test/Class2.java\r\nNotes for JAVA code:\r\n- your code must be placed in a package to run properly.\r\n - if there are multiple files you wish to compile and run, please make sure that the file containing the main method is first in the list.\r\n\r\nExample for C++: Upload a main.cpp file, a func.cpp (we're assuming this requires a custom header.h) file and a header.h file.\r\nTo compile and run this code type run cpp main.cpp func.cpp.\r\n\r\nFor PERL, Python and PHP simply upload a file containing the main code (not necessary to include the path to the interpretor)\r\nand type run php file.php or run perl file.pl or run python file.py\r\n\r\nRestrictions apply: your program may not run for more than " + MAX_PROCESS_TIME + " seconds, files you upload are deleted every 15 minutes and may not be more than 200 KB in size each.\r\n\r\nPlease drop an e-mail to [email protected] or AIM velorienz if you have any suggestions or questions.", "text/plain"));
                    return;
                }
                // start tutorial
                else if (@params.Length == 1 && @params[0].ToLower().Equals("tutorial"))
                {
                    if (onTutorial.ContainsKey(piSender.Name))
                    {
                        piImSession.SendIm(session.CreateIm("You're already on the tutorial, type quit to quit it.",
                            "text/plain"));
                        return;
                    }

                    piImSession.SendIm(session.CreateIm(
                        TUTORIAL_MSG[0] +
                        COMPILE_RUN_MSG[0] + "\r\n" +
                        SOURCE_MSG + "\r\n" +
                        NEXT_MSG + "\r\n" +
                        QUIT_TUTORIAL_MSG, "text/plain"));

                    onTutorial.Add(piSender.Name, 1);
                    // copy the files used in this tut
                    CopyTutorialFiles(piSender.Name, 1);

                    return;
                }
                // quit tutorial
                else if (@params.Length == 1 && @params[0].ToLower().Equals("quit"))
                {
                    if (onTutorial.ContainsKey(piSender.Name))
                    {
                        piImSession.SendIm(session.CreateIm("You have now quit the tutorial.",
                            "text/plain"));
                        onTutorial.Remove(piSender.Name);
                        return;
                    }
                }
                // advance tutorial
                else if (@params.Length == 1 && @params[0].ToLower().Equals("next"))
                {
                    if (onTutorial.ContainsKey(piSender.Name))
                    {
                        // quit the tut if at last part
                        if (onTutorial[piSender.Name] == 6)
                        {
                            piImSession.SendIm(session.CreateIm("You have now quit the tutorial.",
                                "text/plain"));
                            onTutorial.Remove(piSender.Name);
                            return;
                        }

                        onTutorial[piSender.Name]++;
                        // copy the files used in this tut
                        CopyTutorialFiles(piSender.Name, onTutorial[piSender.Name]);

                        piImSession.SendIm(session.CreateIm(
                            TUTORIAL_MSG[onTutorial[piSender.Name] - 1] +
                            COMPILE_RUN_MSG[onTutorial[piSender.Name] - 1] + "\r\n" +
                            SOURCE_MSG + "\r\n" +
                            NEXT_MSG + "\r\n" +
                            QUIT_TUTORIAL_MSG, "text/plain"));

                        return;
                    }
                }
                else if (@params.Length == 1 && @params[0].ToLower().Equals("version"))
                {
                    // send version information
                    StringBuilder buf = new StringBuilder();
                    buf.Append("\r\n").
                        Append(CODEREMOTE_VERSION).Append("\r\n").Append("Latest change: ").Append(UPDATES).
                        Append("\r\n\r\n").
                        Append(CSH_VERSION).Append("\r\n").
                        Append(JAVA_VERSION).Append("\r\n").
                        Append(CPP_VERSION).Append("\r\n").
                        Append(PHP_VERSION).Append("\r\n").
                        Append(PERL_VERSION).Append("\r\n").
                        Append(PYTHON_VERSION).Append("\r\n");
                    piImSession.SendIm(session.CreateIm(buf.ToString(), "text/plain"));
                    return;
                }
                // download files used in this tutorial
                else if (@params.Length == 1 && @params[0].ToLower().Equals("source"))
                {
                    if (onTutorial.ContainsKey(piSender.Name))
                    {
                        // read files and send source
                        StringBuilder buf = new StringBuilder();
                        foreach (string tutorialFile in TUTORIAL_SOURCE_CODE[onTutorial[piSender.Name] - 1])
                        {
                            string path = BASE_PATH + piSender.Name + "//" + tutorialFile;
                            // is it a directory?
                            if (Directory.Exists(path))
                            {
                                // iterate through its files
                                foreach (string fileInDir in Directory.GetFiles(path))
                                {
                                    TextReader tr = new StreamReader(fileInDir);
                                    string line = "\r\n[Source code for file: " + tutorialFile + "\\" +
                                        fileInDir.Substring((path + "\\").Length) + "]\r\n";
                                    buf.Append(line);
                                    while ((line = tr.ReadLine()) != null)
                                    {
                                        buf.Append(line + "\r\n");
                                    }
                                    tr.Close();
                                    buf.Append("\r\n");
                                }
                            }
                            // if file, check if the file exists
                            else if (File.Exists(path))
                            {
                                TextReader tr = new StreamReader(BASE_PATH + piSender.Name + "//" + tutorialFile);
                                string line = "\r\n[Source code for file: " + tutorialFile + "]\r\n";
                                buf.Append(line);
                                while ((line = tr.ReadLine()) != null)
                                {
                                    buf.Append(line + "\r\n");
                                }
                                tr.Close();
                                buf.Append("\r\n");
                            }
                        }

                        if (buf.Length == 0)
                        {
                            buf.Append("This tutorial session has expired. Please type quit to quit it.");
                        }

                        // send the message
                        piImSession.SendIm(session.CreateIm(buf.ToString(), "text/plain"));
                        return;
                    }
                }

                if (@params.Length < 3 || !@params[0].ToLower().Equals("run"))
                {
                    if (!uploadSize.ContainsKey(piSender.Name))
                    {
                        piImSession.SendIm(session.CreateIm("\r\nHi! The purpose of this bot is to compile and run C++/C#/PHP/Perl/Python/Java code for you.\r\nCommands:\r\n\r\nhelp - for instructions on how to use the bot to compile and run code.\r\ntutorial - to run through a short tutorial that will teach you the basics" +
                            "\r\nversion - to get some useful information regarding the version of the bot and of the compilers/interpretors used", "text/plain"));
                        uploadSize.Add(piSender.Name, 0);
                    }
                    else
                    {
                        //string random = GetRandomMessage();
                        //Console.WriteLine("sent random message: " + random);
                        piImSession.SendIm(session.CreateIm("Bad syntax, type help for help", "text/plain"));
                    }

                    return;
                }

                string user = piImSession.
                    get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString();
                string file = BASE_PATH + user + "\\" + @params[2];

                for (int i = 2; i < @params.Length; i++)
                {
                    if (!File.Exists(BASE_PATH + user + "\\" + @params[i]))
                    {
                        piImSession.SendIm(session.CreateIm("This file doesn't exist: " + @params[i] + ". You must first send the bot a source code file with that name for this to work.", "text/plain"));
                        return;
                    }
                }

                // check for supported languages
                if (@params[1].ToLower().Equals("php") ||
                    @params[1].ToLower().Equals("csh") ||
                    @params[1].ToLower().Equals("cpp") ||
                    @params[1].ToLower().Equals("java") ||
                    @params[1].ToLower().Equals("python") ||
                    @params[1].ToLower().Equals("perl"))
                {
                    // compile it and run it
                    ProcessStartInfo oInfo = null;
                    string sRes = null;
                    string sErr = null;
                    string runTime = null;

                    if (@params[1].ToLower().Equals("php"))
                    {
                        oInfo = new ProcessStartInfo(
                            "E:\\php\\php.exe", " " + file);

                        oInfo.UseShellExecute = false;
                        oInfo.ErrorDialog = false;
                        oInfo.CreateNoWindow = true;
                        oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        oInfo.RedirectStandardOutput = true;
                        oInfo.RedirectStandardError = true;
                        if (useLimitedUser)
                        {
                            oInfo.UserName = PROCESS_USERNAME;
                            oInfo.Password = new SecureString();
                            for (int i = 0; i < PROCESS_PASSWORD.Length; i++)
                            {
                                oInfo.Password.AppendChar(PROCESS_PASSWORD[i]);
                            }
                            oInfo.WorkingDirectory = BASE_PATH;
                        }

                        string pId = DateTime.Now.ToString() + "php";
                        processes.Add(pId, new RunProcess());
                        DateTime start = DateTime.Now;

                        processes[pId].Process = Process.Start(oInfo);
                        System.IO.StreamReader oReader = processes[pId].Process.StandardOutput;
                        sRes = oReader.ReadToEnd();
                        System.IO.StreamReader oReader2 = processes[pId].Process.StandardError;
                        sErr = oReader2.ReadToEnd();

                        if (sErr == null || sErr.Trim().Length == 0)
                        {
                            TimeSpan ts = DateTime.Now.Subtract(start);
                            runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)";
                            if (processes[pId].KilledOff)
                            {
                                runTime += "\r\nProcess was ended prematurely.";
                            }
                        }
                        processes.Remove(pId);
                    }
                    else if (@params[1].ToLower().Equals("python"))
                    {
                        oInfo = new ProcessStartInfo(
                            "E:\\Python25\\python.exe", " " + file);

                        oInfo.UseShellExecute = false;
                        oInfo.ErrorDialog = false;
                        oInfo.CreateNoWindow = true;
                        oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        oInfo.RedirectStandardOutput = true;
                        oInfo.RedirectStandardError = true;
                        if (useLimitedUser)
                        {
                            oInfo.UserName = PROCESS_USERNAME;
                            oInfo.Password = new SecureString();
                            for (int i = 0; i < PROCESS_PASSWORD.Length; i++)
                            {
                                oInfo.Password.AppendChar(PROCESS_PASSWORD[i]);
                            }
                            oInfo.WorkingDirectory = BASE_PATH;
                        }

                        string pId = DateTime.Now.ToString() + "python";
                        processes.Add(pId, new RunProcess());
                        DateTime start = DateTime.Now;

                        processes[pId].Process = Process.Start(oInfo);
                        System.IO.StreamReader oReader = processes[pId].Process.StandardOutput;
                        sRes = oReader.ReadToEnd();
                        System.IO.StreamReader oReader2 = processes[pId].Process.StandardError;
                        sErr = oReader2.ReadToEnd();

                        if (sErr == null || sErr.Trim().Length == 0)
                        {
                            TimeSpan ts = DateTime.Now.Subtract(start);
                            runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)";
                            if (processes[pId].KilledOff)
                            {
                                runTime += "\r\nProcess was ended prematurely.";
                            }
                        }
                        processes.Remove(pId);
                    }
                    else if (@params[1].ToLower().Equals("perl"))
                    {
                        oInfo = new ProcessStartInfo(
                            "C:\\strawberry\\perl\\bin\\perl.exe", " " + file);

                        oInfo.UseShellExecute = false;
                        oInfo.ErrorDialog = false;
                        oInfo.CreateNoWindow = true;
                        oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        oInfo.RedirectStandardOutput = true;
                        oInfo.RedirectStandardError = true;
                        if (useLimitedUser)
                        {
                            oInfo.UserName = PROCESS_USERNAME;
                            oInfo.Password = new SecureString();
                            for (int i = 0; i < PROCESS_PASSWORD.Length; i++)
                            {
                                oInfo.Password.AppendChar(PROCESS_PASSWORD[i]);
                            }
                            oInfo.WorkingDirectory = BASE_PATH;
                        }

                        string pId = DateTime.Now.ToString() + "perl";
                        processes.Add(pId, new RunProcess());
                        DateTime start = DateTime.Now;

                        processes[pId].Process = Process.Start(oInfo);
                        System.IO.StreamReader oReader = processes[pId].Process.StandardOutput;
                        sRes = oReader.ReadToEnd();
                        System.IO.StreamReader oReader2 = processes[pId].Process.StandardError;
                        sErr = oReader2.ReadToEnd();

                        if (sErr == null || sErr.Trim().Length == 0)
                        {
                            TimeSpan ts = DateTime.Now.Subtract(start);
                            runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)";
                            if (processes[pId].KilledOff)
                            {
                                runTime += "\r\nProcess was ended prematurely.";
                            }
                        }
                        processes.Remove(pId);
                    }
                    else if (@params[1].ToLower().Equals("csh"))
                    {
                        string files = "";
                        for (int i = 2; i < @params.Length; i++)
                        {
                            files += BASE_PATH + user + "\\" + @params[i] + " ";
                        }
                        files = files.Substring(0, files.Length - 1);

                        // exe name will be name of first source file + .exe extension
                        string output = (@params[2].LastIndexOf(".") != -1 ? @params[2].Substring(0, @params[2].LastIndexOf(".")) :
                            @params[2]);

                        // temporarily add them so that they do not get deleted ahead of time
                        uploads.Add(piSender.Name + "//" + output + ".exe",
                            new Upload(piSender.Name + "//" + output + ".exe", DateTime.Now));
                        uploads.Add(piSender.Name + "//" + output + ".pdb",
                            new Upload(piSender.Name + "//" + output + ".pdb", DateTime.Now));

                        oInfo = new ProcessStartInfo(
                            "C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\csc.exe",

                            " /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE "
                            + "/reference:C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.Data.dll "
                            + "/reference:C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.dll "
                            + "/reference:C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.Xml.dll "
                            + "/debug:pdbonly /optimize+ /out:" + BASE_PATH + user + "\\" + output + ".exe" + " "
                            + "/target:exe " + files);

                        oInfo.UseShellExecute = false;
                        oInfo.ErrorDialog = false;
                        oInfo.CreateNoWindow = true;
                        oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        oInfo.RedirectStandardOutput = true;
                        oInfo.RedirectStandardError = true;
                        if (useLimitedUser)
                        {
                            oInfo.UserName = PROCESS_USERNAME;
                            oInfo.Password = new SecureString();
                            for (int i = 0; i < PROCESS_PASSWORD.Length; i++)
                            {
                                oInfo.Password.AppendChar(PROCESS_PASSWORD[i]);
                            }
                            oInfo.WorkingDirectory = BASE_PATH;
                        }

                        Process p = Process.Start(oInfo);
                        StreamReader oReader = p.StandardOutput;
                        sRes = oReader.ReadToEnd();

                        StreamReader oReader2 = p.StandardError;
                        sErr = oReader2.ReadToEnd();
                        Thread.Sleep(100); // leave time for the compiler to exit

                        // continue only if compilation was successfull
                        if (File.Exists(BASE_PATH + user + "\\" + output + ".exe"))
                        {
                            oInfo = new ProcessStartInfo(
                                BASE_PATH + user + "\\" + output + ".exe");

                            oInfo.UseShellExecute = false;
                            oInfo.ErrorDialog = false;
                            oInfo.CreateNoWindow = true;
                            oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            oInfo.RedirectStandardOutput = true;
                            oInfo.RedirectStandardError = true;

                            string pId = DateTime.Now.ToString() + "csh";
                            processes.Add(pId, new RunProcess());
                            DateTime start = DateTime.Now;

                            processes[pId].Process = Process.Start(oInfo);
                            oReader = processes[pId].Process.StandardOutput;
                            sRes = oReader.ReadToEnd();
                            oReader2 = processes[pId].Process.StandardError;
                            sErr = oReader2.ReadToEnd();

                            TimeSpan ts = DateTime.Now.Subtract(start);
                            runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)";
                            if (processes[pId].KilledOff)
                            {
                                runTime += "\r\nProcess was ended prematurely.";
                            }
                            processes.Remove(pId);
                        }

                        // clean up

                        try
                        {
                            // exe
                            if (uploads.ContainsKey(piSender.Name + "//" + output + ".exe"))
                            {
                                uploads.Remove(piSender.Name + "//" + output + ".exe");
                            }
                            if (File.Exists(BASE_PATH + user + "\\" + output + ".exe"))
                            {
                                File.Delete(BASE_PATH + user + "\\" + output + ".exe");
                            }

                            // pdb file
                            if (uploads.ContainsKey(piSender.Name + "//" + output + ".pdb"))
                            {
                                uploads.Remove(piSender.Name + "//" + output + ".pdb");
                            }
                            if (File.Exists(BASE_PATH + user + "\\" + output + ".pdb"))
                            {
                                File.Delete(BASE_PATH + user + "\\" + output + ".pdb");
                            }
                        }
                        catch (Exception)
                        {
                            // do nothing
                        }
                    }
                    else if (@params[1].ToLower().Equals("cpp"))
                    {
                        string files = "";
                        for (int i = 2; i < @params.Length; i++)
                        {
                            files += BASE_PATH + user + "\\" + @params[i] + " ";
                        }
                        files = files.Substring(0, files.Length - 1);

                        // exe name will be name of first source file + .exe extension
                        string output = (@params[2].LastIndexOf(".") != -1 ? @params[2].Substring(0, @params[2].LastIndexOf(".")) :
                            @params[2]);

                        // temporarily add them so that they do not get deleted ahead of time
                        uploads.Add(piSender.Name + "//" + output + ".exe",
                            new Upload(piSender.Name + "//" + output + ".exe", DateTime.Now));
                        uploads.Add(piSender.Name + "//" + output + ".obj",
                            new Upload(piSender.Name + "//" + output + ".obj", DateTime.Now));

                        // set environment variables too
                        oInfo = new ProcessStartInfo(
                            "cmd.exe", " /c C:\\vcvars32.bat && C:\\cl.exe /EHsc " + files + " /Fe"
                            + BASE_PATH + user + "\\" + output + ".exe");

                        oInfo.UseShellExecute = false;
                        oInfo.ErrorDialog = false;
                        oInfo.CreateNoWindow = true;
                        oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        oInfo.RedirectStandardOutput = true;
                        oInfo.RedirectStandardError = true;
                        if (useLimitedUser)
                        {
                            oInfo.UserName = PROCESS_USERNAME;
                            oInfo.Password = new SecureString();
                            for (int i = 0; i < PROCESS_PASSWORD.Length; i++)
                            {
                                oInfo.Password.AppendChar(PROCESS_PASSWORD[i]);
                            }
                            oInfo.WorkingDirectory = BASE_PATH;
                        }

                        Process p = Process.Start(oInfo);
                        StreamReader oReader = p.StandardOutput;
                        sRes = oReader.ReadToEnd();

                        StreamReader oReader2 = p.StandardError;
                        sErr = oReader2.ReadToEnd();
                        Thread.Sleep(100); // leave time for the compiler to exit

                        // continue only if compilation was successfull
                        if (File.Exists(BASE_PATH + user + "\\" + output + ".exe"))
                        {
                            oInfo = new ProcessStartInfo(
                                BASE_PATH + user + "\\" + output + ".exe");

                            oInfo.UseShellExecute = false;
                            oInfo.ErrorDialog = false;
                            oInfo.CreateNoWindow = true;
                            oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            oInfo.RedirectStandardOutput = true;
                            oInfo.RedirectStandardError = true;

                            string pId = DateTime.Now.ToString() + "cpp";
                            processes.Add(pId, new RunProcess());
                            DateTime start = DateTime.Now;

                            processes[pId].Process = Process.Start(oInfo);
                            oReader = processes[pId].Process.StandardOutput;
                            sRes = oReader.ReadToEnd();
                            oReader2 = processes[pId].Process.StandardError;
                            sErr = oReader2.ReadToEnd();

                            TimeSpan ts = DateTime.Now.Subtract(start);
                            runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)";
                            if (processes[pId].KilledOff)
                            {
                                runTime += "\r\nProcess was ended prematurely.";
                            }
                            processes.Remove(pId);
                        }

                        try
                        {
                            // clean up
                            // exe
                            if (uploads.ContainsKey(piSender.Name + "//" + output + ".exe"))
                            {
                                uploads.Remove(piSender.Name + "//" + output + ".exe");
                            }
                            if (File.Exists(BASE_PATH + user + "\\" + output + ".exe"))
                            {
                                File.Delete(BASE_PATH + user + "\\" + output + ".exe");
                            }

                            // obj file
                            if (uploads.ContainsKey(piSender.Name + "//" + output + ".obj"))
                            {
                                uploads.Remove(piSender.Name + "//" + output + ".obj");
                            }
                            if (File.Exists(BASE_PATH + user + "\\" + output + ".obj"))
                            {
                                File.Delete(BASE_PATH + user + "\\" + output + ".obj");
                            }
                        }
                        catch (Exception)
                        {
                            // do nothing
                        }
                    }
                    else if (@params[1].ToLower().Equals("java"))
                    {
                        string files = "";
                        for (int i = 2; i < @params.Length; i++)
                        {
                            string classFile = (@params[i].LastIndexOf(".") != -1 ? @params[i].Substring(0, @params[i].LastIndexOf(".")) : @params[i]) + ".class";
                            // temporarily add the class files to uploaded files so they dont get removed ahead of time
                            uploads.Add(piSender.Name + "//" + classFile,
                                new Upload(piSender.Name + "//" + classFile, DateTime.Now));

                            files += BASE_PATH + user + "\\" + @params[i] + " ";
                        }
                        files = files.Substring(0, files.Length - 1);

                        // exe name will be name of first source file + .exe extension
                        string output = (@params[2].LastIndexOf(".") != -1 ? @params[2].Substring(0, @params[2].LastIndexOf(".")) :
                            @params[2]);

                        oInfo = new ProcessStartInfo(
                            "C:\\jdk1.5.0_12\\bin\\javac",
                            " " + files);

                        oInfo.UseShellExecute = false;
                        oInfo.ErrorDialog = false;
                        oInfo.CreateNoWindow = true;
                        oInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        oInfo.RedirectStandardOutput = true;
                        oInfo.RedirectStandardError = true;
                        if (useLimitedUser)
                        {
                            oInfo.UserName = PROCESS_USERNAME;
                            oInfo.Password = new SecureString();
                            for (int i = 0; i < PROCESS_PASSWORD.Length; i++)
                            {
                                oInfo.Password.AppendChar(PROCESS_PASSWORD[i]);
                            }
                            oInfo.WorkingDirectory = BASE_PATH;
                        }

                        Process p = Process.Start(oInfo);
                        StreamReader oReader = p.StandardOutput;
                        sRes = oReader.ReadToEnd();

                        StreamReader oReader2 = p.StandardError;
                        sErr = oReader2.ReadToEnd();

                        // continue only if compilation was successfull
                        if (sErr == null || sErr.Trim().Length == 0)
                        {
                            oInfo = new ProcessStartInfo("C:\\jdk1.5.0_12\\bin\\java",
                                " -cp " + BASE_PATH + user + "\\" + " " + output);

                            oInfo.UseShellExecute = false;
                            oInfo.ErrorDialog = false;
                            oInfo.CreateNoWindow = true;
                            oInfo.RedirectStandardOutput = true;
                            oInfo.RedirectStandardError = true;

                            string pId = DateTime.Now.ToString() + "java";
                            processes.Add(pId, new RunProcess());
                            DateTime start = DateTime.Now;

                            processes[pId].Process = Process.Start(oInfo);
                            oReader = processes[pId].Process.StandardOutput;
                            sRes = oReader.ReadToEnd();
                            oReader2 = processes[pId].Process.StandardError;
                            sErr = oReader2.ReadToEnd();

                            TimeSpan ts = DateTime.Now.Subtract(start);
                            runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)";
                            if (processes[pId].KilledOff)
                            {
                                runTime += "\r\nProcess was ended prematurely.";
                            }
                            processes.Remove(pId);
                        }

                        // clean up
                        // delete all the class files
                        try
                        {
                            for (int i = 2; i < @params.Length; i++)
                            {
                                string classFile = (@params[i].LastIndexOf(".") != -1 ? @params[i].Substring(0, @params[i].LastIndexOf(".")) : @params[i]) + ".class";
                                if (uploads.ContainsKey(piSender.Name + "//" + classFile))
                                {
                                    uploads.Remove(piSender.Name + "//" + classFile);
                                }

                                string deleteFile = BASE_PATH + user + "\\" + classFile;
                                if (File.Exists(deleteFile))
                                {
                                    File.Delete(deleteFile);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            // do nothing
                        }
                    }

                    if (runTime == null)
                    {
                        runTime = "\r\nProcess run time: 0 second(s)";
                    }
                    string message = "\r\nResult:\r\n" + sErr + "\r\n" + sRes + runTime;
                    if (message.Length <= MAX_MESSAGE_BREAK_LENGTH)
                    {
                        piImSession.SendIm(session.CreateIm(message, "text/plain"));
                    }
                    else
                    {
                        if (message.Length > MAX_MESSAGE_LENGTH)
                        {
                            message = "\r\nResult:\r\n" + sErr + "\r\n" + sRes;
                            message = message.Substring(0, MAX_MESSAGE_LENGTH - runTime.Length);
                            message += runTime;
                        }

                        // break it up into multiple messages
                        while (message.Length > MAX_MESSAGE_BREAK_LENGTH)
                        {
                            piImSession.SendIm(session.CreateIm(message.Substring(0, MAX_MESSAGE_BREAK_LENGTH),
                                "text/plain"));
                            message = message.Substring(MAX_MESSAGE_BREAK_LENGTH);
                        }
                        piImSession.SendIm(session.CreateIm(message,
                            "text/plain"));
                    }
                }
                else
                {
                    piImSession.SendIm(session.CreateIm("Programming language not supported: " + @params[1] + ". If you would like support for " +
                        "additional programming languages send your suggestion to [email protected].", "text/plain"));
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("exception encountered during code compile/run: {0} {1}", e.Message, e.StackTrace);
            }
        }
コード例 #6
0
ファイル: tylerplugin.cs プロジェクト: wied03/AIMDisclaimer
        // runs before the IM is sent
        private void m_session_sendhandler(AccSession piSession,
										   IAccImSession theIMSession,
										   IAccParticipant theParticipant,
										   IAccIm theIM)
        {
            // determine if we're sending to someone in that group

                // get the "hot" group
                IAccBuddyList theBuddyList = piSession.BuddyList;
                IAccGroup dcGroup = theBuddyList.GetGroupByName(m_selectedBuddyGroup);

                bool foundThem = false;

                for (int i = 0; i < dcGroup.BuddyCount; i++)
                {
                    // iterate through the whole group and see if
                    // the person we are talking to is on the list
                    IAccUser dcUser = dcGroup.GetBuddyByIndex(i);

                    // create a session for the group user since AIM sucks and this is the
                    // easiest way to decide of we are conversing
                    // with this person

                    AccImSessionType theSessType =
                            (AccImSessionType) theIMSession.get_Property(AccImSessionProp.AccImSessionProp_SessionType);

                    IAccImSession dummySession =
                            piSession.CreateImSession(dcUser.Name,
                                                      theSessType);
                    // since AIM will return a the same session if we
                    // are already talking with them, compare them
                    // if they are equal we have the person

                    if (dummySession == theIMSession)
                    {
                        foundThem = true;
                        break;
                    }
                }
                if (foundThem)
                {
                    TimeSpan theSpan = DateTime.Now.Subtract(m_lastSent);
                    Trace.WriteLine("session handler");
                    Trace.WriteLine("timespan is " + theSpan.Minutes);
                    Trace.WriteLine("interval is " + m_reminderInterval);
                    if (theSpan.Minutes > m_reminderInterval)
                    {
                        // ok we found them
                        theIM.Text = m_disclaimerText + " " + theIM.Text;
                        m_lastSent = DateTime.Now;
                    }
                }
        }