Exemplo n.º 1
0
        public virtual ActionResult DisplayFile(Guid fileId, string fileName)
        {
            if (fileId != Guid.Empty)
            {
                // find agreement
                var agreement = _queryProcessor.Execute(new GetMyInstitutionalAgreementByFileGuidQuery(User, fileId));

                // make sure user owns this agreement
                if (agreement != null && agreement.Files != null && agreement.Files.Count > 0)
                {
                    if (agreement.Visibility == InstitutionalAgreementVisibility.Private &&
                        !User.IsInRole(RoleName.InstitutionalAgreementManager) &&
                        !User.IsInRole(RoleName.InstitutionalAgreementSupervisor))
                    {
                        return(HttpNotFound());
                    }
                    var file = agreement.Files.SingleOrDefault(f => f.EntityId.Equals(fileId));
                    if (file != null)
                    {
                        //Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", file.Name));
                        return(File(_binaryData.Get(file.Path), file.MimeType));
                    }
                }
            }
            return(HttpNotFound());
        }
        protected EmployeeModuleSettings Seed(CreateEmployeeModuleSettings command)
        {
            // make sure entity does not already exist
            var employeeModuleSettings = _queryProcessor.Execute(
                new EmployeeModuleSettingsByEstablishmentId(command.EstablishmentId, true));

            if (employeeModuleSettings != null)
            {
                return(employeeModuleSettings);
            }

            var iconsBinaryPath = string.Format("{0}/{1}/", EmployeeConsts.SettingsBinaryStoreBasePath,
                                                EmployeeConsts.IconsBinaryStorePath);

            foreach (var icon in UsfEmployeeModuleSettingsSeeder.UsfEmployeeModuleSettingIcons)
            {
                var iconPath = Path.Combine(iconsBinaryPath, icon.Value.Third.ToString());
                if (!_binaryStore.Exists(iconPath))
                {
                    var filePath = string.Format("{0}{1}{2}", AppDomain.CurrentDomain.BaseDirectory,
                                                 @"..\UCosmic.Infrastructure\SeedData\SeedMediaFiles\",
                                                 icon.Key);

                    using (var fileStream = File.OpenRead(filePath))
                        _binaryStore.Put(iconPath, fileStream.ReadFully());
                }

                if (string.IsNullOrEmpty(command.GlobalViewIconPath) && icon.Value.First == "Global")
                {
                    command.GlobalViewIconFileName = icon.Value.Third.ToString();
                    command.GlobalViewIconLength   = _binaryStore.Get(iconPath).Length;
                    command.GlobalViewIconMimeType = "image/png";
                    command.GlobalViewIconName     = icon.Value.Second;
                    command.GlobalViewIconPath     = iconsBinaryPath;
                }

                if (string.IsNullOrEmpty(command.FindAnExpertIconPath) && icon.Value.First == "Expert")
                {
                    command.FindAnExpertIconFileName = icon.Value.Third.ToString();
                    command.FindAnExpertIconLength   = _binaryStore.Get(iconPath).Length;
                    command.FindAnExpertIconMimeType = "image/svg+xml";
                    command.FindAnExpertIconName     = icon.Value.Second;
                    command.FindAnExpertIconPath     = iconsBinaryPath;
                }
            }

            _createEmployeeModuleSettings.Handle(command);

            _unitOfWork.SaveChanges();

            return(command.CreatedEmployeeModuleSettings);
        }
Exemplo n.º 3
0
        public void Handle(CopyActivityValues command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var copyToActivity = command.CopyToActivity
                                 ?? _entities.Get <Activity>().ById(command.CopyToActivityId);

            var copiedActivityValues = _detachedEntities.Query <ActivityValues>()
                                       .EagerLoad(_entities, new Expression <Func <ActivityValues, object> >[]
            {
                x => x.Locations,
                x => x.Types,
                x => x.Tags,
                x => x.Documents,
            })
                                       .ById(command.ActivityValuesId, false);

            copiedActivityValues.Activity   = copyToActivity;
            copiedActivityValues.ActivityId = copyToActivity.RevisionId;
            copiedActivityValues.Mode       = command.Mode;
            copiedActivityValues.RevisionId = 0;
            EnableForCopy(copiedActivityValues, command);

            foreach (var location in copiedActivityValues.Locations)
            {
                EnableForCopy(location, command);
            }

            foreach (var type in copiedActivityValues.Types)
            {
                EnableForCopy(type, command);
            }

            foreach (var tag in copiedActivityValues.Tags)
            {
                EnableForCopy(tag, command);
            }

            var documentsToCopy = copiedActivityValues.Documents;

            copiedActivityValues.Documents = new Collection <ActivityDocument>();
            foreach (var document in documentsToCopy)
            {
                _createActivityDocument.Handle(new CreateActivityDocument(command.Principal, copiedActivityValues)
                {
                    FileName = document.FileName,
                    MimeType = document.MimeType,
                    Content  = _binaryData.Get(document.Path),
                    Title    = document.Title,
                    EntityId = document.EntityId,
                    NoCommit = true,
                });
            }

            command.CreatedActivityValues = copiedActivityValues;
            _entities.Create(copiedActivityValues);
            if (!command.NoCommit)
            {
                _entities.SaveChanges();
            }
        }
        public void Handle(ApplicationStarted @event)
        {
            /* One time to get icons in blob storage */
#if false
            {
                /* ----- Global View and Find an Expert Icons ----- */

                var iconsBinaryPath = string.Format("{0}/{1}/", EmployeeConsts.SettingsBinaryStoreBasePath,
                                                    EmployeeConsts.IconsBinaryStorePath);

                //* Create default Global View icon */
                if (_binaryStore.Get(iconsBinaryPath + EmployeeConsts.DefaultGlobalViewIconGuid) == null)
                {
                    string filePath = string.Format("{0}{1}{2}", AppDomain.CurrentDomain.BaseDirectory,
                                                    @"..\UCosmic.Web.Mvc\images\icons\global\",
                                                    "global_24_black.png");

                    using (var fileStream = File.OpenRead(filePath))
                    {
                        var content = fileStream.ReadFully();
                        _binaryStore.Put(iconsBinaryPath + EmployeeConsts.DefaultGlobalViewIconGuid, content);
                    }
                }

                //* Create default Find an Expert icon */
                if (_binaryStore.Get(iconsBinaryPath + EmployeeConsts.DefaultFindAnExpertIconGuid) == null)
                {
                    var filePath = string.Format("{0}{1}{2}", AppDomain.CurrentDomain.BaseDirectory,
                                                 @"..\UCosmic.Web.Mvc\images\icons\nounproject\",
                                                 "noun_project_5795_compass.svg");
                    using (var fileStream = File.OpenRead(filePath))
                    {
                        var content = fileStream.ReadFully();
                        _binaryStore.Put(iconsBinaryPath + EmployeeConsts.DefaultFindAnExpertIconGuid, content);
                    }
                }

                /* ----- Activity Type icons for USF ----- */
                var activityTypeFilenames = new string[]
                {
                    "noun_project_762_idea.svg",
                    "noun_project_14888_teacher.svg",
                    "noun_project_17372_medal.svg",
                    "noun_project_16986_podium.svg",
                    "noun_project_401_briefcase.svg"
                };

                var activityTypeFilenameMap = new Dictionary <string, string>
                {
                    { "noun_project_762_idea.svg", "5117FFC4-C3CD-42F8-9C68-6B4362930A99" },
                    { "noun_project_14888_teacher.svg", "0033E48C-95CD-487B-8B0D-571E71EFF844" },
                    { "noun_project_17372_medal.svg", "8C746B8A-6B24-4881-9D4D-D830FBCD723A" },
                    { "noun_project_16986_podium.svg", "E44978F8-3664-4F7A-A2AF-6A0446D38099" },
                    { "noun_project_401_briefcase.svg", "586DDDBB-DE01-429B-8428-57A9D03189CB" }
                };

                var activityTypeIconBinaryPath = string.Format("{0}/{1}/{2}/", EmployeeConsts.SettingsBinaryStoreBasePath,
                                                               1, // USF
                                                               EmployeeConsts.IconsBinaryStorePath);


                for (var i = 0; i < activityTypeFilenames.Length; i += 1)
                {
                    string iconBinaryFilePath =
                        String.Format("{0}{1}", activityTypeIconBinaryPath,
                                      activityTypeFilenameMap[activityTypeFilenames[i]]);

                    if (_binaryStore.Get(iconBinaryFilePath) == null)
                    {
                        string filePath = string.Format("{0}{1}{2}", AppDomain.CurrentDomain.BaseDirectory,
                                                        @"..\UCosmic.Web.MVC\images\icons\nounproject\",
                                                        activityTypeFilenames[i]);

                        using (var fileStream = File.OpenRead(filePath))
                        {
                            var content = fileStream.ReadFully();
                            _binaryStore.Put(iconBinaryFilePath, content);
                        }
                    }
                }
            }
#endif

#if false
            /* ----- Update the EmployeeModuleSettings rows ----- */
            {
                var iconsBinaryPath = string.Format("{0}/{1}/", EmployeeConsts.SettingsBinaryStoreBasePath,
                                                    EmployeeConsts.IconsBinaryStorePath);

                /* ----- Activity Type icons for USF ----- */
                //var activityTypeFilenames = new string[]
                //{
                //    "noun_project_762_idea.svg",
                //    "noun_project_14888_teacher.svg",
                //    "noun_project_17372_medal.svg",
                //    "noun_project_16986_podium.svg",
                //    "noun_project_401_briefcase.svg"
                //};

                var activityTypeFilenameMap = new Dictionary <string, string>
                {
                    { "noun_project_762_idea.svg", "5117FFC4-C3CD-42F8-9C68-6B4362930A99" },
                    { "noun_project_14888_teacher.svg", "0033E48C-95CD-487B-8B0D-571E71EFF844" },
                    { "noun_project_17372_medal.svg", "8C746B8A-6B24-4881-9D4D-D830FBCD723A" },
                    { "noun_project_16986_podium.svg", "E44978F8-3664-4F7A-A2AF-6A0446D38099" },
                    { "noun_project_401_briefcase.svg", "586DDDBB-DE01-429B-8428-57A9D03189CB" }
                };

                var activityTypeIconBinaryPath = string.Format("{0}/{1}/{2}/", EmployeeConsts.SettingsBinaryStoreBasePath,
                                                               1, // USF
                                                               EmployeeConsts.IconsBinaryStorePath);


                var settings = _entities.Get <EmployeeModuleSettings>().SingleOrDefault(x => x.Establishment.RevisionId == 3306 /* USF */);
                if (settings == null)
                {
                    return;
                }

                EmployeeActivityType activityType;

                activityType =
                    settings.ActivityTypes.Single(a => a.Type == "Research or Creative Endeavor");
                activityType.IconLength =
                    _binaryStore.Get(activityTypeIconBinaryPath + activityTypeFilenameMap["noun_project_762_idea.svg"])
                    .Length;
                activityType.IconMimeType = "image/svg+xml";
                activityType.IconName     = "Research.svg";
                activityType.IconPath     = activityTypeIconBinaryPath;
                activityType.IconFileName = activityTypeFilenameMap["noun_project_762_idea.svg"];

                activityType =
                    settings.ActivityTypes.Single(a => a.Type == "Teaching or Mentoring");
                activityType.IconLength =
                    _binaryStore.Get(activityTypeIconBinaryPath +
                                     activityTypeFilenameMap["noun_project_14888_teacher.svg"]).Length;
                activityType.IconMimeType = "image/svg+xml";
                activityType.IconName     = "Teaching.svg";
                activityType.IconPath     = activityTypeIconBinaryPath;
                activityType.IconFileName = activityTypeFilenameMap["noun_project_14888_teacher.svg"];

                activityType =
                    settings.ActivityTypes.Single(a => a.Type == "Award or Honor");
                activityType.IconLength =
                    _binaryStore.Get(activityTypeIconBinaryPath +
                                     activityTypeFilenameMap["noun_project_17372_medal.svg"]).Length;
                activityType.IconMimeType = "image/svg+xml";
                activityType.IconName     = "Award.svg";
                activityType.IconPath     = activityTypeIconBinaryPath;
                activityType.IconFileName = activityTypeFilenameMap["noun_project_17372_medal.svg"];

                activityType =
                    settings.ActivityTypes.Single(
                        a => a.Type == "Conference Presentation or Proceeding");
                activityType.IconLength =
                    _binaryStore.Get(activityTypeIconBinaryPath +
                                     activityTypeFilenameMap["noun_project_16986_podium.svg"]).Length;
                activityType.IconMimeType = "image/svg+xml";
                activityType.IconName     = "Conference.svg";
                activityType.IconPath     = activityTypeIconBinaryPath;
                activityType.IconFileName = activityTypeFilenameMap["noun_project_16986_podium.svg"];

                activityType =
                    settings.ActivityTypes.Single(
                        a => a.Type == "Professional Development, Service or Consulting");
                activityType.IconLength =
                    _binaryStore.Get(activityTypeIconBinaryPath +
                                     activityTypeFilenameMap["noun_project_401_briefcase.svg"]).Length;
                activityType.IconMimeType = "image/svg+xml";
                activityType.IconName     = "Professional.svg";
                activityType.IconPath     = activityTypeIconBinaryPath;
                activityType.IconFileName = activityTypeFilenameMap["noun_project_401_briefcase.svg"];


                var updateCommand = new UpdateEmployeeModuleSettings(settings.Id)
                {
                    EmployeeFacultyRanks       = settings.FacultyRanks,
                    NotifyAdminOnUpdate        = settings.NotifyAdminOnUpdate,
                    NotifyAdmins               = settings.NotifyAdmins,
                    PersonalInfoAnchorText     = settings.PersonalInfoAnchorText,
                    Establishment              = settings.Establishment,
                    EmployeeActivityTypes      = settings.ActivityTypes,
                    OfferCountry               = settings.OfferCountry,
                    OfferActivityType          = settings.OfferActivityType,
                    OfferFundingQuestions      = settings.OfferFundingQuestions,
                    InternationalPedigreeTitle = settings.InternationalPedigreeTitle,

                    GlobalViewIconLength   = _binaryStore.Get(iconsBinaryPath + EmployeeConsts.DefaultGlobalViewIconGuid).Length,
                    GlobalViewIconMimeType = "image/png",
                    GlobalViewIconName     = "GlobalViewIcon.png",
                    GlobalViewIconPath     = iconsBinaryPath,
                    GlobalViewIconFileName = EmployeeConsts.DefaultGlobalViewIconGuid,

                    FindAnExpertIconLength   = _binaryStore.Get(iconsBinaryPath + EmployeeConsts.DefaultFindAnExpertIconGuid).Length,
                    FindAnExpertIconMimeType = "image/svg+xml",
                    FindAnExpertIconName     = "FindAnExpertIcon.svg",
                    FindAnExpertIconPath     = iconsBinaryPath,
                    FindAnExpertIconFileName = EmployeeConsts.DefaultFindAnExpertIconGuid,
                };

                _updateEmployeeModuleSettings.Handle(updateCommand);
            }
#endif
        }
Exemplo n.º 5
0
        public void Handle(PurgeActivity command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // load the activity along with its documents & alternate copies
            var activity = _entities.Get <Activity>()
                           .EagerLoad(_entities, new Expression <Func <Activity, object> >[]
            {
                x => x.Values.Select(y => y.Documents),
                x => x.WorkCopy,
                x => x.Original,
            })
                           .SingleOrDefault(x => x.RevisionId == command.ActivityId);

            if (activity == null)
            {
                return;
            }

            // deleting activity will cascade delete documents,
            // so they must be removed from the binary store
            command.DeletedDocuments = new Dictionary <string, byte[]>();
            foreach (var path in activity.Values.SelectMany(x => x.Documents.Select(y => y.Path)))
            {
                if (_binaryData.Exists(path))
                {
                    command.DeletedDocuments.Add(path, _binaryData.Get(path));
                    _binaryData.Delete(path);
                }
            }

            // if this activity is a work copy, also delete the original if it is empty
            PurgeActivity deleteOriginal = null;

            // if a work copy exists, delete it too
            PurgeActivity deleteWorkCopy = null;

            if (activity.Original != null && activity.Original.RevisionId != command.OuterActivityId && activity.Original.IsEmpty())
            {
                deleteOriginal = new PurgeActivity(command.Principal, activity.Original.RevisionId)
                {
                    NoCommit        = true,
                    OuterActivityId = command.ActivityId,
                };
                Handle(deleteOriginal);
            }
            else if (activity.WorkCopy != null && activity.WorkCopy.RevisionId != command.OuterActivityId)
            {
                deleteWorkCopy = new PurgeActivity(command.Principal, activity.WorkCopy.RevisionId)
                {
                    NoCommit        = true,
                    OuterActivityId = command.ActivityId,
                };
                Handle(deleteWorkCopy);
            }

            // log audit
            var audit = new CommandEvent
            {
                RaisedBy      = command.Principal.Identity.Name,
                Name          = command.GetType().FullName,
                Value         = JsonConvert.SerializeObject(new { command.ActivityId }),
                PreviousState = activity.ToJsonAudit(),
            };

            _entities.Create(audit);
            _entities.Purge(activity);

            try
            {
                // wrap removal in try block
                if (!command.NoCommit)
                {
                    _entities.SaveChanges();
                }
            }
            catch
            {
                // restore binary data when savechanges fails
                foreach (var path in command.DeletedDocuments)
                {
                    _binaryData.Put(path.Key, path.Value, true);
                }

                if (deleteOriginal != null)
                {
                    foreach (var path in deleteOriginal.DeletedDocuments)
                    {
                        _binaryData.Put(path.Key, path.Value, true);
                    }
                }

                if (deleteWorkCopy != null)
                {
                    foreach (var path in deleteWorkCopy.DeletedDocuments)
                    {
                        _binaryData.Put(path.Key, path.Value, true);
                    }
                }
            }
        }
        public override void Seed()
        {
            var establishment = _entities.Get <Establishment>().Single(x => x.WebsiteUrl == "www.usf.edu");
            var settings      = _entities.Get <EmployeeModuleSettings>().SingleOrDefault(x => x.Establishment.RevisionId == establishment.RevisionId);

            if (settings != null)
            {
                return;
            }

            #region CreateEmployeeModuleSettings

            CreatedEmployeeModuleSettings = Seed(new CreateEmployeeModuleSettings
            {
                EmployeeFacultyRanks = new Collection <EmployeeFacultyRank>
                {
                    new EmployeeFacultyRank {
                        Rank = "Distinguished University Professor", Number = 1
                    },
                    new EmployeeFacultyRank {
                        Rank = "Professor", Number = 2
                    },
                    new EmployeeFacultyRank {
                        Rank = "Associate Professor", Number = 3
                    },
                    new EmployeeFacultyRank {
                        Rank = "Assistant Professor", Number = 4
                    },
                    new EmployeeFacultyRank {
                        Rank = "Other", Number = 5
                    }
                },
                NotifyAdminOnUpdate    = false,
                PersonalInfoAnchorText = "My USF Profile",
                EstablishmentId        = establishment.RevisionId,
                EmployeeActivityTypes  = new Collection <EmployeeActivityType>
                {
                    new EmployeeActivityType
                    {
                        Type     = "Research or Creative Endeavor",
                        Rank     = 1,
                        CssColor = "blue",
                    },
                    new EmployeeActivityType
                    {
                        Type     = "Teaching or Mentoring",
                        Rank     = 2,
                        CssColor = "green",
                    },
                    new EmployeeActivityType
                    {
                        Type     = "Award or Honor",
                        Rank     = 3,
                        CssColor = "yellow",
                    },
                    new EmployeeActivityType
                    {
                        Type     = "Conference Presentation or Proceeding",
                        Rank     = 4,
                        CssColor = "orange",
                    },
                    new EmployeeActivityType
                    {
                        Type     = "Professional Development, Service or Consulting",
                        Rank     = 5,
                        CssColor = "red",
                    }
                },
                OfferCountry               = true,
                OfferActivityType          = true,
                OfferFundingQuestions      = true,
                InternationalPedigreeTitle = "My Formal Education Outside the US",
                ReportsDefaultYearRange    = 10
            });

            #endregion
            #region ActivityType Icons

            var activityTypeIconBinaryPath = string.Format("{0}/{1}/{2}/", EmployeeConsts.SettingsBinaryStoreBasePath,
                                                           CreatedEmployeeModuleSettings.EstablishmentId,
                                                           EmployeeConsts.IconsBinaryStorePath);

            foreach (var fileName in UsfActivityTypeIcons.Keys)
            {
                var binaryFilePath = string.Format("{0}{1}",
                                                   activityTypeIconBinaryPath, UsfActivityTypeIcons[fileName].Third);

                if (_binaryStore.Get(binaryFilePath) == null)
                {
                    var localFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                     @"..\UCosmic.Infrastructure\SeedData\SeedMediaFiles\", fileName);

                    using (var fileStream = File.OpenRead(localFilePath))
                        _binaryStore.Put(binaryFilePath, fileStream.ReadFully());
                }

                var activityType = CreatedEmployeeModuleSettings.ActivityTypes.Single(a => a.Type == UsfActivityTypeIcons[fileName].First);
                activityType.IconLength   = _binaryStore.Get(binaryFilePath).Length;
                activityType.IconMimeType = "image/svg+xml";
                activityType.IconName     = UsfActivityTypeIcons[fileName].Second;
                activityType.IconPath     = activityTypeIconBinaryPath;
                activityType.IconFileName = UsfActivityTypeIcons[fileName].Third.ToString();
            }

            #endregion
            #region UpdateEmployeeModuleSettings

            var updateCommand = new UpdateEmployeeModuleSettings(CreatedEmployeeModuleSettings.EstablishmentId)
            {
                EmployeeFacultyRanks       = CreatedEmployeeModuleSettings.FacultyRanks,
                NotifyAdminOnUpdate        = CreatedEmployeeModuleSettings.NotifyAdminOnUpdate,
                NotifyAdmins               = CreatedEmployeeModuleSettings.NotifyAdmins,
                PersonalInfoAnchorText     = CreatedEmployeeModuleSettings.PersonalInfoAnchorText,
                Establishment              = CreatedEmployeeModuleSettings.Establishment,
                EmployeeActivityTypes      = CreatedEmployeeModuleSettings.ActivityTypes,
                OfferCountry               = CreatedEmployeeModuleSettings.OfferCountry,
                OfferActivityType          = CreatedEmployeeModuleSettings.OfferActivityType,
                OfferFundingQuestions      = CreatedEmployeeModuleSettings.OfferFundingQuestions,
                InternationalPedigreeTitle = CreatedEmployeeModuleSettings.InternationalPedigreeTitle
            };

            #endregion

            _updateEmployeeModuleSettings.Handle(updateCommand);
        }