예제 #1
0
 public virtual void SetByteArray(byte[] value)
 {
     if (value.Length == 0)
     {
         m_text = "''";
     }
     else
     {
         m_text = "0x" + StringTool.EncodeHex(value);
     }
 }
예제 #2
0
        public static bool GetLicense(string name, string email, string product)
        {
            var            desc = ApiDescriptor.GetInstance();
            HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(desc.RequestLicense);

            req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            req.Method      = "POST";

            Dictionary <string, string> pars = new Dictionary <string, string>();

            FeedbackTool.FillStdParams(pars, false);
            pars["NAME"]    = name;
            pars["EMAIL"]   = email;
            pars["PRODUCT"] = product;

            string pars_enc = StringTool.UrlEncode(pars, Encoding.UTF8);

            byte[] data = Encoding.UTF8.GetBytes(pars_enc);
            req.ContentLength = data.Length;

            using (Stream fw = req.GetRequestStream())
            {
                fw.Write(data, 0, data.Length);
            }
            using (var resp = req.GetResponse())
            {
                using (Stream fr = resp.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(fr))
                    {
                        string licdata = reader.ReadToEnd();
                        if (LicenseTool.LoadLicenseFromString(licdata) == null)
                        {
                            return(false);
                        }
                        using (var fw = new StreamWriter(Path.Combine(Framework.LicensesDirectory, Guid.NewGuid().ToString())))
                        {
                            fw.Write(licdata);
                            return(true);
                        }
                    }
                }
            }
        }
예제 #3
0
        public virtual string ReadHash(IBedValueReader reader, BedValueConvertor auxConv, BedValueHolder auxHolder)
        {
            switch (reader.GetFieldType())
            {
            case TypeStorage.String:
                return(reader.GetString().ToLower());

            case TypeStorage.ByteArray:
            {
                byte[] data = reader.GetByteArray();
                if (data.Length == 32)
                {
                    return(Encoding.UTF8.GetString(data));
                }
                return(StringTool.EncodeHex(data).ToLower());
            }
            }
            auxConv.ConvertValue(reader, TypeStorage.String, auxHolder);
            return(auxHolder.GetString());
        }
예제 #4
0
 public SqlServerVersion(string version)
 {
     OrigName = version;
     if (version == null)
     {
         IsMax = true;
         return;
     }
     try
     {
         string[] vers = version.Split('.');
         V1 = StringTool.ParseIntStart(vers[0]);
         V2 = vers.Length >= 2 ? StringTool.ParseIntStart(vers[1]) : 0;
         V3 = vers.Length >= 3 ? StringTool.ParseIntStart(vers[2]) : 0;
     }
     catch
     {
         V1    = V2 = V3 = 0;
         IsMax = true;
     }
 }
예제 #5
0
        public static bool Send(string subject, string body, bool sendanswer, string email)
        {
            var            desc = ApiDescriptor.GetInstance();
            HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(desc.SendFeedback);

            req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            req.Method      = "POST";

            Dictionary <string, string> pars = new Dictionary <string, string>();

            //if (CheckAutoUpdate.UpdateID != null) pars["PROGRAMUPDATE"] = CheckAutoUpdate.UpdateID.ToString();
            FeedbackTool.FillStdParams(pars, false);
            pars["SUBJECT"]    = subject;
            pars["BODY"]       = body;
            pars["SENDANSWER"] = sendanswer ? "1" : "0";
            pars["EMAIL"]      = email;

            string pars_enc = StringTool.UrlEncode(pars, Encoding.UTF8);

            byte[] data = Encoding.UTF8.GetBytes(pars_enc);
            req.ContentLength = data.Length;

            using (Stream fw = req.GetRequestStream())
            {
                fw.Write(data, 0, data.Length);
            }
            using (var resp = req.GetResponse())
            {
                using (Stream fr = resp.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(fr))
                    {
                        var doc = new XmlDocument();
                        doc.Load(reader);
                        string state = doc.DocumentElement.GetAttribute("state");
                        return(state == "ok");
                    }
                }
            }
        }
예제 #6
0
        public string FormatBlob(byte[] data)
        {
            switch (BlobMode)
            {
            case DataFormatBlobMode.InfoText:
                return(BlobInfo);

            case DataFormatBlobMode.Base64:
                return(Convert.ToBase64String(data) + "=");

            case DataFormatBlobMode.Hexa:
                if (HexBytesOnLine > 0)
                {
                    return(StringTool.EncodeHex(data, HexBytesOnLine));
                }
                else
                {
                    return(StringTool.EncodeHex(data));
                }
            }
            return("");
        }
예제 #7
0
        public override void ShowCurrentData()
        {
            byte[] d = null;
            switch (m_holder.GetFieldType())
            {
            case TypeStorage.String:
                d = Encoding.UTF8.GetBytes(m_holder.GetString());
                break;

            case TypeStorage.ByteArray:
                d = m_holder.GetByteArray();
                break;
            }
            if (d != null)
            {
                textBox1.Text = StringTool.EncodeHexNice(d, 32).Replace("\n", "\r\n");
            }
            else
            {
                Controls.ShowError(true);
            }
        }
예제 #8
0
        //public static void DoSendUsage()
        //{
        //    foreach (string file in Directory.GetFiles(Core.UsageDirectory))
        //    {
        //        if (GlobalSettings.Pages.General.AllowUploadUsageStats)
        //        {
        //            UploadUsageFile(file);
        //        }
        //        File.Delete(file);
        //    }
        //}

        //public static void UploadUsageFile(string file)
        //{
        //    using (StreamReader sr = new StreamReader(file))
        //    {
        //        UploadUsageData(sr.ReadToEnd());
        //    }
        //}

        //public static void UploadUsageData(string usageData)
        //{
        //    try
        //    {
        //        var desc = ApiDescriptor.GetInstance();
        //        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(desc.SendUsage);
        //        req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
        //        req.Method = "POST";

        //        Dictionary<string, string> pars = new Dictionary<string, string>();
        //        pars["DATA"] = usageData;
        //        FeedbackTool.FillStdParams(pars);

        //        string pars_enc = StringTool.UrlEncode(pars, Encoding.UTF8);
        //        byte[] data = Encoding.UTF8.GetBytes(pars_enc);
        //        req.ContentLength = data.Length;

        //        using (Stream fw = req.GetRequestStream())
        //        {
        //            fw.Write(data, 0, data.Length);
        //        }
        //        using (var resp = req.GetResponse())
        //        {
        //            using (Stream fr = resp.GetResponseStream())
        //            {
        //                using (StreamReader reader = new StreamReader(fr))
        //                {
        //                    string line = reader.ReadToEnd();
        //                    Logging.Debug("Read result from datadmin feedback:" + line);
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception err)
        //    {
        //        Errors.ReportSilent(err);
        //    }
        //}

        private static void DoSendUsage()
        {
            try
            {
                var            desc = ApiDescriptor.GetInstance();
                HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(desc.SendUsage);
                req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
                req.Method      = "POST";

                Dictionary <string, string> pars = new Dictionary <string, string>();
                FeedbackTool.FillStdParams(pars, true);

                string pars_enc = StringTool.UrlEncode(pars, Encoding.UTF8);
                byte[] data     = Encoding.UTF8.GetBytes(pars_enc);
                req.ContentLength = data.Length;

                using (Stream fw = req.GetRequestStream())
                {
                    fw.Write(data, 0, data.Length);
                }
                using (var resp = req.GetResponse())
                {
                    using (Stream fr = resp.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(fr))
                        {
                            string line = reader.ReadToEnd();
                            Logging.Debug("Read result from datadmin feedback:" + line);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Errors.ReportSilent(err);
            }
        }
예제 #9
0
        private static void DoSendError(Exception error, List <LogMessageRecord> logHistory, Bitmap screenshot)
        {
            try
            {
                var            desc = ApiDescriptor.GetInstance();
                HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(desc.SendError);
                req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
                req.Method      = "POST";

                XmlDocument doc = XmlTool.CreateDocument("Error");
                XmlElement  xml = doc.DocumentElement;

                xml.SetAttribute("version", VersionInfo.VERSION);
                xml.AddChild("Message").InnerText    = error.Message;
                xml.AddChild("Type").InnerText       = error.GetType().FullName;
                xml.AddChild("StackTrace").InnerText = error.StackTrace;
                //xml.AddChild("DataTree").InnerText = GetDataTree();
                Exception se = error;
                while (se != null)
                {
                    XmlTool.SaveParameters(xml, se.Data);
                    se = se.InnerException;
                }

                xml.AddChild("Text").InnerText = error.ToString();

                //if (logHistory != null && CheckAutoUpdate.SendErrorLogs) Logging.SaveLogs(logHistory, xml.AddChild("LogHistory"));

                Dictionary <string, string> pars = new Dictionary <string, string>();
                StringWriter sw = new StringWriter();
                doc.Save(sw);
                pars["DATA"] = sw.ToString();
                //if (screenshot != null && CheckAutoUpdate.SendErrorScreenshots) pars["SCREENSHOT"] = SerializeScreenshot(screenshot);
                //if (CheckAutoUpdate.UpdateID != null) pars["PROGRAMUPDATE"] = CheckAutoUpdate.UpdateID.ToString();
                FeedbackTool.FillStdParams(pars, true);

                string pars_enc = StringTool.UrlEncode(pars, Encoding.UTF8);
                byte[] data     = Encoding.UTF8.GetBytes(pars_enc);
                req.ContentLength = data.Length;

                using (Stream fw = req.GetRequestStream())
                {
                    fw.Write(data, 0, data.Length);
                }
                using (var resp = req.GetResponse())
                {
                    using (Stream fr = resp.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(fr))
                        {
                            string line = reader.ReadToEnd();
                            Logging.Debug("Read result from datadmin feedback:" + line);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Errors.ReportSilent(err, false);
            }
        }
예제 #10
0
        private static void DoRunCheckThreadCore()
        {
            var            desc = ApiDescriptor.GetInstance();
            HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(desc.GetUpdate);

            req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            req.Method      = "POST";
            Dictionary <string, string> pars = new Dictionary <string, string>();

            FeedbackTool.FillStdParams(pars, true);
            if (m_checked)
            {
                pars["REPEATED"] = "1";
            }
            string pars_enc = StringTool.UrlEncode(pars, Encoding.UTF8);

            byte[] data = Encoding.UTF8.GetBytes(pars_enc);
            req.ContentLength = data.Length;
            req.Timeout       = 5000;
            using (Stream requestStream = req.GetRequestStream())
            {
                requestStream.Write(data, 0, data.Length);
            }

            using (WebResponse resp = req.GetResponse())
            {
                XmlDocument doc = new XmlDocument();
                using (Stream fr = resp.GetResponseStream())
                {
                    doc.Load(fr);
                }
                string version = doc.SelectSingleNode("/update/version").InnerText;
                string url     = doc.SelectSingleNode("/update/url").InnerText;
                //try { UpdateID = Int32.Parse(doc.SelectSingleNode("/update/updateid").InnerText); }
                //catch { }
                DateTime updatedat;
                try { updatedat = DateTime.ParseExact(doc.SelectSingleNode("/update/updatedat").InnerText, "s", CultureInfo.InvariantCulture); }
                catch { updatedat = DateTime.UtcNow; }
                //try { SendErrorLogs = doc.SelectSingleNode("/update/errorlogs").InnerText == "1"; }
                //catch { SendErrorLogs = true; }
                //try { ScreenshotWidth = Int32.Parse(doc.SelectSingleNode("/update/screenshots").InnerText); }
                //catch { ScreenshotWidth = 0; }

                if (VersionInfo.AllowAutoUpdate && CompareVersions(version, VersionInfo.VERSION) > 0)
                {
                    if (Framework.Instance.GetCheckNewVersion() == CheckNewVersions.CheckOnly)
                    {
                        //MainWindow.Instance.RunInMainWindow(delegate() { StdDialog.ShowInfo(Texts.Get("s_new_version_available$version", "version", version)); });
                        Framework.MainWindow.SendVersionInfo(Texts.Get("s_new_version_available$version", "version", version), null);
                    }
                    if (Framework.Instance.GetCheckNewVersion() == CheckNewVersions.CheckAndDownload)
                    {
                        if (File.Exists(VersionFile) && File.Exists(InstallExeFile))
                        {
                            string downloadedVersion = IOTool.LoadTextFile(VersionFile).Trim();
                            if (CompareVersions(version, downloadedVersion) > 0)
                            {
                                File.Delete(VersionFile);
                                File.Delete(InstallExeFile);
                            }
                            else
                            {
                                Logging.Debug("Version allready downloaded");
                                return;
                            }
                        }

                        Framework.MainWindow.SendVersionInfo(Texts.Get("s_downloading_version$version", "version", version), null);
                        WebRequest req2 = WebRequest.Create(url);
                        using (WebResponse resp2 = req2.GetResponse())
                        {
                            using (Stream fr = resp2.GetResponseStream())
                            {
                                using (FileStream fw = new FileStream(InstallExeFile, FileMode.Create))
                                {
                                    IOTool.CopyStream(fr, fw);
                                }
                            }
                        }
                        using (StreamWriter fw = new StreamWriter(VersionFile)) fw.Write(version);
                        using (StreamWriter fw = new StreamWriter(InstallTimestampFile)) fw.Write(updatedat.ToString("s"));

                        Framework.MainWindow.SendVersionInfo(Texts.Get("s_new_version_downloaded$version", "version", version), version);
                    }
                }
                else
                {
                    if (VersionInfo.AllowAutoUpdate)
                    {
                        Framework.MainWindow.SendVersionInfo(Texts.Get("s_you_have_current_version"), null);
                    }
                }
            }
        }
예제 #11
0
 public static string ToWebName(this Color color)
 {
     return(String.Format("#{0}{1}{2}", StringTool.EncodeHex(color.R), StringTool.EncodeHex(color.G), StringTool.EncodeHex(color.B)));
 }