Пример #1
0
        private void CustomGraphButton_Click(object sender, RoutedEventArgs e)
        {
            string path = Path.GetFullPath("../../../GraphGenerator/CustomGraphs");

            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Custom graph files (*.huu)|*.huu";
            dlg.InitialDirectory = path;

            if ( dlg.ShowDialog() == true )
            {
                try
                {
                    List<Graph> graphsList;

                    CustomXmlSerializer xmlSerializer = new CustomXmlSerializer(typeof(List<Graph>));

                    string encryptedXml = File.ReadAllText(dlg.FileName);
                    string plainXml = StringEncryption.Decrypt(encryptedXml, "Yaranaika?");

                    using (StringReader reader = new StringReader(plainXml))
                    {
                        graphsList = (List<Graph>)xmlSerializer.Deserialize(reader);
                    }

                    if (graphsList.Count != 1)
                        throw new Exception("W pliku powinien być dokładnie jeden graf.");

                    this.Hide();

                    ChooseAlgorithmView algorithmView = new ChooseAlgorithmView(graphsList[0]);               // First graph is always user graph
                    algorithmView.ShowDialog();

                    this.Show();
                }
                catch (Exception)
                {
                    MessageBox.Show("Wystąpił błąd podczas wczytywania pliku. Upewnij się, że nie jest on uszkodzony.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Пример #2
0
        public ExamViewModel(string algorithmName) : base("../../Resources/Graphs/ExamData.huu")
        {
            this.IsExamPanelVisible = true;
            this.PageColors.Add(Brushes.Yellow);
            this.PageColors.Add(Brushes.Yellow);

            try
            {
                Func<INotifyPropertyChanged, Type> typeLocator = (t) => App.GetViewClassTypeLocalizer(t);
                this._dialogService = new DialogService(null, typeLocator);

                this.AlgorithmName = algorithmName;
                this.LoadGraphs = GetGraphsFromList;

                List<Graph> graphsList;

                CustomXmlSerializer xmlSerializer = new CustomXmlSerializer(typeof(List<Graph>));

                string encryptedXml = File.ReadAllText(GRAPH_PATH);
                string plainXml = StringEncryption.Decrypt(encryptedXml, "Yaranaika?");

                using (StringReader reader = new StringReader(plainXml))
                {
                    graphsList = (List<Graph>)xmlSerializer.Deserialize(reader);
                }

                InitializeAlgorithmFromGraph(graphsList);
                InitializeAlgorithms();

                RaisePropertyChanged("CanvasNodes");
            }
            catch (Exception)
            {
                MessageBox.Show("Wystąpil nieoczekiwany błąd. Upewnij się, że pliki danych nie są uszkodzone.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);

                this.DialogResult = false;
            }
        }
Пример #3
0
        void LoadGraphExecute()
        {
            string path = Path.GetFullPath("../../CustomGraphs/");                  // Can bug in release, test it

            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.InitialDirectory = path;
            openDialog.Filter = "Custom graph file (*.huu)|*.huu";

            if (openDialog.ShowDialog() == true)
            {
                CustomXmlSerializer xmlSerializer = new CustomXmlSerializer( typeof(List<Graph>) );

                try
                {
                    string encryptedXml = File.ReadAllText(openDialog.FileName);
                    string plainXml = StringEncryption.Decrypt(encryptedXml, "Yaranaika?");
                    //string plainXml = encryptedXml;

                    //-------------------

                    //string dataPath = Path.GetFullPath("../../CustomGraphs/FullData.huu");
                    //plainXml = File.ReadAllText(dataPath);

                    //encryptedXml = StringEncryption.Encrypt(plainXml, "Yaranaika?");

                    //-------------------

                    using (StringReader reader = new StringReader(plainXml))
                    {
                        List<Graph> graphsList = ( (List<Graph>) xmlSerializer.Deserialize(reader) );

                        if (graphsList.Count != 1)
                            throw new Exception("W pliku powinien być dokładnie jeden graf.");

                        //Graph graph = ((List<Graph>)xmlSerializer.Deserialize(reader))[0];
                        Graph graph = graphsList[0];

                        //this.CanvasItems.Clear();
                        this.CanvasItems = graph.CanvasGraph;

                        for (int i = 0; i < Colors.Count; i++)
                        {
                            Colors[i] = graph.AlgorithmsSupported[i] ?
                                Brushes.Green : Brushes.Red;
                        }

                        RaisePropertyChanged("CanSaveGraph");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Wystąpił błąd podczas wczytywania pliku. Upewnij się, że nie jest on uszkodzony.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }