Esempio n. 1
0
        public static void Show(string title,string msg, bool topmost, bool pause)
        {
            PopupWindow tow = new PopupWindow();

            tow.TopMost = topmost;
            
            tow.Title(title);
            tow.GotDebug(msg);
            if (pause)
                tow.ShowDialog();
            else
                tow.Show();
        }
Esempio n. 2
0
        public bool isAuthorized(string key, bool appendrandom, bool throwexception, bool showerrorbox)
        {
            WebClient wc   = new WebClient();
            string    rurl = url;

            if (appendrandom)
            {
                if (!rurl.Contains("?"))
                {
                    rurl += "?";
                }
                Random rand = new Random((int)DateTime.Now.Ticks);
                string last = rurl.Substring(url.Length - 1, 1);
                if ((last != "?") || (last != "&"))
                {
                    rurl += "&";
                }
                rurl += "r=" + rand.Next().ToString();
            }
            string res = "";

            try
            {
                res = wc.DownloadString(rurl);
            }
            catch (WebException ex) { res = ex.Message; }
            bool   reg = res.Contains(key);
            string err = "Registration Key " + key + " not found. Contact your software provider to register software.";

            if (throwexception && !reg)
            {
                throw new UnregisteredException(err);
            }
            if (showerrorbox && !reg)
            {
                PopupWindow.Show("Registration Error", err);
            }
            return(reg);
        }
Esempio n. 3
0
        /// <summary>
        /// see if given key is authorized
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="appendrandom">whether random parameter is appended to url to prevent results caching</param>
        /// <param name="throwexception">throw exceptions on errors</param>
        /// <param name="showerrorbox">show registration dialog if not authorized</param>
        /// <param name="pause">pause execution when showing dialog</param>
        /// <returns></returns>
        public bool isAuthorized(string key, bool appendrandom, bool throwexception, bool showerrorbox, bool pause)
        {
            bool reg = false;

            _lastauth = false;
            try
            {
                if (key == null)
                {
                    debug("null keys not allowed");
                    return(false);
                }
                if (key.Contains(" "))
                {
                    debug("spaces not allowed in key: " + key);
                    return(false);
                }
                if (key == string.Empty)
                {
                    debug("Empty key not allowed, authorization failing...");
                    return(false);
                }
                if (!hasuser)
                {
                    WebClient wc   = new WebClient();
                    string    rurl = url;
                    if (appendrandom)
                    {
                        if (!rurl.Contains("?"))
                        {
                            rurl += "?";
                        }
                        Random rand = new Random((int)DateTime.Now.Ticks);
                        string last = rurl.Substring(url.Length - 1, 1);
                        if ((last != "?") || (last != "&"))
                        {
                            rurl += "&";
                        }
                        rurl += "r=" + rand.Next().ToString();
                    }
                    string res = "";
                    res = wc.DownloadString(rurl);
                    reg = res.Contains(key);
                }
                else
                {
                    HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
                    req.Credentials     = new System.Net.NetworkCredential(_un, _pw);
                    req.PreAuthenticate = true;
                    SetBasicAuthHeader(req, _un, _pw);
                    if (req == null)
                    {
                        throw new NullReferenceException("request is not a http request");
                    }


                    // Process response
                    HttpWebResponse        res            = req.GetResponse() as HttpWebResponse;
                    System.IO.StreamReader responseReader = new System.IO.StreamReader(res.GetResponseStream());
                    string fullResponse = responseReader.ReadToEnd();
                    res.Close();
                    reg = fullResponse.Contains(key);
                }
            }
            catch (Exception ex)
            {
                debug("authexcept: " + ex.Message + " " + ex.StackTrace);
                reg = false;
            }
            _lastauth = reg;
            _authtime = Util.ToTLTime();
            string err = "Registration Key " + key + " not found. Contact your software provider to register software.";

            if (throwexception && !reg)
            {
                throw new UnregisteredException(err);
            }
            if (showerrorbox && !reg)
            {
                PopupWindow.Show("Registration Error", err, true, pause);
            }
            if (reg)
            {
                debug("authorization succeeded: " + key);
            }
            else
            {
                debug(err);
            }

            return(reg);
        }
Esempio n. 4
0
        /// <summary>
        /// see if given key is authorized
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="appendrandom">whether random parameter is appended to url to prevent results caching</param>
        /// <param name="throwexception">throw exceptions on errors</param>
        /// <param name="showerrorbox">show registration dialog if not authorized</param>
        /// <param name="pause">pause execution when showing dialog</param>
        /// <returns></returns>
        public bool isAuthorized(string key, bool appendrandom, bool throwexception, bool showerrorbox, bool pause)
        {
            bool reg = false;

            _lastauth = false;
            try
            {
                if (key == null)
                {
                    debug("null keys not allowed");
                    return(false);
                }
                if (key.Contains(" "))
                {
                    debug("spaces not allowed in key: " + key);
                    return(false);
                }
                if (key == string.Empty)
                {
                    debug("Empty key not allowed, authorization failing...");
                    return(false);
                }
                string rurl = url;
                if (appendrandom)
                {
                    if (!rurl.Contains("?"))
                    {
                        rurl += "?";
                    }
                    Random rand = new Random((int)DateTime.Now.Ticks);
                    string last = rurl.Substring(url.Length - 1, 1);
                    if ((last != "?") || (last != "&"))
                    {
                        rurl += "&";
                    }
                    rurl += "r=" + rand.Next().ToString();
                }
                string res = Util.geturl(rurl, debug);
                reg = res.Contains(key);
            }
            catch (Exception ex)
            {
                debug("authexcept: " + ex.Message + " " + ex.StackTrace);
                reg = false;
            }
            _lastauth = reg;
            _authtime = Util.ToTLTime();
            string err = "Registration Key " + key + " not found. Contact your software provider to register software.";

            if (throwexception && !reg)
            {
                throw new UnregisteredException(err);
            }
            if (showerrorbox && !reg)
            {
                PopupWindow.Show("Registration Error", err, true, pause);
            }
            if (reg)
            {
                debug("authorization succeeded: " + key);
            }
            else
            {
                debug(err);
            }

            return(reg);
        }