示例#1
0
        /// <summary>
        /// Enumerates all non-archive local files, BLT encodes them and adds them to the InstallFile
        /// </summary>
        /// <param name="maxDegreeOfParallelism"></param>
        /// <returns></returns>
        public void ExportFiles(int maxDegreeOfParallelism = 15)
        {
            var results = new ConcurrentBag <CASRecord>();

            var block = new ActionBlock <string>(file =>
            {
                // strip the local path and normalise
                var name = file[(file.IndexOf(BaseDirectory, Comparison) + BaseDirectory.Length)..].WoWNormalise();

                // block table encode and export to the temp folder
                // then add appropiate tags
                var record  = BlockTableEncoder.EncodeAndExport(file, Options.TempDirectory, name);
                record.Tags = TagGenerator.GetTags(file);

                if (!EncodingCache.ContainsEKey(record.EKey))
                {
                    EncodingCache.AddOrUpdate(record);
                }
                else
                {
                    record.BLTEPath = "";
                }

                results.Add(record);
            },
示例#2
0
        private static void Run(Options options)
        {
            Clean(options);

            options.LoadConfig();

            EncodingCache.Initialise(options);

            // create the repo
            var tactRepo = CreateRepo(options);

            // load the the Install/Download tag lookups
            TagGenerator.Load(tactRepo);

            // load the readers
            var dirReader = new DirectoryReader(options, tactRepo);
            var mpqReader = new MPQReader(options, tactRepo, dirReader.PatchArchives);

            // populate the Install and Root files
            PopulateInstallFile(tactRepo, dirReader, mpqReader);
            PopulateRootFile(tactRepo, dirReader, mpqReader);

            // build and save the repo
            Log.WriteLine("Building and Saving repo");
            tactRepo.Save(options.OutputFolder, Path.Combine(options.OutputFolder, options.BuildName));

            EncodingCache.Save();

            // cleanup
            Clean(options);
        }
        public void SetUp()
        {
            _page     = MockRepository.GenerateMock <IFubuPage <InputModel> >();
            _renderer = MockRepository.GenerateStub <IPartialRenderer>();
            var serviceLocator   = MockRepository.GenerateStub <IServiceLocator>();
            var namingConvention = MockRepository.GenerateStub <IElementNamingConvention>();

            _tags = new TagGenerator <InputModel>(new TagProfileLibrary(), namingConvention,
                                                  serviceLocator);

            _viewTypeRegistry = MockRepository.GenerateStub <IPartialViewTypeRegistry>();
            serviceLocator.Stub(s => s.GetInstance <IPartialViewTypeRegistry>()).Return(_viewTypeRegistry);

            var inMemoryFubuRequest = new InMemoryFubuRequest();

            inMemoryFubuRequest.Set(new InputModel());

            _page.Stub(s => s.Get <IFubuRequest>()).Return(inMemoryFubuRequest);

            _model = new InputModel {
                Partials = new List <PartialModel> {
                    new PartialModel()
                }
            };
            _page.Expect(p => p.Get <ITagGenerator <InputModel> >()).Return(_tags);
            _page.Expect(p => p.Model).Return(_model);
            _page.Expect(p => p.Get <IPartialRenderer>()).Return(_renderer);
            _page.Expect(p => p.ServiceLocator).Return(serviceLocator);
        }
示例#4
0
        public static HtmlTag Label <TModel>(this IHtmlHelper <TModel> helper, Expression <Func <TModel, object> > expression)
        {
            var options = helper.ViewContext.HttpContext.RequestServices.GetService <HtmlConventionOptions>();
            var tag     = new TagGenerator(options.Conventions.Select(x => (HtmlConvention)helper.ViewContext.HttpContext.RequestServices.GetService(x)).ToList());

            return(tag.GenerateLabelFor(helper.ViewContext, expression));
        }
 public override TagEntity Get(string key)
 {
     return(Get(key, (tag) => {
         var gen = new TagGenerator();
         return gen.GetOrCreate(tag);
     }));
 }
示例#6
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new InvalidOperationException(
                          "Missing or invalid 'for' attribute value. Specify a valid model expression for the 'for' attribute value.");
            }

            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), t => ViewContext.HttpContext.RequestServices.GetService(t));

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
示例#7
0
        /// <summary>
        /// Probably only useful for testing
        /// </summary>
        /// <param name="library"></param>
        /// <param name="activators"></param>
        /// <returns></returns>
        public static ElementGenerator <T> For(HtmlConventionLibrary library, IEnumerable <ITagRequestActivator> activators = null)
        {
            var tags = new TagGenerator <ElementRequest>(library.For <ElementRequest>(),
                                                         new TagRequestBuilder(activators ?? new ITagRequestActivator[0]), new ActiveProfile());

            return(new ElementGenerator <T>(tags, new InMemoryFubuRequest()));
        }
示例#8
0
        public static MvcForm GenerateForm(Type inputType, ViewContext viewContext, Action <FormTag> modifier, string url)
        {
            viewContext.RequestContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = inputType;
            var tagGenerator = new TagGenerator(HtmlConventionFactory.HtmlConventions);
            var tag          = tagGenerator.GenerateTagFor(viewContext, () => (FormTag) new FormTag(url).NoClosingTag());

            modifier(tag);
            viewContext.Writer.WriteLine(tag);
            return(new InputTypeMvcForm(viewContext));
        }
示例#9
0
        public void ShouldBeAbleToGenerateTagForLooselyTypedProperty()
        {
            var setting = new Settings();

            var accessor = ReflectionUtil.GetAccessor(setting.GetType().GetProperty("Name"));

            var tagGenerator = new TagGenerator(HtmlConventionFactory.HtmlConventions);
            var html         = tagGenerator.GenerateInputFor(MvcMockHelpers.MockViewContext(), accessor);

            Assert.AreEqual("<input type=\"text\" id=\"Name\" name=\"Name\" />", html.ToString());
        }
示例#10
0
        public void use_the_prefix_in_determining_element_names()
        {
            var naming = new DefaultElementNamingConvention();
            var generator = new TagGenerator<AddressViewModel>(new TagProfileLibrary(), naming, null)
            {
                Model = new AddressViewModel(),
                ElementPrefix = "Site"
            };

            generator.GetRequest(x => x.Address.Address1).ElementId.ShouldEqual("SiteAddressAddress1");
        }
示例#11
0
        public void use_the_prefix_in_determining_element_names()
        {
            var naming    = new DefaultElementNamingConvention();
            var generator = new TagGenerator <AddressViewModel>(new TagProfileLibrary(), naming, null)
            {
                Model         = new AddressViewModel(),
                ElementPrefix = "Site"
            };

            generator.GetRequest(x => x.Address.Address1).ElementId.ShouldEqual("SiteAddressAddress1");
        }
        public void ShouldBeAbleToGenerateTagForLooselyTypedProperty()
        {
            var setting = new Settings();

            var accessor = ReflectionUtil.GetAccessor(setting.GetType().GetProperty("Name"));

            var tagGenerator = new TagGenerator(HtmlConventionFactory.HtmlConventions);
            var html = tagGenerator.GenerateInputFor(MvcMockHelpers.MockViewContext(), accessor);

            Assert.AreEqual("<input type=\"text\" id=\"Name\" name=\"Name\" />", html.ToString());
        }
示例#13
0
        /// <summary>
        /// Extracts a collection of files from an archive and BLTE encodes them
        /// </summary>
        /// <param name="mpq"></param>
        /// <param name="filenames"></param>
        /// <param name="maxDegreeOfParallelism"></param>
        /// <returns></returns>
        private async Task ExportFiles(MpqArchive mpq, IEnumerable <string> filenames, bool applyTags = false, int maxDegreeOfParallelism = 150)
        {
            var block = new ActionBlock <string>(file =>
            {
                using var fs = mpq.OpenFile(file);

                // ignore PTCH files
                if (fs.Flags.HasFlag(MPQFileAttributes.PatchFile))
                {
                    return;
                }

                // patch has marked file for deletion so remove from filelist
                if (fs.Flags.HasFlag(MPQFileAttributes.DeleteMarker))
                {
                    FileList.TryRemove(file, out _);
                    return;
                }

                if (fs.CanRead && fs.Length > 0)
                {
                    var map = BlockTableEncoder.GetEMapFromExtension(file, fs.Length);

                    if (!EncodingCache.TryGetRecord(MD5Hash.Parse(fs.GetMD5Hash()), file, out var record))
                    {
                        record = BlockTableEncoder.EncodeAndExport(fs, map, Options.TempDirectory, file);
                        EncodingCache.AddOrUpdate(record);
                    }

                    if (applyTags)
                    {
                        record.Tags = TagGenerator.GetTags(file, fs);
                    }

                    record.EBlock.EncodingMap = map;
                    FileList.TryAdd(file, record);
                }
            },
                                                 new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = maxDegreeOfParallelism
            });

            foreach (var file in filenames)
            {
                if (!FileList.ContainsKey(file))
                {
                    block.Post(file);
                }
            }

            block.Complete();
            await block.Completion;
        }
示例#14
0
        public static MvcForm GenerateForm(Type inputType, ViewContext viewContext, Action <FormTag> modifier, string url)
        {
            var options = viewContext.HttpContext.RequestServices.GetService <HtmlConventionOptions>();

            viewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = inputType;
            var tagGenerator = new TagGenerator(options.Conventions.Select(x => (HtmlConvention)viewContext.HttpContext.RequestServices.GetService(x)).ToList());
            var tag          = tagGenerator.GenerateTagFor(viewContext, () => (FormTag) new FormTag(url).NoClosingTag());

            modifier(tag);
            viewContext.Writer.WriteLine(tag);
            return(new InputTypeMvcForm(viewContext));
        }
示例#15
0
        private static ITagGenerator <T> GetGenerator <T>(HtmlHelper <T> helper, Expression <Func <T, object> > expression) where T : class
        {
            TagGenerator <T> generator = ObjectFactory.Container.GetInstance <ITagGenerator <T> >() as TagGenerator <T>;

            generator.Model = helper.ViewData.Model;
            if (helper.ViewData.TemplateInfo.HtmlFieldPrefix.IsNotEmpty())
            {
                generator.ElementPrefix = helper.ViewData.TemplateInfo.HtmlFieldPrefix + ".";
            }
            else
            {
                Accessor accessor = expression.ToAccessor();
                if (!accessor.OwnerType.Name.ToLowerInvariant().Contains("viewmodel"))
                {
                    generator.ElementPrefix = accessor.OwnerType.Name + ".";
                }
            }
            return(generator);
        }
示例#16
0
        public void SetUp()
        {
            var registry =
                new FubuRegistry(
                    x => { x.StringConversions(s => { s.ForStruct<DateTime>(d => d.ToShortDateString()); }); });

            container = new Container(x => x.For<IFubuRequest>().Singleton());
            var facility = new StructureMapContainerFacility(container);

            new FubuBootstrapper(facility, registry).Bootstrap(new List<RouteBase>());

            var request = container.GetInstance<IFubuRequest>();

            address = new Address();
            request.Set(address);

            request.Get<Address>().ShouldBeTheSameAs(address);

            generator = container.GetInstance<TagGenerator<Address>>();
        }
示例#17
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), t => ViewContext.HttpContext.RequestServices.GetService(t));

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
示例#18
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService<HtmlConventionLibrary>();

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), t => ViewContext.HttpContext.RequestServices.GetService(t));

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
示例#19
0
        public void Setup()
        {
            var registry = new FubuRegistry(x =>
            {
                x.HtmlConvention <DefaultHtmlConventions>();
            });
            var container = new Container(x => x.For <IFubuRequest>().Singleton());
            var facility  = new StructureMapContainerFacility(container);

            new FubuBootstrapper(facility, registry).Bootstrap(new List <RouteBase>());
            Model = new Address
            {
                Address1    = "123 Main St.",
                DateEntered = new DateTime(2010, 5, 25, 11, 30, 0),
                Order       = 42
            };
            container.GetInstance <IFubuRequest>().Set(Model);

            Generator       = container.GetInstance <TagGenerator <Address> >();
            Generator.Model = Model;
            Tag             = createTag();
        }
示例#20
0
        /// <summary>
        /// Iterates all loose files within the data directory and BLT encodes them
        /// </summary>
        /// <param name="filenames"></param>
        public void EnumerateLooseDataFiles(IEnumerable <string> filenames)
        {
            if (!filenames.Any())
            {
                return;
            }

            Log.WriteLine("Exporting loose Data files");

            var block = new ActionBlock <string>(file =>
            {
                var filename = GetInternalPath(file);

                var record  = BlockTableEncoder.EncodeAndExport(file, Options.TempDirectory, filename);
                record.Tags = TagGenerator.GetTags(file);

                if (!EncodingCache.ContainsEKey(record.EKey))
                {
                    EncodingCache.AddOrUpdate(record);
                }
                else
                {
                    record.BLTEPath = "";
                }

                FileList.TryAdd(filename, record);
            },
                                                 new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 150
            });

            foreach (var f in filenames)
            {
                block.Post(f);
            }

            block.Complete();
            block.Completion.Wait();
        }
        public void SetUp()
        {
            _page = MockRepository.GenerateMock<IFubuPage<InputModel>>();
            _renderer = MockRepository.GenerateStub<IPartialRenderer>();
            var serviceLocator = MockRepository.GenerateStub<IServiceLocator>();
            var namingConvention = MockRepository.GenerateStub<IElementNamingConvention>();
            _tags = new TagGenerator<InputModel>(new TagProfileLibrary(), namingConvention,
                                                 serviceLocator);

            _viewTypeRegistry = MockRepository.GenerateStub<IPartialViewTypeRegistry>();
            serviceLocator.Stub(s => s.GetInstance<IPartialViewTypeRegistry>()).Return(_viewTypeRegistry);

            var inMemoryFubuRequest = new InMemoryFubuRequest();
            inMemoryFubuRequest.Set(new InputModel());

            _page.Stub(s => s.Get<IFubuRequest>()).Return(inMemoryFubuRequest);

            _model = new InputModel{Partials=new List<PartialModel>{new PartialModel()}};
            _page.Expect(p => p.Get<ITagGenerator<InputModel>>()).Return(_tags);
            _page.Expect(p => p.Model).Return(_model);
            _page.Expect(p => p.Get<IPartialRenderer>()).Return(_renderer);
            _page.Expect(p => p.ServiceLocator).Return(serviceLocator);
        }
        public void Setup()
        {
            var registry = new FubuRegistry(x =>
            {
                x.Import <DefaultHtmlConventions>();
            });
            var container = new Container(x => x.For <IFubuRequest>().Singleton());


            FubuApplication.For(registry).StructureMap(container).Bootstrap();


            Model = new Address
            {
                Address1    = "123 Main St.",
                DateEntered = new DateTime(2010, 5, 25, 11, 30, 0),
                Order       = 42
            };
            container.GetInstance <IFubuRequest>().Set(Model);

            Generator       = container.GetInstance <TagGenerator <Address> >();
            Generator.Model = Model;
            Tag             = createTag();
        }
示例#23
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new InvalidOperationException(
                          "Missing or invalid 'for' attribute value. Specify a valid model expression for the 'for' attribute value.");
            }

            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            var additionalServices = new object[]
            {
                For.ModelExplorer,
                ViewContext,
                new ElementName(For.Name)
            };

            object ServiceLocator(Type t) => additionalServices.FirstOrDefault(t.IsInstanceOfType) ?? ViewContext.HttpContext.RequestServices.GetService(t);

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), ServiceLocator);

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
示例#24
0
        public void SetUp()
        {
            var registry = new FubuRegistry(x =>
            {
                x.HtmlConvention<OverrideFieldLayout>();
            });
            container = new Container(x => x.For<IFubuRequest>().Singleton());

            FubuApplication.For(registry)
                .StructureMap(container)
                .Bootstrap();

            var request = container.GetInstance<IFubuRequest>();

            address = new Address();
            request.Set(address);
            request.Get<Address>().ShouldBeTheSameAs(address);

            generator = container.GetInstance<TagGenerator<Address>>();
            generator.Model = address;
        }
        public void SetUp()
        {
            var registry = new FubuRegistry(x => x.HtmlConvention<TestHtmlConventions>());
            container = new Container(x => x.For<IFubuRequest>().Singleton());
            var facility = new StructureMapContainerFacility(container);

            new FubuBootstrapper(facility, registry).Bootstrap(new List<RouteBase>());

            var request = container.GetInstance<IFubuRequest>();

            address = new Address();
            request.Set(address);

            request.Get<Address>().ShouldBeTheSameAs(address);

            generator = container.GetInstance<TagGenerator<Address>>();
        }
示例#26
0
 public static string IdFor <TModel, T>(this LoopItem <TModel, T> loopItem, Expression <Func <T, object> > expression)
 {
     return(TagGenerator.BuildRequestData(loopItem.Info.HtmlHelper.ViewContext, loopItem.Info.TranslateExpression(expression)).Id);
 }
示例#27
0
 public static string NameFor <TModel>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, object> > expression)
 {
     return(TagGenerator.BuildRequestData(htmlHelper.ViewContext, expression).Name);
 }
        public void Setup()
        {
            var registry = new FubuRegistry(x => x.HtmlConvention<DefaultHtmlConventions>());
            var container = new Container(x => x.For<IFubuRequest>().Singleton());
            var facility = new StructureMapContainerFacility(container);

            new FubuBootstrapper(facility, registry).Bootstrap(new List<RouteBase>());
            Model = new Address
            {
                Address1 = "123 Main St.",
                DateEntered = new DateTime(2010, 5, 25, 11, 30, 0),
                Order = 42
            };
            container.GetInstance<IFubuRequest>().Set(Model);

            Generator = container.GetInstance<TagGenerator<Address>>();
            Generator.Model = Model;
            Tag = createTag();
        }
示例#29
0
        public static HtmlTag Label <TModel>(this HtmlHelper <TModel> helper, Expression <Func <TModel, object> > expression)
        {
            var tag = new TagGenerator(HtmlConventionFactory.HtmlConventions);

            return(tag.GenerateLabelFor(helper.ViewContext, expression));
        }
        public void Setup()
        {
            var registry = new FubuRegistry(x =>
            {

                x.HtmlConvention<DefaultHtmlConventions>();
            });
            var container = new Container(x => x.For<IFubuRequest>().Singleton());

            FubuApplication.For(registry).StructureMap(container).Bootstrap();

            Model = new Address
            {
                Address1 = "123 Main St.",
                DateEntered = new DateTime(2010, 5, 25, 11, 30, 0),
                Order = 42
            };
            container.GetInstance<IFubuRequest>().Set(Model);

            Generator = container.GetInstance<TagGenerator<Address>>();
            Generator.Model = Model;
            Tag = createTag();
        }
示例#31
0
 public Markdown()
 {
     stackedTags  = new Stack <MarkdownTag>();
     replacements = new List <MarkdownTag>();
     tagGenerator = new TagGenerator();
 }