示例#1
0
        /// <summary>
        /// Deletes all files in this database.
        /// </summary>
        /// <param name="database">The database to be cleared.</param>
        public static void Clear(this IDatabaseInfo database)
        {
            Console.WriteLine("Database: " + database.ToString());
            Console.Write("This will delete _every_ file in the database. Do you wish to proceed? [y/n]: ");
            string line = Console.ReadLine();

            if (line.ToLower().Equals("y"))
            {
                database.Controller.ClearDatabase();
                Console.WriteLine("Database successfully cleared.");
            }
            else
            {
                Console.WriteLine("Database clear cancelled.");
            }
        }
示例#2
0
文件: Job.cs 项目: rohitvuppala/BoSSS
        private void FiddleControlFile(BatchProcessorClient bpc)
        {
            if (m_ctrl == null)
            {
                return;
            }

            // check the database
            // ==================
            IDatabaseInfo ctrl_db = m_ctrl.GetDatabase();

            if (bpc.AllowedDatabases != null && bpc.AllowedDatabases.Count > 0)
            {
                IDatabaseInfo newDb = null;
                if (ctrl_db == null)
                {
                    newDb = bpc.AllowedDatabases[0];
                }
                else
                {
                    bool ok = false;
                    foreach (var allow_dba in bpc.AllowedDatabases)
                    {
                        if (allow_dba.Equals(ctrl_db))
                        {
                            ok = true;
                            break;
                        }
                    }

                    if (!ok)
                    {
                        newDb = bpc.AllowedDatabases[0];
                    }
                }

                if (newDb != null)
                {
                    Console.WriteLine("Resetting database for control object to " + newDb.ToString());

                    //newDb.AlternateDbPaths



                    m_ctrl.SetDatabase(newDb);
                    ctrl_db = newDb;
                }

                Console.WriteLine("Submitting job with the following database info: ");
                Console.WriteLine("Primary: " + m_ctrl.DbPath);
                if (ctrl_db.AlternateDbPaths != null && ctrl_db.AlternateDbPaths.Length > 0)
                {
                    int cnt = 0;
                    foreach (var t in ctrl_db.AlternateDbPaths)
                    {
                        Console.WriteLine($" Alternative[{cnt}]: {t.DbPath}, MachineFilter: '{t.MachineFilter}'");
                        cnt++;
                    }
                }
                else
                {
                    Console.WriteLine("No alternative paths specified.");
                }
            }
            else
            {
                Console.WriteLine("");
            }

            // check grid & restart info
            // =========================

            if (ctrl_db != null)
            {
                if (!m_ctrl.GridGuid.Equals(Guid.Empty))
                {
                    var GridIn_ctrl_db = ctrl_db.Grids.FirstOrDefault(GrdInf => GrdInf.ID.Equals(m_ctrl.GridGuid));

                    if (GridIn_ctrl_db == null)
                    {
                        Console.WriteLine($"Grid {m_ctrl.GridGuid} is not present in database - copy to target system...");

                        var grid2copy = InteractiveShell.AllGrids.FirstOrDefault(dbGrid => dbGrid.ID.Equals(m_ctrl.GridGuid));
                        if (grid2copy == null)
                        {
                            // maybe replace exception with a warning, if job should be tried anyway
                            throw new IOException($"Unable to find grid '{m_ctrl.GridGuid}' in any database - job will most likely crash.");
                        }
                        else
                        {
                            grid2copy.Copy(ctrl_db);
                        }

                        Console.WriteLine("done.");
                    }
                }
                else
                {
                    Console.Error.WriteLine($"Warning: no grid seems to be specified for the job to submit.");
                }

                if (m_ctrl.RestartInfo != null)
                {
                    Guid Rstsess_guid = m_ctrl.RestartInfo.Item1;


                    var Rstsess_ctrl_db = ctrl_db.Sessions.FirstOrDefault(sinf => sinf.ID.Equals(Rstsess_guid));

                    if (Rstsess_ctrl_db == null)
                    {
                        Console.WriteLine($"Session {m_ctrl.GridGuid} to restart from is not present in database - copy to target system...");

                        var sess_2copy = InteractiveShell.AllSessions.FirstOrDefault(sinf => sinf.ID.Equals(Rstsess_guid));
                        if (sess_2copy == null)
                        {
                            // maybe replace exception with a warning, if job should be tried anyway
                            throw new IOException($"Unable to find session '{sess_2copy}' in any database - job will most likely crash.");
                        }
                        else
                        {
                            sess_2copy.Copy(ctrl_db);
                        }

                        Console.WriteLine("done.");
                    }
                }
            }
            else
            {
                Console.Error.WriteLine($"Warning: no database is set for the job to submit; nothing ma be saved.");
            }

            // finally, serialize the object
            // =============================
            {
                string text;
                m_ctrl_index = -1;
                if (m_ctrl.GeneratedFromCode)
                {
                    text         = m_ctrl.ControlFileText;
                    ControlName  = "control.cs";
                    m_ctrl_index = m_ctrl.ControlFileText_Index;
                }
                else
                {
                    text        = m_ctrl.Serialize();
                    ControlName = "control.obj";
                }
                byte[] buffer = Encoding.UTF8.GetBytes(text);

                int remIdx = AdditionalDeploymentFiles.IndexWhere(tt => tt.Item2 == ControlName);
                if (remIdx >= 0)
                {
                    AdditionalDeploymentFiles.RemoveAt(remIdx);
                }

                AdditionalDeploymentFiles.Add(new Tuple <byte[], string>(buffer, ControlName));
            }
        }