Exemplo n.º 1
0
        private bool SynchronizePhotos(EventTDO ev)
        {
            try {
                string scopeName = GenerateScopeName(AppConfig.PhotoSyncScopeName, ev.EventId.ToString());
                if (!InitializePhotoSyncProviders(ev, scopeName, AppConfig.PhotoStaticSyncTables, AppConfig.PhotoDynamicSyncTables))
                {
                    return(false);
                }

                _sqlPhotoClientSync.ChangesApplied += new ChangesAppliedEventHandler(OnDbChangesApplied);

                FotoShoutUtils.Log.LogManager.Info(_logger, "Uploading photos and guests to central server...");
                _sqlPhotoClientSync.Synchronize(_sqlPhotoServerSync);
                //_sqlPhotoClientSync.Synchronize(sqlServerSync.Provider);

                FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully uploaded.");

                return(true);
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Exception when synchronizing database of photos of the \"{0}\" event.\n{1}", ev.EventName, ex.ToString()));
            }
            finally {
                RemoveClientUploadSyncEventHandlers(_sqlPhotoClientSync);
            }

            return(false);
        }
Exemplo n.º 2
0
        private void PublishEvents()
        {
            try {
                _emailService.EmailServerAccount = _fsWebService.GetEmailServerConfiguration();
                if (!_emailService.IsValid())
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, "There is not enough email server info, so there will be no email sent out to guests for this event.\r\n");
                }
            }
            catch (HttpClientServiceException ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.Message + "\r\n");
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString() + "\r\n");
            }

            try {
                IEnumerable <EventTDO> tdos = _fsWebService.GetEvents("Open");
                if (!tdos.Any())
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, "There is no opening events for the current user.\r\n");
                    return;
                }

                foreach (EventTDO tdo in tdos)
                {
                    EventTDO ev = _fsWebService.GetEvent(tdo.EventId);
                    PostProcessEvent(ev);
                    PublishEvent(ev);
                }
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString() + "\r\n");
            }
        }
Exemplo n.º 3
0
        private void UploadEventsData()
        {
            FotoShoutUtils.Log.LogManager.Info(_logger, "Getting events...");
            IEnumerable <EventTDO> events = _fsClientService.GetEvents("Open");

            if (!events.Any())
            {
                FotoShoutUtils.Log.LogManager.Info(_logger, "There is no events in the local machine for the current FotoShout user.");
                return;
            }

            IEnumerable <EventTDO> serverEvents = _fsServerService.GetEvents("All");

            foreach (EventTDO ev in events)
            {
                bool processSync = (!string.IsNullOrEmpty(AppConfig.SyncAction) && !AppConfig.SyncAction.Equals(FotoShoutUtils.Constants.ASV_SYNCACTION_PROVISION, StringComparison.InvariantCultureIgnoreCase));
                if (!processSync)
                {
                    EventTDO serverEvent = serverEvents.Where(se => se.EventId == ev.EventId && se.EventName.Equals(ev.EventName, StringComparison.InvariantCulture)).SingleOrDefault();
                    processSync = (serverEvent != null);
                }
                if (processSync)
                {
                    UploadEventData(ev);
                }
                else
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("The \"{0}\" event was locally created on the PC, so its photos won't be uploaded to the central server.", ev.EventName));
                }
            }
        }
Exemplo n.º 4
0
        private string GenerateDefaultEmailContent(UserTDO user, EventTDO ev, GuestTDO guest, string permalink)
        {
            var model = new {
                Name        = !string.IsNullOrEmpty(guest.Salutation) ? (guest.Salutation + " ") : "" + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : "Sir/Madam"),
                FirstName   = !string.IsNullOrEmpty(guest.FirstName) ? guest.FirstName : "",
                LastName    = !string.IsNullOrEmpty(guest.LastName) ? guest.LastName : "",
                EventName   = !string.IsNullOrEmpty(ev.EventName) ? ev.EventName : "",
                Email       = !string.IsNullOrEmpty(guest.Email) ? guest.Email : "",
                UserName    = (!string.IsNullOrEmpty(user.FirstName) ? (user.FirstName + " ") : "") + (!string.IsNullOrEmpty(user.LastName) ? user.LastName : ""),
                AccountName = !string.IsNullOrEmpty(user.AccountName) ? user.AccountName : "",
                PermaLink   = permalink
            };
            string template = @"<html>
                                    <head><title>@Model.LastName</title></head>
                                    <body>
                                        Dear @Model.FirstName:<br />
                                        <p>
                                        Thank you for joining us at @Model.EventName. We hope that you enjoy it.
                                        </p>
                                        <p>
                                        Please follow the <a href='@Model.PermaLink'>link</a> to view your photo.
                                        </p>
                                        <br />
                                        <p>
                                        Sincerely,<br />
                                        @Model.UserName - @Model.AccountName
                                        </p>
                                    </body>
                                </html>";

            return(Razor.Parse(template, model));
        }
Exemplo n.º 5
0
        public ActionResult EditEvent(EventTDO ev)
        {
            if (ModelState.IsValid)
            {
                try {
                    ev.EventFolder = ev.EventFolder.Trim();
                    if (fsWebService.UpdateEvent(ev.EventId, ev) != null)
                    {
                        return(RedirectToAction("Events"));
                    }
                    else
                    {
                        this.AddModelError(string.Format(Errors.ERROR_EVENT_UPDATE_UNEXPECTED, ev.EventName), _logger);
                    }
                }
                catch (Exception ex) {
                    GenerateErrorMessage(Constants.ACTION_EVENT_MODIFY, ex, ev);
                }
            }
            else
            {
                this.AddModelError(ModelState.Values.SelectMany(v => v.Errors).ToList(), _logger);
            }

            InitParameters(ev);
            ViewBag.StartedSubmitting = fsWebService.GetNumProcessedPhotos(ev.EventId) != 0;

            return(View(EventController.OPER_VIEW_MODIFY, ev));
        }
Exemplo n.º 6
0
        //FilteringSqlServerSync sqlServerSync = null;

        private bool InitializePhotoSyncProviders(EventTDO ev, string scopeName, string[] staticSyncTables, string[] dynamicSyncTables)
        {
            if (string.IsNullOrEmpty(AppConfig.PhotoDbServerSyncClass))
            {
                FotoShoutUtils.Log.LogManager.Error(_logger, "The type of the database server upload sync need to be defined in app config.");
                return(false);
            }

            //sqlServerSync = new FilteringSqlServerSync();
            //sqlServerSync.Configure(AppConfig.SyncAction, scopeName, AppConfig.ServerConnection, staticSyncTables, dynamicSyncTables);

            _sqlPhotoServerSync = new SqlServerSyncProviderProxy(AppConfig.SyncAction, scopeName, AppConfig.ServerConnection, staticSyncTables, dynamicSyncTables, AppConfig.PhotoDbServerSyncClass, SyncEngine.WFC_SERVICE_SQLSERVER);
            FotoShoutUtils.Log.LogManager.Info(_logger, "Server Upload Sync - " + _sqlPhotoServerSync.Ping());

            DbSyncScopeDescription scopeDescription = _sqlPhotoServerSync.GetScopeDescription(scopeName);

            //DbSyncScopeDescription scopeDescription = sqlServerSync.GetScopeDescription(scopeName);
            _sqlPhotoClientSync = InitiateSyncScope(scopeName, scopeDescription, (SyncDirectionOrder)Enum.Parse(typeof(SyncDirectionOrder), AppConfig.PhotoSyncDirection));
            if (_sqlPhotoClientSync != null)
            {
                _sqlPhotoClientSync.Synchronized += new FotoShoutUtils.Sync.Db.SynchronizedEventHandler(OnDbUploadSynchronized);
            }

            return(_sqlPhotoClientSync != null);
        }
Exemplo n.º 7
0
 internal void SendEmails(UserTDO user, EventTDO ev, PhotoAnnotation photoAnnotation, ICollection <string> permalinks)
 {
     this.Error = "";
     foreach (GuestTDO guest in (IEnumerable <GuestTDO>)photoAnnotation.Guests)
     {
         this.SendEmailTo(user, ev, guest, permalinks);
     }
 }
Exemplo n.º 8
0
 private void UpdateTDO(EventTDO tdo, Event ev)
 {
     tdo.EventId          = ev.EventId;
     tdo.Created          = ev.Created;
     tdo.CreatedBy        = ev.CreatedBy;
     tdo.EventVirtualPath = ev.EventVirtualPath;
     tdo.Thumbnail        = AppConfigs.VirtualRoot + EventPhotosService.GetThumbnailUrl(ev.EventId, ev.EventFolder, ev.EventVirtualPath, db);
 }
Exemplo n.º 9
0
        // GET api/Events
        public IEnumerable <EventTDO> GetEvents(string eventType = "")
        {
            EventStatus        evType = EventPhotosService.GetEventStatus(eventType);
            HashSet <EventTDO> tdos   = new HashSet <EventTDO>();

            try {
                IEnumerable <Event> events = (evType != EventStatus.Undefined) ?
                                             db.Events.Where(ev => ev.User.Id == CurrentUser.Id && ev.EventStatus == (byte)evType).Include(e => e.EventOption).OrderBy(ev => ev.EventName).ToList() :
                                             db.Events.Where(ev => ev.User.Id == CurrentUser.Id).Include(e => e.EventOption).OrderBy(ev => ev.EventName).ToList();
                if (events.Any())
                {
                    foreach (Event ev in events)
                    {
                        string error = DirectoryUtils.GenerateDirectories(ev.EventFolder);
                        if (!string.IsNullOrEmpty(error))
                        {
                            this.GenerateException(HttpStatusCode.InternalServerError, error, _logger);
                        }
                        FotoShoutApi.Services.IO.DirectoryService.GenerateVirtualPath(ev.EventFolder);

                        if (evType != EventStatus.Undefined || EventPhotosService.IsEventType(ev, eventType))
                        {
                            EventTDO tdo = new EventTDO {
                                EventId          = ev.EventId,
                                EventName        = ev.EventName,
                                EventDescription = ev.EventDescription,
                                EventDate        = ev.EventDate,
                                EventLocation    = ev.EventLocation,
                                EventFolder      = ev.EventFolder,
                                EventVirtualPath = ev.EventVirtualPath,
                                Created          = ev.Created,
                                CreatedBy        = ev.CreatedBy,
                                EventOptionId    = ev.EventOption.EventOptionId,
                                EventStatus      = ev.EventStatus,
                                PublishAlbum     = ev.PublishAlbum
                            };

                            try {
                                string relativeThumbnail = EventPhotosService.GetThumbnailUrl(tdo.EventId, tdo.EventFolder, tdo.EventVirtualPath, db);
                                tdo.Thumbnail = string.IsNullOrEmpty(relativeThumbnail) ? "" : AppConfigs.VirtualRoot + relativeThumbnail;
                            }
                            catch (ObjectNotFoundException) {
                                tdo.Thumbnail = "";
                            }
                            tdos.Add(tdo);
                        }
                    }
                }
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(tdos);
        }
Exemplo n.º 10
0
        internal void SendEmails(UserTDO user, EventTDO ev, PhotoAnnotation photoAnnotation, string permalink)
        {
            Error = "";

            ICollection <GuestTDO> guests = photoAnnotation.Guests;

            foreach (GuestTDO guest in guests)
            {
                SendEmailTo(user, ev, guest, permalink);
            }
        }
Exemplo n.º 11
0
        private void InitParameters(EventTDO ev)
        {
            ev.ChannelGroups = GetChannelGroups();
            EventTDO temp = fsWebService.GetEvent(0);

            if (temp != null)
            {
                ev.EventOptions   = temp.EventOptions;
                ev.Sponsors       = temp.Sponsors;
                ev.EmailTemplates = temp.EmailTemplates;
            }
        }
Exemplo n.º 12
0
        internal void SendEmailTo(UserTDO user, EventTDO ev, GuestTDO guest, ICollection <string> permalinks)
        {
            if (string.IsNullOrEmpty(guest.Email))
            {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no email address stored for {0}.", ((!string.IsNullOrEmpty(guest.FirstName)) ? (guest.FirstName + " ") : "") + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : guest.GuestId.ToString())));
                return;
            }

            foreach (string permalink in permalinks)
            {
                SendEmailTo(user, ev, guest, permalink);
            }
        }
Exemplo n.º 13
0
        private void SendEmails(UserTDO user, EventTDO ev, PhotoTDO photo, PhotoAnnotation photoAnnotation, string photoUrl)
        {
            if (ev.WebsiteId != null)
            {
                Website website = _fsWebService.Get <Website>("Websites/" + ev.WebsiteId, true);
                photoUrl = GeneratePhotoWebsiteUrl(photoUrl, website); // string.Format("{0}PhotoWebsite/{1}?website={2}", Regex.Replace(AppSettings.FsApiBaseAddress, @"api/", ""), photo.PhotoId, ev.WebsiteId);
            }

            ICollection <GuestTDO>   guests = photoAnnotation.Guests;
            IEnumerable <PhotoEmail> list   = this._fsWebService.GetList <PhotoEmail>("PhotoEmails/" + (object)photo.PhotoId, true);

            foreach (GuestTDO guestTdo in (IEnumerable <GuestTDO>)guests)
            {
                GuestTDO   guest      = guestTdo;
                bool       flag       = true;
                PhotoEmail postObject = list.Where(ee => ee.PhotoId == photo.PhotoId && ee.GuestId == guest.GuestId).FirstOrDefault();
                if (postObject == null)
                {
                    postObject = new PhotoEmail {
                        EventId = ev.EventId,
                        PhotoId = photo.PhotoId,
                        GuestId = guest.GuestId
                    };
                    flag = false;
                }
                else if (postObject.Status == (byte)1)
                {
                    continue;
                }
                this._emailService.Error = "";
                this._emailService.SendEmailTo(user, ev, guest, photoUrl);
                if (string.IsNullOrEmpty(this._emailService.Error))
                {
                    postObject.Status = (byte)1;
                    postObject.Error  = null;
                }
                else
                {
                    postObject.Status = byte.MaxValue;
                    postObject.Error  = this._emailService.Error;
                }
                if (flag)
                {
                    this._fsWebService.UploadString("PhotoEmails?photoEmailId=" + (object)postObject.PhotoEmailId, this.GeneratePostContent <PhotoEmail>(postObject), "PUT");
                }
                else
                {
                    this._fsWebService.UploadString("PhotoEmails", this.GeneratePostContent <PhotoEmail>(postObject), null);
                }
            }
        }
Exemplo n.º 14
0
        //
        // GET: /Event/DeleteEvent/5
        public ActionResult DeleteEvent(int id = 0)
        {
            EventTDO ev = fsWebService.GetEvent(id);
            int      numProcessedPhotos = fsWebService.GetNumProcessedPhotos(id);

            if (numProcessedPhotos != 0)
            {
                return(PartialView("_PreventDeletion", ev));
            }
            else
            {
                return(PartialView("_DeleteConfirmation", ev));
            }
        }
Exemplo n.º 15
0
        private bool UpdateEventInfo(int id)
        {
            EventTDO ev = fsWebService.GetEvent(id);

            if (ev != null)
            {
                ViewBag.EventName = ev.EventName;
                ViewBag.EventDate = ev.EventDate.ToString("dddd MM/dd/yyyy");
                return(true);
            }

            ViewBag.Error = "Unexpected error: An event with the id of {0} not found.";
            return(false);
        }
Exemplo n.º 16
0
        public ActionResult DeleteConfirmed(int id)
        {
            try {
                EventTDO ev = fsWebService.DeleteEvent(id);
                if (ev == null)
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format(Errors.ERROR_EVENT_DELETE, id));
                    ViewBag.Error = string.Format(Errors.ERROR_EVENT_DELETE, id);
                }
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                ViewBag.Error = ex.Message;
            }

            return(Events("Open"));
        }
Exemplo n.º 17
0
        private ActionResult ProcessEvent(string viewName, int id)
        {
            try {
                EventTDO ev = fsWebService.GetEvent(id);
                if (ev != null)
                {
                    ev.ChannelGroups = GetChannelGroups();
                    ev.Websites      = fsWebService.GetEventWebsites();
                    return(View(viewName, ev));
                }

                return((id != 0) ? HttpNotFound(string.Format(Errors.ERROR_EVENT_DETAIL, id)) : HttpNotFound(Errors.ERROR_EVENT_EVENTOPTIONS));
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                return(HttpNotFound(ex.Message));
            }
        }
Exemplo n.º 18
0
        private void SynchronizeFiles(EventTDO ev)
        {
            FileStoreSync  fsClientSync = null;
            FileStoreProxy fsServerSync = null;

            try {
                string evFolder = ev.EventFolder;
                if (string.IsNullOrEmpty(evFolder))
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("The event folder name for the \"{0}\" event is empty.", ev.EventName));
                    return;
                }

                DirectoryInfo di = new DirectoryInfo(evFolder);
                if (!di.Exists)
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("The \"{0}\" folder of the \"{1}\" event not found.", evFolder, ev.EventName));
                    return;
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Synchronizing photos of the \"{0}\" event.", ev.EventName));
                string[] imgExts = ImageUtils.GetImageExts().Split('|');
                fsClientSync = InitializeSyncFileSystem(evFolder, SyncDirectionOrder.Upload, imgExts);
                fsServerSync = new FileStoreProxy(evFolder, SyncEngine.WFC_SERVICE_FILESERVER, imgExts);
                FotoShoutUtils.Log.LogManager.Info(_logger, fsServerSync.Ping());

                fsClientSync.Synchronize(fsServerSync, SyncDetails.BATCHSIZE_DEFAULT);
                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Successfully Synchronized photos of the \"{0}\" event.", ev.EventName));
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Exception when synchronizing photos of the \"{0}\" event.\n{1}", ev.EventName, ex.ToString()));
            }
            finally {
                if (fsClientSync != null)
                {
                    // De-register event handlers for file system sync
                    fsClientSync.AppliedChange   -= new AppliedChangeEventHandler(OnFileSystemAppliedChange);
                    fsClientSync.SkippedChange   -= new SkippedChangeEventHandler(OnFileSystemSkippedChange);
                    fsClientSync.ItemConflicting -= new FotoShoutSyncService.ItemConflictingEventHandler(OnFileSystemItemConflicting);
                    fsClientSync.ItemConstraint  -= new FotoShoutSyncService.ItemConstraintEventHandler(OnFileSystemItemConstraint);
                    fsClientSync.Synchronized    -= new FotoShoutSyncService.SynchronizedEventHandler(OnFileSystemSynchronized);
                }
            }
        }
Exemplo n.º 19
0
        private string GetEmailContent(UserTDO user, EventTDO ev, GuestTDO guest, string permalink)
        {
            var model = new {
                Name        = !string.IsNullOrEmpty(guest.Salutation) ? (guest.Salutation + " ") : "" + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : "Sir/Madam"),
                FirstName   = !string.IsNullOrEmpty(guest.FirstName) ? guest.FirstName : "",
                LastName    = !string.IsNullOrEmpty(guest.LastName) ? guest.LastName : "",
                EventName   = !string.IsNullOrEmpty(ev.EventName) ? ev.EventName : "",
                Email       = !string.IsNullOrEmpty(guest.Email) ? guest.Email : "",
                UserName    = (!string.IsNullOrEmpty(user.FirstName) ? (user.FirstName + " ") : "") + (!string.IsNullOrEmpty(user.LastName) ? user.LastName : ""),
                AccountName = !string.IsNullOrEmpty(user.AccountName) ? user.AccountName : "",
                PermaLink   = permalink
            };
            string emailContent = "";

            try {
                emailContent = Razor.Parse(EmailTemplate.EmailContent, model);
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Error: {0} - Publishing service will use the default email content.", ex.ToString()));
            }
            return(emailContent);
        }
Exemplo n.º 20
0
        private void PublishEvent(EventTDO ev)
        {
            try {
                if (ev.ChannelGroupId == 0 || ev.ChannelGroupId == null)
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("There is no publish channel group being configured for the \"{0}\" event, so no photos will be published for this event.", ev.EventName));
                    return;
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Getting details of the channel group {0}...", ev.ChannelGroupId));
                ChannelGroup channelGroup = _c9WebService.Get <ChannelGroup>("Template/" + ev.ChannelGroupId, true);
                if (channelGroup == null)
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no channel group with the id {0}.", ev.ChannelGroupId));
                }

                IEnumerable <PhotoTDO> photos = _fsWebService.GetAuthorizedPhotos(ev.EventId);
                if (!photos.Any())
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, FotoShoutUtils.Constants.INFO_EVENT_AUTHORIZEDPHOTOS_NOPHOTOS);
                    return;
                }
                foreach (PhotoTDO photo in photos)
                {
                    PublishPhoto(ev, photo, channelGroup);
                    Thread.Sleep(PublishDelay * 1000);
                    //await PublishDelayAsync();
                }
            }
            catch (HttpClientServiceException ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("HTTP request failed\r\nStatus Code: {0} - {1}\r\n{2}", (int)ex.StatusCode, ex.Message, ex.ToString()));
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
            }
        }
Exemplo n.º 21
0
        //private async Task<string> PublishDelayAsync() {
        //    await Task.Delay(PublishDelay * 1000);
        //    return "Done";
        //}

        private void PublishPhoto(EventTDO ev, PhotoTDO photo, ChannelGroup channelGroup)
        {
            bool pending        = false;
            bool publishedPhoto = false;
            bool published      = false;

            try {
                this.Error = "";
                string filename = photo.Folder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? photo.Folder : (photo.Folder + Path.DirectorySeparatorChar) + Constants.STR_PROCESSED + Path.DirectorySeparatorChar + photo.Filename;
                if (File.Exists(filename))
                {
                    HttpResponseMessage response = _fsWebService.Put("EventPhotos/PendingPublish/" + ev.EventId + "?filename=" + photo.Filename, null, true);
                    if (!response.IsSuccessStatusCode)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to mark the {0} as pending publish.\r\nStatus Code: {0} - {1}\r\n{2}", (int)response.StatusCode, response.ReasonPhrase));
                    }
                    pending = true;

                    PublishPhotoToChannel(ev, photo, channelGroup);

                    publishedPhoto = true;

                    response = _fsWebService.Put("EventPhotos/Published/" + ev.EventId + "?filename=" + photo.Filename, null, true);
                    if (!response.IsSuccessStatusCode)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to mark the {0} as published.\r\nStatus Code: {0} - {1}\r\n{2}", (int)response.StatusCode, response.ReasonPhrase));
                    }
                    published = true;
                }
                else
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("{0} has not been uploaded. It will be published once uploaded.", filename));
                }
            }
            catch (HttpClientServiceException ex) {
                this.Error = string.Format("HTTP request failed\r\nStatus Code: {0} - {1}\r\n{2}", (int)ex.StatusCode, ex.Message, ex.ToString());
                FotoShoutUtils.Log.LogManager.Error(_logger, this.Error);
            }
            catch (Exception ex) {
                this.Error = ex.ToString();
                FotoShoutUtils.Log.LogManager.Error(_logger, this.Error);
            }
            finally {
                if (!published)
                {
                    if (publishedPhoto)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("The {0} photo of the {1} event is published. However, it failed to mark the photo as published.", photo.Filename, ev.EventName));
                    }
                    else if (pending)
                    {
                        try {
                            _fsWebService.Put("EventPhotos/UnpendingPublish/" + ev.EventId + "?filename=" + photo.Filename + "&error=" + this.Error, null, true);
                        }
                        catch (Exception ex) {
                            FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
 public EventTDO CreateEvent(EventTDO ev)
 {
     return(Modify <EventTDO>("Events", ev, string.Format(Constants.INFO_EVENT_CREATE, ev.EventName)));
 }
Exemplo n.º 23
0
        private void PostProcessEvent(EventTDO ev)
        {
            try {
                _emailService.EmailTemplate = null;
                if (_emailService.IsValid())
                {
                    if (ev.EmailTemplateId <= 0)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, "There is no email template assigned to the event, so there will be no email sent out to guests for this event.");
                        return;
                    }
                    else
                    {
                        _emailService.EmailTemplate = _fsWebService.GetEmailTemplate((int)ev.EmailTemplateId);
                    }
                }

                IEnumerable <PhotoTDO> unauthorizedPhotos = this._fsWebService.GetUnauthorizedPhotos(ev.EventId);
                foreach (PhotoTDO photo in unauthorizedPhotos)
                {
                    PhotoAnnotation photoAnnotation = this._fsWebService.Get <PhotoAnnotation>("PhotoAnnotation/" + photo.PhotoId, true);
                    if (photoAnnotation != null && photoAnnotation.Guests.Any <GuestTDO>() && this._emailService.EmailTemplate != null)
                    {
                        this.SendEmails(this.User, ev, photo, photoAnnotation, photo.Image);
                    }
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Getting broadcasts of the {0} event...", ev.EventName));
                IEnumerable <EventBroadcast> broadcasts = _fsWebService.GetList <EventBroadcast>("EventBroadcasts/" + ev.EventId, true);
                if (!broadcasts.Any())
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, "There is no broadcast published recently.");
                    return;
                }

                foreach (EventBroadcast bc in broadcasts)
                {
                    PhotoAnnotation photoAnnotation = _fsWebService.Get <PhotoAnnotation>("PhotoAnnotation/" + bc.PhotoId, true);
                    if (photoAnnotation != null && photoAnnotation.Guests.Any())
                    {
                        FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Getting the permalinks for the broadcast {0}.", bc.BroadcastId));
                        try {
                            IDictionary <string, string> permalinksDict = _c9WebService.GetPermaLinks(bc.BroadcastId);
                            if (!permalinksDict.Any())
                            {
                                FotoShoutUtils.Log.LogManager.Debug(_logger, string.Format("The broadcast with the id of {0} does not provide any perma-link. It might not be published yet.", bc.BroadcastId));
                            }
                            else
                            {
                                bool updated = false;
                                ICollection <string> newPermaLinks = new List <string>();
                                updated = UpdatePermaLinks(bc, permalinksDict, newPermaLinks);
                                if (_emailService.EmailTemplate != null && updated)
                                {
                                    _emailService.SendEmails(User, ev, photoAnnotation, newPermaLinks);
                                    bc.Error = _emailService.Error;
                                    if (string.IsNullOrEmpty(_emailService.Error))
                                    {
                                        bc.Status = permalinksDict.ContainsKey("pending") ? (byte)EventBroadcastStatus.PublishPending : (byte)EventBroadcastStatus.Processed;
                                    }
                                    else
                                    {
                                        bc.Error = _emailService.Error;
                                    }
                                    updated = true;
                                }
                                else if (updated)
                                {
                                    bc.Status = permalinksDict.ContainsKey("pending") ? (byte)EventBroadcastStatus.PublishPending : (byte)EventBroadcastStatus.Processed;
                                }
                                if (updated)
                                {
                                    _fsWebService.UploadString("EventBroadcasts?broadcastId=" + bc.EventBroadcastId, GeneratePostContent <EventBroadcast>(bc), "PUT");
                                }
                            }
                        }
                        catch (Exception ex) {
                            FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
            }
        }
Exemplo n.º 24
0
 public EventTDO UpdateEvent(int id, EventTDO ev)
 {
     return(Modify <EventTDO>("Events/" + id.ToString(), ev, string.Format(Constants.INFO_EVENT_UPDATE, ev.EventName), "PUT"));
 }
Exemplo n.º 25
0
        internal void SendEmailTo(UserTDO user, EventTDO ev, GuestTDO guest, string permalink)
        {
            string receiver = ((!string.IsNullOrEmpty(guest.FirstName)) ? (guest.FirstName + " ") : "") + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : "");

            if (string.IsNullOrEmpty(receiver))
            {
                receiver = guest.GuestId.ToString();
            }
            FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Sending the \"{0}\" link to \"{1}\"...", permalink, receiver));

            try {
                string emailContent = "";
                if (EmailTemplate != null)
                {
                    emailContent = GetEmailContent(user, ev, guest, permalink);
                }
                if (string.IsNullOrEmpty(emailContent))
                {
                    emailContent = GenerateDefaultEmailContent(user, ev, guest, permalink);
                }

                using (MailMessage message = new MailMessage()) {
                    message.From = new MailAddress(EmailServerAccount.Username);
                    message.To.Add(new MailAddress(guest.Email));
                    message.Subject      = EmailTemplate.EmailSubject;
                    message.IsBodyHtml   = true;
                    message.Body         = emailContent;
                    message.BodyEncoding = System.Text.Encoding.UTF8;

                    int        port       = (int)EmailServerAccount.Port;
                    SmtpClient mailClient = (port == 0) ? new SmtpClient(EmailServerAccount.Server) : new SmtpClient(EmailServerAccount.Server, port);
                    bool       enableSsl  = EmailServerAccount.EnableSSL;
                    try {
                        if (enableSsl)
                        {
                            mailClient.EnableSsl = true;
                            FotoShoutUtils.Log.LogManager.Info(_logger, "Enabled SSL");
                        }
                        //mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                        if (!string.IsNullOrEmpty(EmailServerAccount.Username))
                        {
                            mailClient.Credentials = string.IsNullOrEmpty(EmailServerAccount.Domain) ?
                                                     new NetworkCredential(EmailServerAccount.Username, EmailServerAccount.Password) :
                                                     new NetworkCredential(EmailServerAccount.Username, EmailServerAccount.Password, EmailServerAccount.Domain);
                        }
                        else
                        {
                            mailClient.UseDefaultCredentials = true;
                        }
                        FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Mail Server: {0}, From: {1} - {2}", EmailServerAccount.Server, message.From.Address, message.From.DisplayName));
                        mailClient.Send(message);
                    }
                    finally {
                        if (mailClient != null)
                        {
                            mailClient.Dispose();
                        }
                    }
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully sending email");
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to send the \"{0}\" link to \"{1}\"...", permalink, receiver));
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                Error = ex.Message;
            }
        }
Exemplo n.º 26
0
        //
        // GET: /Event/CompleteEvent/5
        public ActionResult CompleteEvent(int id = 0)
        {
            EventTDO ev = fsWebService.GetEvent(id);

            return(PartialView("_CompleteConfirmation", ev));
        }
Exemplo n.º 27
0
 private void UploadEventData(EventTDO ev)
 {
     SynchronizeFiles(ev);
     SynchronizePhotos(ev);
 }
Exemplo n.º 28
0
        private void PublishPhotoToChannel(EventTDO ev, PhotoTDO photo, ChannelGroup channelGroup)
        {
            if (channelGroup.Fields == null || !channelGroup.Fields.Any())
            {
                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("There is no broadcast fields in the {0} template.", channelGroup.Name));
                return;
            }

            PhotoAnnotation annotation = _fsWebService.Get <PhotoAnnotation>("PhotoAnnotation/" + photo.PhotoId, true);

            FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Publishing the {0} photo to the {1} channel group...", photo.Filename, string.IsNullOrEmpty(channelGroup.Name) ? channelGroup.ID.ToString() : channelGroup.Name));

            string        filename = photo.Folder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? photo.Folder : (photo.Folder + Path.DirectorySeparatorChar) + Constants.STR_PROCESSED + Path.DirectorySeparatorChar + photo.Filename;
            PostBroadcast bc       = new PostBroadcast {
                TemplateID      = channelGroup.ID,
                Status          = "Pending Publish",
                Description     = "FotoShout Broadcast",
                Name            = Path.GetFileNameWithoutExtension(photo.Filename),
                ScheduledTime   = DateTime.Now.ToShortDateString(),
                BroadcastFields = new List <BroadcastFieldValue>()
            };

            foreach (BroadcastField bf in channelGroup.Fields)
            {
                if (bf.Name.Equals("Album Title", StringComparison.InvariantCultureIgnoreCase))
                {
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = string.IsNullOrEmpty(ev.PublishAlbum) ? ev.EventName : ev.PublishAlbum
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Album Description", StringComparison.InvariantCultureIgnoreCase))
                {
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = string.IsNullOrEmpty(ev.PublishAlbum) ? ev.EventName : ev.PublishAlbum
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Upload Photos", StringComparison.InvariantCultureIgnoreCase))
                {
                    string serverUri = _c9WebService.UploadFile("Media/Upload", filename);
                    if (string.IsNullOrEmpty(serverUri))
                    {
                        throw new PublishingException(string.Format("Unexpected error: Can not upload the {0} photo.", photo.Filename));
                    }
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = serverUri
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Title", StringComparison.InvariantCultureIgnoreCase))
                {
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = bc.Name
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Image File", StringComparison.InvariantCultureIgnoreCase))
                {
                    string serverUri = _c9WebService.UploadFile("Media/Upload", filename);
                    if (string.IsNullOrEmpty(serverUri))
                    {
                        throw new PublishingException(string.Format("Unexpected error: Can not upload the {0} photo.", photo.Filename));
                    }
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = serverUri
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("File", StringComparison.InvariantCultureIgnoreCase))
                {
                    string serverUri = _c9WebService.UploadFile("Media/Upload", filename);
                    if (string.IsNullOrEmpty(serverUri))
                    {
                        throw new PublishingException(string.Format("Unexpected error: Can not upload the {0} photo.", photo.Filename));
                    }
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = serverUri
                    };
                    bc.BroadcastFields.Add(bfv);
                }
            }

            string ret = _c9WebService.UploadString("Broadcast", GeneratePostContent <PostBroadcast>(bc));

            if (!string.IsNullOrEmpty(ret))
            {
                EventBroadcast eventBroadcast = new EventBroadcast {
                    BroadcastId = int.Parse(ret.Trim(new char[] { '\"' })),
                    EventId     = ev.EventId,
                    PhotoId     = photo.PhotoId,
                    Status      = 0
                };
                ret = _fsWebService.UploadString("EventBroadcasts", GeneratePostContent <EventBroadcast>(eventBroadcast));
            }
            else
            {
                throw new PublishingException(string.Format("Unsuccessully publishing the \"{0}\" photo using the \"{1}\" channel group.", photo.Filename, channelGroup.Name));
            }

            FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Published the {0} photo.", photo.Filename));
        }
Exemplo n.º 29
0
        // POST api/Events
        public HttpResponseMessage PostEvent(EventTDO tdo)
        {
            if (ModelState.IsValid && tdo != null)
            {
                // Check for duplicated names
                var temp = db.Events.Where(e => e.EventName.Equals(tdo.EventName, StringComparison.InvariantCultureIgnoreCase) &&
                                           e.User.Id == CurrentUser.Id).SingleOrDefault();
                if (temp != null)
                {
                    this.GenerateException(HttpStatusCode.InternalServerError, string.Format("The {0} event already exists.", tdo.EventName), _logger);
                }

                Event ev = null;
                try {
                    string error = DirectoryUtils.GenerateDirectories(tdo.EventFolder);
                    if (!string.IsNullOrEmpty(error))
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound, error));
                    }

                    ev = new Event {
                        EventName        = tdo.EventName,
                        EventDescription = tdo.EventDescription,
                        EventDate        = tdo.EventDate,
                        EventLocation    = tdo.EventLocation,
                        EventFolder      = tdo.EventFolder,
                        EventVirtualPath = FotoShoutApi.Services.IO.DirectoryService.GenerateVirtualPath(tdo.EventFolder),
                        Created          = DateTime.Now,
                        CreatedBy        = CurrentUser.Id,
                        EventStatus      = (byte)EventStatus.Open,
                        PublishAlbum     = tdo.PublishAlbum,
                        User             = db.Users.Where(u => u.Id == CurrentUser.Id).SingleOrDefault()
                    };

                    if (tdo.EventOptionId != 0)
                    {
                        EventOption evo = db.EventOptions.Where(eo => eo.EventOptionId == tdo.EventOptionId).SingleOrDefault();
                        if (evo != null)
                        {
                            ev.EventOption = evo;
                        }
                    }

                    if (tdo.EmailTemplateId != 0)
                    {
                        EmailTemplate emailTemplate = db.EmailTemplates.Where(e => e.EmailTemplateId == tdo.EmailTemplateId).SingleOrDefault();
                        if (emailTemplate != null)
                        {
                            ev.EmailTemplate = emailTemplate;
                        }
                    }

                    if (tdo.SponsorIds != null)
                    {
                        IEnumerable <Sponsor> sponsors = db.Sponsors.Where(s => tdo.SponsorIds.Contains(s.SponsorId));
                        if (sponsors.Any())
                        {
                            foreach (Sponsor sponsor in sponsors)
                            {
                                ev.Sponsors.Add(sponsor);
                            }
                        }
                    }

                    ev.ChannelGroupId = tdo.ChannelGroupId;
                    ev.WebsiteId      = tdo.WebsiteId;

                    db.Events.Add(ev);
                }
                catch (Exception ex) {
                    FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                    this.GenerateException(HttpStatusCode.InternalServerError, ex.Message);
                }

                try {
                    db.SaveChanges();
                }
                catch (Exception ex) {
                    FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                    this.GenerateException(HttpStatusCode.NotFound, ex.Message);
                }

                // Update the TDO object
                UpdateTDO(tdo, ev);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, tdo);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Events", id = ev.EventId }));
                return(response);
            }
            else if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.Values.SelectMany(v => v.Errors)));
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NoContent));
            }
        }
Exemplo n.º 30
0
        private EventTDO GenerateTDO(Event ev = null)
        {
            EventTDO tdo = null;

            IEnumerable <EventOptionTDO> eventOptions = (from evo in db.EventOptions orderby evo.EventOptionName select
                                                         new EventOptionTDO {
                EventOptionId = evo.EventOptionId,
                EventOptionName = evo.EventOptionName,
                SalutationOption = evo.SalutationOption,
                FirstNameOption = evo.FirstNameOption,
                LastNameOption = evo.LastNameOption,
                EmailOption = evo.EmailOption,
                AddressOption = evo.AddressOption,
                PhoneOption = evo.PhoneOption,
                FaxOption = evo.FaxOption,
                SignatureOption = evo.SignatureOption
            }).ToList();
            IEnumerable <SponsorTDO> sponsors             = (from s in db.Sponsors.Where(s => s.User.Id == CurrentUser.Id).OrderBy(s => s.SponsorName) select new SponsorTDO {
                SponsorId = s.SponsorId, SponsorName = s.SponsorName
            }).ToList();
            IEnumerable <EmailTemplateTDO> emailTemplates = (from e in db.EmailTemplates.Where(e => e.User.Id == CurrentUser.Id).OrderBy(e => e.EmailTemplateName) select new EmailTemplateTDO {
                EmailTemplateId = e.EmailTemplateId, EmailTemplateName = e.EmailTemplateName
            }).ToList();

            if (ev != null)
            {
                tdo = new EventTDO {
                    EventId          = ev.EventId,
                    EventName        = ev.EventName,
                    EventDescription = ev.EventDescription,
                    EventDate        = ev.EventDate,
                    EventLocation    = ev.EventLocation,
                    EventFolder      = ev.EventFolder,
                    EventVirtualPath = ev.EventVirtualPath,
                    Created          = ev.Created,
                    CreatedBy        = ev.CreatedBy,
                    EventStatus      = ev.EventStatus,
                    PublishAlbum     = ev.PublishAlbum,
                    EventOptionId    = (ev.EventOption != null) ? ev.EventOption.EventOptionId : 0,
                    SponsorIds       = ev.Sponsors.OrderBy(s => s.SponsorName).Select(s => s.SponsorId),
                    EmailTemplateId  = (ev.EmailTemplate != null) ? ev.EmailTemplate.EmailTemplateId : 0,
                    ChannelGroupId   = ev.ChannelGroupId,
                    WebsiteId        = ev.WebsiteId,
                    EventOptions     = eventOptions,
                    Sponsors         = sponsors,
                    EmailTemplates   = emailTemplates
                }
            }
            ;
            else
            {
                tdo = new EventTDO {
                    EventDate      = DateTime.Now,
                    EventOptions   = eventOptions,
                    Sponsors       = sponsors,
                    EmailTemplates = emailTemplates
                }
            };

            return(tdo);
        }