Пример #1
0
        private void btnSaveSession_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EncogOCR_Session session = new EncogOCR_Session()
                {
                    ImageSize = _pixels,
                    Sketches  = _prevSketches.ToArray(),
                };

                //C:\Users\<username>\AppData\Roaming\Asteroid Miner\EncogOCR\
                string foldername = UtilityCore.GetOptionsFolder();
                foldername = System.IO.Path.Combine(foldername, FOLDER);
                Directory.CreateDirectory(foldername);

                string filename = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff - ");
                filename += cboSession.Text + ".xml";       //TODO: convert illegal chars
                filename  = System.IO.Path.Combine(foldername, filename);

                UtilityCore.SerializeToFile(filename, session);

                LoadSessionsCombobox();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #2
0
        private Tuple <bool, string> TryLoadSession(string name = "")
        {
            #region Find file

            //C:\Users\<username>\AppData\Roaming\Asteroid Miner\EncogOCR\
            string foldername = UtilityCore.GetOptionsFolder();
            foldername = System.IO.Path.Combine(foldername, FOLDER);

            if (!Directory.Exists(foldername))
            {
                return(Tuple.Create(false, "Saves folder doesn't exist"));
            }

            string[] filenames;
            if (string.IsNullOrEmpty(name))
            {
                filenames = Directory.GetFiles(foldername);
            }
            else
            {
                filenames = Directory.GetFiles(foldername, "*" + name + "*");
            }

            string filename = filenames.
                              OrderByDescending(o => o). // the files all start with a date same (ymdhmsf), so the last file alphabetically will be the latest
                              FirstOrDefault();

            if (filename == null)
            {
                return(Tuple.Create(false, "Couldn't find session"));
            }

            #endregion

            #region Deserialize session

            EncogOCR_Session session = null;
            try
            {
                session = UtilityCore.DeserializeFromFile <EncogOCR_Session>(filename);
            }
            catch (Exception ex)
            {
                return(Tuple.Create(false, ex.Message));
            }

            #endregion

            #region Load session

            _isLoadingSession = true;

            ClearEverything();

            _pixels        = session.ImageSize;
            txtPixels.Text = _pixels.ToString();

            if (session.Sketches != null)
            {
                foreach (var sketch in session.Sketches)
                {
                    sketch.GenerateBitmap(session.ImageSize);
                    sketch.GenerateImageControl();

                    AddSketch(sketch);
                }
            }

            _isLoadingSession = false;

            #endregion

            // The combo should already have this, be just making sure
            LoadSessionsCombobox();
            cboSession.Text = GetSessionNameFromFilename(filename);

            #region Redraw

            canvasInk.Strokes.Clear();

            RedrawSmallImage();

            //TODO: When the NN gets serialized/deserialized, turn this off
            RedrawPreviousImages(true);

            #endregion

            return(Tuple.Create(true, ""));
        }
Пример #3
0
        private void btnSaveSession_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EncogOCR_Session session = new EncogOCR_Session()
                {
                    ImageSize = _pixels,
                    Sketches = _prevSketches.ToArray(),
                };

                //C:\Users\<username>\AppData\Roaming\Asteroid Miner\EncogOCR\
                string foldername = UtilityCore.GetOptionsFolder();
                foldername = System.IO.Path.Combine(foldername, FOLDER);
                Directory.CreateDirectory(foldername);

                string filename = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff - ");
                filename += cboSession.Text + ".xml";       //TODO: convert illegal chars
                filename = System.IO.Path.Combine(foldername, filename);

                UtilityCore.SerializeToFile(filename, session);

                LoadSessionsCombobox();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }