Пример #1
0
 private static bool ActivateRunningInstance(bool useHttps)
 {
     using (var client = new XWebClient(500))
       {
     try
     {
       var result = client.DownloadString((useHttps ? "https" : "http") + "://127.0.0.1:27963/bringToFront");
       if (result == "ok")
     return true;
     }
     catch
     {
     }
       }
       return false;
 }
Пример #2
0
        public void Run()
        {
            try
              {
            using (var client = new XWebClient(1000))
            {
              client.Encoding = Encoding.UTF8;

              string url = config.GetString("masterServer") + "/version";
              string remoteVersionInfo = client.DownloadString(new Uri(url));
              MasterServerVersionInfoReceived(remoteVersionInfo);
            }
              }
              catch (Exception ex)
              {
            Log("Failed to check for latest extraQL.exe version: " + ex.Message);
              }
        }
Пример #3
0
 private string DownloadText(string url)
 {
     try
       {
     using (var webRequest = new XWebClient())
     {
       webRequest.Encoding = Encoding.UTF8;
       return webRequest.DownloadString(url);
     }
       }
       catch (Exception ex)
       {
     Log(ex.Message);
     return null;
       }
 }
Пример #4
0
        private void LoginToQlFocus()
        {
            using (var webRequest = new XWebClient())
              {
            webRequest.Encoding = Encoding.UTF8;
            var html = webRequest.DownloadString("http://focus.quakelive.com/focusgate/");
            string js = @"
            document.loginform.login.value = '" + this.comboEmail.Text + @"';
            document.loginform.passwd.value = '" + this.txtPassword.Text + @"';
            document.loginform.submit();";
            html = html.Replace("document.loginform.login.focus();", js);
            var file = Path.GetTempFileName();
            File.Move(file, file + ".html");
            file += ".html";
            File.WriteAllText(file, html);
            Process.Start(file);

            Timer timer = new Timer();
            timer.Interval = 5000;
            timer.Tick += (sender2, args) =>
            {
              timer.Stop();
              File.Delete(file);
              ((IDisposable)sender2).Dispose();
            };
            timer.Start();
              }
        }
Пример #5
0
 private void UpdateExe()
 {
     try
       {
     using (var client = new XWebClient())
     {
       client.Timeout = 10000;
       client.Encoding = Encoding.UTF8;
       byte[] bin = client.DownloadData(new Uri(config.GetString("masterServer") + "/extraQL.exe"));
       ExeDownloadComplete(bin);
     }
       }
       catch (Exception ex)
       {
     Log("Failed to check for latest extraQL.exe version: " + ex.Message);
       }
 }
Пример #6
0
        private void ProcessNextItemInUpdateQueue(object sender, ElapsedEventArgs e)
        {
            lock (this)
              {
            if (updateQueue.Count == 0)
            {
              updateTimer.Stop();
              Log("Script update check completed");
              return;
            }

            UpdateQueueItem queueItem = updateQueue[0];
            updateQueue.Remove(queueItem);

            try
            {
              var client = new XWebClient(2500);
              client.DownloadDataCompleted += ScriptFile_DownloadDataCompleted;
              client.DownloadDataAsync(queueItem.Uri, queueItem);
            }
            catch (Exception ex)
            {
              Log("Failed to get script source from " + queueItem.Uri + ": " + ex.Message);
            }
              }
        }
Пример #7
0
 private void LoadUpdatesFromMasterServer()
 {
     var client = new XWebClient(2000);
       client.DownloadStringCompleted += RepositoryJsonDownloadCompleted;
       var url = new Uri(string.Format(SCRIPTINDEX_URL_FORMAT, masterServer));
       client.DownloadStringAsync(url, new WebRequestState(url));
 }
Пример #8
0
        public ScriptInfo GetScriptByIdOrUrl(string scriptIdOrUrl)
        {
            lock (this)
              {
            ScriptInfo script;
            if (scriptById.TryGetValue(scriptIdOrUrl, out script))
            {
              // refresh script info it file was modified locally (e.g. while developing)
              if (script.Timestamp < new FileInfo(script.Filepath).LastWriteTimeUtc.Ticks)
              {
            string content = File.ReadAllText(script.Filepath);
            ScriptHeaderFields meta = ParseHeaderFields(content);
            script = new ScriptInfo(script.Filepath, content, meta);
            scriptById[scriptIdOrUrl] = script;
              }
              return script;
            }
              }

              return null;
            #if false
              // download script from external URL
              using (var webRequest = new XWebClient())
              {
            webRequest.Encoding = Encoding.UTF8;
            string url = scriptIdOrUrl;
            try
            {
              string filename = Path.GetFileName(new Uri(url).AbsolutePath);
              var code = webRequest.DownloadString(url);
              var meta = this.ParseHeaderFields(code);
              var id = meta.ContainsKey("id") ? meta["id"][0] : "";
              if (string.IsNullOrEmpty(id))
            id = this.StripAllExtenstions(filename);
              var filePath = ScriptDir + "\\" + StripAllExtenstions(filename) + ".usr.js";
              File.WriteAllText(filePath, code);
              script = new ScriptInfo(id, filePath, meta, code);
              this.Log("Downloaded script from " + url);
              this.scriptById[scriptIdOrUrl] = script;
            }
            catch (Exception)
            {
              this.Log("Failed to download script from " + url);
            }
            return script;
              }
            #endif
        }