Beispiel #1
0
        public void insere_plano_copiaseguranca(string name, string verify, string incremental, string overwrite, string companiesByComma, string periodo)
        {
            init();
            string newid = System.Guid.NewGuid().ToString();

            AdmBEPlanoCopiasSeg newPC = new AdmBEPlanoCopiasSeg();
            AdmBECalendario objCal = new AdmBECalendario();

            newPC.set_Id(newid);
            objCal.Id = newid;

            if (periodo.Equals("mensal"))
                objCal.set_Periodo(EnumPeriodoExecucao.prMensal);
            else if (periodo.Equals("semanal"))
                objCal.set_Periodo(EnumPeriodoExecucao.prSemanal);
            else
                objCal.set_Periodo(EnumPeriodoExecucao.prDiario);

            // Exec 23h (TODO change this by arg)
            objCal.set_FreqUnicaHora(new DateTime(1900, 1, 1, 23, 0, 0));

            adm.Calendario.Actualiza(objCal);

            StringWriter stringwriter = new StringWriter();

            XmlWriterSettings xmlsettings = new XmlWriterSettings();
            xmlsettings.OmitXmlDeclaration = true;
            xmlsettings.Indent = false;
            XmlWriter xmlwriter = XmlWriter.Create(stringwriter, xmlsettings);

            xmlwriter.WriteStartElement("backupPlan");
            xmlwriter.WriteAttributeString("id", "{" + newPC.get_Id() + "}");

            xmlwriter.WriteAttributeString("name", name);
            xmlwriter.WriteAttributeString("verify", verify);
            xmlwriter.WriteAttributeString("incremental", incremental);
            xmlwriter.WriteAttributeString("overwrite", overwrite);

            string backupsdir = Backupsdir;
            if( backupsdir==null ) backupsdir = adm.SQLServer.DirectoriaBackup();

            xmlwriter.WriteAttributeString("destination", backupsdir);
            xmlwriter.WriteAttributeString("schedule", "{" + objCal.Id + "}");

            //Common.WriteToConsoleOut(" date: " + xmlreader.GetAttribute("date"));
            DateTime datenow = DateTime.Now;
            xmlwriter.WriteAttributeString("date", datenow.ToString("dd-MM-yyyy HH:mm:ss"));

            //Common.WriteToConsoleOut(" lastExecution: " + xmlreader.GetAttribute("lastExecution"));
            DateTime lastdate = objCal.UltimaOcorrencia;
            xmlwriter.WriteAttributeString("lastExecution", lastdate.ToString("dd-MM-yyyy HH:mm:ss"));

            //Common.WriteToConsoleOut(" nextExecution: " + xmlreader.GetAttribute("nextExecution"));
            //DateTime nextdate = new DateTime(datenow.Year,datenow.Month,datenow.Day);
            DateTime nextdate = objCal.ProximaOcorrencia;
            xmlwriter.WriteAttributeString("nextExecution", nextdate.ToString("dd-MM-yyyy HH:mm:ss"));

            // companies
            xmlwriter.WriteStartElement("companies");

            //string companiesByComma = "DEMO,PRIDEMO;DEMOX,PRIDEMOX";
            string[] companies = companiesByComma.Split(new char[] { ';' });

            foreach (string company in companies)
            {
                string[] cfields = company.Split(new char[] { ',' });
                if (cfields.Length == 2)
                {
                    xmlwriter.WriteStartElement("company");

                    xmlwriter.WriteStartElement("properties");
                    xmlwriter.WriteAttributeString("key", cfields[0]);
                    xmlwriter.WriteAttributeString("name", cfields[1]);
                    xmlwriter.WriteEndElement(); // properties

                    xmlwriter.WriteEndElement(); // company
                }
            }

            xmlwriter.WriteEndElement(); // companies

            xmlwriter.WriteEndElement(); // backupPlan

            xmlwriter.Flush();

            //Common.WriteToConsoleOut("xml string: " + stringwriter.ToString());

            //string strBackupPlan = "<backupPlan id=\"" + newpc_id + "\" name=\"teste all\" verify=\"False\" incremental=\"False\" overwrite=\"False\" destination=\"C:\\PROGRAM FILES\\MICROSOFT SQL SERVER\\MSSQL10.PRIMAVERA\\MSSQL\\BACKUP\\\" schedule=\"" + newpc_id + "\" date=\"" + DateTime.Now.ToString() + "\" lastExecution=\"undefined\" nextExecution=\"" + DateTime.Now.ToString("dd-MM-yyyy") + " 23:00:00\"><companies><company><properties key=\"OBIADM\" name=\"BIADM\"/></company><company><properties key=\"EDEMO\" name=\"PRIDEMO\"/></company><company><properties key=\"EDEMOX\" name=\"PRIDEMOX\"/></company><company><properties key=\"OPRIEMPRE\" name=\"PRIEMPRE\"/></company></companies></backupPlan>";
            newPC.set_Plano(stringwriter.ToString());

            adm.PlanosCopiasSeguranca.Actualiza(newPC);
            adm.PlanosCopiasSeguranca.ListaPlanos().Insere(newPC);

            Common.WriteToConsoleOut(" Plano de Copia Seguranca inserido com id: " + newPC.get_Id());
        }
Beispiel #2
0
        public void insere_plano_copiaseguranca(string name, string verify, string incremental, string overwrite, string companiesByComma, string periodo)
        {
            init();
            string newid = System.Guid.NewGuid().ToString();

            AdmBEPlanoCopiasSeg newPC  = new AdmBEPlanoCopiasSeg();
            AdmBECalendario     objCal = new AdmBECalendario();

            newPC.set_Id(newid);
            objCal.Id = newid;

            if (periodo.Equals("mensal"))
            {
                objCal.set_Periodo(EnumPeriodoExecucao.prMensal);
            }
            else if (periodo.Equals("semanal"))
            {
                objCal.set_Periodo(EnumPeriodoExecucao.prSemanal);
            }
            else
            {
                objCal.set_Periodo(EnumPeriodoExecucao.prDiario);
            }

            // Exec 23h (TODO change this by arg)
            objCal.set_FreqUnicaHora(new DateTime(1900, 1, 1, 23, 0, 0));

            _admBs.Calendario.Actualiza(objCal);

            StringWriter stringwriter = new StringWriter();

            XmlWriterSettings xmlsettings = new XmlWriterSettings();

            xmlsettings.OmitXmlDeclaration = true;
            xmlsettings.Indent             = false;
            XmlWriter xmlwriter = XmlWriter.Create(stringwriter, xmlsettings);

            xmlwriter.WriteStartElement("backupPlan");
            xmlwriter.WriteAttributeString("id", "{" + newPC.get_Id() + "}");

            xmlwriter.WriteAttributeString("name", name);
            xmlwriter.WriteAttributeString("verify", verify);
            xmlwriter.WriteAttributeString("incremental", incremental);
            xmlwriter.WriteAttributeString("overwrite", overwrite);

            string backupsdir = Backupsdir;

            if (backupsdir == null)
            {
                backupsdir = _admBs.SQLServer.DirectoriaBackup();
            }

            xmlwriter.WriteAttributeString("destination", backupsdir);
            xmlwriter.WriteAttributeString("schedule", "{" + objCal.Id + "}");

            // Console.WriteLine(" date: " + xmlreader.GetAttribute("date"));
            DateTime datenow = DateTime.Now;

            xmlwriter.WriteAttributeString("date", datenow.ToString("dd-MM-yyyy HH:mm:ss"));

            // Console.WriteLine(" lastExecution: " + xmlreader.GetAttribute("lastExecution"));
            DateTime lastdate = objCal.UltimaOcorrencia;

            xmlwriter.WriteAttributeString("lastExecution", lastdate.ToString("dd-MM-yyyy HH:mm:ss"));

            // Console.WriteLine(" nextExecution: " + xmlreader.GetAttribute("nextExecution"));
            //DateTime nextdate = new DateTime(datenow.Year,datenow.Month,datenow.Day);
            DateTime nextdate = objCal.ProximaOcorrencia;

            xmlwriter.WriteAttributeString("nextExecution", nextdate.ToString("dd-MM-yyyy HH:mm:ss"));

            // companies
            xmlwriter.WriteStartElement("companies");

            //string companiesByComma = "DEMO,PRIDEMO;DEMOX,PRIDEMOX";
            string[] companies = companiesByComma.Split(new char[] { ';' });

            foreach (string company in companies)
            {
                string[] cfields = company.Split(new char[] { ',' });
                if (cfields.Length == 2)
                {
                    xmlwriter.WriteStartElement("company");

                    xmlwriter.WriteStartElement("properties");
                    xmlwriter.WriteAttributeString("key", cfields[0]);
                    xmlwriter.WriteAttributeString("name", cfields[1]);
                    xmlwriter.WriteEndElement(); // properties

                    xmlwriter.WriteEndElement(); // company
                }
            }

            xmlwriter.WriteEndElement(); // companies

            xmlwriter.WriteEndElement(); // backupPlan

            xmlwriter.Flush();

            // Console.WriteLine("xml string: " + stringwriter.ToString());

            //string strBackupPlan = "<backupPlan id=\"" + newpc_id + "\" name=\"teste all\" verify=\"False\" incremental=\"False\" overwrite=\"False\" destination=\"C:\\PROGRAM FILES\\MICROSOFT SQL SERVER\\MSSQL10.PRIMAVERA\\MSSQL\\BACKUP\\\" schedule=\"" + newpc_id + "\" date=\"" + DateTime.Now.ToString() + "\" lastExecution=\"undefined\" nextExecution=\"" + DateTime.Now.ToString("dd-MM-yyyy") + " 23:00:00\"><companies><company><properties key=\"OBIADM\" name=\"BIADM\"/></company><company><properties key=\"EDEMO\" name=\"PRIDEMO\"/></company><company><properties key=\"EDEMOX\" name=\"PRIDEMOX\"/></company><company><properties key=\"OPRIEMPRE\" name=\"PRIEMPRE\"/></company></companies></backupPlan>";
            newPC.set_Plano(stringwriter.ToString());

            _admBs.PlanosCopiasSeguranca.Actualiza(newPC);
            _admBs.PlanosCopiasSeguranca.ListaPlanos().Insere(newPC);

            Console.WriteLine(" Plano de Copia Seguranca inserido com id: " + newPC.get_Id());
        }