Commits

HexRx committed 3a6fd90

Added DropboxClientProxy.cs to hg

Comments (0)

Files changed (1)

KPDataSave/DropboxClientProxy.cs

+/*
+    KPDataSave - KeePass plugin which saves database in Dropbox service
+    Copyright (C) 2011-2014 HexRx
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Text;
+using KeePass;
+using KeePassLib;
+
+namespace KPDataSave
+{
+    class DropboxClientProxy : DropboxAPI.DropboxClient
+    {
+        public DropboxClientProxy(string appKey, string appSecret)
+            : base(appKey, appSecret)
+        {
+            Proxy = GetProxyConfig();
+        }
+
+        public DropboxClientProxy(string appKey, string appSecret, string accessToken, string accessTokenSecret)
+            : base(appKey, appSecret, accessToken, accessTokenSecret)
+        {
+            Proxy = GetProxyConfig();
+        }
+
+        private IWebProxy GetProxyConfig()
+        {
+            var integration = Program.Config.Integration;
+            if (integration.ProxyType == ProxyServerType.Manual)
+            {
+                return new WebProxy(integration.ProxyAddress, Convert.ToInt32(integration.ProxyPort))
+                    {
+                        Credentials = new NetworkCredential(integration.ProxyUserName, integration.ProxyPassword)
+                    };
+            }
+            // Системные настройки прокси
+            if (integration.ProxyType == ProxyServerType.System)
+            {
+                return WebRequest.DefaultWebProxy;
+            }
+            return null;
+        }
+    }
+}