Exemple #1
0
        private void PerformCheckIn(SPItemEventProperties properties, SPFile mainFile, SPFile minifiedFile)
        {
            CheckInType checkInType = new CheckInTypeDetector(properties).Detect();

            if (checkInType != CheckInType.MajorVersion)
            {
                return;
            }

            var hash           = FileUtilities.GetMD5Hash(minifiedFile.OpenBinary());
            var path           = FileUtilities.RemoveStyleLibraryFromPath(mainFile.Url);
            var fileNameParser = new FileNameParser(path);

            minifiedFile.CheckIn("", SPCheckinType.MajorCheckIn);
            minifiedFile.Item[SPBuiltInFieldId.FileLeafRef] = fileNameParser.GenerateMinifiedVersionFileName(hash);
            minifiedFile.Item.SystemUpdate();

            var fileHashDictionary = new FileHashDictionary(properties.ListItem.Web.Site);

            fileHashDictionary.Update(path, hash);
        }
Exemple #2
0
        /// <summary>
        /// Gets the final path for the specified asset based on the environment mode
        /// </summary>
        /// <returns>Final path</returns>
        protected string GetFinalPath()
        {
            string path = FilePath;

            if (EnvironmentMode == EnvironmentMode.Production)
            {
                var fileNameParser = new FileNameParser(path);

                if (fileNameParser.ShouldBeMinified)
                {
                    var fileHashDictionary = new FileHashDictionary(SPContext.Current.Site);
                    var fileHash           = fileHashDictionary[path];
                    var minifiedFileName   = fileNameParser.GenerateMinifiedVersionFileName(fileHash);

                    path = String.Format("{0}/{1}", Constants.SPMinFolderName, minifiedFileName);
                }
            }

            path = String.Format("{0}/Style Library/{1}", SPContext.Current.Site.RootWeb.ServerRelativeUrl, path);
            path = FileUtilities.RemoveDuplicatedSlashesFromPath(path);

            return(path);
        }
Exemple #3
0
        private void RunForMainFile(SPItemEventProperties properties, Action <FileNameParser, SPFolder, SPFile, SPFile> action)
        {
            SPListItem item = properties.ListItem;

            if (item.Folder != null)
            {
                return;
            }

            var url            = FileUtilities.RemoveStyleLibraryFromPath(item.File.Url);
            var fileNameParser = new FileNameParser(url);

            if (fileNameParser.ShouldBeMinified)
            {
                SPList   styleLibrary = properties.ListItem.ParentList;
                SPFolder spminFolder  = EnsureSPMinFolder(styleLibrary);

                var fileHashDictionary = new FileHashDictionary(properties.ListItem.Web.Site);
                var fileHash           = fileHashDictionary[url];

                SPFile minifiedFile = FileUtilities.GetFile(spminFolder, fileNameParser.GenerateMinifiedVersionFileName(fileHash));
                action(fileNameParser, spminFolder, item.File, minifiedFile);
            }
        }
Exemple #4
0
        private void RunForMainFile(SPItemEventProperties properties, Action<FileNameParser, SPFolder, SPFile, SPFile> action)
        {
            SPListItem item = properties.ListItem;
            if (item.Folder != null)
                return;

            var url = FileUtilities.RemoveStyleLibraryFromPath(item.File.Url);
            var fileNameParser = new FileNameParser(url);

            if (fileNameParser.ShouldBeMinified)
            {
                SPList styleLibrary = properties.ListItem.ParentList;
                SPFolder spminFolder = EnsureSPMinFolder(styleLibrary);

                var fileHashDictionary = new FileHashDictionary(properties.ListItem.Web.Site);
                var fileHash = fileHashDictionary[url];

                SPFile minifiedFile = FileUtilities.GetFile(spminFolder, fileNameParser.GenerateMinifiedVersionFileName(fileHash));
                action(fileNameParser, spminFolder, item.File, minifiedFile);
            }
        }
Exemple #5
0
        private void PerformCheckIn(SPItemEventProperties properties, SPFile mainFile, SPFile minifiedFile)
        {
            CheckInType checkInType = new CheckInTypeDetector(properties).Detect();
            if (checkInType != CheckInType.MajorVersion)
                return;

            var hash = FileUtilities.GetMD5Hash(minifiedFile.OpenBinary());
            var path = FileUtilities.RemoveStyleLibraryFromPath(mainFile.Url);
            var fileNameParser = new FileNameParser(path);

            minifiedFile.CheckIn("", SPCheckinType.MajorCheckIn);
            minifiedFile.Item[SPBuiltInFieldId.FileLeafRef] = fileNameParser.GenerateMinifiedVersionFileName(hash);
            minifiedFile.Item.SystemUpdate();

            var fileHashDictionary = new FileHashDictionary(properties.ListItem.Web.Site);
            fileHashDictionary.Update(path, hash);
        }