// Constructor
        public MainPage()
        {
            InitializeComponent();

            UI ui = new UI(this);
            TodoList todoList = new TodoList();

            Manager manager = new Manager(ui,todoList);

            ui.TodoList = todoList;

            manager.ReCalc();

            // jubis testing WPCal
            cal = new WPCal(TestWPCal);
            cal.LoadUserEvents();

            Debug.WriteLine("starting");

            // SieniMaagi testing TodoList
            TestTodoList();
            TestTimeList();
        }
Beispiel #2
0
        public Algo(List<Event> pEventList, TodoList pTodoList, Action pCallback)
        {
            //aikaa_kaikelle = kuinka paljon aikaa tarvitaan kaikkien listassa olevien toteutukseen
            todolist = pTodoList;

            PopulateSorting();

            //tee timelist
            timelist = new TimeList(pEventList);

            // OPERATE
            // NOW => PANIC
            TodoEvent now = GetNextASAP();
            while (now != null) {
                Panic(now);
                now = GetNextASAP();
            }

            //for DL in DLs
            TodoEvent dl = GetNextDL();
            while (dl != null) {
                //	timeRqd = DL.Duration() * 3/2
                int time_required = (int)dl.Required.TotalMinutes;
                //	counter = timeRqd * 2
                int counter = time_required * 2;

                // deadlinen index, puolitettu tarvittaessa
                int end_index = timelist.GetTimeIndex(dl.GetTimeToDeadline());

                // start_index iteroidaan alaspäin
                int start_index = end_index - 1;
                // kuinka paljon tultiin alaspäin
                int duration = 0;

                while (start_index > 0) {
                    TimeList.Time element = timelist.GetElement(start_index);
                    // lisätään jokatapauksessa duration
                    duration += (int)element.Span.TotalMinutes;
                    // jos saadaan lisää tyhjää aikaa
                    if (element.Priority == Priority.FREE) {
                        counter -= (int)element.Span.TotalMinutes;
                    }
                    // jos tultiin tarpeeksi pitkälle
                    if (counter < 0) {
                        duration += counter;
                        int start_instance = dl.GetTimeToDeadline() - duration;
                        start_index = timelist.GetTimeIndex(start_instance);
                    }
                }
                if (timelist.GetTimeBetween(start_index, end_index) < time_required) {
                    Panic(dl);
                }
                TimeList list_dl = CropAndSort(start_index, end_index, timelist);
                Position(dl, list_dl);

                dl = GetNextDL();
            } // LOOP WHILE THERE IS DL

            // sijoita ensin continuous
            foreach (TodoEvent te in sortedLazy) {
                if (!te.Split) {
                    Position(te, timelist);
                }
            }
            // sijoita sitten jaettavat
            foreach (TodoEvent te in sortedLazy) {
                if (te.Split) {
                    Position(te, timelist);
                }
            }

            pCallback.Invoke();
        }
        /*
         * Testing ends
         */
        /**
         * SieniMaagi testing TodoList
         */
        void TestTodoList()
        {
            TodoList List = new TodoList();

            List.AddTodo("Tiskaus", new TimeSpan(0, 60, 0), Priority.LAZY, new DateTime(2013, 3, 12), "", true);
            List.AddTodo("Sali", new TimeSpan(0, 60, 0), Priority.ASAP, new DateTime(), "", false);

            Debug.WriteLine(List.GetTotalDuration());
        }