예제 #1
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     TemplateLocation.RegisterLocation(typeof(PackagePathTemplateLocation));
 }
 public override bool Equals(TemplateLocation other)
 {
     var otherPackagePathLoc = other as WebServiceTemplateLocation;
     return (otherPackagePathLoc != null)
            && string.Equals(PackageID, otherPackagePathLoc.PackageID, StringComparison.Ordinal)
            && string.Equals(HostAddress, otherPackagePathLoc.HostAddress, StringComparison.OrdinalIgnoreCase)
            && string.Equals(_templateDir, otherPackagePathLoc._templateDir, StringComparison.Ordinal);
 }
예제 #3
0
        public ITemplateLocation StubLocationForProcess(bool searchSubDirectories = false, bool registerAllAsPartials = false)
        {
            var location = new TemplateLocation();

            location.SearchSubDirectories  = searchSubDirectories;
            location.RegisterAllAsPartials = registerAllAsPartials;
            return(location);
        }
예제 #4
0
        public CompileContext(Type baseType, Type modelType, string templateNamespace = null, string templateName = null, string templatePath = null, LogHandler logHandler = null)
        {
            _templateBaseType = baseType;
            _location         = new TemplateLocation(templatePath);
            _macroManager     = new MacroManager(baseType);
            _modelTypeName    = ClassContext.GetTypeName(modelType);

            _stateTypeName = $"TxMark.Template.IState<{_modelTypeName}>";

            _nameTagManager = new NameTagManager();

            _bagsByReference = new Bag <object>();

            _variableTypeByName = new Dictionary <string, VariableTypes>();

            if (templateNamespace == null)
            {
                templateNamespace = DEFAULT_NAMESPACE;
            }
            if (templateName == null)
            {
                templateName = "Template_" + Guid.NewGuid().ToString().Replace('-', '_');
            }

            _logHandler       = logHandler ?? DefaultLogHandler;
            _codeContextStack = new Stack <ICodeContext>();

            _metadataReferenceManager = new MetadataReferenceManager();

            AddNamespaceFor(typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException));

            AddNamespaceFor(typeof(DynamicObject));

            AddNamespaceFor(typeof(string));

            AddNamespaceFor(baseType);

            AddNamespaceFor(modelType);

            AddNamespaceFor(typeof(TemplateState <object>));

            AddNamespaceFor(typeof(Dictionary <string, object>));

            _namespace = SF.NamespaceDeclaration(SF.IdentifierName(templateNamespace));

            _codeContext = new ClassContext(templateName, baseType, modelType, (classDeclaration) =>
            {
                _namespace = _namespace.AddMembers(classDeclaration);
                List <UsingDirectiveSyntax> usingDirectives = new List <UsingDirectiveSyntax>();
                foreach (var namespaceName in _usingNamespaces)
                {
                    //usingDirectives.Add(SF.UsingDirective(SF.IdentifierName(namespaceName)));
                }
                _compilationUnit = SF.CompilationUnit();
                //.AddUsings(usingDirectives.ToArray());
                _compilationUnit = _compilationUnit.AddMembers(_namespace);
            });
        }
예제 #5
0
        public ITemplateLocation StubLocationForRegister(bool hasDirectory = true)
        {
            var location = new TemplateLocation();

            templateLocations.Add(location);

            svc.Setup(x => x.TestDirectoryExists(location));
            svc.Setup(x => x.ProcessTemplates(directory.Object, ref templates, location));

            if (hasDirectory)
            {
                svc.Setup(x => x.GetDirectory(location)).Returns(directory.Object);
            }
            else
            {
                svc.Setup(x => x.GetDirectory(location)).Returns((DirectoryInfo)null);
            }

            return(location);
        }
예제 #6
0
 public TemplateClass(TemplateLocation location, string classNameFormat)
 {
     ClassNameFormat = classNameFormat;
     Location        = location;
 }
예제 #7
0
        private string _title = null; //A cached title when non-null.

        #endregion Fields

        #region Constructors

        //Constructors
        /// <summary>
        /// Construct a Template object.
        /// </summary>
        /// <param name="fileName">The template file name.</param>
        /// <param name="location">The location of the template.</param>
        /// <include file="../Shared/Help.xml" path="Help/string/param[@name='switches']"></include>
        /// <include file="../Shared/Help.xml" path="Help/string/param[@name='key']"></include>
        public Template(string fileName, TemplateLocation location, string switches = "", string key = "")
        {
            if (string.IsNullOrEmpty(fileName))
                throw new ArgumentException("fileName");

            if (location == null)
                throw new ArgumentException("location");

            FileName = fileName;
            Location = location;
            Switches = string.IsNullOrEmpty(switches) ? "" : switches;
            Key = string.IsNullOrEmpty(key) ? "" : key;
        }
예제 #8
0
 public GenerateMethod(string nameFormat, TemplateLocation location, bool callBase)
     : base(location)
 {
     _callBase  = callBase;
     NameFormat = nameFormat;
 }
예제 #9
0
 public GenerateProperty(TemplateLocation location)
     : base(location)
 {
 }
예제 #10
0
 public GenerateMember(TemplateLocation location)
 {
     Location = location;
 }
예제 #11
0
        public bool Perform(ExecuteWhen exec, IEngineContext context, IController controller, IControllerContext controllerContext)
        {
            if (controllerContext.SelectedViewName == null)
            {
                return(true);
            }

            if (context.IsAjax())
            {
                controllerContext.LayoutNames = null;
            }

            var p        = Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture);
            var template = new TemplateLocation();

            if (context.Request.AcceptHeader != null && context.Request.AcceptHeader.Contains("application/json"))
            {
                template.Area                 = controllerContext.AreaName;
                template.Controller           = controllerContext.Name;
                template.Action               = "json";
                controllerContext.LayoutNames = null;
            }
            else
            {
                var view = context.GetParameter("view");

                template.Area       = controllerContext.AreaName;
                template.Controller = controllerContext.Name;
                template.Action     = string.IsNullOrEmpty(view) ? controllerContext.Action : view;

                if (view == "json")
                {
                    controllerContext.LayoutNames = null;
                }
                else
                {
                    var layout = context.GetParameter("layout");
                    if (context.Services.ViewEngineManager.HasTemplate(p + "layouts" + p + layout))
                    {
                        controllerContext.LayoutNames = new[] { layout };
                    }
                }
            }

            var t = template.ToString();

            if (context.Services.ViewEngineManager.HasTemplate(t))
            {
                controllerContext.SelectedViewName = t;
            }
            else
            {
                template.Area       = null;
                template.Controller = "common";
                t = template.ToString();
                if (context.Services.ViewEngineManager.HasTemplate(t))
                {
                    controllerContext.SelectedViewName = t;
                }
            }
            return(true);
        }
예제 #12
0
 public GenerateMethod(TemplateLocation location)
     : base(location)
 {
 }
예제 #13
0
 public GenerateMethod(string nameFormat, TemplateLocation location, bool callBase)
     : base(location)
 {
     _callBase = callBase;
     NameFormat = nameFormat;
 }
예제 #14
0
 public GenerateMethod(TemplateLocation location, bool callBase)
     : base(location)
 {
     CallBase = callBase;
 }
예제 #15
0
 public Inside(TemplateLocation location)
 {
     TemplateLocation = location;
 }
예제 #16
0
 public TemplateClass(TemplateLocation location, string classNameFormat)
 {
     ClassNameFormat = classNameFormat;
     Location = location;
 }
예제 #17
0
 public AsAbstract(TemplateLocation location)
 {
     _location = location;
 }
예제 #18
0
 public GenerateConstructor(TemplateLocation location, params string[] baseCallArgs)
     : base(location)
 {
     BaseCallArgs = baseCallArgs;
 }
예제 #19
0
 public GenerateProperty(TemplateLocation location, string nameFormat)
     : base(location)
 {
     NameFormat = nameFormat;
 }
예제 #20
0
        public void TestTemplateLocationEquatability()
        {
            string templateDir = Path.Combine(GetSamplePortalTemplateDir(), "TestTemplates");
            string dir1        = Path.Combine(templateDir, "temp");
            string dir2        = Path.Combine(templateDir, "tĕmp");
            string dir3        = Path.Combine(templateDir, "tëmp");

            // ensure PathTemplateLocation is case insensitive and not diacritic insensitive
            var loc1a = new PathTemplateLocation(dir1);
            var loc1b = new PathTemplateLocation(dir1.ToUpper());
            var loc2a = new PathTemplateLocation(dir2);
            var loc2b = new PathTemplateLocation(dir2.ToUpper());
            var loc3  = new PathTemplateLocation(dir3);
            PathTemplateLocation loc4 = null;
            PathTemplateLocation loc5 = null;

            // Try to get a TemplateLocation from an invalid locator.
            TemplateLocation loc = TemplateLocation.Locate(Util.EncryptString("abcdefg"));

            Assert.IsNull(loc);

            try
            {
                loc = TemplateLocation.Locate(Util.EncryptString("abc|defg"));
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("The type abc is not registered"));
            }

            // ensure PathTemplateLocation is case insensitive
            Assert.AreNotEqual(loc1a, "");
            Assert.AreEqual(loc1a, loc1b);
            Assert.AreEqual(loc1a.GetHashCode(), loc1b.GetHashCode());
            Assert.AreEqual(loc2a, loc2b);
            Assert.AreEqual(loc2a.GetHashCode(), loc2b.GetHashCode());
            // ensure PathTemplateLocation is not unicode/diacritic insensitive
            Assert.AreNotEqual(loc1a, loc2a);
            Assert.AreNotEqual(loc1a.GetHashCode(), loc2a.GetHashCode());
            Assert.AreNotEqual(loc1a, loc3);
            Assert.AreNotEqual(loc1a.GetHashCode(), loc3.GetHashCode());
            Assert.AreNotEqual(loc2b, loc3);
            Assert.AreNotEqual(loc2b.GetHashCode(), loc3.GetHashCode());
            // ensure we can tell the difference between nulls & non
            Assert.AreNotEqual(loc1a, loc4);
            Assert.AreEqual(loc4, loc5);             // null template locations are equal to each other, I suppose

            // ensure hashing is working pretty much like we expect it to
            var set = new HashSet <TemplateLocation>();

            set.Add(loc1a);
            Assert.IsTrue(set.Contains(loc1a));
            Assert.IsTrue(set.Contains(loc1b));
            Assert.IsFalse(set.Contains(loc2a));
            Assert.IsFalse(set.Contains(loc2b));
            Assert.IsFalse(set.Contains(loc3));
            Assert.IsFalse(set.Contains(loc4));
            Assert.IsFalse(set.Contains(loc5));
            set.Add(loc3);
            Assert.IsTrue(set.Contains(loc1a));
            Assert.IsTrue(set.Contains(loc1b));
            Assert.IsFalse(set.Contains(loc2a));
            Assert.IsFalse(set.Contains(loc2b));
            Assert.IsTrue(set.Contains(loc3));
            Assert.IsFalse(set.Contains(loc4));
            Assert.IsFalse(set.Contains(loc5));
            set.Add(loc2b);
            Assert.IsTrue(set.Contains(loc1a));
            Assert.IsTrue(set.Contains(loc1b));
            Assert.IsTrue(set.Contains(loc2a));
            Assert.IsTrue(set.Contains(loc2b));
            Assert.IsFalse(set.Contains(loc4));
            Assert.IsFalse(set.Contains(loc5));
            set.Add(loc4);
            Assert.IsTrue(set.Contains(loc4));
            Assert.IsTrue(set.Contains(loc5));

            // now test PackagePathTemplateLocation too (& in combination)
            var pkgloc1a = new PackagePathTemplateLocation(@"2f98a9f3-d106-44a8-ba16-e01d8cd65cbd", Path.Combine(dir1, "temp.pkg"));
            var pkgloc1b = new PackagePathTemplateLocation(@"2f98a9f3-d106-44a8-ba16-e01d8cd65cbd", Path.Combine(dir1, "TEMP.pkg"));
            var pkgloc2a = new PackagePathTemplateLocation(@"2f98a9f3-d106-44a8-ba16-e01d8cd65cbD", Path.Combine(dir1, "TEMP.pkg"));
            var pkgloc3a = new PackagePathTemplateLocation(@"l'identité unique", Path.Combine(dir3, "tëmp.pkg"));
            var pkgloc3b = new PackagePathTemplateLocation(@"l'identité unique", Path.Combine(dir3, "TËMP.pkg"));
            var pkgloc4a = new PackagePathTemplateLocation(@"l'identité unique", Path.Combine(dir2, "tĕmp.pkg"));
            var pkgloc5a = new PackagePathTemplateLocation(@"l'identite unique", Path.Combine(dir2, "TĔMP.pkg"));

            // ensure package ID is case sensitive & package path is case insensitive
            Assert.AreEqual(pkgloc1a, pkgloc1b);
            Assert.AreEqual(pkgloc1a.GetHashCode(), pkgloc1b.GetHashCode());
            Assert.AreNotEqual(pkgloc1a, pkgloc2a);
            Assert.AreNotEqual(pkgloc1a.GetHashCode(), pkgloc2a.GetHashCode());
            Assert.AreNotEqual(pkgloc1b, pkgloc2a);
            Assert.AreNotEqual(pkgloc1b.GetHashCode(), pkgloc2a.GetHashCode());
            // ensure package ID & path are diacritic sensitive
            Assert.AreEqual(pkgloc3a, pkgloc3b);
            Assert.AreEqual(pkgloc3a.GetHashCode(), pkgloc3b.GetHashCode());
            Assert.AreNotEqual(pkgloc3a, pkgloc4a);
            Assert.AreNotEqual(pkgloc3a.GetHashCode(), pkgloc4a.GetHashCode());
            Assert.AreNotEqual(pkgloc3b, pkgloc5a);
            Assert.AreNotEqual(pkgloc3b.GetHashCode(), pkgloc5a.GetHashCode());

            // TODO: check comparisons/equality of different types of TemplateLocations with each other.
            // (should always be not equal, hopefully even if null?)
        }
예제 #21
0
 public GenerateMethod(TemplateLocation location, bool callBase)
     : base(location)
 {
     CallBase = callBase;
 }
 public GenerateConstructor(TemplateLocation location, params string[] baseCallArgs)
     : base(location)
 {
     BaseCallArgs = baseCallArgs;
 }
예제 #23
0
 public GenerateMethod(TemplateLocation location)
     : base(location)
 {
 }
예제 #24
0
 public Template(string name, TemplateType type, TemplateLocation source)
 {
     Name   = name;
     Type   = type;
     Source = source;
 }
예제 #25
0
 public AsAbstract(TemplateLocation location)
 {
     _location = location;
 }
 /// <summary>
 /// Implements IEquatable&lt;TemplateLocation&gt;.Equals().
 /// </summary>
 /// <param name="other">The other template location to compare equality.</param>
 /// <returns>A value indicating whether or not the two locations are the same.</returns>
 public override bool Equals(TemplateLocation other)
 {
     var otherPathLoc = other as PathTemplateLocation;
     return (otherPathLoc != null)
         && string.Equals(_templateDir, otherPathLoc._templateDir, StringComparison.OrdinalIgnoreCase);
 }
예제 #27
0
 public GenerateMember(TemplateLocation location)
 {
     Location = location;
 }
예제 #28
0
 public GenerateProperty(TemplateLocation location, string nameFormat)
     : base(location)
 {
     NameFormat = nameFormat;
 }
예제 #29
0
 public TemplateClass(TemplateLocation location)
 {
     Location = location;
 }
예제 #30
0
 public GenerateProperty(TemplateLocation location)
     : base(location)
 {
   
 }
예제 #31
0
 public Inside(TemplateLocation location)
 {
     TemplateLocation = location;
 }
예제 #32
0
 public TemplateClass(TemplateLocation location)
 {
     Location = location;
 }