Esempio n. 1
0
        private void DestroyMissingVenues(EventMetadataRecord eventMeta, EntityVm[] venues)
        {
            var eventVenues   = GetEventVenues(eventMeta, null);
            var missingVenues = eventVenues
                                .Where(ev => venues.All(v => v.Id != ev.Id))
                                .ToArray();

            foreach (var venueVm in missingVenues)
            {
                var venue = _entityRepository.Get(venueVm.Id);
                if (venue == null)
                {
                    continue;
                }

                venueVm.Destroy = true;
                SaveVenueDetail(eventMeta, venue, venueVm);
            }

            var missingVenueIds = missingVenues.Select(v => v.Id).ToArray();
            var shows           = eventMeta.ShowRecords.Where(s => missingVenueIds.Contains(s.EntityRecord.Id));

            foreach (var show in shows)
            {
                show.IsDeleted    = true;
                show.DateModified = DateTime.UtcNow;
            }
        }
Esempio n. 2
0
        public static EventMetadataVm CreateViewModel(EventMetadataRecord record, LoadMode mode,
                                                      IStorageProvider storageProvider)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            var result = new EventMetadataVm {
                Id = record.Id
            };

            if (mode == LoadMode.Compact || mode == LoadMode.Full)
            {
                result.Title     = record.Title;
                result.StartDate = record.StartTime;
                result.EndDate   = record.EndTime;
                result.Picture   = FileUtil.GetPictureUrl(record.Picture, storageProvider);
            }

            if (mode == LoadMode.Full)
            {
                result.CombineType          = (CombineType)record.CombineType;
                result.VenueOrderType       = (VenueOrderType)record.VenueOrderType;
                result.VenueTitleFormatType = (VenueTitleFormatType)record.VenueTitleFormatType;
                result.Latitude             = record.Latitude;
                result.Longitude            = record.Longitude;
                result.Status      = (EventStatus)record.Status;
                result.Description = record.Description;
            }

            return(result);
        }
Esempio n. 3
0
        private static void SaveVenueDetail(EventMetadataRecord eventMeta, EntityRecord venue, EntityVm venueVm)
        {
            // ReSharper disable once AccessToForEachVariableInClosure
            var entityDetail = eventMeta
                               .EventEntityDetailRecords
                               .FirstOrDefault(eedr => eedr.EntityRecord.Id == venueVm.Id);

            if (venueVm.EventDetail != null)
            {
                entityDetail = entityDetail ?? new EventEntityDetailRecord
                {
                    EntityRecord        = venue,
                    EventMetadataRecord = eventMeta
                };

                EntityService
                .ViewModelFactory
                .UpdateByViewModel(entityDetail, venueVm.EventDetail);

                if (entityDetail.Id == 0)
                {
                    eventMeta.EventEntityDetailRecords.Add(entityDetail);
                }

                entityDetail.IsDeleted = venueVm.Destroy;
            }
            else if (entityDetail != null)
            {
                entityDetail.IsDeleted = true;
            }
        }
Esempio n. 4
0
        private static void UpdateByViewModelPicture(EventMetadataRecord eventRec, ShowRecord record,
                                                     ShowVm showVm, IStorageProvider storageProvider)
        {
            var previousPictureUrl = FileUtil.GetPictureUrl(record.Picture, storageProvider);

            if (previousPictureUrl != showVm.Picture)
            {
                record.Picture = FileUtil.ProcessUploadedPicture(record.Picture, showVm.Picture,
                                                                 Path.Combine("event", eventRec.Id.ToString(CultureInfo.InvariantCulture), "shows"),
                                                                 storageProvider);
            }
        }
Esempio n. 5
0
        private static void SetEventMetadataCoordinate(
            EventMetadataRecord eventMetadata,
            IEnumerable <Venue> venues)
        {
            var coordinates = venues.SelectMany(
                v =>
                v.Addresses != null
                    ? v.Addresses.Select(
                    a => new PointF((float)a.Latitude, (float)a.Longitude))
                    : Enumerable.Empty <PointF>()).ToArray();

            var middle = MapUtil.GetMiddleCoordinate(coordinates);

            eventMetadata.Latitude  = middle.X;
            eventMetadata.Longitude = middle.Y;
        }
Esempio n. 6
0
        private static void UpdateReferenceShow(
            EventMetadataRecord eventMeta,
            EntityRecord venue,
            bool addReference)
        {
            var refShow = eventMeta
                          .ShowRecords
                          .FirstOrDefault(
                s =>
                s.EntityRecord.Id == venue.Id &&
                s.IsReference);

            if (addReference)
            {
                // creating a new ref show if venue is empty and there was no ref before
                if (refShow == null)
                {
                    refShow = new ShowRecord
                    {
                        EventMetadataRecord = eventMeta,
                        EntityRecord        = venue,
                        DateCreated         = DateTime.UtcNow,
                        IsReference         = true
                    };
                    eventMeta.ShowRecords.Add(refShow);
                }
                // restoring existing ref show
                else
                {
                    refShow.IsDeleted = false;
                }
            }
            else
            {
                // if ref show exists mark it as deleted
                if (refShow != null)
                {
                    refShow.IsDeleted = true;
                }
            }

            if (refShow != null)
            {
                refShow.DateModified = DateTime.UtcNow;
            }
        }
Esempio n. 7
0
        public static void UpdateByViewModel(EventMetadataRecord record, EventMetadataVm eventVm, EntityRecord host)
        {
            if (!eventVm.StartDate.HasValue)
            {
                throw new ArgumentNullException("eventVm.StartDate");
            }

            record.DateModified = DateTime.UtcNow;

            record.EntityRecord         = host;
            record.Title                = eventVm.Title.TrimIt().StripTags();
            record.Description          = eventVm.Description.TrimIt().StripTags();
            record.StartTime            = eventVm.StartDate.Value;
            record.EndTime              = eventVm.EndDate;
            record.CombineType          = (byte)eventVm.CombineType;
            record.Status               = (byte)eventVm.Status;
            record.VenueOrderType       = (byte)eventVm.VenueOrderType;
            record.VenueTitleFormatType = (byte)eventVm.VenueTitleFormatType;
        }
Esempio n. 8
0
        private EventMetadataRecord CreateEventMetadata(
            Event xmlOrgEvent,
            EntityRecord hostEntity,
            SmartWalkUserRecord user)
        {
            var result = _eventMetadataRepository
                         .Get(evMet =>
                              evMet.EntityRecord.Id == hostEntity.Id &&
                              evMet.StartTime == xmlOrgEvent.StartDateObject.Date);

            if (result == null)
            {
                result = new EventMetadataRecord
                {
                    EntityRecord        = hostEntity,
                    StartTime           = xmlOrgEvent.StartDateObject.Date,
                    CombineType         = (int)CombineType.None,
                    SmartWalkUserRecord = user,
                    DateCreated         = DateTime.UtcNow,
                    DateModified        = DateTime.UtcNow,
                    Status = (byte)EventStatus.Public
                };

                _eventMetadataRepository.Create(result);
                _log.Add(string.Format("{0} event metadata created", result.Title));
            }

            result.Title       = xmlOrgEvent.Title;
            result.Description = xmlOrgEvent.Description;
            result.Picture     = xmlOrgEvent.Logo;
            SetEventMetadataCoordinate(result, xmlOrgEvent.Venues);

            _eventMetadataRepository.Update(result);
            _eventMetadataRepository.Flush();
            _log.Add(string.Format(
                         "{0} event metadata coordinates updated to ({1}, {2})",
                         result.Title,
                         result.Latitude,
                         result.Longitude));

            return(result);
        }
Esempio n. 9
0
        private static void RecalcEventCoordinates(EventMetadataRecord eventMeta)
        {
            var coords = eventMeta
                         .ShowRecords
                         .Where(s => !s.IsDeleted)
                         .Select(s => s.EntityRecord)
                         .SelectMany(v => v.AddressRecords)
                         .Select(address => new PointF((float)address.Latitude, (float)address.Longitude))
                         .ToArray();

            if (coords.Length != 0)
            {
                var eventCoord = MapUtil.GetMiddleCoordinate(coords);
                eventMeta.Latitude  = eventCoord.X;
                eventMeta.Longitude = eventCoord.Y;
            }
            else
            {
                eventMeta.Latitude  = 0;
                eventMeta.Longitude = 0;
            }
        }
Esempio n. 10
0
        private EventMetadataVm CreateViewModelContract(
            EventMetadataRecord eventMeta,
            int?day,
            LoadMode mode = LoadMode.Full)
        {
            if (eventMeta == null)
            {
                throw new ArgumentNullException("eventMeta");
            }

            var result = ViewModelFactory.CreateViewModel(eventMeta, mode, _storageProvider);

            result.Host =
                EntityService
                .ViewModelFactory.CreateViewModel(eventMeta.EntityRecord, mode, _storageProvider);

            if (mode == LoadMode.Full)
            {
                result.Venues = GetEventVenues(eventMeta, day);
            }

            return(result);
        }
Esempio n. 11
0
        public static void UpdateByViewModelPicture(EventMetadataRecord record, EventMetadataVm eventVm,
                                                    Dictionary <ShowRecord, ShowVm> shows, IStorageProvider storageProvider)
        {
            var previousPictureUrl = FileUtil.GetPictureUrl(record.Picture, storageProvider);

            if (previousPictureUrl != eventVm.Picture)
            {
                record.Picture = FileUtil.ProcessUploadedPicture(record.Picture, eventVm.Picture,
                                                                 Path.Combine("event", record.Id.ToString(CultureInfo.InvariantCulture)),
                                                                 storageProvider);
            }

            foreach (var showRec in record.ShowRecords
                     .Where(s => !s.IsReference && !s.IsDeleted)
                     .ToArray())
            {
                ShowVm showVm;
                if (shows.TryGetValue(showRec, out showVm))
                {
                    UpdateByViewModelPicture(record, showRec, showVm, storageProvider);
                }
            }
        }
Esempio n. 12
0
        public static EventMetadata CreateDataContract(
            EventMetadataRecord record,
            string[] fields,
            string[] storages,
            IStorageProvider storageProvider,
            PictureSize?pictureSize,
            IImageProfileManager imageProfileManager)
        {
            var result = new EventMetadata
            {
                Id = record.Id
            };

            if (fields != null)
            {
                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataHost) &&
                    record.EntityRecord != null)
                {
                    result.Host = GetEntityReferences(record.EntityRecord, storages);
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataTitle))
                {
                    result.Title = record.Title;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataDescription))
                {
                    result.Description = record.Description;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataPicture))
                {
                    var picture = FileUtil.GetPictureUrl(record.Picture, storageProvider);
                    result.Picture = FileUtil.GetResizedPicture(picture, pictureSize, imageProfileManager);
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataPictures))
                {
                    var picture = FileUtil.GetPictureUrl(record.Picture, storageProvider);
                    result.Pictures = FileUtil.GetResizedPictures(picture, imageProfileManager);
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataStartTime))
                {
                    result.StartTime = record.StartTime;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataEndTime))
                {
                    result.EndTime = record.EndTime;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataLatitude))
                {
                    result.Latitude = record.Latitude;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataLongitude))
                {
                    result.Longitude = record.Longitude;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataCombineType))
                {
                    result.CombineType = (CombineType)record.CombineType;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataVenueOrderType))
                {
                    result.VenueOrderType = (VenueOrderType)record.VenueOrderType;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataVenueTitleFormatType))
                {
                    result.VenueTitleFormatType = (VenueTitleFormatType)record.VenueTitleFormatType;
                }

                if (fields.ContainsIgnoreCase(QueryContext.Instance.EventMetadataShows))
                {
                    result.Shows =
                        record.ShowRecords
                        .Where(s => !s.IsDeleted)
                        .Select(mr => new Reference
                    {
                        Id      = mr.Id,
                        Storage = StorageKeys.SmartWalk
                    })
                        .ToArray();
                }
            }

            return(result);
        }
Esempio n. 13
0
        private IList <EntityVm> GetEventVenues(EventMetadataRecord eventMeta, int?day)
        {
            var range      = new Tuple <DateTime?, DateTime?>(eventMeta.StartTime, eventMeta.EndTime);
            var currentDay =
                day == null
                    ? null
                    : (eventMeta.IsMultiDay() && eventMeta.StartTime.HasValue
                        ? (DateTime?)eventMeta.StartTime.Value.AddDays(day.Value)
                        : null);

            var allShows =
                eventMeta.ShowRecords
                .Where(s =>
                       !s.IsDeleted &&
                       (s.IsReference || s.StartTime.IsTimeThisDay(currentDay, range)))
                .ToArray();

            var venues = allShows
                         .Select(s => s.EntityRecord)
                         .Distinct()
                         .Select(e =>
            {
                var venueDetail = eventMeta
                                  .EventEntityDetailRecords
                                  .FirstOrDefault(eedr => !eedr.IsDeleted && eedr.EntityRecord.Id == e.Id);
                var venueVm = EntityService
                              .ViewModelFactory
                              .CreateViewModel(e, venueDetail, _storageProvider);

                venueVm.Shows = allShows
                                .Where(s => s.EntityRecord.Id == e.Id && !s.IsReference)
                                .OrderBy(s => s.StartTime)
                                .Select(s => ViewModelFactory.CreateViewModel(s, _storageProvider))
                                .ToArray();

                return(venueVm);
            });

            EntityVm[] result;

            if (eventMeta.VenueOrderType == (byte)VenueOrderType.Custom)
            {
                result = venues
                         .OrderBy(v =>
                                  v.EventDetail != null &&
                                  v.EventDetail.SortOrder != null
                            ? v.EventDetail.SortOrder.Value
                            : 0)
                         .ToArray();
            }
            else if (eventMeta.VenueOrderType == (byte)VenueOrderType.Name)
            {
                result = venues
                         .OrderBy(v => v.Name, NameComparer)
                         .ToArray();
            }
            else
            {
                result = venues.ToArray();
            }

            return(result);
        }
Esempio n. 14
0
        private void CreateOrUpdateShows(
            EventMetadataRecord eventMetadata,
            EntityRecord venue,
            Show[] xmlShows)
        {
            var shows = eventMetadata.ShowRecords;

            if (xmlShows != null && xmlShows.Any())
            {
                foreach (var xmlShow in xmlShows)
                {
                    string title;
                    string description    = null;
                    var    xmlDescription = xmlShow.Desciption.TrimIt();

                    if (xmlDescription.Length >= 255)
                    {
                        title       = xmlDescription.Substring(0, 50);
                        description = xmlDescription;
                    }
                    else
                    {
                        title = xmlDescription;
                    }

                    var show = shows.FirstOrDefault(s =>
                                                    s.EntityRecord.Id == venue.Id &&
                                                    s.Title == title);
                    if (show == null)
                    {
                        show = new ShowRecord
                        {
                            EntityRecord        = venue,
                            EventMetadataRecord = eventMetadata,
                            Title        = title,
                            Description  = description,
                            IsDeleted    = false,
                            DateCreated  = DateTime.UtcNow,
                            DateModified = DateTime.UtcNow,
                        };
                        _showRepository.Create(show);
                        _log.Add(string.Format("{0} show created", show.Title));
                    }

                    show.StartTime  = xmlShow.StartTimeObject;
                    show.EndTime    = xmlShow.EndTimeObject;
                    show.Picture    = xmlShow.Logo.TrimIt();
                    show.DetailsUrl = xmlShow.Web.TrimIt();

                    _showRepository.Update(show);
                    _showRepository.Flush();
                    _log.Add(string.Format("{0} show updated", show.Title));
                }
            }
            else
            {
                var refShow = shows.FirstOrDefault(s =>
                                                   s.EntityRecord.Id == venue.Id &&
                                                   s.IsReference);
                if (refShow == null)
                {
                    refShow = new ShowRecord
                    {
                        EntityRecord        = venue,
                        EventMetadataRecord = eventMetadata,
                        IsReference         = true,
                        IsDeleted           = false,
                        DateCreated         = DateTime.UtcNow,
                        DateModified        = DateTime.UtcNow,
                    };
                    _showRepository.Create(refShow);
                    _showRepository.Flush();
                    _log.Add(string.Format("Reference show created"));
                }
            }
        }
Esempio n. 15
0
 public static bool IsMultiDay(this EventMetadataRecord eventMetadata)
 {
     return(DateTimeExtensions.IsMultiDay(eventMetadata.StartTime, eventMetadata.EndTime));
 }