Пример #1
0
        /// <summary>
        /// Navigates to a specific URL
        /// </summary>
        public void BrowseTo(string url, bool forceRefresh = false)
        {
            TargetUrl = url.Trim();

            if (TargetUrl.Length == 0)
            {
                return;
            }

            // Skip the initial load if the user is navigating to WebBrowserPage a second time
            if (!forceRefresh && TargetUrl.Equals(CurrentUrl))
            {
                return;
            }

            InProgress = true;
            DismissMessage();

            try
            {
                // Default to http
                if (!(url.StartsWith("http://") || url.StartsWith("https://")))
                {
                    url = "http://" + url;
                }

                if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    // Enable Search
                    url = string.Format("http://{0}/search?q={1}", Constants.BingHomePageUrl, TargetUrl);
                }

                // Navigate
                WebViewController.Navigate(new Uri(url));

                App.TelemetryService.WriteEvent("WebBrowserGoButtonClicked");
            }
            catch (Exception)
            {
                TargetUrl = Constants.BingHomePageUrl;
            }
        }
Пример #2
0
        /// <summary>
        /// Generates the script neccessary to open the dialog.
        /// </summary>
        /// <remarks>
        /// <p>Calling <see cref="DialogWindowBase.Open"/> will cause this script to be sent to the client browser.</p>
        /// <p>This method can also be used to open the dialog on the client without postingback.</p>
        /// <p>This method is only public for developers who want to customize how and when the window is opened via code or a custom server control.</p>
        /// </remarks>
        public override String GetDialogOpenScript()
        {
            StringBuilder finalUrl = new StringBuilder();
            String        safeUrl  = this.TargetUrl.Replace(@"\", @"\\").Replace("'", @"\'").Replace("%", "%25");

            finalUrl.Append(this.ResolveUrl(safeUrl));
            String argAppender = "&";

            if (TargetUrl.IndexOf("?", StringComparison.Ordinal) == -1)
            {
                argAppender = "?";
            }
            if (this.dialogArguments != null)
            {
                foreach (String key in this.dialogArguments.Keys)
                {
                    finalUrl.Append(argAppender);
                    if (argAppender == "?")
                    {
                        argAppender = "&";
                    }
                    finalUrl.Append(HttpUtility.UrlEncode(key));
                    finalUrl.Append("=");
                    finalUrl.Append(HttpUtility.UrlEncode(this.dialogArguments[key]));
                }
            }
            NameValueCollection features = this.GetStandardFeatures();

            if (this.WindowHeight != Unit.Empty)
            {
                features["height"]      = this.WindowHeight.Value.ToString(CultureInfo.InvariantCulture);
                features["innerHeight"] = this.WindowHeight.Value.ToString(CultureInfo.InvariantCulture);
            }
            if (this.WindowWidth != Unit.Empty)
            {
                features["width"]      = this.WindowWidth.Value.ToString(CultureInfo.InvariantCulture);
                features["innerWidth"] = this.WindowWidth.Value.ToString(CultureInfo.InvariantCulture);
            }

            return(this.GetDialogOpenScript(finalUrl.ToString(), features));
        }
Пример #3
0
        private async Task <IKeyEvent> Execute(bool isByValue)
        {
            var values = new FormBodyBuilder()
                         .Add(Constants.Etcd.Parameter_Value, Value)
                         // ReSharper disable once PossibleInvalidOperationException
                         .Add(Ttl.HasValue, Constants.Etcd.Parameter_Ttl, () => Ttl.Value)
                         .Build();

            try
            {
                return(await TargetUrl
                       .Conditionally(isByValue, x => x.SetQueryParam(Constants.Etcd.Parameter_PrevValue, ExpectedValue))
                       .Conditionally(!isByValue, x => x.SetQueryParam(Constants.Etcd.Parameter_PrevIndex, ExpectedIndex))
                       .SendUrlEncodedAsync(HttpMethod.Put, values)
                       .ReceiveEtcdResponse <KeyEvent>(EtcdClient));
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Пример #4
0
        public void Start(TextWriter inputWriter)
        {
            _httpClientWrapper = new HttpClientWrapper();
            var reporter   = new CertificateCheckReporter(inputWriter);
            var targetUrls = TargetUrl.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var targetUrl in targetUrls)
            {
                var healthCheck = new CertificateValidityCheck(
                    App.Title,
                    targetUrl,
                    ValidityDays);

                _certificateCheckTasks.Add(new CertificateCheckTask(
                                               healthCheck,
                                               TimeSpan.FromSeconds(IntervalSeconds),
                                               reporter,
                                               _httpClientWrapper,
                                               Log));
            }
        }
        public void ExtendFrom(SubscriptionConfiguration parent)
        {
            if (parent == null)
            {
                return;
            }

            if (parent.Id.HasValue())
            {
                Id = Id.HasValue() ? parent.Id + "." + Id : parent.Id;
            }

            Enabled ??= parent.Enabled;
            Comments        = Comments.Or(parent.Comments);
            AwsRegion       = AwsRegion.Or(parent.AwsRegion);
            LogGroupName    = LogGroupName.Or(parent.LogGroupName);
            LogGroupPattern = LogGroupPattern.Or(parent.LogGroupPattern);

            StartTimeIso = StartTimeIso.Or(parent.StartTimeIso);
            EndTimeIso   = EndTimeIso.Or(parent.EndTimeIso);
            StartTimeSecondsAgo ??= parent.StartTimeSecondsAgo;
            EndTimeSecondsAgo ??= parent.EndTimeSecondsAgo;

            EventFilterPattern  = EventFilterPattern.Or(parent.EventFilterPattern);
            LogStreamNamePrefix = LogStreamNamePrefix.Or(parent.LogStreamNamePrefix);
            if (parent.LogStreamNames.SafeAny())
            {
                LogStreamNames = LogStreamNames.SafeUnion(parent.LogStreamNames).ToList();
            }

            ReadMaxBatchSize ??= parent.ReadMaxBatchSize;
            MinIntervalSeconds ??= parent.MinIntervalSeconds;
            MaxIntervalSeconds ??= parent.MaxIntervalSeconds;
            ClockSkewProtectionSeconds ??= parent.ClockSkewProtectionSeconds;

            TargetUrl = TargetUrl.Or(parent.TargetUrl);
            TargetTimeoutSeconds ??= parent.TargetTimeoutSeconds;
            TargetMaxBatchSize ??= parent.TargetMaxBatchSize;
            TargetSubscriptionData = TargetSubscriptionData.Or(parent.TargetSubscriptionData);
        }
Пример #6
0
        /// <summary>
        /// Generates the script neccessary to open the dialog.
        /// </summary>
        /// <remarks>
        /// <p>Calling <see cref="DialogWindowBase.Open"/> will cause this script to be sent to the client browser.</p>
        /// <p>This method can also be used to open the dialog on the client without postingback.</p>
        /// <p>This method is only public for developers who want to customize how and when the window is opened via code or a custom server control.</p>
        /// </remarks>
        public override String GetDialogOpenScript()
        {
            StringBuilder finalUrl = new StringBuilder();

            finalUrl.Append(this.ResolveUrl(this.TargetUrl.ToString()));
            String argAppender = "&";

            if (TargetUrl.ToString().IndexOf("?") == -1)
            {
                argAppender = "?";
            }
            if (this.dialogArguments != null)
            {
                foreach (String key in this.dialogArguments.Keys)
                {
                    finalUrl.Append(argAppender);
                    if (argAppender == "?")
                    {
                        argAppender = "&";
                    }
                    finalUrl.Append(HttpUtility.UrlEncode(key));
                    finalUrl.Append("=");
                    finalUrl.Append(HttpUtility.UrlEncode(this.dialogArguments[key]));
                }
            }
            NameValueCollection features = this.GetStandardFeatures();

            if (this.WindowHeight != Unit.Empty)
            {
                features["height"]      = this.WindowHeight.Value.ToString();
                features["innerHeight"] = this.WindowHeight.Value.ToString();
            }
            if (this.WindowWidth != Unit.Empty)
            {
                features["width"]      = this.WindowWidth.Value.ToString();
                features["innerWidth"] = this.WindowWidth.Value.ToString();
            }

            return(this.GetDialogOpenScript(new Uri(finalUrl.ToString()), features));
        }
Пример #7
0
        public async Task <IKeyEvent> Execute()
        {
            var values = new FormBodyBuilder()
                         .Add(
                IsDirectory ? Constants.Etcd.Parameter_Directory : Constants.Etcd.Parameter_Value,
                IsDirectory ? Constants.Etcd.Parameter_True : Value
                )
                         // ReSharper disable once PossibleInvalidOperationException
                         .Add(Existing.HasValue, Constants.Etcd.Parameter_PrevExist, () => Existing.Value ? Constants.Etcd.Parameter_True : Constants.Etcd.Parameter_False)
                         // ReSharper disable once PossibleInvalidOperationException
                         .Add(Ttl.HasValue, Constants.Etcd.Parameter_Ttl, () => Ttl.Value)
                         .Build();

            try
            {
                return(await TargetUrl
                       .Conditionally(IsQueue, values, (x, v) => x.PostUrlEncodedAsync(v), (x, v) => x.SendUrlEncodedAsync(HttpMethod.Put, v))
                       .ReceiveEtcdResponse <KeyEvent>(EtcdClient));
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Пример #8
0
    protected virtual async Task ProcessRequest(HttpListenerContext context)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        var url = TargetUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);

        using (var msg = new HttpRequestMessage(new HttpMethod(context.Request.HttpMethod), url + context.Request.RawUrl))
        {
            msg.Version = context.Request.ProtocolVersion;

            if (context.Request.HasEntityBody)
            {
                msg.Content = new StreamContent(context.Request.InputStream); // disposed with msg
            }

            string host = null;
            foreach (string headerName in context.Request.Headers)
            {
                var headerValue = context.Request.Headers[headerName];
                if (headerName == "Content-Length" && headerValue == "0") // useless plus don't send if we have no entity body
                {
                    continue;
                }

                bool contentHeader = false;
                switch (headerName)
                {
                // some headers go to content...
                case "Allow":
                case "Content-Disposition":
                case "Content-Encoding":
                case "Content-Language":
                case "Content-Length":
                case "Content-Location":
                case "Content-MD5":
                case "Content-Range":
                case "Content-Type":
                case "Expires":
                case "Last-Modified":
                    contentHeader = true;
                    break;

                case "Referer":
                    if (RewriteReferer && Uri.TryCreate(headerValue, UriKind.Absolute, out var referer))     // if relative, don't handle
                    {
                        var builder = new UriBuilder(referer);
                        builder.Host = TargetUrl.Host;
                        builder.Port = TargetUrl.Port;
                        headerValue  = builder.ToString();
                    }
                    break;

                case "Host":
                    host = headerValue;
                    if (RewriteHost)
                    {
                        headerValue = TargetUrl.Host + ":" + TargetUrl.Port;
                    }
                    break;
                }

                if (contentHeader)
                {
                    msg.Content.Headers.Add(headerName, headerValue);
                }
                else
                {
                    msg.Headers.Add(headerName, headerValue);
                }
            }

            using (var response = await _client.SendAsync(msg).ConfigureAwait(false))
            {
                using (var os = context.Response.OutputStream)
                {
                    context.Response.ProtocolVersion   = response.Version;
                    context.Response.StatusCode        = (int)response.StatusCode;
                    context.Response.StatusDescription = response.ReasonPhrase;

                    foreach (var header in response.Headers)
                    {
                        context.Response.Headers.Add(header.Key, string.Join(", ", header.Value));
                    }

                    foreach (var header in response.Content.Headers)
                    {
                        if (header.Key == "Content-Length") // this will be set automatically at dispose time
                        {
                            continue;
                        }

                        context.Response.Headers.Add(header.Key, string.Join(", ", header.Value));
                    }

                    var ct = context.Response.ContentType;
                    if (RewriteTargetInText && host != null && ct != null &&
                        (ct.IndexOf("text/html", StringComparison.OrdinalIgnoreCase) >= 0 ||
                         ct.IndexOf("application/json", StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        using (var ms = new MemoryStream())
                        {
                            using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                            {
                                await stream.CopyToAsync(ms).ConfigureAwait(false);

                                var enc  = context.Response.ContentEncoding ?? Encoding.UTF8;
                                var html = enc.GetString(ms.ToArray());
                                if (TryReplace(html, "//" + _targetHost + ":" + _targetPort + "/", "//" + host + "/", out var replaced))
                                {
                                    var bytes = enc.GetBytes(replaced);
                                    using (var ms2 = new MemoryStream(bytes))
                                    {
                                        ms2.Position = 0;
                                        await ms2.CopyToAsync(context.Response.OutputStream).ConfigureAwait(false);
                                    }
                                }
                                else
                                {
                                    ms.Position = 0;
                                    await ms.CopyToAsync(context.Response.OutputStream).ConfigureAwait(false);
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                        {
                            await stream.CopyToAsync(context.Response.OutputStream).ConfigureAwait(false);
                        }
                    }
                }
            }
        }
    }
Пример #9
0
        private void GetVideoList_Click(object sender, EventArgs e)
        {
            String input = TargetUrl.Text.Trim();

            if (String.IsNullOrEmpty(input))
            {
                MessageBox.Show("请输入网址", "出错了", MessageBoxButtons.OK);
                return;
            }

            bool isVaild   = false;
            bool hasPlugin = false;

            targetPlugin = null;

            foreach (IPlugin plugin in AddinManager.GetExtensionObjects <IPlugin>())
            {
                hasPlugin = true;
                if (plugin.isVaild(input))
                {
                    isVaild = true;
                    if (targetPlugin == null)
                    {
                        targetPlugin = plugin;
                    }
                    else if (targetPlugin.GetVersionNumber() < plugin.GetVersionNumber())
                    {
                        targetPlugin = plugin;
                    }
                }
            }

            if (!hasPlugin)
            {
                MessageBox.Show("没有找到插件...\n请检查plugins目录是否存在或者重新下载程序", "出错了", MessageBoxButtons.OK);
                System.Diagnostics.Process.Start("http://vdhelper.sinaapp.com");
                return;
            }

            if (isVaild)
            {
                if (!getlistWorker.IsBusy)
                {
                    VideoInfoList.Items.Clear();
                    ChangeState(true);
                    MessageLabel.Text = "获取中...请等待";
                    getlistWorker.RunWorkerAsync();
                }
                else
                {
                    MessageBox.Show("上一个任务还没有完成,请等待", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                if (DialogResult.OK == MessageBox.Show("你输入的地址错误,请检查后重新输入\r\n如果不清楚要输入何种类型的网址,请点击确认访问http://vdhelper.sinaapp.com/support.html", "出错了", MessageBoxButtons.OKCancel))
                {
                    System.Diagnostics.Process.Start("http://vdhelper.sinaapp.com/support.html?1.6");
                }
                TargetUrl.Text = string.Empty;
                TargetUrl.Focus();
            }
        }
Пример #10
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            //Validate

            if (!IsValidUrl())
            {
                MessageBox.Show("Incorrect url. Try Again", Title, MessageBoxButton.OK, MessageBoxImage.Information);
                TargetUrl.Focus();
                TargetUrl.SelectAll();
                return;
            }

            if (StartPosition.Value > EndPosition.Value)
            {
                MessageBox.Show("Incorrect users range. Try Again", Title, MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (manager.UserCount == 0)
            {
                MessageBox.Show("No users in file. Try Again", Title, MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            //Initialize

            StartButton.IsEnabled   = false;
            TargetUrl.IsReadOnly    = true;
            StartPosition.IsEnabled = false;
            EndPosition.IsEnabled   = false;

            manager.FirstWatcher = (StartPosition.Value != null) ? (int)(StartPosition.Value - 1) : 0;
            manager.LastWatcher  = EndPosition.Value ?? manager.UserCount;
            manager.Channel      = TargetUrl.Text.Trim();

            if (CaptchaCheckBox.IsChecked == true)
            {
                ReCaptchaSettings settings = new ReCaptchaSettings
                {
                    ApiKey      = RuCaptchaApiKey.Text.Trim(),
                    FirstDelay  = FirstCaptchaWait.Value.HasValue ? (int)FirstCaptchaWait.Value : -1,
                    SecondDelay = FirstCaptchaWait.Value.HasValue ? (int)SecongCaptchaWait.Value : -1,
                    Attempts    = CaptchaRequest.Value.HasValue ? (int)CaptchaRequest.Value : -1
                };
                manager.SetCaptchaSolver(settings);
            }

            //Start

            Overlay overLay = new Overlay()
            {
                Owner = this, MyMessage = "Starting..."
            };
            bool isOverlayClosed = false;

            manager.WatcherManagerCreatedEvent += (s, arg) => {
                overLay.Dispatcher.Invoke(() => overLay.Close());
                isOverlayClosed = true;
                EnablePreview.Dispatcher.Invoke(() => EnablePreview.IsEnabled   = true);
                SaveButton.Dispatcher.Invoke(() => SaveButton.IsEnabled         = true);
                mainTabControl.Dispatcher.Invoke(() => OptionsTabItem.IsEnabled = false);
            };
            manager.StartAsync();
            if (!isOverlayClosed)
            {
                overLay.ShowDialog();
            }
        }
Пример #11
0
 public void PasteTargetUrl(string targetUrl)
 {
     TargetUrl.Clear();
     TargetUrl.SendKeys(targetUrl);
 }
    protected virtual async Task ProcessRequestAsync(HttpListenerContext context)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }
        var url = TargetUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);

        using (var msg = new HttpRequestMessage(new HttpMethod(context.Request.HttpMethod), url + context.Request.RawUrl))
        {
            msg.Version = context.Request.ProtocolVersion;
            if (context.Request.HasEntityBody)
            {
                var stream = context.Request.InputStream;
                msg.Content = new StreamContent(stream);     // disposed with msg
            }
            foreach (string headerName in context.Request.Headers)
            {
                var contentHeader = false;
                var headerValue   = context.Request.Headers[headerName];
                switch (headerName)
                {
                // these headers go to content...
                case "Allow":
                case "Content-Disposition":
                case "Content-Encoding":
                case "Content-Language":
                case "Content-Length":
                case "Content-Location":
                case "Content-MD5":
                case "Content-Range":
                case "Content-Type":
                case "Expires":
                case "Last-Modified":
                    contentHeader = true;
                    break;

                // rewrite referer
                case "Referer":
                    if (Uri.TryCreate(headerValue, UriKind.Absolute, out var referer))         // if relative, don't handle
                    {
                        var builder = new UriBuilder(referer);
                        builder.Host = TargetUrl.Host;
                        builder.Port = TargetUrl.Port;
                        headerValue  = builder.ToString();
                    }
                    break;

                // rewrite host
                case "Host":
                    headerValue = TargetUrl.Host + ":" + TargetUrl.Port;
                    break;
                }
                if (contentHeader)
                {
                    msg.Content.Headers.Add(headerName, headerValue);
                }
                else
                {
                    msg.Headers.Add(headerName, headerValue);
                }
            }
            using (var response = await _client.SendAsync(msg).ConfigureAwait(false))
            {
                using (var os = context.Response.OutputStream)
                {
                    context.Response.StatusCode        = (int)response.StatusCode;
                    context.Response.StatusDescription = response.ReasonPhrase;
                    context.Response.ProtocolVersion   = response.Version;
                    foreach (var header in response.Headers)
                    {
                        context.Response.Headers.Add(header.Key, string.Join(", ", header.Value));
                    }
                    foreach (var header in response.Content.Headers)
                    {
                        if (header.Key == "Content-Length")     // this will be set automatically at dispose time
                        {
                            continue;
                        }
                        context.Response.Headers.Add(header.Key, string.Join(", ", header.Value));
                    }
                    using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                    {
                        await stream.CopyToAsync(context.Response.OutputStream).ConfigureAwait(false);
                    }
                }
            }
        }
    }