Exemplo n.º 1
0
        private bool LoadContentFile(ReusableContentInfo reusableContentInfo)
        {
            var isSuccess = false;

            // Validate the Filename
            if (!reusableContentInfo.FileName.EndsWith(".html", true, CultureInfo.InstalledUICulture))
            {
                this.logger.Error("ReusableContentHelper.ParseReusableContent: Invalid filename for the HTML File, it does not ends with .html. (value : {0}", reusableContentInfo.FileName);
            }

            // HTML Content of the file
            var htmlContent = string.Empty;

            string pathLayout = reusableContentInfo.HTMLFilePath;

            // File validation
            if (string.IsNullOrEmpty(pathLayout) || !File.Exists(pathLayout))
            {
                this.logger.Error("Unable to locate file at path '{0}' for reusable content.", pathLayout);
            }
            else
            {
                try
                {
                    // Load the HTML file content
                    using (var fileStream = new FileStream(pathLayout, FileMode.Open, FileAccess.Read))
                    {
                        using (var streamReader = new StreamReader(fileStream))
                        {
                            htmlContent = streamReader.ReadToEnd();
                            isSuccess   = true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (exception is FileNotFoundException || exception is SecurityException || exception is DirectoryNotFoundException)
                    {
                        this.logger.Error("An exception occured while tryin to read the file content at path '{0}' for reusable content.", pathLayout);
                        this.logger.Exception(exception);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            reusableContentInfo.Content = htmlContent;

            return(isSuccess);
        }
Exemplo n.º 2
0
        public void ReusableContentInfo_ShouldSupportStringSerializationAndDeserialization()
        {
            // Arrange
            var serializer = this.GetSerializer();
            var objectToSerialize = new ReusableContentInfo("Reusable Content Name", "Dynamite", true, false, "filename.html", "GSoft.Dynamite/html");
            objectToSerialize.Content = "<h1>Hello World!</h1>";

            // Act
            string serializedRepresentation = serializer.Serialize(objectToSerialize);

            var deserializedObject = serializer.Deserialize<ReusableContentInfo>(serializedRepresentation);

            // Assert
            Assert.AreEqual(objectToSerialize.Title, deserializedObject.Title);
            Assert.IsTrue(deserializedObject.IsAutomaticUpdate);
            Assert.IsFalse(deserializedObject.IsShowInRibbon);
            Assert.AreEqual(objectToSerialize.HTMLFilePath, deserializedObject.HTMLFilePath);
            Assert.AreEqual(objectToSerialize.Content, deserializedObject.Content);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the reusable content by title.
        /// </summary>
        /// <param name="site">The Site Collection.</param>
        /// <param name="reusableContentTitle">The reusable content title.</param>
        /// <returns>The reusable content</returns>
        public ReusableContentInfo GetByTitle(SPSite site, string reusableContentTitle)
        {
            var list = this.listLocator.GetByUrl(site.RootWeb, this.ReusableContentListRelativeUrl);

            var cultureSuffix = "_" + CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToUpperInvariant();

            var listItem = this.GetListItemByTitle(list, reusableContentTitle);

            if (listItem == null)
            {
                listItem = this.GetListItemByTitle(list, reusableContentTitle + cultureSuffix);
            }

            if (listItem != null)
            {
                var entity = new ReusableContentInfo();
                this.binder.ToEntity <ReusableContentInfo>(entity, listItem);
                return(entity);
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the reusable content by title.
        /// </summary>
        /// <param name="site">The Site Collection.</param>
        /// <param name="reusableContentTitle">The reusable content title.</param>
        /// <returns>The reusable content</returns>
        public ReusableContentInfo GetByTitle(SPSite site, string reusableContentTitle)
        {
            var list = this.listLocator.GetByUrl(site.RootWeb, this.ReusableContentListRelativeUrl);

            var cultureSuffix = "_" + CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToUpperInvariant();

            var listItem = this.GetListItemByTitle(list, reusableContentTitle);

            if (listItem == null)
            {
                listItem = this.GetListItemByTitle(list, reusableContentTitle + cultureSuffix);
            }

            if (listItem != null)
            {
                var entity = new ReusableContentInfo();
                this.binder.ToEntity<ReusableContentInfo>(entity, listItem);
                return entity;
            }

            return null;
        }
Exemplo n.º 5
0
        private bool LoadContentFile(ReusableContentInfo reusableContentInfo)
        {
            var isSuccess = false;

            // Validate the Filename
            if (!reusableContentInfo.FileName.EndsWith(".html", true, CultureInfo.InstalledUICulture))
            {
                this.logger.Error("ReusableContentHelper.ParseReusableContent: Invalid filename for the HTML File, it does not ends with .html. (value : {0}", reusableContentInfo.FileName);
            }

            // HTML Content of the file
            var htmlContent = string.Empty;

            string pathLayout = reusableContentInfo.HTMLFilePath;

            // File validation
            if (string.IsNullOrEmpty(pathLayout) || !File.Exists(pathLayout))
            {
                this.logger.Error("Unable to locate file at path '{0}' for reusable content.", pathLayout);
            }
            else
            {
                try
                {
                    // Load the HTML file content
                    using (var fileStream = new FileStream(pathLayout, FileMode.Open, FileAccess.Read))
                    {
                        using (var streamReader = new StreamReader(fileStream))
                        {
                            htmlContent = streamReader.ReadToEnd();
                            isSuccess = true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (exception is FileNotFoundException || exception is SecurityException || exception is DirectoryNotFoundException)
                    {
                        this.logger.Error("An exception occured while tryin to read the file content at path '{0}' for reusable content.", pathLayout);
                        this.logger.Exception(exception);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            reusableContentInfo.Content = htmlContent;

            return isSuccess;
        }