Esempio n. 1
0
        private bool MyGetIsOk()
        {
            // Non blocking lock
            if (Monitor.TryEnter(_TimerLocker))
            {
                // Create web client instance
                MyWebClient WebClient = null;

                try
                {
                    WebClient = new MyWebClient();

                    // Log-in in if neccessary
                    if (!String.IsNullOrEmpty(_UserName) && !String.IsNullOrEmpty(_Password))
                    {
                        // Readc login page and dump result to dummy string
                        string Dump = (new StreamReader(WebClient.OpenRead(_Uri.ToString() + "loginEntry"))).ReadToEnd();

                        System.Collections.Specialized.NameValueCollection Variables = new System.Collections.Specialized.NameValueCollection();
                        Variables.Add("j_username", _UserName);
                        Variables.Add("j_password", _Password);
                        Variables.Add("from", "/");
                        Variables.Add("Submit", "log in");

                        WebClient.UploadValues(_Uri.ToString() + "j_acegi_security_check", "POST", Variables);
                    }

                    StreamReader RequestReader = new StreamReader(WebClient.OpenRead(_Uri.ToString() + _HudsonFiler));
                    string ResponseFromServer = RequestReader.ReadToEnd();

                    XElement XElement = XElement.Parse(ResponseFromServer);

                    foreach (XElement Element in XElement.Elements())
                    {
                        // TODO mk from mk; meybe add project filtering
                        //Element.Element("name");
                        XElement LastBuildElement = Element.Element("lastBuild");

                        if (LastBuildElement != null)
                        {
                            XElement IsSuccessResult = LastBuildElement.Element("result");

                            if (IsSuccessResult != null && IsSuccessResult.Value.Equals("FAILURE"))
                            {
                                _IsOk = false;
                                break;
                            }
                        }

                        _IsOk = true;
                    }
                }
                catch (Exception ex)
                {
                    _LogProvider.Error(ex);
                }
                finally
                {
                    WebClient.Dispose();

                    // Exit from critical section
                    Monitor.Exit(_TimerLocker);
                }
            }
            return _IsOk;
        }
Esempio n. 2
0
        private bool MyGetIsOk()
        {
            // Non blocking lock
            if (Monitor.TryEnter(_TimerLocker))
            {
                // Create web client instance
                MyWebClient WebClient = null;

                try
                {
                    WebClient = new MyWebClient();

                    // Log-in in if neccessary
                    if (!String.IsNullOrEmpty(_UserName) && !String.IsNullOrEmpty(_Password))
                    {
                        // Readc login page and dump result to dummy string
                        string Dump = (new StreamReader(WebClient.OpenRead(_Uri.ToString() + "loginEntry"))).ReadToEnd();

                        System.Collections.Specialized.NameValueCollection Variables = new System.Collections.Specialized.NameValueCollection();
                        Variables.Add("j_username", _UserName);
                        Variables.Add("j_password", _Password);
                        Variables.Add("from", "/");
                        Variables.Add("Submit", "log in");

                        WebClient.UploadValues(_Uri.ToString() + "j_acegi_security_check", "POST", Variables);
                    }

                    StreamReader RequestReader      = new StreamReader(WebClient.OpenRead(_Uri.ToString() + _HudsonFiler));
                    string       ResponseFromServer = RequestReader.ReadToEnd();

                    XElement XElement = XElement.Parse(ResponseFromServer);

                    foreach (XElement Element in XElement.Elements())
                    {
                        // TODO mk from mk; meybe add project filtering
                        //Element.Element("name");
                        XElement LastBuildElement = Element.Element("lastBuild");

                        if (LastBuildElement != null)
                        {
                            XElement IsSuccessResult = LastBuildElement.Element("result");

                            if (IsSuccessResult != null && IsSuccessResult.Value.Equals("FAILURE"))
                            {
                                _IsOk = false;
                                break;
                            }
                        }

                        _IsOk = true;
                    }
                }
                catch (Exception ex)
                {
                    _LogProvider.Error(ex);
                }
                finally
                {
                    WebClient.Dispose();

                    // Exit from critical section
                    Monitor.Exit(_TimerLocker);
                }
            }
            return(_IsOk);
        }