Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 3
0
        void SaveGraphExecute()
        {
            string path = Path.GetFullPath("../../CustomGraphs/");                  // Can bug in release, test it

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

            if (saveDialog.ShowDialog() == true)
            {
                List<Graph> graphsList = new List<Graph>();                         // Graphs will be initially stored as list - algorithm views will read random graph from it,
                                                                                    // and user graphs will always be the first and only element in the list
                Graph graph = new Graph();
                graph.CanvasGraph = CanvasItems;

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

                graphsList.Add(graph);
                CustomXmlSerializer xmlSerializer = new CustomXmlSerializer( typeof(List<Graph>) );

                using ( StringWriter writer = new StringWriter() )
                {
                    xmlSerializer.Serialize(writer, graphsList);

                    string plainXml = writer.GetStringBuilder().ToString();
                    string encryptedXml = StringEncryption.Encrypt(plainXml, "Yaranaika?");
                    //string encryptedXml = plainXml;

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

                    //string dataPath = Path.GetFullPath("../../CustomGraphs/Prawdziwe algorytmy - learning/Data.huu");
                    //string encryptedDataPath = Path.GetFullPath("../../CustomGraphs/Prawdziwe algorytmy - learning/EncryptedData.huu");

                    //string dataPath = Path.GetFullPath("../../CustomGraphs/Prawdziwe algorytmy - egzamin/Data.huu");
                    //string encryptedDataPath = Path.GetFullPath("../../CustomGraphs/Prawdziwe algorytmy - egzamin/EncryptedData.huu");

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

                    //File.WriteAllText(encryptedDataPath, encryptedXml);

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

                    File.WriteAllText(saveDialog.FileName, encryptedXml);
                }
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }