示例#1
0
        /// <summary>
        /// Creates a new view.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <param name="viewType">
        /// The view type.
        /// </param>
        /// <param name="modelName">
        /// The model name.
        /// </param>
        /// <param name="viewBody">
        /// The view body.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the create was successful.
        /// </returns>
        public override PluginViewEditorContent CreateNewView(string fileName, PluginViewType viewType, string modelName, string viewBody)
        {
            var virtualPath = GetVirtualPathByPlugViewType(viewType);

            var mapped = EnsureMappedPath(virtualPath);

            fileName = fileName.Replace(" ", string.Empty);

            var fullFileName = string.Format("{0}{1}", mapped, fileName);

            if (!File.Exists(fullFileName))
            {
                using (var sw = File.CreateText(fullFileName))
                {
                    sw.WriteLine("@inherits Merchello.Web.Mvc.MerchelloHelperViewPage<{0}>", modelName);
                    sw.WriteLine("@using Merchello.Core");
                    sw.WriteLine("@using Merchello.Core.Models");
                    sw.WriteLine("@*");
                    sw.WriteLine("     MerchelloHelperViewPage<T> inherits from UmbracoViewPage<t> and exposes the MerchelloHelper as 'Merchello'");
                    sw.WriteLine("     Example usage:  var product = Merchello.TypedProductContent(YOURPRODUCTKEY);");
                    sw.WriteLine("*@");
                    sw.Close();
                }

                return(GetView(virtualPath, fileName, viewType));
            }

            var logData = MultiLogger.GetBaseLoggingData();
            var ex      = new InvalidDataException("File already exists");

            MultiLogHelper.Error <PluginViewEditorProvider>("Cannot create a duplicate file", ex, logData);
            throw ex;
        }
 /// <summary>
 /// Gets the virtual path by view type.
 /// </summary>
 /// <param name="viewType">
 /// The view type.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 protected static string GetVirtualPathByPlugViewType(PluginViewType viewType)
 {
     switch (viewType)
     {
     default:
         return(MerchelloConfiguration.Current.GetSetting("NotificationTemplateBasePath"));
     }
 }
示例#3
0
 /// <summary>
 /// Maps <see cref="FileInfo"/> to <see cref="PluginViewEditorContent"/>.
 /// </summary>
 /// <param name="fi">
 /// The fi.
 /// </param>
 /// <param name="virtualPath">
 /// The virtual Path.
 /// </param>
 /// <param name="viewType">
 /// The view Type.
 /// </param>
 /// <returns>
 /// The <see cref="PluginViewEditorContent"/>.
 /// </returns>
 public static PluginViewEditorContent ToAppPluginViewEditorContent(this FileInfo fi, string virtualPath, PluginViewType viewType = PluginViewType.Notification)
 {
     if (fi.Extension != ".cshtml") return null;
     return new PluginViewEditorContent
                {
                    VirtualPath = virtualPath,
                    FileName = fi.Name,
                    ViewBody = File.ReadAllText(fi.FullName),
                    PluginViewType = viewType
                };
 }
        /// <summary>
        /// Saves an existing view.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <param name="viewType">
        /// The view type.
        /// </param>
        /// <param name="viewBody">
        /// The view body.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the save was successful.
        /// </returns>
        public virtual bool SaveView(string fileName, PluginViewType viewType, string viewBody)
        {
            var virtualPath = GetVirtualPathByPlugViewType(viewType);
            var mapped      = EnsureMappedPath(virtualPath);

            var fullFileName = string.Format("{0}{1}", mapped, fileName);

            if (File.Exists(fullFileName))
            {
                File.WriteAllText(fullFileName, viewBody, Encoding.UTF8);

                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Maps <see cref="FileInfo"/> to <see cref="PluginViewEditorContent"/>.
 /// </summary>
 /// <param name="fi">
 /// The fi.
 /// </param>
 /// <param name="virtualPath">
 /// The virtual Path.
 /// </param>
 /// <param name="viewType">
 /// The view Type.
 /// </param>
 /// <returns>
 /// The <see cref="PluginViewEditorContent"/>.
 /// </returns>
 public static PluginViewEditorContent ToAppPluginViewEditorContent(this FileInfo fi, string virtualPath, PluginViewType viewType = PluginViewType.Notification)
 {
     if (fi.Extension != ".cshtml")
     {
         return(null);
     }
     return(new PluginViewEditorContent
     {
         VirtualPath = virtualPath,
         FileName = fi.Name,
         ViewBody = File.ReadAllText(fi.FullName),
         PluginViewType = viewType
     });
 }
 /// <summary>
 /// Creates a new view.
 /// </summary>
 /// <param name="fileName">
 /// The file name.
 /// </param>
 /// <param name="viewType">
 /// The view type.
 /// </param>
 /// <param name="modelName">
 /// The model name.
 /// </param>
 /// <param name="viewBody">
 /// The view body.
 /// </param>
 /// <returns>
 /// A value indicating whether or not the create was successful.
 /// </returns>
 public abstract TModel CreateNewView(string fileName, PluginViewType viewType, string modelName, string viewBody);
 /// <summary>
 /// Gets a specific view.
 /// </summary>
 /// <param name="virtualPath">
 /// The virtual path.
 /// </param>
 /// <param name="fileName">
 /// The file Name.
 /// </param>
 /// <param name="viewType">
 /// The view type.
 /// </param>
 /// <returns>
 /// The <see cref="TModel"/>.
 /// </returns>
 public abstract TModel GetView(string virtualPath, string fileName, PluginViewType viewType);
示例#8
0
        /// <summary>
        /// Gets a specific view.
        /// </summary>
        /// <param name="virtualPath">
        /// The virtual path.
        /// </param>
        /// <param name="fileName">
        /// The file Name.
        /// </param>
        /// <param name="viewType">
        /// The view type.
        /// </param>
        /// <returns>
        /// The <see cref="PluginViewEditorContent"/>.
        /// </returns>
        public override PluginViewEditorContent GetView(string virtualPath, string fileName, PluginViewType viewType)
        {
            if (virtualPath.IsNullOrWhiteSpace())
            {
                throw new System.Exception("VirtualPath cannot be null or whitespace");
            }

            var mapped = EnsureMappedPath(virtualPath);

            var fullFileName = string.Format("{0}{1}", mapped, fileName.Replace(" ", string.Empty));

            if (!File.Exists(fullFileName))
            {
                var nullRef = new NullReferenceException("File does not exist on disk.");
                var logData = MultiLogger.GetBaseLoggingData();
                MultiLogHelper.Error <PluginViewEditorProvider>("File does not exist.", nullRef, logData);
                throw nullRef;
            }

            var file = new FileInfo(fullFileName);

            return(file.ToAppPluginViewEditorContent(virtualPath));
        }