Example #1
0
        public void GetAlterations(IDataStoreItem item)
        {
            item.Alterations.Clear();
            System.Diagnostics.Debug.Print("GetAlterations(DatastoreItem item)....");
            RetrievalCriteria        rc1    = new RetrievalCriteria("DataStoreItemName", CriteraType.ExactTextMatch, item.ConcreteType.Name);
            RetrievalCriteria        rc2    = new RetrievalCriteria("ItemIDNumber", CriteraType.Equals, item.ID);
            List <RetrievalCriteria> rcList = new List <RetrievalCriteria>();

            rcList.Add(rc1);
            rcList.Add(rc2);
            System.Diagnostics.Debug.Print("    abou to get tmpList");
            AsyncObservableCollection <IDataStoreItem> tmpList = GetItems(typeof(DataStoreItemAlteration), rcList);

            System.Diagnostics.Debug.Print("    tmpList retrieved");
            foreach (IDataStoreItem i in tmpList)
            {
                System.Diagnostics.Debug.Print("         " + i.ConcreteType.Name);
                item.Alterations.Add(i as DataStoreItemAlteration);
            }
            System.Diagnostics.Debug.Print("GetAlterations(DatastoreItem item....Complete!");
        }
Example #2
0
        AsyncObservableCollection <IDataStoreItem> IDataLibrarian.GetAppointments(DateTime selectedDate)
        {
            if (AppointmentLists.Where(x => x.SelectedDate.Date == selectedDate.Date).Any())
            {
                return(AppointmentLists.Where(x => x.SelectedDate.Date == selectedDate.Date).First().Appointments);
            }

            List <RetrievalCriteria> rc    = new List <RetrievalCriteria>();
            RetrievalCriteria        first = new RetrievalCriteria("ScheduledArrivalTime", CriteraType.GreaterThan, selectedDate.Date);

            rc.Add(first);
            RetrievalCriteria second = new RetrievalCriteria("ScheduledArrivalTime", CriteraType.LessThan, selectedDate.Date.AddDays(1));

            rc.Add(second);
            AppointmentList ls = new AppointmentList();

            ls.Appointments = GetItems(typeof(Appointment), rc);

            ls.SelectedDate = selectedDate;

            AppointmentLists.Add(ls);

            return(ls.Appointments);
        }
Example #3
0
        public void UpdateAppointments()
        {
            DateTime start = DateTime.Now;

            lock (thisLock)
            {
                try
                {
                    foreach (AppointmentList al in AppointmentLists)
                    {
                        try
                        {
                            List <RetrievalCriteria> rc    = new List <RetrievalCriteria>();
                            RetrievalCriteria        first = new RetrievalCriteria("ScheduledArrivalTime", CriteraType.GreaterThan, al.SelectedDate.Date);
                            rc.Add(first);
                            RetrievalCriteria second = new RetrievalCriteria("ScheduledArrivalTime", CriteraType.LessThan, al.SelectedDate.Date.AddDays(1));
                            rc.Add(second);

                            //Create a new retriever item
                            EFDataRetriever spareRetriever = new EFDataRetriever();

                            List <IDataStoreItem> items = spareRetriever.RetrieveItems(typeof(Appointment), rc, true);

                            foreach (IDataStoreItem dt in items)
                            {
                                //rmember dt = item fress from database
                                //check if this already exists in the list of appointments
                                if (al.Appointments.Where(x => x.ID == dt.ID).Any())
                                {
                                    //this means this items is in the appointment list, we must check for updates
                                    IDataStoreItem oldItem = al.Appointments.Where(x => x.ID == dt.ID).First();


                                    if (oldItem.LastEditDate != dt.LastEditDate)
                                    {
                                        logger.Trace("Found appointment in current list -- Needs to be updated");

                                        retriever.UpdateItem(oldItem);
                                    }
                                    else
                                    {
                                    }

                                    //Now we check all the tasks for this appointment
                                    foreach (BasicTask bt in ((Appointment)dt).Tasks)
                                    {
                                        try
                                        {
                                            if (((Appointment)oldItem).Tasks.Where(x => x.ID == bt.ID).Any())
                                            {
                                                //this task is already in the appointment - check for updates needed
                                                BasicTask ot = ((Appointment)oldItem).Tasks.Where(x => x.ID == bt.ID).First();
                                                if (ot.LastEditDate != bt.LastEditDate)
                                                {
                                                    retriever.UpdateItem(ot);
                                                }
                                                //foreach (BaseConstraint c in bt.Constraints)
                                                //{
                                                //    if (ot.Constraints.Where(x => x.ID == c.ID).Any())
                                                //    {
                                                //        //this constraint exists in our version
                                                //        if (ot.Constraints.Where(x => x.ID == c.ID).First().LastEditDate != c.LastEditDate)
                                                //        {
                                                //            retriever.UpdateItem(ot.Constraints.Where(x => x.ID == c.ID).First());

                                                //        }
                                                //    }
                                                //    else
                                                //    {



                                                //    }
                                                //}
                                            }
                                            else
                                            {
                                                //need to add this task
                                                //(oldItem as Appointment).Tasks.Add(bt);

                                                retriever.UpdateItem(oldItem);
                                                System.Diagnostics.Debug.WriteLine("New task found ... appointment reloaded");
                                                if (bt is ArrivalTask)
                                                {
                                                    System.Diagnostics.Debug.WriteLine("task being added is arrivalTask");
                                                    (oldItem as Appointment).FireArrivalEvent();
                                                }
                                                else
                                                {
                                                    System.Diagnostics.Debug.WriteLine("task being added is NOT arrivalTask");
                                                }
                                                retriever.SaveItem(oldItem);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    //This one is not in the list of appointments must add it.
                                    logger.Trace("Could not find this appointment in the current list");

                                    al.Appointments.Add(dt);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Caught exception during appointment refresh: " + ex.Message);
                        }
                    }
                }
                catch
                {
                }

                logger.Trace("UpdateAppointments()...done");
            }
        }