示例#1
0
        private async void bt_installRelease_Click(object sender, EventArgs e)
        {
            try
            {
                using Global_GUI.CursorWait cw = new Global_GUI.CursorWait();

                bt_installRelease.Enabled = false;
                bt_installRelease.Text    = "Working";

                string filename = Path.Combine(Directory.GetCurrentDirectory(), releases[0].Assets[0].Name);

                if (!System.IO.File.Exists(filename))
                {
                    var response = await client.Connection.Get <object>(new Uri(releases[0].Assets[0].Url), new Dictionary <string, string>(), "application/octet-stream");

                    System.IO.File.WriteAllBytes(filename, (byte[])response.Body);
                }

                ExploreFile(filename);
                Process.Start(filename);

                this.DialogResult = DialogResult.OK;
                this.Close();
                //if (filename.Has(".exe"))
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error downloading", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                bt_installRelease.Enabled = true;
                bt_installRelease.Text    = "Download";
            }
        }
示例#2
0
        private async void btTest_Click(object sender, EventArgs e)
        {
            btnCancel.Enabled = false;
            btnSave.Enabled   = false;
            btTest.Enabled    = false;
            try
            {
                using (Global_GUI.CursorWait cw = new Global_GUI.CursorWait())
                {
                    Global.Log("------ TESTING TRIGGERS --------");

                    bool result = await AITOOL.Trigger(cam, null, true);

                    Global.Log("------ DONE TESTING TRIGGERS --------");

                    if (result)
                    {
                        MessageBox.Show($"Succeeded! See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show($"Failed. See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch { }
            finally
            {
                btnCancel.Enabled = true;
                btnSave.Enabled   = true;
                btTest.Enabled    = true;
            }
        }
示例#3
0
        public static void FilterFOLV(FastObjectListView OLV, string FilterText, bool Filter)
        {
            using var cw = new Global_GUI.CursorWait();

            try
            {
                if (!string.IsNullOrEmpty(FilterText))
                {
                    if (Filter)
                    {
                        OLV.UseFiltering = true;
                    }
                    else
                    {
                        OLV.UseFiltering = false;
                    }
                    TextMatchFilter filter = TextMatchFilter.Regex(OLV, FilterText);
                    OLV.ModelFilter = filter;
                    HighlightTextRenderer renderererer = new HighlightTextRenderer(filter);
                    SolidBrush            brush        = renderererer.FillBrush as SolidBrush ?? new SolidBrush(Color.Transparent);
                    brush.Color            = System.Drawing.Color.FromArgb(100, Color.LightSeaGreen); //
                    renderererer.FillBrush = brush;
                    OLV.DefaultRenderer    = renderererer;
                    Global.SaveRegSetting("SearchText", FilterText);
                }
                else
                {
                    OLV.ModelFilter = null;
                }
                OLV.Refresh();
                //Application.DoEvents();
            }
            catch { }
        }
        private async void btTest_ClickAsync(object sender, EventArgs e)
        {
            btTest.Enabled    = false;
            btnSave.Enabled   = false;
            btnCancel.Enabled = false;

            try
            {
                AppSettings.Settings.mqtt_serverandport = tb_ServerPort.Text.Trim();
                AppSettings.Settings.mqtt_password      = tb_Password.Text.Trim();
                AppSettings.Settings.mqtt_username      = tb_Username.Text.Trim();
                AppSettings.Settings.mqtt_UseTLS        = cb_UseTLS.Checked;

                using (Global_GUI.CursorWait cw = new Global_GUI.CursorWait())
                {
                    Global.Log("------ TESTING MQTT --------");


                    string topic   = AITOOL.ReplaceParams(this.cam, null, tb_Topic.Text.Trim());
                    string payload = AITOOL.ReplaceParams(this.cam, null, tb_Payload.Text.Trim());

                    List <string> topics   = Global.Split(topic, ";|");
                    List <string> payloads = Global.Split(payload, ";|");

                    MQTTClient mq = new MQTTClient();
                    MqttClientPublishResult pr = null;

                    for (int i = 0; i < topics.Count; i++)
                    {
                        pr = await mq.PublishAsync(topics[i], payloads[i], cam.Action_mqtt_retain_message);
                    }

                    Global.Log("------ DONE TESTING MQTT --------");

                    if (pr != null && (pr.ReasonCode == MqttClientPublishReasonCode.Success))
                    {
                        MessageBox.Show("Success! See Log for details.");
                    }
                    else if (pr != null)
                    {
                        MessageBox.Show($"Failed. See log for details. Reason={pr.ReasonCode}", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show($"Failed. See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                btTest.Enabled    = true;
                btnSave.Enabled   = true;
                btnCancel.Enabled = true;
            }
        }
        private async void btTest_Click(object sender, EventArgs e)
        {
            this.btnCancel.Enabled = false;
            this.btnSave.Enabled   = false;
            this.btTest.Enabled    = false;
            try
            {
                using (Global_GUI.CursorWait cw = new Global_GUI.CursorWait())
                {
                    Log("----------------------- TESTING TRIGGERS ----------------------------");

                    if (!string.IsNullOrEmpty(this.cam.last_image_file_with_detections) && File.Exists(this.cam.last_image_file_with_detections))
                    {
                        //test by copying the file as a new file into the watched folder'
                        string folder   = Path.GetDirectoryName(this.cam.last_image_file_with_detections);
                        string filename = Path.GetFileNameWithoutExtension(this.cam.last_image_file_with_detections);
                        string ext      = Path.GetExtension(this.cam.last_image_file_with_detections);
                        string testfile = Path.Combine(folder, $"{filename}_AITOOLTEST_{DateTime.Now.TimeOfDay.TotalSeconds}{ext}");
                        File.Copy(this.cam.last_image_file_with_detections, testfile, true);
                        string str = "Created test image file based on last detected object for the camera: " + testfile;
                        Log(str);
                        MessageBox.Show(str, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //do a generic test of the trigger
                        //bool result = await AITOOL.Trigger(cam, null, true);
                        bool result = await AITOOL.TriggerActionQueue.AddTriggerActionAsync(TriggerType.All, this.cam, null, null, true, true, null, "");

                        if (result)
                        {
                            MessageBox.Show($"Succeeded! See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show($"Failed. See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    Log("---------------------- DONE TESTING TRIGGERS -------------------------");
                }
            }
            catch { }
            finally
            {
                this.btnCancel.Enabled = true;
                this.btnSave.Enabled   = true;
                this.btTest.Enabled    = true;
            }
        }
示例#6
0
        private async void bt_InstallBeta_Click(object sender, EventArgs e)
        {
            try
            {
                using Global_GUI.CursorWait cw = new Global_GUI.CursorWait();

                bt_InstallBeta.Enabled = false;
                bt_InstallBeta.Text    = "Working";

                //get the latest beta version installer file
                var repo = await client.Repository.Get("VorlonCD", "bi-aidetection");

                var contents = await client.Repository.Content.GetAllContents("VorlonCD", "bi-aidetection", "src/UI/Installer");

                //Octokit.ApiException: 'Unsupported 'Accept' header: 'application/octet-stream'. Must accept 'application/json'.'

                string filename = Path.Combine(Directory.GetCurrentDirectory(), contents[0].Name);

                if (!System.IO.File.Exists(filename))
                {
                    var response = await client.Connection.Get <object>(new Uri(contents[0].DownloadUrl), new Dictionary <string, string>(), "application/octet-stream");

                    System.IO.File.WriteAllBytes(filename, (byte[])response.Body);
                }
                ExploreFile(filename);
                Process.Start(filename);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error downloading", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                bt_InstallBeta.Enabled = true;
                bt_InstallBeta.Text    = "Download";
            }
        }
示例#7
0
        private async void btTest_ClickAsync(object sender, EventArgs e)
        {
            this.btTest.Enabled    = false;
            this.btnSave.Enabled   = false;
            this.btnCancel.Enabled = false;

            try
            {
                AppSettings.Settings.mqtt_serverandport = this.tb_ServerPort.Text.Trim();
                AppSettings.Settings.mqtt_password      = this.tb_Password.Text.Trim();
                AppSettings.Settings.mqtt_username      = this.tb_Username.Text.Trim();
                AppSettings.Settings.mqtt_UseTLS        = this.cb_UseTLS.Checked;

                using (Global_GUI.CursorWait cw = new Global_GUI.CursorWait())
                {
                    Log("------ TESTING MQTT --------");


                    string topic   = AITOOL.ReplaceParams(this.cam, null, null, this.tb_Topic.Text.Trim());
                    string payload = AITOOL.ReplaceParams(this.cam, null, null, this.tb_Payload.Text.Trim());

                    List <string> topics   = Global.Split(topic, ";|");
                    List <string> payloads = Global.Split(payload, ";|");

                    MQTTClient mq = new MQTTClient();
                    MqttClientPublishResult pr     = null;
                    ClsImageQueueItem       CurImg = null;


                    for (int i = 0; i < topics.Count; i++)
                    {
                        if (this.cam.Action_mqtt_send_image)
                        {
                            if (topics[i].IndexOf("/image", StringComparison.OrdinalIgnoreCase) >= 0)
                            {
                                if (!string.IsNullOrEmpty(this.cam.last_image_file_with_detections) && File.Exists(this.cam.last_image_file_with_detections))
                                {
                                    CurImg = new ClsImageQueueItem(this.cam.last_image_file_with_detections, 0);
                                }
                                else if (!string.IsNullOrEmpty(this.cam.last_image_file) && File.Exists(this.cam.last_image_file))
                                {
                                    CurImg = new ClsImageQueueItem(this.cam.last_image_file, 0);
                                }
                                else
                                {
                                    CurImg = null;
                                }
                            }
                            else
                            {
                                CurImg = null;
                            }
                        }

                        pr = await mq.PublishAsync(topics[i], payloads[i], this.cam.Action_mqtt_retain_message, CurImg);
                    }

                    Log("------ DONE TESTING MQTT --------");

                    if (pr != null && (pr.ReasonCode == MqttClientPublishReasonCode.Success))
                    {
                        MessageBox.Show("Success! See Log for details.");
                    }
                    else if (pr != null)
                    {
                        MessageBox.Show($"Failed. See log for details. Reason={pr.ReasonCode}", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show($"Failed. See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                this.btTest.Enabled    = true;
                this.btnSave.Enabled   = true;
                this.btnCancel.Enabled = true;
            }
        }
示例#8
0
        private async void bt_check_Click(object sender, EventArgs e)
        {
            try
            {
                this.ControlBox = false;

                Assembly CurAssm  = Assembly.GetExecutingAssembly();
                string   AssemVer = CurAssm.GetName().Version.Major + "." + CurAssm.GetName().Version.Minor + "." + CurAssm.GetName().Version.Build;
                CurrentVerTime          = Global.RetrieveLinkerTimestamp();
                lbl_CurrentVersion.Text = $"{AssemVer} ({CurrentVerTime.ToShortDateString()})";

                List <ReleaseNote> notes = new List <ReleaseNote>();

                using Global_GUI.CursorWait cw = new Global_GUI.CursorWait();
                bt_check.Enabled = false;
                bt_check.Text    = "Checking...";

                //first get the most recent release:
                if (client.IsNull())
                {
                    client = new GitHubClient(new ProductHeaderValue("AITOOL-VORLONCD"));
                }


                Log("Loading latest Github release...");

                releases = await client.Repository.Release.GetAll("VorlonCD", "bi-aidetection");

                //var assets = await client.rel Release.GetAllAssets("VorlonCD", "bi-aidetection", releases[0]);
                //var myAsset_zipFile = assets[0];

                string releasever = $"{releases[0].TagName} ({releases[0].PublishedAt.Value.LocalDateTime.ToShortDateString()})";
                linkLabelRelease.Text = releasever;

                ReleaseNote rn = new ReleaseNote();
                rn.Date    = releases[0].PublishedAt.Value.LocalDateTime;
                rn.Title   = releases[0].Name;
                rn.Body    = releases[0].Body;
                rn.Version = releases[0].TagName;
                rn.Type    = "Release";
                notes.Add(rn);



                //get the latest beta version installer file
                var repo = await client.Repository.Get("VorlonCD", "bi-aidetection");

                var contents = await client.Repository.Content.GetAllContents("VorlonCD", "bi-aidetection", "src/UI/Installer");

                //get the date on the file
                var path   = contents[0].Path; //"src/UI/Installer";
                var branch = "master";

                var request = new CommitRequest {
                    Path = path, Sha = branch
                };

                // find the latest commit to the file on a specific branch
                var commitsForFile = await client.Repository.Commit.GetAll(repo.Id, request);

                var mostRecentCommit = commitsForFile[0];
                var authorDate       = mostRecentCommit.Commit.Author.Date;
                var fileEditDate     = authorDate.LocalDateTime;

                string ver     = contents[0].Name.GetWord(".", ".exe");
                string betaver = $"{ver} ({fileEditDate.ToShortDateString()})";
                linkLabelBeta.Text = betaver;

                if (CurAssm.GetName().Version < new Version(ver))
                {
                    lbl_message.Visible = true;
                }
                else
                {
                    lbl_message.Visible = false;
                }

                var commits = await client.Repository.Commit.GetAll("VorlonCD", "bi-aidetection");

                for (int i = 0; i < commits.Count; i++)
                {
                    if (commits[i].Commit.Author.Date > releases[0].PublishedAt.Value.LocalDateTime)
                    {
                        rn       = new ReleaseNote();
                        rn.Date  = commits[i].Commit.Author.Date.LocalDateTime;
                        rn.Title = !commits[i].Label.IsNull() ? rn.Title : "";
                        rn.Body  = commits[i].Commit.Message;
                        bool hasdash = rn.Body.TrimStart().StartsWith("-");
                        bool hasstar = rn.Body.TrimStart().StartsWith("*");
                        if (!hasdash && !hasstar)
                        {
                            rn.Body = "* " + rn.Body.Trim();
                        }

                        if (i == 0)
                        {
                            rn.Version = ver;
                        }
                        else
                        {
                            rn.Version = "";
                        }

                        rn.Type = "Commit";
                        notes.Insert(0, rn);
                    }
                }


                //sort by date
                notes = notes.OrderByDescending((d) => d.Date).ToList();

                StringBuilder Markup = new StringBuilder();


                foreach (var note in notes)
                {
                    Markup.AppendLine($"{note.Version} ({note.Date}) {note.Title}");
                    Markup.AppendLine("");
                    Markup.AppendLine($"{note.Body}");
                    Markup.AppendLine("");
                    Markup.AppendLine("");
                }

                var html = Markdig.Markdown.ToHtml(Markup.ToString());
                webBrowser1.DocumentText = html;

                // get the download URL for this file on a specific branch
                //var file = await client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch);

                bt_InstallBeta.Enabled    = true;
                bt_installRelease.Enabled = true;

                //Setup the versions
                //Version latestGitHubVersion = new Version(releases[0].TagName);
                //Version localVersion = new Version("X.X.X");
            }
            catch (Exception ex)
            {
                Log("Error: " + ex.Msg());
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.ControlBox  = true;
                bt_check.Enabled = true;
                bt_check.Text    = "Check";
            }
        }
        private async void bt_check_Click(object sender, EventArgs e)
        {
            try
            {
                this.ControlBox = false;

                Assembly CurAssm  = Assembly.GetExecutingAssembly();
                string   AssemVer = CurAssm.GetName().Version.Major + "." + CurAssm.GetName().Version.Minor + "." + CurAssm.GetName().Version.Build;
                CurrentVerTime          = Global.RetrieveLinkerTimestamp();
                lbl_CurrentVersion.Text = $"{AssemVer} ({CurrentVerTime.ToShortDateString()})";

                List <ReleaseNote> notes = new List <ReleaseNote>();

                using Global_GUI.CursorWait cw = new Global_GUI.CursorWait();
                bt_check.Enabled = false;
                bt_check.Text    = "Checking...";

                //first get the most recent release:
                if (client.IsNull())
                {
                    client = new GitHubClient(new ProductHeaderValue("AITOOL-VORLONCD"));
                }

                Log("Getting Github rate limits...");

                var miscellaneousRateLimit = await client.Miscellaneous.GetRateLimits();

                //  The "core" object provides your rate limit status except for the Search API.
                var coreRateLimit = miscellaneousRateLimit.Resources.Core;

                var howManyCoreRequestsCanIMakePerHour = coreRateLimit?.Limit;
                var howManyCoreRequestsDoIHaveLeft     = coreRateLimit?.Remaining;
                var whenDoesTheCoreLimitReset          = coreRateLimit?.Reset.ToLocalTime(); // UTC time

                // the "search" object provides your rate limit status for the Search API.
                var searchRateLimit = miscellaneousRateLimit.Resources.Search;

                var howManySearchRequestsCanIMakePerMinute = searchRateLimit?.Limit;
                var howManySearchRequestsDoIHaveLeft       = searchRateLimit?.Remaining;
                var whenDoesTheSearchLimitReset            = searchRateLimit?.Reset.ToLocalTime(); // UTC time

                Log($"Github>>     Max Core Requests per hour: {howManyCoreRequestsCanIMakePerHour}  (remaining={howManyCoreRequestsDoIHaveLeft} left)");
                Log($"Github>> Max Search Requests per minute: {howManySearchRequestsCanIMakePerMinute}  (remaining={howManySearchRequestsDoIHaveLeft} left)");

                //------------------------------
                //Max Core=60/hr
                //Max search=10/min
                //WE USE ABOUT 20 CORE REQUESTS EACH UPDATE CHECK
                //doesnt look like we actually use "SEARCH" requests for this update check -Vorlon
                //------------------------------

                if (howManyCoreRequestsDoIHaveLeft <= 1 && whenDoesTheCoreLimitReset.IsNotNull())
                {
                    string err = $"GitHub>> Please wait until after {whenDoesTheSearchLimitReset} to check for updates again.\r\n\r\n(CORE Limit={howManyCoreRequestsCanIMakePerHour}/hr, remaining={howManyCoreRequestsDoIHaveLeft})";
                    Log(err);
                    MessageBox.Show(err, "GITHUB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (howManySearchRequestsDoIHaveLeft <= 1 && whenDoesTheSearchLimitReset.IsNotNull())
                {
                    string err = $"GitHub>> Please wait until after {whenDoesTheSearchLimitReset} to check for updates again.\r\n\r\n(SEARCH Limit={howManySearchRequestsCanIMakePerMinute}/min, remaining={howManySearchRequestsDoIHaveLeft})";
                    Log(err);
                    MessageBox.Show(err, "GITHUB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                Log("Loading latest Github release...");

                releases = await client.Repository.Release.GetAll("VorlonCD", "bi-aidetection");

                //var assets = await client.rel Release.GetAllAssets("VorlonCD", "bi-aidetection", releases[0]);
                //var myAsset_zipFile = assets[0];

                string releasever = $"{releases[0].TagName} ({releases[0].PublishedAt.Value.LocalDateTime.ToShortDateString()})";
                linkLabelRelease.Text = releasever;

                ReleaseNote rn = new ReleaseNote();
                rn.Date    = releases[0].PublishedAt.Value.LocalDateTime;
                rn.Title   = releases[0].Name;
                rn.Body    = releases[0].Body;
                rn.Version = releases[0].TagName;
                rn.Type    = "Release";
                notes.Add(rn);



                //get the latest beta version installer file
                var repo = await client.Repository.Get("VorlonCD", "bi-aidetection");

                var contents = await client.Repository.Content.GetAllContents("VorlonCD", "bi-aidetection", "src/UI/Installer");

                //get the date on the file
                var path   = contents[0].Path; //"src/UI/Installer";
                var branch = "master";

                var request = new CommitRequest {
                    Path = path, Sha = branch
                };

                // find the latest commit to the file on a specific branch
                var commitsForFile = await client.Repository.Commit.GetAll(repo.Id, request);

                var mostRecentCommit = commitsForFile[0];
                var authorDate       = mostRecentCommit.Commit.Author.Date;
                var fileEditDate     = authorDate.LocalDateTime;

                string ver     = contents[0].Name.GetWord(".", ".exe");
                string betaver = $"{ver} ({fileEditDate.ToShortDateString()})";
                linkLabelBeta.Text = betaver;

                if (CurAssm.GetName().Version < new Version(ver))
                {
                    lbl_message.Visible = true;
                }
                else
                {
                    lbl_message.Visible = false;
                }

                var commits = await client.Repository.Commit.GetAll("VorlonCD", "bi-aidetection");

                for (int i = 0; i < commits.Count; i++)
                {
                    if (commits[i].Commit.Author.Date > releases[0].PublishedAt.Value.LocalDateTime)
                    {
                        rn       = new ReleaseNote();
                        rn.Date  = commits[i].Commit.Author.Date.LocalDateTime;
                        rn.Title = !commits[i].Label.IsNull() ? rn.Title : "";
                        rn.Body  = commits[i].Commit.Message;
                        bool hasdash = rn.Body.TrimStart().StartsWith("-");
                        bool hasstar = rn.Body.TrimStart().StartsWith("*");
                        if (!hasdash && !hasstar)
                        {
                            rn.Body = "* " + rn.Body.Trim();
                        }

                        if (i == 0)
                        {
                            rn.Version = ver;
                        }
                        else
                        {
                            rn.Version = "";
                        }

                        rn.Type = "Commit";
                        notes.Insert(0, rn);
                    }
                }


                //sort by date
                notes = notes.OrderByDescending((d) => d.Date).ToList();

                StringBuilder Markup = new StringBuilder();


                foreach (var note in notes)
                {
                    Markup.AppendLine($"{note.Version} ({note.Date}) {note.Title}");
                    Markup.AppendLine("");
                    Markup.AppendLine($"{note.Body}");
                    Markup.AppendLine("");
                    Markup.AppendLine("");
                }

                var html = Markdig.Markdown.ToHtml(Markup.ToString());


                webBrowser1.DocumentText = html;



                // get the download URL for this file on a specific branch
                //var file = await client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch);

                bt_InstallBeta.Enabled    = true;
                bt_installRelease.Enabled = true;

                //Setup the versions
                //Version latestGitHubVersion = new Version(releases[0].TagName);
                //Version localVersion = new Version("X.X.X");
            }
            catch (Exception ex)
            {
                Log("Error: " + ex.Msg());
                MessageBox.Show("Error: " + ex.Message, "GITHUB API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.ControlBox  = true;
                bt_check.Enabled = true;
                bt_check.Text    = "Check";
            }
        }