예제 #1
0
        //Внутренний метод для получения коллекции событий
        private EventShort[] GetEventsDataInternal(int whatevents)
        {
            EventShort[] NewEvents = new EventShort[1] {
                new EventShort()
            };
            //TO DO
            //using (var client = new UserClientExchange())
            //{
            //    for (int i = 0; i < 3; i++)
            //    {
            //        try
            //        {
            //            var syncSessionId = client.Login("Emeri", "Emeri", new Captcha());
            //            NewEvents = client.GetEventsList(syncSessionId, 0, true, whatevents, true);
            //            SavingEvents.SavingShortEvents("events.sqlite", NewEvents);                                   //Передаем для сохранения в БД массив скачанных коротких описаний событий
            //            client.Logout(syncSessionId);



            //            return NewEvents;
            //        }
            //        catch (Exception r)
            //        {
            //            var l = r.Message;
            //            //И пробуем работать без Интернета!
            //        }
            //    }

            //}
            WeHaveInetData = false;
            if (!WeHaveInetData)                //Если данных от сервера нет - достаем что есть из локальной БД
            {
                string            usedEventsDB  = "events.sqlite";
                List <EventShort> fittingEvents = new List <EventShort>();
                using (var eventFromDB = new SQLite.SQLiteConnection(Path.Combine(WorkingInetAndSQL.destinationPath, usedEventsDB), true))
                {
                    var query = eventFromDB.Query <EventsShort>("SELECT * FROM EventsShort WHERE EventDateTime > ?", new DateTime(2014, 04, 01).Ticks);                  //"SELECT * FROM EventsShort WHERE EventDateTime > ? AND EventDateTime < ?", new DateTime(2013, 01, 01, 00, 00, 00), new DateTime(2020, 01, 01, 00, 00, 00));
                    if (query.FirstOrDefault() != null)
                    {
                        List <EventsShort> queryList = query.ToList <EventsShort>();
                        foreach (EventsShort currEvent in queryList)
                        {
                            EventShort requestedEventShort = new EventShort();
                            requestedEventShort.Id = currEvent.EventServerID;
                            if (currEvent.EventName != null)
                            {
                                requestedEventShort.Name = currEvent.EventName;
                            }
                            else
                            {
                                requestedEventShort.Name = "UFO";
                            }
                            if (currEvent.EventDateTime != null)
                            {
                                requestedEventShort.Date = currEvent.EventDateTime;
                            }
                            else
                            {
                                requestedEventShort.Date = DateTime.Today;
                            }
                            if (currEvent.OrganizerName != null)
                            {
                                requestedEventShort.OrganizerName = currEvent.OrganizerName;
                            }
                            else
                            {
                                requestedEventShort.OrganizerName = "Universum";
                            }
                            if (currEvent.PhotoID != null)
                            {
                                requestedEventShort.PrimaryPhotoId = currEvent.PhotoID;
                            }
                            fittingEvents.Add(requestedEventShort);
                        }
                    }
                    else
                    {
                        EventShort emptyItem = new EventShort();
                        emptyItem.Id            = 1001;
                        emptyItem.Name          = "Событий не найдено";
                        emptyItem.Date          = DateTime.Today;
                        emptyItem.OrganizerName = "Universum";
                        //emptyItem.PrimaryPhotoId = 1;
                        fittingEvents.Add(emptyItem);
                    }
                    NewEvents = fittingEvents.ToArray();
                }
            }
            return(NewEvents);
        }
예제 #2
0
        //Спец метод для получения полной инфы по событию, зная его серверную ID
        private EventShort[] GetEventShortInternal(Int64 ourEventServerID)
        {
            EventShort[] NewEvents      = new EventShort[] {};
            EventShort[] resultingEvent = new EventShort[1] {
                new EventShort()
            };

            if (!CheckServerDataPresent(true))                  //Если данные от сервера есть - грузим из Инета
            {
                return(resultingEvent);

                //TO DO
                //using (var client = new UserClientExchange())
                //{
                //    try
                //    {
                //        for (int howManyTimesTryDownload = 0; howManyTimesTryDownload < 3; howManyTimesTryDownload++)
                //        {
                //            var syncSessionId = client.Login("Emeri", "Emeri", new Captcha());
                //            NewEvents = client.GetEventsList(syncSessionId, 0, true, 100, true);      //Массив событий
                //            SavingEvents.SavingShortEvents("events.sqlite", NewEvents);                                   //Передаем для сохранения в БД массив скачанных коротких описаний событий
                //            client.Logout(syncSessionId);

                //            howManyTimesTryDownload = 3;
                //        }
                //    }
                //    catch (Exception e)
                //    {
                //        var k = e.Message;
                //        //И пробуем работать без Интернета!
                //    }

                //    resultingEvent = NewEvents.Where(v => v.Id == ourEventServerID).ToArray();
                //    return resultingEvent;
                //}
            }
            else                                              //Если данных от сервера нет - грузим
            {
                string usedEventsDB = "events.sqlite";
                using (var eventFromDB = new SQLite.SQLiteConnection(Path.Combine(WorkingInetAndSQL.destinationPath, usedEventsDB)))
                {
                    var query = eventFromDB.Table <EventsShort>().Where(v => v.EventServerID == ourEventServerID);
                    if (query.FirstOrDefault() != null)             //Если есть в БД
                    {
                        EventShort requestedEventShort = new EventShort();
                        requestedEventShort.Id             = query.FirstOrDefault().EventServerID;
                        requestedEventShort.Name           = query.FirstOrDefault().EventName;
                        requestedEventShort.Date           = query.FirstOrDefault().EventDateTime;
                        requestedEventShort.OrganizerName  = query.FirstOrDefault().OrganizerName;
                        requestedEventShort.PrimaryPhotoId = query.FirstOrDefault().PhotoID;

                        resultingEvent[0] = requestedEventShort;
                        return(resultingEvent);
                    }
                    else
                    {
                        return(resultingEvent);
                    }
                }
            }
        }