Esempio n. 1
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                CookieAwareWebClient client = new CookieAwareWebClient(this.Cookies);
                client.Headers["Content-type"] = "application/xml; charset=utf-8";
                string xml = WeiXinClientUtil.GetPostXmlToWeiXinGZH(this.txtMessage.Text);
                byte[] baData = Encoding.UTF8.GetBytes(xml);
                byte[] result = client.UploadData(this.url,
                    "POST",
                    baData);
                string strResult = Encoding.UTF8.GetString(result);
                this.txtResult.Text = strResult;

                // 将焦点设回输入框
                this.lblMessage.Text = "您刚才发的消息是[" + this.txtMessage.Text + "]";
                this.txtMessage.Text = "";

                this.txtMessage.Focus();
            }
            catch (Exception ex)
            {
                this.txtResult.Text="Exception :" + ex.Message;
            }
        }
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            string userName = this.UserNameBox.Text;
            string password = this.PasswordBox.Password;

            using (var webClient = new CookieAwareWebClient())
            {
                try
                {
                    NameValueCollection collection = new NameValueCollection
                    {
                        {"UserName", userName},
                        {"Password", password}
                    };

                    webClient.UploadValues("https://judge.softuni.bg/Account/Login", "POST", collection);

                    
                    string result = webClient.DownloadString("https://judge.softuni.bg/Contests/Compete/Results/Simple/104");

                }
                catch (WebException webException)
                {
                    MessageBox.Show(webException.Status.ToString());
                }
            }

           var jugdeInformationGetter = new JugdeInformationCollector();
           this.Close();
           jugdeInformationGetter.ShowDialog();

        }
		WebClient GetWebClient(IEnumerable<KeyValuePair<string, string>> headers = null, bool isCacheable = false, bool isSsoCheck = false)
		{
			CookieAwareWebClient webClient;
			if (isCacheable)
				webClient = new CookieAwareCacheableWebClient(cookies);
			else if (isSsoCheck)
				webClient = new SsoWebClient(cookies);
			else
				webClient = new CookieAwareWebClient(cookies);

			if (connectionInfo.AuthType == AuthorizationType.ApiKey)
				webClient.Headers.Add("ZSESSIONID", connectionInfo.ApiKey);
			else if (connectionInfo.AuthType == AuthorizationType.ZSessionID)
				webClient.AddCookie(connectionInfo.Server, "ZSESSIONID", connectionInfo.ZSessionID);

			webClient.Encoding = Encoding.UTF8;
			if (headers != null)
			{
				foreach (var pairs in headers)
					webClient.Headers.Add(pairs.Key, pairs.Value);
			}

			if (credentials != null)
				webClient.Credentials = credentials;
			if (connectionInfo.Proxy != null)
				webClient.Proxy = connectionInfo.Proxy;
			return webClient;
		}
Esempio n. 4
0
 public FileDownloader(string URI, string DestinationFile)
     : base()
 {
     _URI = URI;
     _DestinationFile = DestinationFile;
     _downloader = null;
 }
Esempio n. 5
0
 public TwitchWeb(String user, String password)
 {
     loginWC = new CookieAwareWebClient();
     User = user;
     Password = password;
     GameList = new List<KeyValuePair<string, string>>();
 }
Esempio n. 6
0
        public string InternalRFBGetCaptchaCNPJ()
        {
            try
            {
                var wc = new CookieAwareWebClient();
                wc.Headers["user-agent"] = UserAgent;
                var arrBytes = wc.DownloadData(AddressBase + AddressCaptchaCNPJ);
                var x = new HtmlDocument();
                x.LoadHtml(Encoding.UTF8.GetString(arrBytes));
                var image = x.GetElementbyId("imgcaptcha").GetAttributeValue("src", "");
                var viewstate = (string) null; // x.GetElementbyId("viewstate").GetAttributeValue("value", "");
                image = AddressBase + "/pessoajuridica/cnpj/cnpjreva/" + image.Replace("&amp;", "&");
                var bytes = wc.DownloadData(image);
                var filename = Guid.NewGuid() + ".jpg";
                var path = Server.MapPath("~\\temp\\" + filename);
                if (!Directory.Exists(Path.GetDirectoryName(path)))
                    Directory.CreateDirectory(Path.GetDirectoryName(path));

                System.IO.File.WriteAllBytes(path, bytes);
                Session["GetCNPJViewState"] = viewstate;
                Session["GetCNPJCookies"] = wc.CookieContainer;

                return VirtualPathUtility.ToAbsolute("~/temp/" + filename);
            }
            catch (Exception)
            {
                return null;
            }
        }
Esempio n. 7
0
 public JetSetPro(string user, string password)
 {
     loginLock = new object();
     loginWC = new CookieAwareWebClient();
     _user = user;
     _password = password;
     serializer = new PHPSerializer();
 }
Esempio n. 8
0
        public UrlFetcher(Encoding fallbackEncoding)
        {
            _fallbackEncoding = fallbackEncoding ?? _DefaultFallbackEncoding;

              _webClient = new CookieAwareWebClient();
              _webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1");
              _webClient.Headers.Add("Accept-Encoding", "gzip,deflate");
        }
Esempio n. 9
0
 public override void Download()
 {
     using (_downloader = new CookieAwareWebClient())
     {
         AddHandlers();
         _downloader.DownloadFileAsync(new Uri(_URI, UriKind.Absolute ), _DestinationFile);
     }
 }
Esempio n. 10
0
        public Twitch(string channelName)
        {
            currentChannelName = channelName;

            statsWC = new CookieAwareWebClient();
            statsWC.Headers["User-Agent"] = userAgent;
            statsDownloader = new Timer(new TimerCallback(statsDownloader_Tick), null, Timeout.Infinite, Timeout.Infinite);
        }
Esempio n. 11
0
        public UrlFetcher(Encoding fallbackEncoding)
        {
            _fallbackEncoding = fallbackEncoding ?? _DefaultFallbackEncoding;

              _webClient = new CookieAwareWebClient();
              _webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
              _webClient.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
              _webClient.Headers.Add("Accept-Encoding", "gzip,deflate");
        }
Esempio n. 12
0
        public Twitch(string channelName)
        {
            currentChannelName = channelName;

            wc = new CookieAwareWebClient();
            wc.Headers["User-Agent"] = userAgent;
            CrawlTwitchChannel(currentChannelName);
            bwDownloader = new Timer(new TimerCallback(bwDownloader_Tick), null, 0, 20000);
        }
Esempio n. 13
0
 public WebPollChat()
 {
     chatPollTimer = new Timer( timerPollChatTick, null, Timeout.Infinite, Timeout.Infinite );
     lockChatDownload = new object();
     Headers = new WebHeaderCollection();
     ChatPollPeriod = 10000;
     Method = RequestMethod.GET;
     chatWC = new CookieAwareWebClient();
 }
Esempio n. 14
0
        public SecureWebPage(String loginUrl, NameValueCollection loginParameters, WebHeaderCollection headers)
        {
            _client = new CookieAwareWebClient();

            //perform the login so our webclient is authenticated
            ServicePointManager.Expect100Continue = false;
            _client.Headers = headers;
            _client.UploadValues(loginUrl, loginParameters);
        }
Esempio n. 15
0
        public Hashd(string login, string password)
        {
            _login = login;
            _password = password;
            statsWC = new CookieAwareWebClient();
            loginWC = new CookieAwareWebClient();
            statsDownloader = new Timer(new TimerCallback(statsDownloader_Tick), null, Timeout.Infinite, Timeout.Infinite);
            pingTimer = new Timer(new TimerCallback(pingTimer_Tick), null, Timeout.Infinite, Timeout.Infinite);

        }
 WebClient GetWebClient(IEnumerable<KeyValuePair<string, string>> headers = null)
 {
     var webClient = new CookieAwareWebClient(cookies);
     webClient.Encoding = Encoding.UTF8;
     if (headers != null)
         foreach (var pairs in headers)
             webClient.Headers.Add(pairs.Key, pairs.Value);
     if (credentials != null)
         webClient.Credentials = credentials;
     if (connectionInfo.proxy != null)
         webClient.Proxy = connectionInfo.proxy;
     return webClient;
 }
Esempio n. 17
0
        public UrlFetcher(Encoding fallbackEncoding)
        {
            _fallbackEncoding = fallbackEncoding ?? _DefaultFallbackEncoding;

              _webClient = new CookieAwareWebClient();
              _webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0");
              _webClient.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml");
              _webClient.Headers.Add("Accept-Language", "en-US,en");
              _webClient.Headers.Add("Accept-Encoding", "gzip,deflate");
              _webClient.Headers.Add("Cache-Control", "no-cache");
              _webClient.Headers.Add("Pragma", "no-cache");
              _webClient.Headers.Add("Referer", "https://www.google.com/"); // may help with certain pay walls
        }
 public SitecoreConnectionManager(ISitecoreConnectionSettings model, CookieAwareWebClient client)
 {
     if (model == null) { throw new ArgumentNullException("model"); }
     this.Model = model;
     if (client == null)
     {
         client = new CookieAwareWebClient(null);
     }
     this.Client = client;
     this.BaseUrl = new Uri(model.ClientUrl, UriKind.Absolute);
     this.LoginUrl = new Uri(this.BaseUrl + "/admin/login.aspx");
     this.GetConfigUrl = new Uri(this.BaseUrl + "/admin/showconfig.aspx");
     this.GetVersionUrl = new Uri(this.BaseUrl + "/shell/sitecore.version.xml");
 }
        public void DownloadSub(string path, string downloadUrl)
        {
            var subdivxClient = new CookieAwareWebClient(this.loginCookies);
            subdivxClient.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))";

            var directory = Path.GetDirectoryName(path);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            subdivxClient.DownloadFile(downloadUrl, path);
        }
Esempio n. 20
0
        static void Main()
        {
            var client = new CookieAwareWebClient();
            client.BaseAddress = @"http://bgcoder.com";
            var loginData = new NameValueCollection();
            loginData.Add("UserName", username);
            loginData.Add("Password", password);
            client.UploadValues("/Account/LogOn", "POST", loginData);
 
            string htmlSource = client.DownloadString("Contest/ContestResults/" + numberOfContest);
 
            int[] grades = ExtractGrades(htmlSource);
 
            WriteToConsole(htmlSource, grades);
        }      
Esempio n. 21
0
        public YouTube(string videoId, string lastTime)
        {
            statsWC = new CookieAwareWebClient();
            chatWC = new CookieAwareWebClient();
            chatWC.Encoding = new System.Text.UTF8Encoding(false);
            loginWC = new CookieAwareWebClient();
            loginWC.Encoding = new System.Text.UTF8Encoding(false);

            channelId = videoId;
            LastTime = lastTime;
            viewers = 0;
            
            statsDownloader = new Timer(new TimerCallback(statsDownloader_Tick), null, Timeout.Infinite, Timeout.Infinite);
            chatDownloader = new Timer(new TimerCallback(chatDownloader_Tick), null, Timeout.Infinite, Timeout.Infinite);

        }
Esempio n. 22
0
        /// <summary>
        /// Submits data to a website via POST
        /// </summary>
        /// <param name="url">The URL to POST to</param>
        /// <param name="collection">The data to be POSTed</param>
        /// <returns></returns>
        public async Task<string> PostData(string url, NameValueCollection collection)
        {
            if (this.p_Cookies == null)
                this.p_Cookies = new CookieContainer();

            byte[] response = null;

            using (CookieAwareWebClient client = new CookieAwareWebClient(this.p_Cookies))
            {
                client.Method = "POST";

                response = await client.UploadValuesTaskAsync(url, collection);
            }

            return Encoding.UTF8.GetString(response);
        }
		private CookieAwareWebClient GetWebClient()
		{
			CookieAwareWebClient webClient = new CookieAwareWebClient(Cookies);

			foreach (string key in webClient.Headers.Keys)
				webClient.Headers.Add(key, webClient.Headers[key]);

			webClient.Encoding = Encoding;
			webClient.Credentials = Credentials;

			if (Proxy != null)
			{
				webClient.Proxy = Proxy;
			}

			return webClient;
		}
Esempio n. 24
0
        public Admin()
        {
            log.Debug("Initialise Admin client.");
            client = new CookieAwareWebClient();
            client.BaseAddress = "http://www.hoisinhvien.net/forum/";
            client.Headers.Add("Content-Type: application/x-www-form-urlencoded");
            //client.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5");
            client.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64)");
            client.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            client.Headers.Add("Accept-Encoding: identity");
            client.Headers.Add("Accept-Language: en-US,en;q=0.8");
            client.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");

            // load Spams database
            log.Debug("Loading spams database ...");
            LoadSpamsDatabase();
        }
Esempio n. 25
0
        public qWebIrc()
        {
            stop = false;
            PingTimeout = PING_TIMEOUT;
            PingInterval = PING_INTERVAL;
            lockWC = new object();
            lockSend = new object();
            CachePrevent = random_string();
            ActionIndex = 0;
            wc = new CookieAwareWebClient();
            wcSend = new CookieAwareWebClient();

            timerIRCQuery = new Timer(timerQueryTick, null, Timeout.Infinite, Timeout.Infinite);
            timerPingTimeout = new Timer(timerPingTimeoutTick, null, Timeout.Infinite, Timeout.Infinite);
            timerPing = new Timer(timerPingTick, null, Timeout.Infinite, Timeout.Infinite);
            
        }
Esempio n. 26
0
		private static CookieAwareWebClient Login(string baseUrl, string login, string password)
		{
			var signinUrl = baseUrl + "/Login";
			var loginUrl = baseUrl + "/Login";
			var client = new CookieAwareWebClient();

			var rvToken = GetRequestVerificationToken(client, signinUrl);
			client.UploadValues(loginUrl, new NameValueCollection
			{
				{ "UserName", login },
				{ "Password", password },
				{ "RememberMe", "false" },
				{ rvTokenSignal, rvToken }
			});

			return client;
		}
Esempio n. 27
0
		private static string TryUpload(CookieAwareWebClient client, string uploadUrl, byte[] nfile)
		{
			try
			{
				return Encoding.UTF8.GetString(client.UploadData(uploadUrl, "POST", nfile));
			}
			catch (WebException e)
			{
				var response = e.Response.GetResponseStream().GetString();
				Console.WriteLine("Upload failed");
				Console.WriteLine(uploadUrl);
				Console.WriteLine(e.Message);
				File.WriteAllText("errorResponse.html", response);
				Console.WriteLine("Error details in errorResponse.html");
				throw new OperationFailedGracefully();
			}
		}
Esempio n. 28
0
		private static CookieAwareWebClient LogIn(string baseUrl, string email, string password)
		{
			var signinUrl = string.Format("{0}/signin", baseUrl);
			var loginUrl = string.Format("{0}/login_post", baseUrl);
			var client = new CookieAwareWebClient();
			client.DownloadData(signinUrl);

			var response = JsonConvert.DeserializeObject<dynamic>(Encoding.UTF8.GetString(client.UploadValues(loginUrl, new NameValueCollection
			{
				{ "email", email },
				{ "password", password }
			})));
			if (response.success.ToObject<bool>())
				return client;
			Console.WriteLine("Login failed:");
			Console.WriteLine(response.value.ToObject<string>());
			throw new OperationFailedGracefully();
		}
Esempio n. 29
0
        public Goodgame( string user, string password, bool loadHistory = false )
        {
            loginWC = new CookieAwareWebClient();
            statsWC = new CookieAwareWebClient();
            chatWC = new CookieAwareWebClient();

            _loadHistory = loadHistory;
            _chatId = -1;
            _userId = -1;
            _userToken = null;
            _user = user;
            _password = password;
            viewers = 0;
            FlashViewers = "0";
            GameList = new List<KeyValuePair<string, string>>();
            statsDownloader = new Timer(new TimerCallback(statsDownloader_Tick), null, Timeout.Infinite, Timeout.Infinite);
            restartTimer = new Timer(restartTimer_Tick, null, Timeout.Infinite, Timeout.Infinite);

        }
Esempio n. 30
0
 Task <bool> ILoader.PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
 {
     return(Task.FromResult(true));
 }
    static void Main()
    {
        try{
            String[] configs       = File.ReadAllText(Directory.GetCurrentDirectory() + @"/configs.csv").Split(',');
            var      email         = configs[0];
            var      password      = configs[1];
            var      finalLocation = configs[2];
            var      smtpUser      = configs[3];
            var      smtpPass      = configs[4];
            var      alertEmail    = configs[5];
            var      phone         = configs[6];

            var location = Directory.GetCurrentDirectory() + "/";

            //Json copy pasted from a "get all" request to MISO's api
            var json = "{\"QueryValues\":{\"rctype\":\"Load Pocket Report\"},\"NavigationItem\":{\"ParentPropertyValue\":\"Load Pocket Report\",\"ChildPropertySystemName\":null,\"DisplayResultInGrid\":false,\"GridMetadataColumns\":[],\"ResultSortField\":null,\"ResultSortDirection\":null,\"UseDynamicChoiceMode\":null,\"UseDynamicDateNavigation\":false,\"UseDynamicYearNavigation\":false,\"UseDynamicQuarterNavigation\":false,\"UseDynamicMonthNavigation\":false,\"UseDynamicDayNavigation\":false,\"ChildDocumentNavigationItems\":null,\"Title\":\"\",\"Summary\":\"<p><a title=\\\"MISO Load Pocket Report Readers Guide\\\" href=\\\"/api/documents/getbyguid/c35f6b50-fdc2-5742-bd3c-cf185c23ee57\\\">MISO Load Pocket Report Readers Guide</a></p>\",\"LoadedNavigableDocuments\":[{\"FileName\":\"Load_Pocket_20171121.zip\",\"Name\":\"Load Pocket 20171121\",\"Url\":\"/api/documents/getbymediaid/129294\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129294,\"Uploaded\":\"2018-02-26T19:42:50Z\",\"UploadedBy\":34,\"ObjectId\":137504,\"Created\":\"2018-02-26T19:43:06Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:10Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"221e5d05-c71b-5d66-996c-d9c22d10437c\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171122.zip\",\"Name\":\"Load Pocket 20171122\",\"Url\":\"/api/documents/getbymediaid/129295\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129295,\"Uploaded\":\"2018-02-26T19:42:56Z\",\"UploadedBy\":34,\"ObjectId\":137505,\"Created\":\"2018-02-26T19:43:12Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:15Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"e3aaf099-2679-5c51-a1d3-5d309a0447be\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171123.zip\",\"Name\":\"Load Pocket 20171123\",\"Url\":\"/api/documents/getbymediaid/129233\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129233,\"Uploaded\":\"2018-02-26T19:27:55Z\",\"UploadedBy\":34,\"ObjectId\":137443,\"Created\":\"2018-02-26T19:28:11Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:17Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"018ab122-2ac6-52cc-a241-9f033d9b5143\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171124.zip\",\"Name\":\"Load Pocket 20171124\",\"Url\":\"/api/documents/getbymediaid/129234\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129234,\"Uploaded\":\"2018-02-26T19:28:05Z\",\"UploadedBy\":34,\"ObjectId\":137444,\"Created\":\"2018-02-26T19:28:21Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:27Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"f026d520-5e27-51c1-9858-a08fea7fefdd\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171125.zip\",\"Name\":\"Load Pocket 20171125\",\"Url\":\"/api/documents/getbymediaid/129235\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129235,\"Uploaded\":\"2018-02-26T19:28:16Z\",\"UploadedBy\":34,\"ObjectId\":137445,\"Created\":\"2018-02-26T19:28:31Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:38Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"2f4ae535-4c20-57b1-9060-c63a5298229b\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171126.zip\",\"Name\":\"Load Pocket 20171126\",\"Url\":\"/api/documents/getbymediaid/129296\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129296,\"Uploaded\":\"2018-02-26T19:43:02Z\",\"UploadedBy\":34,\"ObjectId\":137506,\"Created\":\"2018-02-26T19:43:18Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:21Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"7763eb39-3bd5-53da-a29a-91be0327d7e2\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171127.zip\",\"Name\":\"Load Pocket 20171127\",\"Url\":\"/api/documents/getbymediaid/129297\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129297,\"Uploaded\":\"2018-02-26T19:43:08Z\",\"UploadedBy\":34,\"ObjectId\":137507,\"Created\":\"2018-02-26T19:43:24Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:27Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"eb27d73c-aa3a-5820-98c8-23fd308d5d18\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171128.zip\",\"Name\":\"Load Pocket 20171128\",\"Url\":\"/api/documents/getbymediaid/129236\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129236,\"Uploaded\":\"2018-02-26T19:28:26Z\",\"UploadedBy\":34,\"ObjectId\":137446,\"Created\":\"2018-02-26T19:28:42Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:47Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"1e6b4040-2c1b-538f-8091-82f51514dcd4\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171129.zip\",\"Name\":\"Load Pocket 20171129\",\"Url\":\"/api/documents/getbymediaid/129237\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129237,\"Uploaded\":\"2018-02-26T19:28:36Z\",\"UploadedBy\":34,\"ObjectId\":137447,\"Created\":\"2018-02-26T19:28:51Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:57Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"c9e3df76-6555-5ba6-8f1a-a1476c7a5a1f\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171130.zip\",\"Name\":\"Load Pocket 20171130\",\"Url\":\"/api/documents/getbymediaid/129298\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129298,\"Uploaded\":\"2018-02-26T19:43:14Z\",\"UploadedBy\":34,\"ObjectId\":137508,\"Created\":\"2018-02-26T19:43:30Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:33Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"48c75229-1268-5621-8353-57cc4e89cad6\",\"accesstype\":\"Visitors-RA\"}}],\"TotalAvailableResults\":98},\"Filters\":[{\"PropertyName\":\"rctype\",\"Value\":\"\"}],\"EnableFollowDocuments\":null,\"Top\":null,\"Skip\":10}";

            //Stops from running if files for the current date already exist
            if (FileCheck.Check(finalLocation))
            {
                return;
            }

            var webClient = new CookieAwareWebClient();


            var collection = new NameValueCollection();
            collection.Add("Email", email);
            collection.Add("Password", password);



            Console.Write("Attempting to log in to MISO website... \n");
            webClient.Login("https://www.misoenergy.org/Account/Login", collection);

            //Post JSON using cookie authenticated client and JSON from standard request
            Console.Write("Acquiring document list from MISO... \n");
            var response = webClient.PostPage("https://www.misoenergy.org/api/documents/getnavigabledocuments", json);

            //Parse the response JSON
            JObject parsedResponse = JObject.Parse(response);
            var     list           = parsedResponse["documents"].OrderByDescending(t => t["FileName"]).ToList();
            var     single         = list.FirstOrDefault();
            var     url            = "https://www.misoenergy.org" + single["Url"];
            var     filename       = single["FileName"].ToString();

            //Make sure that the load pocket file that is the "latest" is from the current date.
            if (filename != "Load_Pocket_" + DateTime.Now.ToString("yyyyMMdd") + ".zip")
            {
                throw new Exception("The current load pocket file is not from the current date.");
            }

            //Download zip file, store temporarily in location and the extract to finalLocation before deleting zip from location
            webClient.GetFileAndMove(url, filename, location, finalLocation);


            //Used to send alert on working instance
            if (FileCheck.Check(finalLocation))
            {
                Console.Write("Attempting to send email notifications... \n");
                MailHelper.SendAlert(smtpUser, smtpPass, alertEmail, phone);
            }

            Console.Write(filename + " was extracted to " + finalLocation + "");
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }
Esempio n. 32
0
 public Task DownloadAsync(CookieAwareWebClient client, string destination, IProgress <double> progress, CancellationToken cancellation)
 {
     return(DownloadAsync(client, destination, cancellation));
 }
        /// <summary>
        /// Logins into PonAuth, only works if the WebClient has valid Poniverse cookies
        /// </summary>
        private static void LoginPonauth(string poniverse_oauth, CookieAwareWebClient c = null)
        {
            string url = GetPonauthUrl(poniverse_oauth, c);

            SendPonauthUrl(url, c);
        }
        /// <summary>
        /// Logs the user in CanterlotAvenue
        /// </summary>
        public static PoniverseUser Login(string user, string pass, bool remember = false, CookieAwareWebClient c = null)
        {
            if (c == null)
            {
                c = new CookieAwareWebClient();
            }

            c.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.97 Safari/537.36 Vivaldi/1.94.1008.34");
            string result = "";

            try
            {
                byte[] res = c.UploadValues("https://poniverse.net/login", "POST", new NameValueCollection()
                {
                    { "username", user },
                    { "password", pass },
                    { "rememberme", remember ? "1" : "0" },
                    { "submit", "" },
                    { "_token", GetToken(c) }
                });
                result = Encoding.Default.GetString(res);
                PoniverseUser u = new PoniverseUser(ExtractUser(result));

                //Other auth data
                AuthData d = GetAuthData(c);
                LoginPonauth(d.url, c);

                return(u);
            }
            catch (WebException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Response.ContentType);

                return(null);
            }
        }
Esempio n. 35
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            // кнопку "авторизоваться" делаем неактивную
            button.IsEnabled = false;


            label.Content = "Идёт авторизация... подождите...";
            try
            {
                //если поле для логина было пустое
                if (string.IsNullOrWhiteSpace(textBox.Text.ToString()))
                {
                    MessageBox.Show("Введите логин!!!"); button.IsEnabled = true; return;
                }
                //если текст в поле для логина менее 4 символов
                else if (textBox.Text.ToString().Length < 4)
                {
                    MessageBox.Show("Введите корректный логин!!!"); button.IsEnabled = true; return;
                }
                //если текст в поле для пароля пустое
                else if (string.IsNullOrWhiteSpace(passwordBox.Password.ToString()))
                {
                    MessageBox.Show("Пароль!!!"); button.IsEnabled = true; return;
                }
                //если текст в поле для пароля менее 4 символов
                else if (passwordBox.Password.ToString().Length < 4)
                {
                    MessageBox.Show("Введите корректный пароль!!!"); button.IsEnabled = true; return;
                }

                // если всё ок, то создаем аналог HttpWenRequest в awesomium
                using (var client = new CookieAwareWebClient())
                {
                    // используем кодировку сайта UTF8
                    client.Encoding = Encoding.UTF8;

                    //передаем в post запросе логин и пароль от сайта catpost
                    var values = new NameValueCollection
                    {
                        { "submitted2", "1" },
                        { "username", textBox.Text.ToString() },
                        { "password", passwordBox.Password.ToString() }
                    };
                    // отправляем post Запрос
                    client.UploadValues("https://tomnolane.ru/index.html", values);

                    string html = client.DownloadString("https://tomnolane.ru/login-home.php");

                    // правильная html страница должна содержать строку: Меню управления CatPost (если авторизация прошла успешно)
                    if (html.Contains("Меню управления CatPost"))
                    {
                        if (html.Contains("Пополните счёт"))
                        {
                            MessageBox.Show("У вас закончились оплаченные дни.");
                            label.Content    = "У вас закончись оплаченные дни.\nЗайдите в свой личный кабинет на сайте https://tomnolane.ru/ \nи пополните баланс.";
                            label.Foreground = Brushes.Red;
                            button.IsEnabled = true;
                            return;
                        }

                        label.Content          = "Успешно авторизовались.";
                        label.Foreground       = Brushes.Black;
                        textBox.Visibility     = Visibility.Hidden;
                        passwordBox.Visibility = Visibility.Hidden;
                        button.Visibility      = Visibility.Hidden;
                        label_login.Visibility = Visibility.Hidden;
                        label_pass.Visibility  = Visibility.Hidden;
                        main.authorized        = true;
                        Hide();
                    }
                    // если при авторизации был введен неверный логин или пароль
                    else
                    {
                        MessageBox.Show("Авторизация не удалась.\nПроверьте правильность ввода логина и пароля.");
                        label.Content    = "Авторизация не удалась.\nПроверьте правильность ввода логина и пароля.";
                        label.Foreground = Brushes.Red;
                        button.IsEnabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка: " + ex.Message);
                label.Content    = "Ошибка: " + ex.Message;
                label.Foreground = Brushes.Red;
                button.IsEnabled = true;
            }
        }
Esempio n. 36
0
 public WebClientAdapter()
 {
     webclient = new CookieAwareWebClient();
 }
Esempio n. 37
0
        private async Task <string> DownloadResumeSupportAsync([NotNull] CookieAwareWebClient client,
                                                               [NotNull] FlexibleLoaderGetPreferredDestinationCallback getPreferredDestination,
                                                               [CanBeNull] FlexibleLoaderReportDestinationCallback reportDestination, [CanBeNull] Func <bool> checkIfPaused,
                                                               IProgress <long> progress, CancellationToken cancellation)
        {
            // Common variables
            string filename = null, selectedDestination = null, actualFootprint = null;
            Stream remoteData = null;

            var resumeSupported = ResumeSupported;

            try {
                // Read resume-related data and remove it to avoid conflicts
                var resumeDestination             = CacheStorage.Get <string>(_keyDestination);
                var resumePartiallyLoadedFilename = CacheStorage.Get <string>(_keyPartiallyLoadedFilename);
                var resumeLastWriteDate           = CacheStorage.Get <DateTime?>(_keyLastWriteDate);
                var resumePreviousFootprint       = CacheStorage.Get <string>(_keyFootprint);
                ClearResumeData();

                // Collect known information for destination callback
                var information = FlexibleLoaderMetaInformation.FromLoader(this);

                // Opening stream to read…
                var headRequest = HeadRequestSupported && resumeDestination != null;
                using (headRequest ? client.SetMethod("HEAD") : null) {
                    Logging.Warning($"Initial request: {(headRequest ? "HEAD" : "GET")}");
                    remoteData = await client.OpenReadTaskAsync(Url);
                }

                cancellation.ThrowIfCancellationRequested();

                // Maybe we’ll be lucky enough to load the most accurate data
                if (client.ResponseHeaders != null)
                {
                    if (long.TryParse(client.ResponseHeaders[HttpResponseHeader.ContentLength] ?? "",
                                      NumberStyles.Any, CultureInfo.InvariantCulture, out var length))
                    {
                        TotalSize = information.TotalSize = length;
                    }

                    if (TryGetFileName(client.ResponseHeaders, out var fileName))
                    {
                        FileName = information.FileName = fileName;
                    }

                    // For example, Google Drive responds with “none” and yet allows to download file partially,
                    // so this header will only be checked if value is not defined.
                    if (resumeSupported == null)
                    {
                        var accept = client.ResponseHeaders[HttpResponseHeader.AcceptRanges] ?? "";
                        if (accept.Contains("bytes"))
                        {
                            resumeSupported = true;
                        }
                        else if (accept.Contains("none"))
                        {
                            resumeSupported = false;
                        }
                    }

                    client.LogResponseHeaders();
                }

                // Was the file partially loaded before?
                var partiallyLoaded = ResumeSupported != false && resumePartiallyLoadedFilename != null
                        ? new FileInfo(FileUtils.EnsureFilenameIsValid(resumePartiallyLoadedFilename)) : null;
                if (partiallyLoaded != null)
                {
                    Logging.Warning("Not finished: " + partiallyLoaded);
                }

                // Does it still exist
                if (partiallyLoaded?.Exists != true)
                {
                    Logging.Warning($"Partially downloaded file “{partiallyLoaded?.FullName}” does not exist");
                    partiallyLoaded = null;
                }

                // If so, wasn’t it changed since the last time?
                if (partiallyLoaded?.LastWriteTime > resumeLastWriteDate + TimeSpan.FromMinutes(5))
                {
                    Logging.Warning($"Partially downloaded file is newer that it should be: {partiallyLoaded.LastWriteTime}, expected: {resumeLastWriteDate}");
                    partiallyLoaded = null;
                }

                // Looks like file is partially downloaded, but let’s ensure link still leads to the same content
                actualFootprint = GetFootprint(information, client.ResponseHeaders);
                if (partiallyLoaded != null && resumePreviousFootprint != actualFootprint)
                {
                    Logging.Warning($"Footprints don’t match: {resumePreviousFootprint}≠{actualFootprint}");
                    partiallyLoaded = null;
                }

                // Let’s check where to load data, which is potentially the most actual data at this point
                var destination = getPreferredDestination(Url, information);
                selectedDestination = destination.Filename;
                if (partiallyLoaded != null && (!destination.CanResumeDownload || !FileUtils.ArePathsEqual(selectedDestination, resumeDestination)))
                {
                    Logging.Warning($"Different destination chosen: {selectedDestination} (before: {resumeDestination})");
                    partiallyLoaded = null;
                }

                // TODO: Check that header?

                // Where to write?
                // ReSharper disable once MergeConditionalExpression
                filename = partiallyLoaded != null ? partiallyLoaded.FullName : FileUtils.EnsureUnique(true, destination.Filename);
                reportDestination?.Invoke(filename);

                // Set cancellation token
                cancellation.Register(o => client.CancelAsync(), null);

                // Open write stream
                if (partiallyLoaded != null)
                {
                    var rangeFrom = partiallyLoaded.Length;
                    using (client.SetRange(new Tuple <long, long>(rangeFrom, -1))) {
                        Logging.Warning($"Trying to resume download from {rangeFrom} bytes…");

                        remoteData.Dispose();
                        remoteData = await client.OpenReadTaskAsync(Url);

                        cancellation.ThrowIfCancellationRequested();
                        client.LogResponseHeaders();

                        // It’s unknown if resume is supported or not at this point
                        if (resumeSupported == null)
                        {
                            var bytes      = new byte[16];
                            var firstBytes = await remoteData.ReadAsync(bytes, 0, bytes.Length);

                            cancellation.ThrowIfCancellationRequested();

                            if (CouldBeBeginningOfAFile(bytes))
                            {
                                using (var file = File.Create(filename)) {
                                    Logging.Warning("File beginning found, restart download");
                                    file.Write(bytes, 0, firstBytes);
                                    await CopyToAsync(remoteData, file, checkIfPaused, progress, cancellation);

                                    cancellation.ThrowIfCancellationRequested();
                                }

                                Logging.Write("Download finished");
                                return(filename);
                            }

                            rangeFrom += firstBytes;
                        }

                        using (var file = new FileStream(filename, FileMode.Append, FileAccess.Write)) {
                            await CopyToAsync(remoteData, file, checkIfPaused, new Progress <long>(v => {
                                progress?.Report(v + rangeFrom);
                            }), cancellation);

                            cancellation.ThrowIfCancellationRequested();
                        }
                    }
                }
                else
                {
                    if (headRequest)
                    {
                        Logging.Warning("Re-open request to be GET");
                        remoteData.Dispose();
                        remoteData = await client.OpenReadTaskAsync(Url);
                    }

                    using (var file = File.Create(filename)) {
                        Logging.Debug("Downloading the whole file…");
                        await CopyToAsync(remoteData, file, checkIfPaused, progress, cancellation);

                        cancellation.ThrowIfCancellationRequested();
                    }
                }

                Logging.Write("Download finished");
                return(filename);
            } catch (Exception e) when(e is WebException || e.IsCancelled())
            {
                Logging.Write("Download is interrupted! Saving details to resume later…");
                var download = filename == null ? null : new FileInfo(filename);

                if (download?.Exists == true && filename.Length > 0)
                {
                    CacheStorage.Set(_keyDestination, selectedDestination);
                    CacheStorage.Set(_keyPartiallyLoadedFilename, filename);
                    CacheStorage.Set(_keyFootprint, actualFootprint);
                    CacheStorage.Set(_keyLastWriteDate, download.LastWriteTime);
                }
                else
                {
                    ClearResumeData();
                }

                throw;
            } finally {
                remoteData?.Dispose();
            }
        }
Esempio n. 38
0
        public override IEnumerable <IFreeDocument> Execute(IEnumerable <IFreeDocument> documents)
        {
            foreach (var document in documents)
            {
                var path          = document.Query(SavePath);
                var directoryInfo = new DirectoryInfo(path);
                var isdir         = IsDir(path);
                var url           = document[Column]?.ToString();
                if (string.IsNullOrEmpty(url))
                {
                    yield return(document);

                    continue;
                }
                DirectoryInfo folder = null;
                if (!isdir)
                {
                    folder = directoryInfo.Parent;
                }
                else
                {
                    folder = directoryInfo;
                }

                if (folder == null)
                {
                    yield return(document);

                    continue;
                }
                if (!folder.Exists)
                {
                    folder.Create();
                }
                if (isdir)
                {
                    path = folder.ToString();
                    if (path.EndsWith("/") == false)
                    {
                        path += "/";
                    }
                    path += url;
                    path  = getFileName(path);
                    //path += getFileName(url);
                }
                if (File.Exists(path))
                {
                    yield return(document);

                    continue;
                }


                try
                {
                    var webClient = new CookieAwareWebClient();
                    if (!IsAsync)
                    {
                        webClient.DownloadFile(url, path);
                    }
                    else
                    {
                        webClient.DownloadFileAsync(new Uri(url), path);
                    }
                    //HttpStatusCode code;
                    //var bytes = helper.GetFile(crawler.Http, out code, url);
                    //if (bytes != null)
                    //    File.WriteAllBytes(path, bytes);
                }
                catch (Exception ex)
                {
                    XLogSys.Print.Error(ex);
                }

                yield return(document);
            }
        }
Esempio n. 39
0
 public SignInClient(CookieAwareWebClient client)
 {
     this.client = client;
 }
Esempio n. 40
0
        static void UpdateDiagramasONS()
        {
            LogUpdate("#Início - Diagramas ONS", true);
            LogUpdate("cdre.org.br/ conectando...", true);
            IEnumerable <Row> diagramasONS = ScrapOnsDiagramasAsync().GetAwaiter().GetResult();
            int      totalItems            = diagramasONS.Count();
            int      counter      = 1;
            FileInfo jsonInfoFile = new FileInfo(Path.Combine(DiagramasDir, "info.json"));

            string jsonInfo = File.Exists(jsonInfoFile.FullName) ? File.ReadAllText(jsonInfoFile.FullName) : null;

            IEnumerable <Row> localDiagramas = new List <Row>();

            try //problema ao corromper gravação do json //parse arquivo json inválido
            {
                localDiagramas = JsonConvert.DeserializeObject <IEnumerable <Row> >(jsonInfo);
            }
            catch (Exception)
            {
            }
            if (LocalBookmarks.Count == 0)
            {
                localDiagramas = new List <Row>();                           //forçar update completo caso bookmark corrompido
            }
            bool bookmarkUpdate = false;
            var  client         = new CookieAwareWebClient();

            foreach (var diagrama in diagramasONS)
            {
                LogUpdate($"{diagrama.FileLeafRef} atualizando {counter++} de {totalItems}", true);
                string diagramaLink = $"https://cdre.ons.org.br{diagrama.FileRef}";

                FileInfo diagramaFile = new FileInfo(Path.Combine(DiagramasDir, diagrama.FileLeafRef));

                string revisao = localDiagramas.Where(w => w.FileLeafRef == diagrama.FileLeafRef).Select(s => s.Modified).FirstOrDefault();
                if (revisao == diagrama.Modified && diagramaFile.Exists)
                {
                    LogUpdate($"{diagrama.FileLeafRef} já se encontra na revisão vigente");
                    continue;
                }
                try
                {
                    client.DownloadFile(diagramaLink, diagramaFile.FullName);
                    bookmarkUpdate = true;
                    var listBookmarks = GetPdfBookmark(diagramaFile, true, diagrama.MpoAssunto);
                    if (LocalBookmarks.Any(w => w.MpoCodigo == diagrama.FileLeafRef))
                    {
                        foreach (var item in LocalBookmarks)
                        {
                            if (item.MpoCodigo == diagrama.FileLeafRef)
                            {
                                item.Bookmarks = listBookmarks;
                            }
                        }
                    }
                    else
                    {
                        LocalBookmarks.Add(new ModelSearchBookmark
                        {
                            MpoCodigo = diagrama.FileLeafRef,
                            Bookmarks = listBookmarks
                        });
                    }
                    LogUpdate($"{diagrama.FileLeafRef} atualizado da modificação {revisao} para modificação {diagrama.Modified} em {diagramaFile.FullName}");
                }
                catch (Exception)
                {
                    LogUpdate($"{diagrama.FileLeafRef} não foi possível atualização pelo link {diagramaLink}");
                }
            }
            if (bookmarkUpdate)
            {
                File.WriteAllText(jsonBookmarkFile.FullName, JsonConvert.SerializeObject(LocalBookmarks));
            }
            var diagramasVigentes = diagramasONS.Select(s => $"{jsonInfoFile.Directory.FullName}\\{s.FileLeafRef}");
            var diagramasLocal    = Directory.GetFiles(jsonInfoFile.Directory.FullName, "*.pdf").Except(diagramasVigentes);

            foreach (var item in diagramasLocal)
            {
                File.Delete(item);
                LogUpdate($"{Path.GetFileNameWithoutExtension(item)} não está vigente e foi apagado");
            }
            File.WriteAllText(jsonInfoFile.FullName, JsonConvert.SerializeObject(diagramasONS));
            client.Dispose();
            LogUpdate("#Término - Diagramas ONS", true);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string autoIncrementIndexOfData = cntAutoInc.ToString();
            string password = "";

            if (GlobalClass.TestSecretCloud() == true)
            {
                password = GlobalClass.ReadSecretCloud(); //Sha256
            }
            string InputString = "";
            //******************* INITIATE PHPSESSION ***************************
            NameValueCollection  formData  = new NameValueCollection();
            CookieAwareWebClient webClient = new CookieAwareWebClient();

            webClient.Encoding = System.Text.Encoding.Default;


            formData.Clear();
            formData["username"] = "******";
            if (GlobalClass.TestPasswordCloud() == true)
            {
                formData["password"] = GlobalClass.ReadPasswordCloud(); //user pwd
            }
            byte[] responseBytes = webClient.UploadValues("http://your.url.here/lo.php", "POST", formData);
            string responseHTML  = Encoding.UTF8.GetString(responseBytes);

            Uri uriStr;

            if (Uri.TryCreate("http://your.url.here", UriKind.RelativeOrAbsolute, out uriStr) == false)
            {
                System.Diagnostics.Debug.WriteLine("NO");
            }
            foreach (Cookie cookie in webClient.CookieContainer.GetCookies(uriStr))
            {
                System.Diagnostics.Debug.WriteLine(cookie.Name);
                System.Diagnostics.Debug.WriteLine(cookie.Value);
            }
            //******************* INITIATE PHPSESSION ***************************

            //******************* DOWNLOAD XML FILE LIST ***************************

            string  fileList = webClient.DownloadString("http://your.url.here/filelist.php");
            DataSet ds       = new DataSet();

            byte[] byteArray = Encoding.UTF8.GetBytes(fileList);
            ds.ReadXml(new MemoryStream(byteArray));
            if (ds.Tables.Count > 0)
            {
                var result = ds.Tables[0];
            }
            dataGridView1.DataSource = ds.Tables[0];
            //******************* DOWNLOAD XML FILE LIST ***************************

            //******************* DOWNLOAD IV ***************************
            byte[] ivArr = webClient.DownloadData("http://your.url.here/listiv.php?id=" + autoIncrementIndexOfData);
            //******************* DOWNLOAD IV ***************************

            //******************* DOWNLOAD LENGTH ***************************
            byte[] length = webClient.DownloadData("http://your.url.here/getLen.php?id=" + autoIncrementIndexOfData);
            //filesize from files
            int fileSize = 0;

            foreach (byte l in length)
            {
                fileSize += (byte)(l - (byte)(0x30));
                fileSize *= 10;
            }
            fileSize /= 10;
            System.Diagnostics.Debug.WriteLine("filesize: " + fileSize.ToString());
            //******************* DOWNLOAD LENGTH ***************************

            //******************* DOWNL DATA ***************************
            InputString = webClient.DownloadString("http://your.url.here/dwnl.php?id=" + autoIncrementIndexOfData);
            //******************* DOWNL DATA ***************************

            //******************* DOWNLOAD AS FILE ***************************
            webClient.DownloadFile("http://your.url.here/download.php?id=" + autoIncrementIndexOfData.ToString(), "C:\\your\\dir\\here\\akm2Raw.jpg");
            //******************* DOWNLOAD AS FILE ***************************

            ////******************* DOWNLOAD DOWNLOAD ***************************
            string InputStringDownload = webClient.DownloadString("http://your.url.here/download.php");
            ////******************* DOWNLOAD DOWNLOAD ***************************



            //******************* DECRYPT ***************************

            // Create sha256 hash
            SHA256 mySHA256 = SHA256Managed.Create();

            byte[] key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password));

            string decrypted = this.DecryptString(InputString, key, ivArr, fileSize);

            byte[] decryptedArr = Convert.FromBase64String(decrypted);
            //******************* DECRYPT ***************************

            //******************* CHECK SIGN ***************************
            Encoding        encoding = Encoding.UTF8;
            DataTable       dt       = ds.Tables[0];
            BinaryFormatter bf       = new BinaryFormatter();

            using (var ms = new MemoryStream())
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (row["id"].ToString() == autoIncrementIndexOfData)
                    {
                        Debug.WriteLine(row["sign"].ToString());
                        bf.Serialize(ms, row["sign"]);
                    }
                }
                byte[] signObj = ms.ToArray();
            }
            using (HMACSHA256 hmac = new HMACSHA256(key))
            {
                var hash = hmac.ComputeHash(StringToStream(decrypted));

                // Create a new Stringbuilder to collect the bytes and create a string.
                StringBuilder sBuilder = new StringBuilder();
                // Loop through each byte of the hashed data
                // and format each one as a hexadecimal string.
                for (int i = 0; i < hash.Length; i++)
                {
                    sBuilder.Append(hash[i].ToString("x2"));
                }
                // Return the hexadecimal string.
                Debug.WriteLine(sBuilder.ToString());
            }

            Debug.WriteLine("getUUID: " + getUUID());
            //******************* CHECK SIGN ***************************
            File.WriteAllBytes("C:\\your\\dir\\here\\akm2.jpg", decryptedArr); // Requires System.IO
        }
Esempio n. 42
0
        /// <summary>
        /// Loads the latest Speed camera database from PocketGpsWorld
        /// </summary>
        /// <param name="username">PocketGpsWorld username</param>
        /// <param name="password">PocketGpsWorld password</param>
        /// <returns>the latest bundle of cameras</returns>
        /// <exception cref="WebException">Thrown if unable to login, browse to or download the file</exception>
        public static byte[] Load(string username, string password)
        {
            string loginAddress = "https://www.pocketgpsworld.com/modules.php?name=Your_Account";

            var client = new CookieAwareWebClient
            {
                Encoding = Encoding.UTF8
            };

            // Post values
            var values = new NameValueCollection
            {
                { "username", username },
                { "user_password", password },
                { "op", "login" }
            };

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // Logging in
            string loggedInPage = Encoding.ASCII.GetString(client.UploadValues(loginAddress, values));

            // Check for a positive logon error.
            if (loggedInPage.Contains("Login Incorrect!"))
            {
                throw new WebException("Unable to logon to PocketGpsWorld.com, check your username and password");
            }

            // Check for not a subscriber message
            if (loggedInPage.Contains("not subscriber"))
            {
                throw new WebException("PocketGPSworld.com reports your not a current Subscriber, If this is incorrect, please report error 1020 to developer");
            }

            // Check to see the download link exisits, failing this check is the first indicator
            // that someting has changed on the PocketGpsWorld website
            if (!loggedInPage.Contains("<a href=\"/modules.php?name=Cameras\" class=\"sidemenu\">Download Speed Cams</a>"))
            {
                throw new WebException("Unable to find download link at PocketGPSworld.com, Please report error 1000 to developer");
            }

            string downloadAddress       = "https://www.pocketgpsworld.com/modules.php?name=Cameras";
            NameValueCollection postData = new NameValueCollection
            {
                { "op", "DownloadPackage" },
                { "idPackage", "14" },
                { "getPmob", "yes" },
                { "getFrance", "no" },
                { "getSwiss", "no" }
            };

            // Download is preped as a temp file which the browser would normally be redirected to, need to extract the path and download that file.
            string html             = Encoding.ASCII.GetString(client.UploadValues(downloadAddress, postData));
            Regex  metaRefreshRegex = new Regex("<meta http-equiv=refresh content=0;url=(.+)>\\n");
            Match  match            = metaRefreshRegex.Match(html);

            if (match.Success)
            {
                return(client.DownloadData(match.Groups[1].Value));
            }
            else
            {
                throw new WebException("Unable to find download link at PocketGPSworld.com, Please report error 1010 to developer");
            }
        }
Esempio n. 43
0
        internal string UploadFileToVF(string zipFile, string swiftFilename, UploadPercent callback)
        {
            Login();
            string fileUploadInfo = SendGetRequest(ServerUrl + "/testbench/client_upload_url?filename=" + HttpUtility.UrlEncode(swiftFilename));

            if (fileUploadInfo == null)
            {
                // job creation failed
                //job.Status = Job.StatusEnum.Failed;
                return(null);
            }
            int     maxProgress        = 0;
            object  maxProgressLock    = new object();
            dynamic fileUploadInfoJson = Newtonsoft.Json.Linq.JObject.Parse(fileUploadInfo);
            string  fileUploadUrl      = fileUploadInfoJson["url"].Value;

            try
            {
                try
                {
                    using (CookieAwareWebClient webClient = new CookieAwareWebClient())
                    {
                        webClient.cookies = this.AuthCookies;
                        webClient.Timeout = HTTP_WEB_TIMEOUT_BASE;
                        Semaphore progress  = new Semaphore(0, int.MaxValue);
                        Semaphore completed = new Semaphore(0, 1);
                        UploadFileCompletedEventArgs completedData = null;
                        webClient.UploadFileCompleted += delegate(object sender, UploadFileCompletedEventArgs e)
                        {
                            completedData = e;
                            completed.Release();
                        };
                        webClient.UploadProgressChanged += delegate(object sender, UploadProgressChangedEventArgs e)
                        {
                            lock (maxProgressLock)
                            {
                                int percentProgress = (int)(((double)e.BytesSent / e.TotalBytesToSend) * 99.0);
                                if (percentProgress > maxProgress)
                                {
                                    // e.ProgressPercentage is not correct, as (almost) all the time is spent uploading
                                    maxProgress = percentProgress;
                                    callback(maxProgress);
                                }
                            }
                            progress.Release();
                        };
                        webClient.UploadFileAsync(new Uri(fileUploadUrl), "PUT", zipFile);
                        while (true)
                        {
                            WaitHandle[] handles = new WaitHandle[] { completed, progress };
                            int          timeout = HTTP_WEB_TIMEOUT_BASE;
                            lock (maxProgressLock)
                            {
                                // Workaround for Fiddler proxy: Fiddler accepts all the data at once, then uploads to VF
                                if (maxProgress > 98)
                                {
                                    handles = new WaitHandle[] { completed };
                                    timeout = HTTP_WEB_REQUEST_TIMEOUT;
                                }
                            }
                            int handle = WaitHandle.WaitAny(handles, timeout);
                            if (handle == 0)
                            {
                                lock (maxProgressLock)
                                {
                                    maxProgress = 100;
                                    callback(maxProgress);
                                }
                                break;
                            }
                            if (handle == System.Threading.WaitHandle.WaitTimeout)
                            {
                                webClient.CancelAsync();
                                throw new WebException("Connection timed out");
                            }
                            if (handle != 1)
                            {
                                throw new Exception();
                            }
                        }

                        Trace.TraceInformation("Upload to S3 " + Encoding.UTF8.GetString(completedData.Result));
                        return(fileUploadUrl);
                    }
                }
                catch (System.Reflection.TargetInvocationException ex)
                {
                    throw ex.InnerException;
                }
            }
            catch (WebException ex)
            {
                Trace.TraceError("Error uploading to {0}. Exception follows", fileUploadUrl);
                Trace.TraceError(ex.ToString());
            }
            return(null);
        }
Esempio n. 44
0
 private static void initializeWebClient(Settings currentClient)
 {
     webclient             = new CookieAwareWebClient();
     webclient.Credentials = new NetworkCredential(currentClient.username, currentClient.password);
 }
Esempio n. 45
0
 public virtual Task <bool> PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
 {
     return(Task.FromResult(true));
 }
Esempio n. 46
0
    // Downloading large files from Google Drive prompts a warning screen and
    // requires manual confirmation. Consider that case and try to confirm the download automatically
    // if warning prompt occurs
    private static FileInfo DownloadGoogleDriveFileFromURLToPath(string url, string path)
    {
        // You can comment the statement below if the provided url is guaranteed to be in the following format:
        // https://drive.google.com/uc?id=FILEID&export=download
        url = GetGoogleDriveDownloadLinkFromUrl(url);

        using (CookieAwareWebClient webClient = new CookieAwareWebClient())
        {
            FileInfo downloadedFile;

            // Sometimes Drive returns an NID cookie instead of a download_warning cookie at first attempt,
            // but works in the second attempt
            for (int i = 0; i < 2; i++)
            {
                downloadedFile = DownloadFileFromURLToPath(url, path, webClient);
                if (downloadedFile == null)
                {
                    return(null);
                }

                // Confirmation page is around 50KB, shouldn't be larger than 60KB
                if (downloadedFile.Length > 60000)
                {
                    return(downloadedFile);
                }

                // Downloaded file might be the confirmation page, check it
                string content;
                using (var reader = downloadedFile.OpenText())
                {
                    // Confirmation page starts with <!DOCTYPE html>, which can be preceeded by a newline
                    char[] header    = new char[20];
                    int    readCount = reader.ReadBlock(header, 0, 20);
                    if (readCount < 20 || !(new string( header ).Contains("<!DOCTYPE html>")))
                    {
                        return(downloadedFile);
                    }

                    content = reader.ReadToEnd();
                }

                int linkIndex = content.LastIndexOf("href=\"/uc?");
                if (linkIndex < 0)
                {
                    return(downloadedFile);
                }

                linkIndex += 6;
                int linkEnd = content.IndexOf('"', linkIndex);
                if (linkEnd < 0)
                {
                    return(downloadedFile);
                }

                url = "https://drive.google.com" + content.Substring(linkIndex, linkEnd - linkIndex).Replace("&amp;", "&");
            }

            downloadedFile = DownloadFileFromURLToPath(url, path, webClient);

            return(downloadedFile);
        }
    }
Esempio n. 47
0
        public override async Task <bool> PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
        {
            Logging.Debug(Url);
            if (!Url.Contains("://drive.google.com/uc?", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            // First of all, let’s see if there is an HTML-file under that link
            Logging.Debug("GET request is coming…");
            string webPageContent;

            using (client.SetAutoRedirect(false))
                using (var stream = await client.OpenReadTaskAsync(Url)) {
                    if (cancellation.IsCancellationRequested)
                    {
                        return(false);
                    }

                    // If file is freely available to download, server should redirect user to downloading
                    var location = client.ResponseHeaders?.Get("Location");
                    if (location != null)
                    {
                        Url      = location;
                        FileName = new Uri(Url, UriKind.RelativeOrAbsolute).GetQueryParam("id");
                        Logging.Debug("Download URL is ready: " + location);
                        client.LogResponseHeaders();
                        return(true);
                    }

                    Logging.Debug("Content-Type: " + client.ResponseHeaders?.Get("Content-Type"));
                    if (client.ResponseHeaders?.Get("Content-Type").Contains("text/html", StringComparison.OrdinalIgnoreCase) == false)
                    {
                        return(true);
                    }

                    // Looks like it’s a webpage, now we need to download and parse it
                    webPageContent = (await stream.ReadAsBytesAsync()).ToUtf8String();
                    if (cancellation.IsCancellationRequested)
                    {
                        return(false);
                    }

                    Logging.Debug("…done");
                }

            var doc = new HtmlDocument();

            doc.LoadHtml(webPageContent);

            var link = doc.DocumentNode.SelectSingleNode(@"//form[contains(@action, 'export=download')]")?.Attributes[@"action"]?.Value;

            if (link == null)
            {
                if (doc.DocumentNode.SelectSingleNode(@"//head/title/text()")?.InnerText.Contains("Quota exceeded") == true)
                {
                    throw new InformativeException(ToolsStrings.Common_CannotDownloadFile, "Google Drive quota exceeded");
                }

                Logging.Warning(webPageContent);
                throw new InformativeException(ToolsStrings.Common_CannotDownloadFile, ToolsStrings.DirectLoader_GoogleDriveChanged);
            }

            Url = HttpUtility.HtmlDecode(link);
            if (Url.StartsWith("/"))
            {
                Url = @"https://drive.google.com" + Url;
            }

            FileName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode(@"//span[@class='uc-name-size']/a")?.InnerText?.Trim());
            Logging.Write($"Google Drive download link: {Url}");

            try {
                var totalSize = HttpUtility.HtmlDecode(
                    doc.DocumentNode.SelectSingleNode(@"//span[@class='uc-name-size']/text()")?.InnerText?.Trim(' ', '(', ')'));
                Logging.Write($"Total size: {totalSize}");
                if (totalSize != null && LocalizationHelper.TryParseReadableSize(totalSize, null, out var size))
                {
                    Logging.Write($"Parsed size: {size} bytes");
                    TotalSize = size;
                }
            } catch (Exception e) {
                Logging.Warning(e);
            }

            if (OptionManualRedirect)
            {
                using (client.SetDebugMode(OptionDebugMode))
                    using (client.SetAutoRedirect(false)) {
                        var redirect = await client.DownloadStringTaskAsync(Url);

                        // Logging.Debug("First redirect: " + redirect);

                        if (!redirect.Contains("<TITLE>Moved Temporarily</TITLE>"))
                        {
                            throw new InformativeException(ToolsStrings.Common_CannotDownloadFile, ToolsStrings.DirectLoader_GoogleDriveChanged);
                        }

                        var redirectMatch = Regex.Match(redirect, @"href=""([^""]+)", RegexOptions.IgnoreCase);
                        if (!redirectMatch.Success)
                        {
                            throw new InformativeException(ToolsStrings.Common_CannotDownloadFile, ToolsStrings.DirectLoader_GoogleDriveChanged);
                        }

                        Url = HttpUtility.HtmlDecode(redirectMatch.Groups[1].Value);
                        // Logging.Debug("Second redirect: " + Url);

                        for (var i = 0; i < 10; i++)
                        {
                            using (await client.OpenReadTaskAsync(Url)) {
                                if (client.ResponseLocation != null)
                                {
                                    Url = client.ResponseLocation;
                                    // Logging.Debug("Subsequent redirect: " + Url);
                                }
                                else
                                {
                                    // Logging.Debug("File found: " + Url);
                                    break;
                                }
                            }
                        }
                    }
            }

            return(true);
        }
Esempio n. 48
0
 public Chat()
 {
     wc = new CookieAwareWebClient();
     wc.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.0; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1";
 }
Esempio n. 49
0
 private void initializeWebClient()
 {
     webclient          = new CookieAwareWebClient();
     webclient.Encoding = Encoding.UTF8;
 }
 public static string SendLoginForm(string user, string pass, bool remember, string token, CookieAwareWebClient c)
 {
     byte[] res = c.UploadValues("https://poniverse.net/login", "POST", new NameValueCollection()
     {
         { "username", user },
         { "password", pass },
         { "rememberme", remember ? "1" : "0" },
         { "submit", "" },
         { "_token", token }
     });
     return(Encoding.Default.GetString(res));
 }
Esempio n. 51
0
        public override async Task <bool> PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
        {
            Logging.Debug(Url);
            if (!Url.Contains("://drive.google.com/uc?", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            // First of all, let’s see if there is an HTML-file under that link
            Logging.Debug("HEAD request is coming…");
            try {
                using (client.SetMethod("HEAD"))
                    using (client.SetAutoRedirect(false)) {
                        await client.DownloadStringTaskAsync(Url);

                        Logging.Debug("Done");
                    }
            } catch (Exception e) {
                Logging.Warning(e);
            }

            // If file is freely available to download, server should redirect user to downloading
            var location = client.ResponseHeaders?.Get("Location");

            if (location != null)
            {
                Url = location;
                Logging.Debug("Download URL is ready: " + location);
                return(true);
            }

            Logging.Debug("Loading page…");
            var downloadPage = await client.DownloadStringTaskAsync(Url);

            if (cancellation.IsCancellationRequested)
            {
                return(false);
            }

            if (client.ResponseHeaders?.Get("Content-Type").Contains("text/html", StringComparison.OrdinalIgnoreCase) == false)
            {
                return(true);
            }
            var match = Regex.Match(downloadPage, @"href=""(/uc\?export=download[^""]+)", RegexOptions.IgnoreCase);

            if (!match.Success)
            {
                NonfatalError.Notify(ToolsStrings.Common_CannotDownloadFile, ToolsStrings.DirectLoader_GoogleDriveChanged);
                return(false);
            }

            Url = "https://drive.google.com" + HttpUtility.HtmlDecode(match.Groups[1].Value);
            Logging.Write("Google Drive download link: " + Url);

            var fileNameMatch = Regex.Match(downloadPage, @"/<span class=""uc-name-size""><a[^>]*>([^<]+)");

            FileName = fileNameMatch.Success ? fileNameMatch.Groups[1].Value : null;

            try {
                var totalSizeMatch = Regex.Match(downloadPage, @"</a> \((\d+(?:\.\d+)?)([KMGT])\)</span> ");
                if (totalSizeMatch.Success)
                {
                    var value = double.Parse(totalSizeMatch.Groups[1].Value, CultureInfo.InvariantCulture);
                    var unit  = totalSizeMatch.Groups[2].Value;

                    switch (unit.ToLowerInvariant())
                    {
                    case "k":
                        value *= 1024;
                        break;

                    case "m":
                        value *= 1024 * 1024;
                        break;

                    case "g":
                        value *= 1024 * 1024 * 1024;
                        break;

                    case "t":
                        value *= 1024d * 1024 * 1024 * 1024;
                        break;
                    }

                    TotalSize = (long)value;
                }
            } catch (Exception) {
                // ignored
            }

            return(true);
        }
Esempio n. 52
0
 public virtual async Task DownloadAsync(CookieAwareWebClient client, string destination, CancellationToken cancellation)
 {
     await client.DownloadFileTaskAsync(Url, destination);
 }
Esempio n. 53
0
        /// <summary>
        /// 查找新版本
        /// </summary>
        internal static void SearchUpdate(string more, Action <UpdateModel> FindNewVersion = null, bool IsReconnect = false)
        {
            Action action = new Action(() =>
            {
                try
                {
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    string version = assembly.GetName().Version.ToString();//获取主版本号

                    //获取硬件号
                    string uid = Resources.GetRes().UID;

                    if (string.IsNullOrWhiteSpace(uid))
                    {
                        return;
                    }

                    //定义webClient对象
                    CookieAwareWebClient webClient = new CookieAwareWebClient();
                    //定义通信地址 和 JSON数据
                    string URL = "https://www.oybab.net/software/update/";
                    //string URL = "http://192.168.1.100/OyBabNet/software/update/";

                    //组装数据
                    NameValueCollection postValues = new NameValueCollection();
                    postValues.Add("version", version);
                    postValues.Add("uid", uid);
                    postValues.Add("lang", Resources.GetRes().AllLangList.Where(x => x.Value.LangIndex == Resources.GetRes().CurrentLangIndex).FirstOrDefault().Value.Culture.Name);
                    postValues.Add("app", Resources.GetRes().SOFT_SERVICE_NAME);
                    postValues.Add("more", more);
                    postValues.Add("name", Resources.GetRes().KEY_NAME_0);
                    postValues.Add("os", OSCheck.GetOS());
                    postValues.Add("ostype", OSCheck.GetOSType());

                    // 去锁(还有下面的锁住逻辑)
                    postValues.Add("LeftDay", Resources.GetRes().ExpiredRemainingDays.ToString());
                    if (Resources.GetRes().ExpiredRemainingDays < 7 && null != Resources.GetRes().RegTimeRequestCode)
                    {
                        postValues.Add("machineNo", Resources.GetRes().RegTimeRequestCode);
                    }

                    //向服务器发送POST数据
                    byte[] responseArray = webClient.UploadValues(URL, postValues);
                    string data          = Encoding.UTF8.GetString(responseArray);

                    //如果空
                    if (string.IsNullOrWhiteSpace(data))
                    {
                        #if DEBUG
                        ExceptionPro.ExpInfoLog("Response empty!");
                        #endif
                        return;
                    }

                    UpdateModel model = UpdateModel.FromJsonTo <UpdateModel>(data);
                    if (null != model)
                    {
                        //如果成功
                        if (model.Code == "1")
                        {
                            if (null != FindNewVersion)
                            {
                                FindNewVersion(model);
                            }
                        }// 如果需要延长时间
                        else if (model.Code == "8")
                        {
                            if (Res.Key.GetKeys().SetRegCode(model.DisplayMsg))
                            {
                                Res.Key.GetKeys().Clear(true);
                                if (DBOperate.GetDBOperate().IsDataReady)
                                {
                                    Res.Key.GetKeys().Check(false, true);
                                }
                                else
                                {
                                    Res.Key.GetKeys().Check(false);
                                }
#if DEBUG
                                ExceptionPro.ExpInfoLog("Extend Success!");
#endif

                                postValues.Add("RequestId", model.NewVersion);

                                webClient.UploadValues(URL, postValues);
                            }
                            else
                            {
#if DEBUG
                                ExceptionPro.ExpInfoLog("Extend Failed!");
#endif
                            }
                        }
                        //如果需要锁住
                        else if (model.Code == "-4")
                        {
                            if (Res.Key.GetKeys().LockKey())
                            {
                                postValues.Add("ConfirmLock", "1");
                                postValues.Add("TId", model.TId);
                                webClient.UploadValues(URL, postValues);
                                OperateLog.Instance.AddRecord(0, null, "LS#" + OperateType.None);
                            }
                            else
                            {
                                postValues.Add("ConfirmLock", "0");
                                postValues.Add("TId", model.TId);
                                webClient.UploadValues(URL, postValues);
                                OperateLog.Instance.AddRecord(0, null, "LS#" + OperateType.None);
                            }
                            return;
                        }
                        //如果其他或失败
                        else
                        {
                            #if DEBUG
                            if (!string.IsNullOrWhiteSpace(model.ErrorMsg))
                            {
                                throw new OybabException(model.ErrorMsg, true);
                            }
                            else
                            {
                                throw new OybabException(string.Format("Update Unable Error. code: {0}", model.Code), true);
                            }
                            #endif
                        }
                    }
                    //数据返回空或解析失败
                    else
                    {
                        #if DEBUG
                        throw new OybabException("Update Non Return Or Cant Read", true);
                        #endif
                    }
                }
                catch
#if DEBUG
                (Exception ex)
#endif
                {
#if DEBUG
                    ExceptionPro.ExpLog(ex, null, true);
#endif
                }
            });

            action.BeginInvoke(null, null);
        }
Esempio n. 54
0
 public Task<string> DownloadAsync(CookieAwareWebClient client,
         FlexibleLoaderGetPreferredDestinationCallback getPreferredDestination,
         FlexibleLoaderReportDestinationCallback reportDestination, Func<bool> checkIfPaused,
         IProgress<long> progress, CancellationToken cancellation) {
     return DownloadAsyncInner(client, getPreferredDestination, reportDestination, checkIfPaused, progress, cancellation);
 }
Esempio n. 55
0
        public static void GenerateWebInterfaceLinkDocument(string outPath)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<!DOCTYPE html>");
            sb.AppendLine("<html>");
            sb.AppendLine("	<head>");
            sb.AppendLine("		<title>Camera Configuration Links</title>");
            sb.AppendLine(@"		<style type=""text/css"">
body
{
	font-family: Arial;
}
table
{
	border-collapse: collapse;
}
td, th
{
	border-bottom: 1px solid #b5b5b5;
    padding: 2px 12px;
}
img
{
	max-width: 120px;
    max-height: 120px;
	cursor: pointer;
}
		</style>"        );
            sb.AppendLine("	</head>");
            sb.AppendLine("<body>");
            sb.AppendLine("<table><thead><tr><th>Camera Name</th><th>Short Name</th><th>Configuration URL</th><th>Snapshot</th></tr></thead><tbody>");
            RegistryKey cameras = RegistryUtil.HKLM.OpenSubKey("SOFTWARE\\Perspective Software\\Blue Iris\\Cameras");

            if (cameras == null)
            {
                MessageBox.Show("Could not find Blue Iris's camera list in the registry.  Either you have no cameras configured or your Blue Iris version is not compatible.");
                return;
            }
            else
            {
                string[] cameraNames = cameras.GetSubKeyNames();
                if (cameraNames.Length == 0)
                {
                    MessageBox.Show("No cameras were found in Blue Iris's registry settings.  Either you have no cameras configured or your Blue Iris version is not compatible.");
                    return;
                }
                else
                {
                    BiServerInfo.Reload();
                    if (!BiServerInfo.enabled)
                    {
                        MessageBox.Show("This function is not supported on your system.  Possible reasons are that your Blue Iris version is incompatible, or your Blue Iris web server is not enabled.");
                        return;
                    }
                    BiUserInfo.Reload();
                    CookieAwareWebClient wc = new CookieAwareWebClient();
                    wc.Proxy = null;
                    if (BiServerInfo.authenticate == AuthenticationMode.All_connections)
                    {
                        try
                        {
                            wc.CookieContainer.Add(new Cookie("session", GetSecureAuthenticatedSession(wc), "/", BiServerInfo.lanIp));
                        }
                        catch (Exception ex)
                        {
                            Logger.Debug(ex);
                            wc = null;
                        }
                    }

                    List <CameraInfo> camList = new List <CameraInfo>(cameraNames.Length);
                    foreach (string cameraName in cameraNames)
                    {
                        RegistryKey cam       = cameras.OpenSubKey(cameraName);
                        string      shortName = cam.GetValue("shortname").ToString();
                        string      ip        = cam.GetValue("ip").ToString();
                        if (string.IsNullOrWhiteSpace(ip))
                        {
                            continue;
                        }
                        string     port  = cam.GetValue("ip_port").ToString();
                        bool       https = cam.GetValue("https").ToString() != "0";
                        int        index = int.Parse(cam.GetValue("pos").ToString());
                        CameraInfo ci    = new CameraInfo(cameraName, shortName, ip, port, https, index);
                        camList.Add(ci);
                    }
                    camList.Sort(new Comparison <CameraInfo>((c1, c2) => c1.index.CompareTo(c2.index)));
                    foreach (CameraInfo ci in camList)
                    {
                        AddCameraLink(sb, ci, wc);
                    }
                }
            }
            sb.AppendLine("</tbody></table></body>");
            sb.AppendLine("</html>");
            File.WriteAllText(outPath, sb.ToString());
            Process.Start(outPath);
        }
        public override IEnumerable <GameInfo> GetGames()
        {
            System.IO.Directory.CreateDirectory(GetCachePath("icons"));

            List <GameInfo> result     = new List <GameInfo>();
            string          logintoken = LibrarySettings.LoginToken;

            if (string.Equals("", logintoken))
            {
                return(result);
            }

            CookieAwareWebClient cln = new CookieAwareWebClient();
            //cln.Headers.Add(HttpRequestHeader.Cookie,"_simpleauth_sess="+logintoken);
            //cln.Headers.Add(HttpRequestHeader.Cookie, "csrf_cookie="+secret);
            var           cacheFile    = GetCachePath("games.json");
            var           purchaseFile = GetCachePath("purchases.json");
            List <string> purchases    = new List <string>();

            if (!LibrarySettings.AlwaysScanEverything && System.IO.File.Exists(purchaseFile))
            {
                using (StreamReader r = new StreamReader(purchaseFile))
                {
                    string jsonx = r.ReadToEnd();

                    var Items = JsonConvert.DeserializeObject <JArray>(jsonx);
                    foreach (JValue item in Items)
                    {
                        purchases.Add(item.ToString());
                    }
                }
            }


            cln.CookieContainer.SetCookies(new Uri("https://www.humblebundle.com"), "_simpleauth_sess=" + logintoken + ";");

            string myjson = cln.DownloadString("https://www.humblebundle.com/api/v1/user/order");
            //logger.Info(myjson);
            JArray objects = null;

            try{
                objects = JArray.Parse(myjson);
            } catch (Exception e) {
                logger.Info(e.StackTrace);
                throw new Exception("Login Token Wrong, please reauthenticate");
            }
            // Dictionary<int,string> threads = new Dictionary<int,string>(objects.Count);
            Dictionary <Thread, ThreadWithState> threads = new Dictionary <Thread, ThreadWithState>(objects.Count);

            foreach (JObject root in objects)
            {
                foreach (KeyValuePair <String, JToken> app in root)
                {
                    if (!purchases.Contains(app.Value.ToString()))
                    {
                        logger.Info("new purchase id: " + app.Value.ToString());
                        purchases.Add(app.Value.ToString());
                        ThreadWithState tws = new ThreadWithState(this, logintoken, app.Value.ToString());
                        Thread          t   = new Thread(new ThreadStart(tws.ThreadProc));
                        t.Start();
                        threads.Add(t, tws);
                    }
                }
                //break;
            }


            string json = JsonConvert.SerializeObject(purchases.ToArray());

            System.IO.File.WriteAllText(purchaseFile, json);



            //System.IO.File.AppendAllText(cacheFile, "[\n", Encoding.UTF8);

            List <string> already = new List <string>();

            string filecontents = "{\r\n";

            if (System.IO.File.Exists(cacheFile))
            {
                json = System.IO.File.ReadAllText(cacheFile);
            }
            else
            {
                json = "{}";
            }


            Dictionary <string, object> values = JsonConvert.DeserializeObject <Dictionary <string, object> >(json, new JsonConverter[] { new MyConverter() });

            foreach (KeyValuePair <string, object> entry in values)
            {
                Dictionary <string, object> item;
                item = (Dictionary <string, object>)entry.Value;

                var output = JsonConvert.SerializeObject(item, Formatting.Indented);

                //already.Add(entry.Key);
                //logger.Info("xxxXXXxxx  "+output);
                already.Add(entry.Key);

                if (already.Count > 1)
                {
                    filecontents += ",\r\n\"" + entry.Key + "\" : " + output;
                }
                else
                {
                    filecontents += "\"" + entry.Key + "\" : " + output;
                }
            }

            foreach (KeyValuePair <Thread, ThreadWithState> entry in threads)
            {
                entry.Key.Join();
                foreach (KeyValuePair <string, HumbleGameData> pair in entry.Value.Values)
                {
                    if (!already.Contains(pair.Key))
                    {
                        already.Add(pair.Key);
                        result.Add(pair.Value.Info);
                        metadata[pair.Key] = pair.Value.Meta;
                        if (already.Count > 1)
                        {
                            filecontents += ",\r\n\"" + pair.Value.MachineName + "\" : " + pair.Value.Json;
                        }
                        else
                        {
                            filecontents += "\"" + pair.Value.MachineName + "\" : " + pair.Value.Json;
                        }
                    }
                }
            }
            //logger.Info(filecontents+"\r\n}");
            System.IO.File.WriteAllText(cacheFile, filecontents + "\r\n}", Encoding.UTF8);


            //Directory.CreateDirectory(cacheDir);


            return(result);
            //return GetGamesOffline();
        }
        ////////////////////////////////////////////////////////////////////////
        public async System.Threading.Tasks.Task <object> TimTick(object[] parameters)
        {
            string password = "";

            byte[] decryptedArr          = new byte[1];
            NameValueCollection formData = new NameValueCollection();

            //while (true)
            {
                if (TimTickEnabled == true)
                {
                    Uri    uriStr;
                    string autoIncrementIndexOfData = cntAutoInc.ToString();
                    string InputString = "";
                    if (password == "" && GlobalClass.TestSecretCloud() == true)
                    {
                        password = GlobalClass.ReadSecretCloud(); //Sha256
                    }
                    //******************* INITIATE PHPSESSION ***************************
                    CookieAwareWebClient webClient = new CookieAwareWebClient();
                    webClient.Encoding = System.Text.Encoding.Default;
                    formData.Clear();
                    formData["username"] = "******";
                    formData["password"] = "";
                    if ((formData["password"] == "") && GlobalClass.TestPasswordCloud() == true)
                    {
                        formData["password"] = GlobalClass.ReadPasswordCloud(); //Sha256
                    }

                    Uri.TryCreate("http://your.url.here/lo.php", UriKind.RelativeOrAbsolute, out uriStr);
                    Task <byte[]> loTaskString = webClient.UploadValuesTaskAsync(uriStr, "POST", formData);
                    await         loTaskString;
                    byte[]        responseBytes = loTaskString.Result;
                    string        responseHTML  = Encoding.UTF8.GetString(responseBytes);

                    if (Uri.TryCreate("http://your.url.here", UriKind.RelativeOrAbsolute, out uriStr) == false)
                    {
                        System.Diagnostics.Debug.WriteLine("NO");
                    }
                    foreach (Cookie cookie in webClient.CookieContainer.GetCookies(uriStr))
                    {
                        System.Diagnostics.Debug.WriteLine(cookie.Name);
                        System.Diagnostics.Debug.WriteLine(cookie.Value);
                    }
                    //******************* INITIATE PHPSESSION ***************************

                    //******************* DOWNLOAD XML FILE LIST ***************************
                    Uri.TryCreate("http://your.url.here/filelist.php", UriKind.RelativeOrAbsolute, out uriStr);
                    Task <string> fileListTaskString = webClient.DownloadStringTaskAsync(uriStr);
                    await         fileListTaskString;
                    string        fileList  = fileListTaskString.Result;
                    DataSet       ds        = new DataSet();
                    byte[]        byteArray = Encoding.UTF8.GetBytes(fileList);
                    ds.ReadXml(new MemoryStream(byteArray));
                    if (ds.Tables.Count > 0)
                    {
                        var result = ds.Tables[0];
                    }
                    dataGridView1.DataSource = ds.Tables[0];
                    //******************* DOWNLOAD XML FILE LIST ***************************

                    //******************* CHECK MAX ID ***************************
                    DataTable dtMaxId = ds.Tables[0];
                    using (var ms = new MemoryStream())
                    {
                        int   cnt   = dtMaxId.Rows.Count;
                        Int64 newID = Convert.ToInt64(dtMaxId.Rows[cnt - 1]["id"]);
                        autoIncrementIndexOfData = newID.ToString();
                        if (lastId < newID)
                        {
                            lastId = newID;
                            Debug.WriteLine(autoIncrementIndexOfData);
                            //******************* CHECK TIME ***************************
                            DateTime tim = Convert.ToDateTime(dtMaxId.Rows[cnt - 1]["time"]);
                            {
                                Debug.WriteLine(tim);
                            }

                            double timCmop = Convert.ToDouble((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds);
                            if (!((Convert.ToDouble(((tim.ToUniversalTime().AddSeconds(1)) - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds) - timCmop) >= 0.0))
                            {  //last picture is oler than ten seconds
                                Debug.WriteLine("No newId");
                                return(0);
                            }
                            //******************* CHECK TIME ***************************
                        }
                        else //no new Id
                        {
                            Debug.WriteLine("No newId");
                            return(0);
                        }
                    }
                    //******************* CHECK MAX ID ***************************

                    //******************* CHECK TIME  ***************************
                    //DataTable dtMaxTime = ds.Tables[0];
                    //using (var ms = new MemoryStream())
                    //{
                    //    int cnt = dtMaxTime.Rows.Count;
                    //    DateTime tim = Convert.ToDateTime(dtMaxTime.Rows[cnt - 1]["time"]);
                    //    {
                    //        Debug.WriteLine(tim);
                    //    }
                    //}
                    //******************* CHECK TIME  ***************************

                    //******************* DOWNLOAD IV ***************************
                    Task <byte []> ivArrTaskByte = webClient.DownloadDataTaskAsync("http://your.url.here/listiv.php?id=" + autoIncrementIndexOfData);
                    await          ivArrTaskByte;
                    byte[]         ivArr = ivArrTaskByte.Result;
                    //******************* DOWNLOAD IV ***************************

                    //******************* DOWNLOAD LENGTH ***************************
                    Task <byte[]> lengthTaskByte = webClient.DownloadDataTaskAsync("http://your.url.here/getLen.php?id=" + autoIncrementIndexOfData);
                    await         lengthTaskByte;
                    byte[]        length = lengthTaskByte.Result;
                    //filesize from files
                    int fileSize = 0;
                    foreach (byte l in length)
                    {
                        fileSize += (byte)(l - (byte)(0x30));
                        fileSize *= 10;
                    }
                    fileSize /= 10;
                    System.Diagnostics.Debug.WriteLine("filesize: " + fileSize.ToString());
                    //******************* DOWNLOAD LENGTH ***************************

                    //******************* DOWNL DATA ***************************
                    Uri.TryCreate("http://your.url.here/dwnl_delete.php?id=" + autoIncrementIndexOfData, UriKind.RelativeOrAbsolute, out uriStr);
                    Task <string> InputTaskString = webClient.DownloadStringTaskAsync(uriStr);
                    await         InputTaskString;
                    InputString = InputTaskString.Result;
                    //******************* DOWNL DATA ***************************


                    // Create sha256 hash
                    SHA256 mySHA256 = SHA256Managed.Create();
                    byte[] key      = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password));

                    try
                    {
                        string decrypted = this.DecryptString(InputString, key, ivArr, fileSize);
                        decryptedArr = Convert.FromBase64String(decrypted);

                        //******************* DECRYPT ***************************

                        //******************* CHECK SIGN ***************************
                        Encoding        encoding  = Encoding.UTF8;
                        DataTable       dt        = ds.Tables[0];
                        BinaryFormatter bf        = new BinaryFormatter();
                        string          dbSignStr = "";
                        using (var ms = new MemoryStream())
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                if (row["id"].ToString() == autoIncrementIndexOfData)
                                {
                                    Debug.WriteLine(row["sign"].ToString());
                                    bf.Serialize(ms, row["sign"]);
                                    dbSignStr = row["sign"].ToString();
                                }
                            }
                            byte[] signObj = ms.ToArray();
                        }

                        StringBuilder sBuilder = new StringBuilder();
                        using (HMACSHA256 hmac = new HMACSHA256(key))
                        {
                            var hash = hmac.ComputeHash(StringToStream(decrypted));

                            // Create a new Stringbuilder to collect the bytes and create a string.
                            // Loop through each byte of the hashed data
                            // and format each one as a hexadecimal string.
                            for (int i = 0; i < hash.Length; i++)
                            {
                                sBuilder.Append(hash[i].ToString("x2"));
                            }
                            // Return the hexadecimal string.
                            Debug.WriteLine(sBuilder.ToString());
                        }
                        //******************* CHECK SIGN ***************************
                        if (sBuilder.ToString() == dbSignStr) //check signature
                        {                                     //SIGNATURE CHECK SUCCESSFUL
                            try
                            {
                                using (System.IO.StreamWriter file =
                                           new System.IO.StreamWriter(dwnlPath, true))
                                {
                                    await file.WriteLineAsync(Encoding.UTF8.GetChars(decryptedArr));
                                }
                            }
                            catch (Exception ex)
                            {
                                //GlobalClass.Log("ERROR @ WriteFileToPath" + ex.ToString());
                            }
                            //******************* CHECK SIGN ***************************
                        }
                    }
                    catch { }
                    finally { }

                    try
                    {
                        Stream newStream = ByteArrToStream(decryptedArr);

                        // Stretches the image to fit the pictureBox.
                        if (pictureBox1.Image == null)
                        {
                            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                        }
                        if (pictureBox1.Image != null)
                        {
                            pictureBox1.Image.Dispose();
                        }
                        using (Image MyImage = Image.FromStream(newStream))
                        {
                            pictureBox1.Image = (Image)MyImage.Clone();
                            pictureBox1.Update();
                            pictureBox1.Refresh();
                        }
                    }
                    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
                }
                else //false
                {   //stop
                    await System.Threading.Tasks.Task.Delay(1000);

                    return(0);
                }
            }
            return(0);
        }
Esempio n. 58
0
        static void Main(string[] args)
        {
            try
            {
                if (System.Threading.Thread.CurrentThread.CurrentCulture.Name.StartsWith("zh"))
                {
                    language = JsonConvert.DeserializeObject <Language>(Encoding.UTF8.GetString(Properties.Resources.zh_tw));                                                                            //假如是中文語系,就使用中文
                }
                else
                {
                    language = new Language();  //否則,英文
                }
            }
            catch (Exception) { language = new Language(); /*這邊是當跳出錯誤時,使用英文。正常來說是不會有錯誤才對,但有次比賽拿來做測試的時候出了錯誤,也抓不到點,就先認定是語系的問題了*/ }

            Console.Title = language.AppTitle;

            if (OsuPathResolver.Instance.OsuIsRunning)
            {
                FormatWrite(language.DetectionOsuIsRunning, ConsoleColor.Red);
            }

            OpenFileDialog openFileDialog = new OpenFileDialog(); //選擇收藏夾檔案的對話方塊

            openFileDialog.AddExtension    = true;
            openFileDialog.CheckFileExists = true;
            openFileDialog.CheckPathExists = true;
            openFileDialog.DefaultExt      = "json";
            openFileDialog.Filter          = language.OpenFileFilter;
            openFileDialog.Multiselect     = false;

            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                Exit(language.PleaseSelectCollection, true);
            }

            JsonData collectionData = null;

            try { collectionData = JsonConvert.DeserializeObject <JsonData>(File.ReadAllText(openFileDialog.FileName)); } //讀取收藏夾資料
            catch (Exception) { }
            if (collectionData == null || collectionData.collection_data == null)
            {
                Exit(language.ReadCollectionFail, true);
            }

            string osuPath = OsuPathResolver.Instance.GetOsuDir((path) => { //第一次會先偵測osu的路徑,然後提示使用者是否正確
                var dialogResult = MessageBox.Show(
                    string.Format(
                        language.ConfirmOsuPath, Environment.NewLine + path, Environment.NewLine),
                    "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                return(dialogResult == DialogResult.Yes);
            }, (text) => {
                FolderBrowserDialog dialog = new FolderBrowserDialog(); //假如是錯誤的,那就開個資料夾選擇對話框,讓使用者自行選擇osu的路徑

                dialog.ShowNewFolderButton = false;
                dialog.Description         = language.PleaseSelectOsuPath;
                dialog.RootFolder          = Environment.SpecialFolder.MyComputer;
                if (dialog.ShowDialog() == DialogResult.OK && Directory.Exists(dialog.SelectedPath))
                {
                    return(dialog.SelectedPath);
                }
                return("");
            });

            if (osuPath == string.Empty || !Directory.Exists(osuPath))
            {
                Exit(language.NeedValidOsuPath, true);
            }
            if (!osuPath.EndsWith("\\"))
            {
                osuPath += "\\";
            }

            FormatWrite(string.Format(language.OsuPath, osuPath), ConsoleColor.Yellow);
            OsuFileIo.OsuSettings.Load(osuPath);
            OsuFileIo.OsuDatabase.Load(osuPath + "osu!.db"); //載入osu的資料庫來抓取songs的資料夾路徑

            List <BeatmapData> needDownloadBeatmapList = new List <BeatmapData>();
            var collectionManager = new CollectionsManager(OsuFileIo.OsuDatabase.LoadedMaps.Beatmaps); Collection collection;                          //初始化目前osu所有的Beatmap

            collectionManager.EditCollection(CollectionEditArgs.AddCollections(OsuFileIo.CollectionLoader.LoadCollection(osuPath + "collection.db"))); //載入原先的收藏夾

            foreach (CollectionData item in collectionData.collection_data)
            {
                FormatWrite(string.Format(language.CollectionName, item.collection_name), ConsoleColor.Yellow);

                if (collectionManager.CollectionNameExists(item.collection_name))
                {
                    collection = collectionManager.GetCollectionByName(item.collection_name);                                                               //如果收藏夾已經存在,就讀取出來
                }
                else
                {
                    collection = new Collection(OsuFileIo.LoadedMaps)
                    {
                        Name = item.collection_name
                    }
                };                                                                                      //否則新建一個

                foreach (BeatmapData item2 in item.beatmap_data)
                {
                    if (!collection.AllBeatmaps().Any((x) => x.MapId == item2.beatmap_id)) //讀取收藏夾內的Beatmap,如果要匯入的收藏夾Beatmap ID不存在於收藏夾內,那就新增進去
                    {
                        FormatWrite(string.Format(language.AddBeatmapToCollection, item2.beatmap_name), ConsoleColor.Green);
                        collection.AddBeatmapByHash(item2.beatmap_md5);                                         //新增Beatmap,使用Hash新增法
                        if (!OsuFileIo.OsuDatabase.LoadedMaps.Beatmaps.Any((x) => x.MapId == item2.beatmap_id)) //如果osu資料庫裡面沒有該Beatmap
                        {
                            needDownloadBeatmapList.Add(item2);                                                 //就新增到下載清單內
                            FormatWrite(language.NeedDownloadBeatmap, ConsoleColor.Cyan);
                        }
                    }
                }

                collectionManager.EditCollection(CollectionEditArgs.RemoveCollections(new Collections()
                {
                    collection
                }));                                                                                                      //先把收藏夾移除
                collectionManager.EditCollection(CollectionEditArgs.AddCollections(new Collections()
                {
                    collection
                }));                                                                                                   //再把收藏夾新增,以達成重整的效果
            }

            if (needDownloadBeatmapList.Count != 0) //如果下載清單數量不為0,就進入下載程序
            {
                FormatWrite(language.DownloadBeatmapInfo, ConsoleColor.Green);
                CookieAwareWebClient cookieAwareWebClient = new CookieAwareWebClient(); //CollectionManager提供的class,可以讓WebClient使用cookie的功能
                string username, password;
                do
                {
                    Console.Write(language.OsuUsername); username = Console.ReadLine();
                    Console.Write(language.OsuPassword); password = "";
                    do
                    {
                        ConsoleKeyInfo key = Console.ReadKey(true);
                        if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
                        {
                            password += key.KeyChar;
                            Console.Write("*");
                        }
                        else
                        {
                            if (key.Key == ConsoleKey.Backspace && password.Length > 0)
                            {
                                password = password.Substring(0, (password.Length - 1));
                                Console.Write("\b \b");
                            }
                            else if (key.Key == ConsoleKey.Enter)
                            {
                                Console.WriteLine();
                                break;
                            }
                        }
                    } while (true);

                    try { if (!cookieAwareWebClient.Login(loginAddress, string.Format(loginDataStr, username, password)).Contains("I don't have an account"))
                          {
                              break;
                          }
                    }                                                                                                                                                  //登入失敗的話,回傳的網頁資料會有I don't have an account
                    catch (Exception ex) { Exit(string.Format(language.LoginErrorElseReason, ex.Message)); }

                    FormatWrite(language.LoginError, ConsoleColor.Red);
                } while (true);

                bool downloadVideo = MessageBox.Show(language.DownloadBeatmapWithVideo, "", MessageBoxButtons.YesNo) == DialogResult.Yes; //提示下載時是否包含背景影片

                needDownloadBeatmapList.ForEach((item) => {
                    string savePath = OsuFileIo.OsuSettings.CustomBeatmapDirectoryLocation + item.beatmap_setid + " " + StripInvalidCharacters(item.beatmap_name) + ".osz"; //存放路徑: osu的songs資料夾 + BeatmapSet ID + BeatmapSet Name
                    if (!File.Exists(savePath))
                    {
                        FormatWrite(string.Format(language.DownloadBeatmapName, Path.GetFileName(savePath)), ConsoleColor.Green);
                        try { File.WriteAllBytes(savePath, cookieAwareWebClient.DownloadData("https://osu.ppy.sh/d/" + item.beatmap_setid + (downloadVideo ? "n" : ""))); }
                        catch (Exception ex) { Console.WriteLine(string.Format(language.DownloadFali, ex.Message)); }
                    }
                    else
                    {
                        FormatWrite(string.Format(language.DownloadDone, Path.GetFileName(savePath)), ConsoleColor.Yellow);
                    }
                });
            }

            string backupName = "collection.db-" + DateTime.Now.ToFileTime() + ".bak"; //備份舊的收藏夾檔案

            File.Move(osuPath + "collection.db", osuPath + backupName);                //然後覆蓋新的收藏夾檔案
            Console.WriteLine(string.Format(language.BackupCollectionTo, osuPath + backupName));

            Console.WriteLine(language.WritingNewCollection);
            OsuFileIo.CollectionLoader.SaveOsuCollection(collectionManager.LoadedCollections, osuPath + "collection.db");

            if (OsuPathResolver.Instance.OsuIsRunning)
            {
                if (needDownloadBeatmapList.Count != 0)
                {
                    Exit(language.WriteDone1);
                }
                else
                {
                    Exit(language.WriteDone2);
                }
            }
            else
            {
                if (needDownloadBeatmapList.Count != 0)
                {
                    Exit(language.WriteDone3);
                }
                else
                {
                    Exit(language.WriteDone4);
                }
            }
        }
Esempio n. 59
0
 public Chatbox(CookieAwareWebClient c)
 {
     this.CookieClient = c;
 }
Esempio n. 60
-1
File: WebCore.cs Progetto: zuun/wSQL
        public string OpenPage(string url, string loginPage, string userName, string password)
        {
            using (var web = new CookieAwareWebClient())
             {
            var response = web.DownloadString(loginPage);
            web.Headers["Content-Type"] = "application/x-www-form-urlencoded";
            response = web.UploadString(loginPage,
              string.Format("UserName={0}&Password={1}&__RequestVerificationToken=", userName, password) + extractValidationToken(response));

            System.Diagnostics.Debug.WriteLine("OpenPage: " + url);
            response = web.DownloadString(url);
            System.Diagnostics.Debug.WriteLine("OpenPage Done");
            return response;
             }
        }