Exemplo n.º 1
0
 public void ToClipboard(ConfigurationProfile profile)
 {
     if (profile.ClipboardEnabled.IsTrue())
     {
         var text = this.ToArray().Aggregate((a, b) => string.Format("{0}{1}{2}", a, Environment.NewLine, b));
         System.Windows.Forms.Clipboard.SetText(text);
     }
 }
Exemplo n.º 2
0
        //private string hostname, username, password;
        public static void UploadFiles(ConfigurationProfile profile, string temppath, string remotedir)
        {
            // Setup session options
            // add support for: scp/sftp protocols, ssh host/private keys, active/passive mode, port, FtpSecure, timeout, ssl cert,

            using (FTPSClient session = new FTPSClient())
            {

                ESSLSupportMode sslSupportMode = ESSLSupportMode.ClearText;
                RemoteCertificateValidationCallback userValidateServerCertificate;
                userValidateServerCertificate = new RemoteCertificateValidationCallback(ValidateServerCertificate);

                // enable encryption if desired
                if (profile.Encryption.IsTrue())
                {
                    sslSupportMode |= ESSLSupportMode.ControlAndDataChannelsRequired | ESSLSupportMode.CredentialsRequired;
                    if (profile.EncryptionImplicit.IsTrue())
                    {
                        // implicit if desired
                        sslSupportMode |= ESSLSupportMode.Implicit;
                    }
                    if (profile.ForceEncryption.IsTrue())
                    {
                        // force encryption if desired
                        userValidateServerCertificate = new RemoteCertificateValidationCallback(delegate { return true; });
                    }
                }

                session.Connect(profile.Hostname, new System.Net.NetworkCredential(profile.Username, profile.Password), sslSupportMode, userValidateServerCertificate);

                // Upload files
                //TransferOptions transferOptions = new TransferOptions();
                //transferOptions.TransferMode = TransferMode.Binary;

                //TransferOperationResult transferResult;
                //transferResult = session.PutFiles(Path.Combine(temppath, "*"), Common.Parse(remotedir), false, transferOptions);

                try
                {
                    session.SetCurrentDirectory(Common.ParseTemplate(remotedir));
                }
                catch
                {
                    session.MakeDir(Common.ParseTemplate(remotedir));
                }
                session.PutFiles(temppath, Common.ParseTemplate(remotedir), "*", EPatternStyle.Wildcard, false, new FileTransferCallback(TransferCallback));

                // Throw on any error
                //transferResult.Check();

                // Print results
                //foreach (TransferEventArgs transfer in transferResult.Transfers)
                //{
                //    Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
                //}
            }
        }
Exemplo n.º 3
0
        //private string hostname, username, password;

        public static void UploadFiles(ConfigurationProfile profile, string temppath, string remotedir)
        {
            // Setup session options
            // add support for: scp/sftp protocols, ssh host/private keys, active/passive mode, port, FtpSecure, timeout, ssl cert,

            using (FTPSClient session = new FTPSClient())
            {
                ESSLSupportMode sslSupportMode = ESSLSupportMode.ClearText;
                RemoteCertificateValidationCallback userValidateServerCertificate;
                userValidateServerCertificate = new RemoteCertificateValidationCallback(ValidateServerCertificate);

                // enable encryption if desired
                if (profile.Encryption.IsTrue())
                {
                    sslSupportMode |= ESSLSupportMode.ControlAndDataChannelsRequired | ESSLSupportMode.CredentialsRequired;
                    if (profile.EncryptionImplicit.IsTrue())
                    {
                        // implicit if desired
                        sslSupportMode |= ESSLSupportMode.Implicit;
                    }
                    if (profile.ForceEncryption.IsTrue())
                    {
                        // force encryption if desired
                        userValidateServerCertificate = new RemoteCertificateValidationCallback(delegate { return(true); });
                    }
                }

                session.Connect(profile.Hostname, new System.Net.NetworkCredential(profile.Username, profile.Password), sslSupportMode, userValidateServerCertificate);

                // Upload files
                //TransferOptions transferOptions = new TransferOptions();
                //transferOptions.TransferMode = TransferMode.Binary;

                //TransferOperationResult transferResult;
                //transferResult = session.PutFiles(Path.Combine(temppath, "*"), Common.Parse(remotedir), false, transferOptions);

                try
                {
                    session.SetCurrentDirectory(Common.ParseTemplate(remotedir));
                }
                catch
                {
                    session.MakeDir(Common.ParseTemplate(remotedir));
                }
                session.PutFiles(temppath, Common.ParseTemplate(remotedir), "*", EPatternStyle.Wildcard, false, new FileTransferCallback(TransferCallback));

                // Throw on any error
                //transferResult.Check();

                // Print results
                //foreach (TransferEventArgs transfer in transferResult.Transfers)
                //{
                //    Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
                //}
            }
        }
Exemplo n.º 4
0
 public static void PlaySound(ConfigurationProfile profile)
 {
     if (profile.SoundEnabled.IsTrue())
     {
         using (var p = new System.Media.SoundPlayer())
         {
             p.SoundLocation = Path.Combine(Globals.ExecutableDirectory, profile.Soundfile);
             p.PlaySync();
         }
     }
 }
Exemplo n.º 5
0
 public static void PlaySound(ConfigurationProfile profile)
 {
     if (profile.SoundEnabled.IsTrue())
     {
         using (var p = new System.Media.SoundPlayer())
         {
             p.SoundLocation = Path.Combine(Globals.ExecutableDirectory, profile.Soundfile);
             p.PlaySync();
         }
     }
 }
Exemplo n.º 6
0
 public ArgumentData()
 {
     Files = new List<string>();
     Profile = new ConfigurationProfile();
 }
Exemplo n.º 7
0
        public void LoadProfile(string path)
        {
            IniData data = new IniData();

            if (!Path.HasExtension(path))
            {
                var storedprofile = Path.Combine(Globals.DefaultProfileDirectory, string.Concat(path, ".ini"));
                if (File.Exists(storedprofile))
                {
                    path = storedprofile;
                }
                else
                {
                    throw new FileNotFoundException("Relative profile not found.", storedprofile);
                }
            }
            else if (path.Equals(Globals.DefaultProfileFile) && !File.Exists(path))
            {
                // create if not exist
                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Log.LogMessage(string.Format("Profile directory not found. Creating profile directory..."));
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    Log.LogMessage(string.Format("Profile directory created at {0}", Path.GetDirectoryName(path)));
                }
                Log.LogMessage(string.Format("Default profile does not exist. Creating new default profile in {0}...", path));
                data.Sections.AddSection("Profile");
                data["Profile"].AddKey("Hostname");
                data["Profile"].AddKey("Username");
                data["Profile"].AddKey("Password");
                data["Profile"].AddKey("Encryption");
                data["Profile"].AddKey("EncryptionImplicit");
                data["Profile"].AddKey("ForceEncryption");
                data["Profile"].AddKey("RemoteDir");
                data["Profile"].AddKey("Mode");
                data["Profile"].AddKey("ClipboardURL");
                data["Profile"].AddKey("ClipboardEnabled");
                data["Profile"].AddKey("SshHostKey");
                data["Profile"].AddKey("Soundfile");
                data["Profile"].AddKey("SoundEnabled");
                parser.SaveFile(path, data);
                Log.LogMessage("Default profile created.");
                Console.WriteLine("Default profile created. You'll probably want to edit credentials. Program will now exit.");
                Environment.Exit(0);
            }
            else if (!File.Exists(path))
            {
                throw new FileNotFoundException("Profile not found.", Path.GetFullPath(path));
            }

            try
            {
                data = Load(path);
            }
            catch (ParsingException)
            {
                throw;
            }
            ConfigurationProfile profile = new ConfigurationProfile();

            try
            {
                Encryption         = data["Profile"]["Encryption"];
                EncryptionImplicit = data["Profile"]["EncryptionImplicit"];
                ForceEncryption    = data["Profile"]["ForceEncryption"];
                Hostname           = data["Profile"]["Hostname"];
                Username           = data["Profile"]["Username"];
                Password           = data["Profile"]["Password"];
                RemoteDir          = data["Profile"]["RemoteDir"];
                Mode             = data["Profile"]["Mode"];
                ClipboardURL     = data["Profile"]["ClipboardURL"];
                ClipboardEnabled = data["Profile"]["ClipboardEnabled"];
                SshHostKey       = data["Profile"]["SshHostKey"];
                Soundfile        = data["Profile"]["Soundfile"];
                SoundEnabled     = data["Profile"]["SoundEnabled"];
            }
            catch (NullReferenceException)
            {
                throw new FileLoadException("Profile is corrupted.");
            }
        }
Exemplo n.º 8
0
 public ArgumentData()
 {
     Files   = new List <string>();
     Profile = new ConfigurationProfile();
 }
Exemplo n.º 9
0
        public void LoadProfile(string path)
        {
            IniData data = new IniData();
            if (!Path.HasExtension(path))
            {
                var storedprofile = Path.Combine(Globals.DefaultProfileDirectory, string.Concat(path, ".ini"));
                if (File.Exists(storedprofile))
                {
                    path = storedprofile;
                }
                else
                {
                    throw new FileNotFoundException("Relative profile not found.", storedprofile);
                }
            }
            else if (path.Equals(Globals.DefaultProfileFile) && !File.Exists(path))
            {
                // create if not exist
                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Log.LogMessage(string.Format("Profile directory not found. Creating profile directory..."));
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    Log.LogMessage(string.Format("Profile directory created at {0}", Path.GetDirectoryName(path)));
                }
                Log.LogMessage(string.Format("Default profile does not exist. Creating new default profile in {0}...", path));
                data.Sections.AddSection("Profile");
                data["Profile"].AddKey("Hostname");
                data["Profile"].AddKey("Username");
                data["Profile"].AddKey("Password");
                data["Profile"].AddKey("Encryption");
                data["Profile"].AddKey("EncryptionImplicit");
                data["Profile"].AddKey("ForceEncryption");
                data["Profile"].AddKey("RemoteDir");
                data["Profile"].AddKey("Mode");
                data["Profile"].AddKey("ClipboardURL");
                data["Profile"].AddKey("ClipboardEnabled");
                data["Profile"].AddKey("SshHostKey");
                data["Profile"].AddKey("Soundfile");
                data["Profile"].AddKey("SoundEnabled");
                parser.SaveFile(path, data);
                Log.LogMessage("Default profile created.");
                Console.WriteLine("Default profile created. You'll probably want to edit credentials. Program will now exit.");
                Environment.Exit(0);
            }
            else if (!File.Exists(path))
            {
                throw new FileNotFoundException("Profile not found.", Path.GetFullPath(path));
            }

            try
            {
                data = Load(path);
            }
            catch (ParsingException)
            {
                throw;
            }
            ConfigurationProfile profile = new ConfigurationProfile();
            try
            {
                Encryption = data["Profile"]["Encryption"];
                EncryptionImplicit = data["Profile"]["EncryptionImplicit"];
                ForceEncryption = data["Profile"]["ForceEncryption"];
                Hostname = data["Profile"]["Hostname"];
                Username = data["Profile"]["Username"];
                Password = data["Profile"]["Password"];
                RemoteDir = data["Profile"]["RemoteDir"];
                Mode = data["Profile"]["Mode"];
                ClipboardURL = data["Profile"]["ClipboardURL"];
                ClipboardEnabled = data["Profile"]["ClipboardEnabled"];
                SshHostKey = data["Profile"]["SshHostKey"];
                Soundfile = data["Profile"]["Soundfile"];
                SoundEnabled = data["Profile"]["SoundEnabled"];
            }
            catch (NullReferenceException)
            {
                throw new FileLoadException("Profile is corrupted.");
            }
        }
Exemplo n.º 10
0
 public void NotFoundProfileRelativePath()
 {
     var temp = new ConfigurationProfile();
     temp.LoadProfile(@"Phantom");
 }
Exemplo n.º 11
0
 public void NotFoundProfileAbsolutePath()
 {
     var temp = new ConfigurationProfile();
     temp.LoadProfile(Path.Combine(Path.GetTempPath(), "derp.ini"));
 }
Exemplo n.º 12
0
 public void IncorrectSchemaRelativePath()
 {
     var temp = new ConfigurationProfile();
     temp.LoadProfile(@"CorruptedProfile");
 }
Exemplo n.º 13
0
 public void IncorrectSchemaAbsolutePath()
 {
     var temp = new ConfigurationProfile();
     temp.LoadProfile(Path.Combine(Globals.DefaultProfileDirectory, @"CorruptedProfile"));
 }
Exemplo n.º 14
0
 public void CorrectSchemaRelativePath()
 {
     var temp = new ConfigurationProfile();
     temp.LoadProfile(@"BasicProfile");
 }