public TodoForm()
 {
     this.persistence = new Persistence();
     this.listState = new ListState(persistence);
     InitializeComponent();
 }
        private void loadScenarioButton_Click(object sender, EventArgs e)
        {
            new SQLDeleter();
            HcScen_1 testScen = new HcScen_1();

            ScenarioAnalyser analyser = new ScenarioAnalyser(testScen);

            Persistence occConnectedPers = new Persistence();
            testScen.playEvents(this.persistence, occConnectedPers);

            //BackgroundWorker newWorker = new BackgroundWorker();
            //newWorker.WorkerSupportsCancellation = false;
            //newWorker.WorkerReportsProgress = true;
            //newWorker.DoWork += getAllScenarioTestResults;
            //newWorker.ProgressChanged += updateScenarioTestResults;
            //newWorker.RunWorkerAsync();
        }
 public ListState(Persistence persistence)
 {
     this.persistence = persistence;
     currentList = new ListAggregate();
 }
        private void getAllScenarioTestResults(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            List<String> results = new List<String>();
            for (int i = 1; i < 10; i++)
            {
                new SQLDeleter();
                Persistence offLinePersistence = new Persistence();
                this.persistence = new Persistence();

                //string loc = "C:\\TEMP\\set1.txt";
                string loc = "C:\\TEMP\\RScen" + i + ".txt";
                RandomScenarioGenerator randGen = new RandomScenarioGenerator();
                // Scenario generatedScenario = randGen.generateRandomScenario(2000);
                //randGen.ObjectToFile(generatedScenario, loc);
                Scenario temp = (Scenario)randGen.FileToObject(loc);
                //generatedScenario.playEvents(this.persistence, tempPersistence);
                ScenarioAnalyser analyser = new ScenarioAnalyser(loc);
                //Scenario temp = new CustomScenario();

                //CustomOBScenario obScen = new CustomOBScenario();
                temp.playEvents(this.persistence, offLinePersistence);

                results.Add("Testset: " + i +"\n"
                                + "Commited : " + this.persistence.getLatestStreamRevision() + " \n"
                                + "BaseConflicts : " + analyser.baseConflictAmount + " \n"
                                + "FOund conflicts " + offLinePersistence.allConflicts.Count + " \n"
                                + "Percentage solved" + (1 - (float)offLinePersistence.allConflicts.Count / (float)analyser.baseConflictAmount) + " \n"
                                + "" + "" + " \n");

                worker.ReportProgress(0, results[i-1]);

            }
        }
 public void playEvents(Persistence onlinePersistence, Persistence occasionalyConnectedPersistence)
 {
     // Set for each step if it is online, and use it later as if it WAS online.
     bool wasOnline = true;
     foreach (ReplayStep step in replaySteps)
     {
         // If online,  persist the event in the online normal store.
         if (step.GetType() == typeof(OnlineReplayStep))
         {
             // If the last step was not online, it means that the store has come online and has to be set this way.
             if (!wasOnline)
             {
                 occasionalyConnectedPersistence.setConnection(true);
                 wasOnline = true;
             }
             onlinePersistence.PersistEvent(((OnlineReplayStep)step).onlineEvent);
         }
         else if (step.GetType() == typeof(OfflineReplayStep))
         {
             if (wasOnline)
             {
                 occasionalyConnectedPersistence.setConnection(false);
                 wasOnline = false;
             }
             onlinePersistence.PersistEvent(((OfflineReplayStep)step).onlineEvent);
             occasionalyConnectedPersistence.PersistEvent(((OfflineReplayStep)step).offlineEvent);
         }
     }
 }