Ejemplo n.º 1
0
        private void LoadTemplates()
        {
            //var allTemplate = Directory.EnumerateFiles(ImageProcessingManager.TemplatePath, Constants.TEMPLATE_EXTENSION_SEARCH);
            //cmbTemplates.Items.Clear();
            //foreach (string template in allTemplate)
            //{
            //    cmbTemplates.Items.Add( Path.GetFileNameWithoutExtension(template));
            //}

            string tempalteCatalogFileName = ImageProcessingManager.TemplatePath + Constants.TEMPLATE_CATELOG_FILE;

            if (File.Exists(tempalteCatalogFileName) == false)
            {
                MessageBox.Show("There are no template present. Please create and save them.", "Load Template",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            var allTemplate = File.ReadAllLines(tempalteCatalogFileName);

            allLoadedTemplates = new List <TemplateEntity>();
            cmbTemplates.Items.Clear();

            foreach (string templateEntry in allTemplate)
            {
                TemplateEntity newTemplate   = new TemplateEntity();
                var            templateParts = templateEntry.Split(',');
                newTemplate.TemplateName     = templateParts[0];
                newTemplate.WebsiteURL       = templateParts[1];
                newTemplate.TemplateFileName = templateParts[2];
                allLoadedTemplates.Add(newTemplate);

                cmbTemplates.Items.Add(newTemplate.TemplateName + " <-> " + newTemplate.WebsiteURL);
            }
        }
Ejemplo n.º 2
0
        private void btnLoadTemplate_Click(object sender, EventArgs e)
        {
            TemplateEntity selectedEntity = allLoadedTemplates[cmbTemplates.SelectedIndex];

            if (selectedEntity != null)
            {
                //Console.WriteLine("Reading template " + selectedEntity.TemplateName);
                ImageProcessingManager.ReadTemplate(selectedEntity.TemplateFileName);

                MessageBox.Show("Template successfully loaded..", "Chess Master", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Console.WriteLine("Reading template DONE!");
            }
        }
Ejemplo n.º 3
0
        private void btnDeleteTemplate_Click(object sender, EventArgs e)
        {
            try
            {
                //LogHelper.logger.Info("btnDeleteTemplate_Click called...");
                var result = MessageBox.Show("Are you sure to delete this template?", "Chessbot",
                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                TemplateEntity selectedEntity = allLoadedTemplates[cmbTemplates.SelectedIndex];
                if (selectedEntity != null && result == DialogResult.Yes)
                {
                    string tempalteCatalogFileName = ImageProcessingManager.TemplatePath + Constants.TEMPLATE_CATELOG_FILE;
                    if (File.Exists(tempalteCatalogFileName) == false)
                    {
                        MessageBox.Show("There are no template present. Please create and save them.", "Load Template", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    var allTemplate = File.ReadAllLines(tempalteCatalogFileName);

                    List<string> newTemplateList = new List<string>();
                    foreach (string templateEntry in allTemplate)
                    {
                        TemplateEntity newTemplate = new TemplateEntity();
                        var templateParts = templateEntry.Split(',');
                        newTemplate.TemplateName = templateParts[0];
                        newTemplate.WebsiteURL = templateParts[1];
                        newTemplate.TemplateFileName = templateParts[2];
                        if (templateParts[0] != selectedEntity.TemplateName)
                        {
                            newTemplateList.Add(templateEntry);
                        }
                    }
                    File.WriteAllLines(tempalteCatalogFileName, newTemplateList.ToArray());

                    File.Delete(selectedEntity.TemplateFileName);

                    MessageBox.Show("Template Deleted!", "Chessbot",
                   MessageBoxButtons.OK, MessageBoxIcon.Information);

                    LoadTemplates();
                }
            }
            catch (Exception exception)
            {
                LogHelper.logger.Error("btnDeleteTemplate_Click: " + exception.Message);
                LogHelper.logger.Error("btnDeleteTemplate_Click: " + exception.StackTrace);
                MessageBox.Show("An error occurred. Please restart bot", "Chessbot", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //LogHelper.logger.Info("btnDeleteTemplate_Click finished...");
        }
Ejemplo n.º 4
0
        private void LoadTemplates()
        {
            try
            {
                //LogHelper.logger.Info("LoadTemplates called...");
                string tempalteCatalogFileName = ImageProcessingManager.TemplatePath + Constants.TEMPLATE_CATELOG_FILE;
                if (File.Exists(tempalteCatalogFileName) == false)
                {
                    MessageBox.Show("There are no template present. Please create and save them.", "Load Template", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                var allTemplate = File.ReadAllLines(tempalteCatalogFileName);
                allLoadedTemplates = new List<TemplateEntity>();
                cmbTemplates.Items.Clear();

                foreach (string templateEntry in allTemplate)
                {
                    TemplateEntity newTemplate = new TemplateEntity();
                    var templateParts = templateEntry.Split(',');
                    newTemplate.TemplateName = templateParts[0];
                    newTemplate.WebsiteURL = templateParts[1];
                    newTemplate.TemplateFileName = templateParts[2];
                    allLoadedTemplates.Add(newTemplate);

                    cmbTemplates.Items.Add(newTemplate.TemplateName + " <-> " + newTemplate.WebsiteURL);
                }
            }
            catch (Exception exception)
            {
                LogHelper.logger.Error("LoadTemplate: " + exception.Message);
                LogHelper.logger.Error("LoadTemplate: " + exception.StackTrace);
                MessageBox.Show("An error occurred. Please restart bot", "Chessbot", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //LogHelper.logger.Info("LoadTemplates finished...");
        }
Ejemplo n.º 5
0
        private void LoadTemplates()
        {
            //var allTemplate = Directory.EnumerateFiles(ImageProcessingManager.TemplatePath, Constants.TEMPLATE_EXTENSION_SEARCH);
            //cmbTemplates.Items.Clear();
            //foreach (string template in allTemplate)
            //{
            //    cmbTemplates.Items.Add( Path.GetFileNameWithoutExtension(template));
            //}

            string tempalteCatalogFileName = ImageProcessingManager.TemplatePath + Constants.TEMPLATE_CATELOG_FILE;
            if (File.Exists(tempalteCatalogFileName) == false)
            {
                MessageBox.Show("There are no template present. Please create and save them.", "Load Template",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            var allTemplate = File.ReadAllLines(tempalteCatalogFileName);
            allLoadedTemplates = new List<TemplateEntity>();
            cmbTemplates.Items.Clear();

            foreach (string templateEntry in allTemplate)
            {
                TemplateEntity newTemplate = new TemplateEntity();
                var templateParts = templateEntry.Split(',');
                newTemplate.TemplateName = templateParts[0];
                newTemplate.WebsiteURL = templateParts[1];
                newTemplate.TemplateFileName= templateParts[2];
                allLoadedTemplates.Add(newTemplate);

                cmbTemplates.Items.Add(newTemplate.TemplateName + " <-> " + newTemplate.WebsiteURL);
            }
        }