Beispiel #1
0
 public static Aliases FromFile(string file)
 {
     Aliases a;
     try
     {
         using (FileStream fs = new FileStream(file, FileMode.Open))
         {
             BinaryFormatter bf = new BinaryFormatter();
             a = (Aliases) bf.Deserialize(fs);
         }
     }
     catch (FileNotFoundException)
     {
         a = new Aliases(file);
     }
     return a;
 }
Beispiel #2
0
        public static Aliases FromFile(string file)
        {
            Aliases a;

            try
            {
                using (FileStream fs = new FileStream(file, FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    a = (Aliases)bf.Deserialize(fs);
                }
            }
            catch (FileNotFoundException)
            {
                a = new Aliases(file);
            }
            return(a);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(DefaultErrorHandler);

            Console.WriteLine("\nAlchemi [.NET Grid Computing Framework]");
            Console.WriteLine("http://www.alchemi.net\n");

            Console.WriteLine("Job Submitter v{0}", Utils.AssemblyVersion);

            IManager            manager;
            SecurityCredentials sc;

            if (args.Length < 4)
            {
                Usage();
                return;
            }

            try
            {
                manager = (IManager)GNode.GetRemoteRef(new RemoteEndPoint(args[0], int.Parse(args[1]), RemotingMechanism.TcpBinary));
                manager.PingManager();
                sc = new SecurityCredentials(args[2], args[3]);
                manager.AuthenticateUser(sc);
                Console.Write("Connected to Manager at {0}:{1}\n", args[0], args[1]);
            }
            catch (Exception e)
            {
                Error("Could not connect to Manager", e);
                return;
            }

            Aliases aliases = Aliases.FromFile(Path.Combine(System.Windows.Forms.Application.StartupPath, "aliases.dat"));

            string[] cmd;
            bool     interactive;

            if (args.Length > 4)
            {
                cmd = new string[args.Length - 4];
                for (int i = 0; i < args.Length - 4; i++)
                {
                    cmd[i] = args[i + 4];
                }
                interactive = false;
            }
            else
            {
                cmd         = new string[] { "" };
                interactive = true;
            }

            while (true)
            {
                if (interactive)
                {
                    Console.Write("\n> ");
                    string line = Console.ReadLine();
                    cmd    = line.Split();
                    cmd[0] = cmd[0].ToLower();
                }

                try
                {
                    string appId;

                    switch (cmd[0])
                    {
                    case "st":
                    case "submittask":     // taskXmlFile
                        string task = EmbedFiles(Utils.ReadStringFromFile(cmd[1]));
                        appId = CrossPlatformHelper.CreateTask(manager, sc, task);
                        string newAlias = aliases.NewAlias(appId);
                        try
                        {
                            WriteLine("Task submitted (alias = {1}).", appId, newAlias);
                        }
                        catch
                        {
                        }
                        break;

                    case "gfj":
                    case "getfinishedjobs":     // alias, (directory, default=".")
                        appId = (string)aliases.Table[cmd[1]];

                        string taskDir = cmd.Length > 2 ? cmd[2] : ".";

                        string      taskXml = CrossPlatformHelper.GetFinishedJobs(manager, sc, appId);
                        XmlDocument fin     = new XmlDocument();
                        fin.LoadXml(taskXml);

                        WriteLine("Got {0} job(s).", fin.SelectNodes("task/job").Count);
                        Console.WriteLine("Job XML: \n" + taskXml);

                        foreach (XmlNode outputFileNode in fin.SelectNodes("task/job/output/embedded_file"))
                        {
                            //string jobDir = string.Format("{0}\\job_{1}", taskDir, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value);
                            string jobDir = taskDir;
                            if (!Directory.Exists(jobDir))
                            {
                                Directory.CreateDirectory(jobDir);
                            }

                            //if (outputFileNode.InnerText != "")
                            //{
                            string filePath = string.Format("{0}\\{1}", jobDir, outputFileNode.Attributes["name"].Value);
                            Utils.WriteBase64EncodedToFile(
                                filePath,
                                outputFileNode.InnerText
                                );
                            WriteLine("Wrote file {0} for job {1}.", filePath, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value);
                            // }
                        }
                        break;

                    // TODO: (allow option to specify alias)
                    case "ct":
                    case "createtask":     // no arguments
                        appId = manager.Owner_CreateApplication(sc);
                        WriteLine(appId);
                        WriteLine("Task created (alias = {1}).", appId, aliases.NewAlias(appId));
                        break;

                    case "aj":
                    case "addjob":     // alias, jobXml, jobId, (priority, default=0)
                        appId = (string)aliases.Table[cmd[1]];
                        int priority = 0;
                        if (cmd.Length > 4)
                        {
                            priority = int.Parse(cmd[4]);
                        }
                        CrossPlatformHelper.AddJob(manager, sc, appId, int.Parse(cmd[3]), priority, EmbedFiles(Utils.ReadStringFromFile(cmd[2])));
                        WriteLine("Job added.");
                        break;

                    /*
                     * case "listapps": // no arguments
                     *  DataTable apps = manager.Owner_GetLiveApplicationList(null).Tables[0];
                     *  apps.Columns.Add("alias", typeof(string));
                     *  apps.Columns.Add("state_disp", typeof(string));
                     *  foreach (DataRow app in apps.Rows)
                     *  {
                     *      string alias = aliases.GetAlias(app["application_id"].ToString());
                     *      if (alias == "")
                     *      {
                     *          alias = aliases.NewAlias(app["application_id"].ToString());
                     *      }
                     *      app["alias"] = alias;
                     *      app["state_disp"] = Enum.Parse(typeof(ApplicationState), app["state"].ToString()).ToString();
                     *  }
                     *  Console.WriteLine(ConsoleFormatter.FormatDataTable(
                     *      apps,
                     *      new string[] {"alias", "state_disp", "time_created"},
                     *      new string[] {"alias", "state", "time_created"}
                     *      ));
                     *  break;
                     *
                     * case "listthreads": // alias
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  DataTable threads = manager.Owner_GetThreadList(null, appId).Tables[0];
                     *
                     *  threads.Columns.Add("state_disp", typeof(string));
                     *  foreach (DataRow thread in threads.Rows)
                     *  {
                     *      thread["state_disp"] = Enum.Parse(typeof(ThreadState), thread["state"].ToString());
                     *  }
                     *
                     *  Console.WriteLine(ConsoleFormatter.FormatDataTable(
                     *      threads,
                     *      new string[] {"thread_id", "state_disp", "time_started", "time_finished"},
                     *      new string[] {"thread_id", "state", "time_started", "time_finished"}
                     *      ));
                     *  break;
                     *
                     * case "getthreadstate": // alias, threadId
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  ThreadState state = manager.Owner_GetThreadState(null, new ThreadIdentifier(appId, int.Parse(cmd[2])));
                     *  WriteLine("State = {0}.", state);
                     *  break;
                     *
                     * case "abortthread": // alias, threadId
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  manager.Owner_AbortThread(null, new ThreadIdentifier(appId, int.Parse(cmd[2])));
                     *  WriteLine("Thread aborted.");
                     *  break;
                     *
                     * case "stoptask": // alias
                     *  appId = (string) aliases.Table[cmd[1]];
                     *  manager.Owner_StopApplication(null, appId);
                     *  WriteLine("Task stopped.");
                     *  break;
                     *
                     */

                    case "h":
                    case "help":
                    case "?":
                        if (cmd.Length == 2)
                        {
                            Usage(cmd[1]);
                        }
                        else
                        {
                            Usage();
                        }
                        break;

                    case "quit":
                    case "q":
                    case "exit":
                    case "x":
                        return;

                    default:
                        Error("Unknown command '{0}'", cmd[0]);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Error("Incorrect syntax or parameter (" + e.Message.ToString() + ")");
                }

                if (!interactive)
                {
                    return;
                }
            }
        }