Beispiel #1
0
        private static void DownloadStringCallback2(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                Console.WriteLine(e.Result);
                int result;
                if ((result = ExecutionAllowed(e.Result)) > 0)
                {
                    MessageBox.Show("Sorry License expired. reason: " + result.ToString(), "Rudy Meijer.");
                    if (!File.Exists(My.iniFile))
                    {
                        My.WriteToFile(My.iniFile, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<Screen width=\"245\" height=\"162\" />");
                    }
                    Application.Exit();           // Windows application.
                    Environment.Exit(0);          // Console application.
                }
                else if (File.Exists(My.iniFile)) //V214
                {
                    File.Delete(My.iniFile);
                }

                //
                // Update statcounter statistics.
                //
                using (WebClient wc = new WebClient())
                {
                    wc.Headers.Add("user-agent", "Mozilla " + My.Version + " (compatible; Rudy ; Windows NT 5.2; .NET CLR 1.0.3705;)");
                    wc.DownloadStringAsync(new Uri(urlStatCounter)); // "http://c37.statcounter.com/3320106/0/23c12e3e/0/"
                }
            }
            else
            {
                Console.WriteLine(e.Error.Message);
            }
        }
Beispiel #2
0
        public static DialogResult Show(string msg, string title = null, MessageBoxButtons buttons = MessageBoxButtons.OK)
        {
            if (title == null)
            {
                title = $"Dear mr {My.UserName}";
            }
            var res = MessageBox.Show(msg, title, buttons);

            My.Log($"Show {title}: {msg}");
            My.Log($"{res} entered by {My.UserName}.");
            return(res);
        }
Beispiel #3
0
        /// <summary>
        /// Combines paths and create path if not exist.
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        public static string CombinePath(params string[] paths)
        {
            var filename = Path.Combine(paths);
            var path     = Path.GetDirectoryName(filename);

            try
            {
                if (path != "" && !Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                return(filename);
            }
            catch (Exception ee) { My.Status("Error creating directory " + path + " " + ee.Message.TrimEnd('\r', '\n')); return(null); }
        }
Beispiel #4
0
 public static bool ResetAttribute(string filename, FileAttributes fileAttribute)
 {
     try
     {
         FileInfo fi = new FileInfo(filename);
         if (!fi.Exists)
         {
             return(false);
         }
         fi.Attributes &= ~fileAttribute;
         return(true);
     }
     catch (Exception e)
     {
         My.Log($"ResetAttribute: {e.Message} {filename}");
     }
     return(false);
 }
Beispiel #5
0
        public static void Status(string msg, Color?color = null, params object[] args)
        {
            var parent = thistoolStripStatusLabel1?.GetCurrentParent();

            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (parent == null)
            {
                return;
            }
            if (parent.InvokeRequired)
            {
                parent.Invoke(new StringArgReturningVoidDelegate(Status), new object[] { msg, color, args });
            }
            else
            {
                if (msg.Contains("Error"))
                {
                    color = Color.Red;
                }
                if (thistoolStripStatusLabel1 == null)
                {
                    MessageBox.Show("Please add My.InitStatus(toolStripStatusLabel1) in your Form_Load event."); return;
                }
                if (args.Length > 0)
                {
                    msg = String.Format(msg, args);
                }
                if (thistoolStripStatusLabel1.BackColor == SystemColors.Control || color == SystemColors.Control)
                {
                    thistoolStripStatusLabel1.Text      = msg;
                    thistoolStripStatusLabel1.BackColor = color ?? SystemColors.Control;
                }
                if (msg.Length > 0 && !msg.StartsWith(" "))
                {
                    My.Log(msg);
                }
            }
        }
Beispiel #6
0
 public static T LoadFile <T>(string filename)
 {
     return(Deserialize <T>(My.ReadFromFile(filename)));
 }
Beispiel #7
0
 public static void SaveFile(object cls, string filename)
 {
     My.WriteToFile(filename, Serialize(cls));
 }