Пример #1
0
 public DatabaseManager(String file)
 {
     dbConnection = String.Format("Data Source={0}", file);
     if (!File.Exists(file))
     {
         LogMan.AddLog("Arquivo de Banco de Dados não existe. Criando " + file);
         SQLiteConnection.CreateFile(file);
         LogMan.AddLog("Abrindo banco de dados de cache.");
         SQLiteConnection cnn = new SQLiteConnection(dbConnection);
         cnn.Open();
         LogMan.AddLog("Criando tabelas iniciais.");
         SQLiteCommand cmd = new SQLiteCommand(cnn);
         cmd.CommandText = "CREATE TABLE schedules (Id INTEGER PRIMARY KEY, Mailbox STRING, FullBackup INTEGER, LastDays INTEGER, Target STRING, Hour STRING, Minute STRING, DayOfWeek STRING, DayOfMonth STRING, Month STRING )";
         cmd.ExecuteNonQuery();
         cnn.Close();
     }
 }
Пример #2
0
        public void DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            BackgroundWorker worker = sender as BackgroundWorker;
            Runspace         rSpace;
            SecureString     secpass = new SecureString();;

            for (int i = 0; i < password.Length; i++)
            {
                secpass.AppendChar(password[i]);
            }

            PSCredential        cred           = new PSCredential(username, secpass);
            WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
                new Uri("https://" + ip + "/Powershell"),
                "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
                cred);

            connectionInfo.SkipCACheck         = true;
            connectionInfo.SkipRevocationCheck = true;
            connectionInfo.SkipCNCheck         = true;
            LogMan.AddDebug("Trying to connect to \"https://" + ip + "/Powershell\"");
            connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
            rSpace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
            try
            {
                rSpace.Open();
                Pipeline pipeLine = rSpace.CreatePipeline();
                if (scripting)
                {
                    pipeLine.Commands.AddScript(this.workScript);
                    LogMan.AddDebug("Console Script: " + workScript.ToString());
                }
                else
                {
                    foreach (Command cmd in this.workCMD)
                    {
                        pipeLine.Commands.Add(cmd);
                        System.Console.WriteLine(cmd.ToString());
                        String parameters = "";
                        for (int i = 0; i < cmd.Parameters.Count; i++)
                        {
                            parameters += " -" + cmd.Parameters[i].Name + " " + cmd.Parameters[i].Value;
                        }
                        LogMan.AddDebug("Console: " + cmd.ToString() + parameters);
                    }
                }
                Collection <PSObject> commandResults = pipeLine.Invoke();
                RequestOutput         outdata        = new RequestOutput();
                foreach (PSObject cmdlet in commandResults)
                {
                    foreach (PSPropertyInfo prop in cmdlet.Properties)
                    {
                        try
                        {
                            outdata.Add(prop.Name.ToString(), prop.Value.ToString());
                        }
                        catch (Exception) { }
                    }
                }
                completed = true;
                PSBGCompletedEventArgs args = new PSBGCompletedEventArgs();
                LogMan.AddDebug("Outdata: " + outdata.ToString());
                args.Output  = outdata.ToString();
                args.OutData = outdata;
                args.Id      = this.Id;
                args.failed  = false;
                pipeLine.Dispose();
                rSpace.Close();
                if (Completed != null)
                {
                    Completed(this, args);
                }
            }
            catch (Exception exc)
            {
                LogMan.AddDebug("Error: " + exc.Message);
                PSBGCompletedEventArgs args = new PSBGCompletedEventArgs();
                args.Id      = this.Id;
                args.failed  = true;
                args.failmsg = exc.Message;
                rSpace.Close();
                if (Completed != null)
                {
                    Completed(this, args);
                }
            }
        }