- source.zip
- CodeXchange Addin source
- CodeXchangeAddin.sln
- CodeXchangeAddin.suo
- Sand.Services.Codexchange.Client
- API
- Components
- Exceptions
- Interfaces
- bin
- Debug
- Sand.Services.CodeXchange.Client.dll
- Sand.Services.CodeXchange.Client.pdb
- CodeXChangeControl.cs
- CodeXChangeControl.resx
- Controls
- Forms
- Key.snk
- Misc
- obj
- Debug
- DesignTimeResolveAssemblyReferencesInput.cache
- GenerateResource-ResGen.read.1.tlog
- GenerateResource-ResGen.write.1.tlog
- Sand.Services.CodeXchange.Client.CodeXChangeControl.resources
- Sand.Services.CodeXchange.Client.Controls.ExplorerBar.resources
- Sand.Services.CodeXchange.Client.Controls.ExplorerGroup.resources
- Sand.Services.CodeXchange.Client.Controls.SnippetListView.resources
- Sand.Services.CodeXchange.Client.Controls.SourceCodeTextBox.resources
- Sand.Services.CodeXchange.Client.Controls.WhatsNewControl.resources
- Sand.Services.CodeXchange.Client.dll
- Sand.Services.CodeXchange.Client.LoginForm.resources
- Sand.Services.CodeXchange.Client.pdb
- Sand.Services.CodeXchange.Client.PreviewCodeForm.resources
- Sand.Services.CodeXchange.Client.SettingsForm.resources
- Sand.Services.CodeXchange.Client.SnippetAddForm.resources
- Sand.Services.CodeXchange.Client.SnippetCommentsForm.resources
- Sand.Services.CodeXchange.Client.SnippetRating.resources
- Sand.Services.CodeXchange.Client2005.csproj.FileListAbsolute.txt
- TempPE
- Web References.CodeXchangeService.Reference.cs.dll
- Properties
- Providers
- Sand.Services.CodeXchange.Client.csproj
- Sand.Services.CodeXchange.Client2005.csproj
- Sand.Services.CodeXchange.Client2005.csproj.user
- UI
- Combos
- Controls
- Web References
- CodeXchangeService
- CodexchangeService.disco
- CodexchangeService.wsdl
- Comment.datasource
- Comment1.datasource
- Comment2.datasource
- Reference.cs
- Reference.map
- ServiceInfo.datasource
- ServiceInfo1.datasource
- Snippet.datasource
- Snippet1.datasource
- Stats.datasource
- Stats1.datasource
- Sand.Services.CodeXchange.VS2010Addin
- Temp
|
using System;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Sand.Services.CodeXchange.Client
{
/// <summary>
/// Summary description for CodeXchangeSettings.
/// </summary>
public sealed class CodeXchangeSettings
{
private static RegistryKey baseRegistryKey = Registry.LocalMachine;
private static string subKey = "SOFTWARE\\CodeXchange";
public static string UserName
{
get
{
string userData = Read("CodeXchange_Username");
if (UserInformationEncrypted)
return DataProtection.Decrypt(userData, DataProtection.Store.User);
return userData;
}
set
{
string userData = value;
if (UserInformationEncrypted)
userData = DataProtection.Encrypt(userData, DataProtection.Store.User);
Write("CodeXchange_Username", userData);
}
}
public static string Password
{
get
{
string userData = Read("CodeXchange_Password");
if (UserInformationEncrypted)
return DataProtection.Decrypt(userData, DataProtection.Store.User);
return userData;
}
set
{
string userData = value;
if (UserInformationEncrypted)
userData = DataProtection.Encrypt(userData, DataProtection.Store.User);
Write("CodeXchange_Password", userData);
}
}
public static bool PreviewCode {
get {
try {
return Boolean.Parse(Read("CodeXchange_PreviewCode"));
}
catch {
return false;
}
}
set { Write ("CodeXchange_PreviewCode" , value.ToString()); }
}
public static bool UseProxy
{
get {
try {
return Boolean.Parse(Read("CodeXchange_UseProxy"));
}catch{
return false;
}
}
set { Write ("CodeXchange_UseProxy" , value.ToString()); }
}
public static bool UserInformationEncrypted {
get {
try {
return Boolean.Parse(Read("CodeXchange_UserInformationEncrypted"));
}catch {
return false;
}
}
set { Write("CodeXchange_UserInformationEncrypted", value.ToString()); }
}
public static bool AutoLogin {
get {
try {
return Boolean.Parse(Read("CodeXchange_AutoLogin"));
}catch{
return true;
}
}
set { Write("CodeXchange_AutoLogin", value.ToString()); }
}
public static bool UseIEProxySettings
{
get {
try {
return Boolean.Parse(Read("CodeXchange_UseIEProxySettings"));
}catch{
return false;
}
}
set { Write ("CodeXchange_UseIEProxySettings" , value.ToString()); }
}
public static bool BypassProxyOnLocal
{
get {
try {
return Boolean.Parse(Read("CodeXchange_BypassProxyOnLocal"));
}catch{
return false;
}
}
set { Write ("CodeXchange_BypassProxyOnLocal" , value.ToString()); }
}
public static string ProxyBypassList
{
get { return Read("CodeXchange_ProxyBypassList");}
set { Write ("CodeXchange_ProxyBypassList" , value.ToString()); }
}
public static bool ProxyCustomCredentials
{
get {
try
{
return Boolean.Parse(Read("CodeXchange_ProxyCustomCredentials"));
}catch{ return false;}
}
set { Write ("CodeXchange_ProxyCustomCredentials" , value.ToString()); }
}
public static string ProxyAddress
{
get { return Read("CodeXchange_ProxyAddress"); }
set { Write ("CodeXchange_ProxyAddress" , value.ToString()); }
}
public static int ProxyPort
{
get {
try{
return Int32.Parse(Read("CodeXchange_ProxyPort"));
}catch{
return 8080;
}
}
set { Write ("CodeXchange_ProxyPort" , value.ToString()); }
}
public static string ProxyUser
{
get { return Read("CodeXchange_ProxyUser"); }
set { Write ("CodeXchange_ProxyUser" , value.ToString()); }
}
public static string ProxyPassword
{
get { return Read("CodeXchange_ProxyPassword"); }
set { Write ("CodeXchange_ProxyPassword" , value.ToString()); }
}
public static int SecurityEnvironment
{
get {
try{
return Int32.Parse(Read("CodeXchange_SecurityEnvironment"));
}catch{
return 0;
}
}
set { Write ("CodeXchange_SecurityEnvironment" , value.ToString()); }
}
private CodeXchangeSettings()
{
}
/// <summary>
/// To read a registry key.
/// input: KeyName (string)
/// output: value (string)
/// </summary>
private static string Read (string KeyName)
{
// Opening the registry key
RegistryKey rk = baseRegistryKey ;
// Open a subKey as read-only
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistrySubKey doesn't exist -> (null)
if ( sk1 == null )
{
return null;
}
else
{
try
{
// If the RegistryKey exists I get its value
// or null is returned.
return (string)sk1.GetValue(KeyName.ToUpper());
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
return null;
}
}
}
/* **************************************************************************
* **************************************************************************/
/// <summary>
/// To write into a registry key.
/// input: KeyName (string) , Value (object)
/// output: true or false
/// </summary>
private static bool Write(string KeyName, object Value)
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
// I have to use CreateSubKey
// (create or open it if already exits),
// 'cause OpenSubKey open a subKey as read-only
RegistryKey sk1 = rk.CreateSubKey(subKey);
// Save the value
sk1.SetValue(KeyName.ToUpper(), Value);
return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Writing registry " + KeyName.ToUpper());
return false;
}
}
private static void ShowErrorMessage (Exception e, string Title)
{
MessageBox.Show(
e.Message
,Title
,MessageBoxButtons.OK
,MessageBoxIcon.Error);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Hi! I'm 22 years old. I live in a sunny mediterranian city called Barcelona.
I am a big fan of .NET and have been working with c# for a few years now.