Exemplo n.º 1
0
        public void StartTutorial()
        {
            // load language from a YAML file.
            new YamlWatcher(_language, "..\\..\\tutorial5\\language.yaml"); // "..\\..\\" since we run the tutorial in vstudio
            Validator.Language = _language.GetChild("Validator") ?? LanguageNode.Empty;

            // since we do not use files on disk, we'll just add the resource template loader.
            ResourceTemplateLoader templateLoader = new ResourceTemplateLoader();

            templateLoader.LoadTemplates("/", Assembly.GetExecutingAssembly(), "Tutorial.Tutorial5.views");
            TemplateManager templateManager = new TemplateManager(templateLoader);

            templateManager.AddType(typeof(WebHelper));
            templateManager.Add("haml", new HamlGenerator());


            // we've just one controller. Add it.
            ControllerModule controllerModule = new ControllerModule();

            controllerModule.Add(new UserController(templateManager, _language));
            _server.Add(controllerModule);

            // add file module, to be able to handle files
            ResourceFileModule fileModule = new ResourceFileModule();

            fileModule.AddResources("/", Assembly.GetExecutingAssembly(), "Tutorial.Tutorial5.public");
            _server.Add(fileModule);

            // ok. We should be done. Start the server.
            _server.Start(IPAddress.Any, 8081);

            Console.WriteLine("Tutorial 5 is running. Go to http://localhost:8081/user/");
            Console.WriteLine("Try to add '?lcid=1053' and '?lcid=1033' to address to switch language (i.e: http://localhost:8081/user/?lcid=1053).");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Template generators are used to render templates
            // (convert code + html to pure html).
            TemplateManager mgr = new TemplateManager();

            mgr.Add("haml", new HamlGenerator());

            // The httpserver is quite dumb and will only serve http, nothing else.
            HttpServer server = new HttpServer();

            // a controller mode implements a MVC pattern
            // You'll add all controllers to the same module.
            ControllerModule mod = new ControllerModule();

            mod.Add(new UserController(mgr));
            server.Add(mod);

            // file module will be handling files
            FileModule fh = new FileModule("/", Environment.CurrentDirectory);

            fh.AddDefaultMimeTypes();
            server.Add(fh);

            // Let's start pure HTTP, we can also start a HTTPS listener.
            server.Start(IPAddress.Any, 8081);

            Console.ReadLine();
        }
        public ActionResult Add(AddTemplateViewModel addTemplateViewModel)
        {
            addTemplateViewModel.PageId = "Template";
            if (addTemplateViewModel.fileUpload != null && addTemplateViewModel.fileUpload.ContentLength > 0)
            {
                if (addTemplateViewModel.fileUpload.FileName.Split('.')[1] != "docx")
                {
                    ModelState.AddModelError("error", "فرمت فایل قالب باید ورد باشد.");
                    return(View(addTemplateViewModel));
                }

                //addTemplateViewModel.template.File = new ArchiveFile();
                //Get Content of image
                MemoryStream target = new MemoryStream();
                addTemplateViewModel.fileUpload.InputStream.CopyTo(target);
                addTemplateViewModel.template.File.Content = target.ToArray();
                //addTemplateViewModel.template.File.Name = addTemplateViewModel.fileUpload.FileName;
                addTemplateViewModel.template.File.ContentType = addTemplateViewModel.fileUpload.ContentType;
            }
            else
            {
                ModelState.AddModelError("error", "فایل قالب وارد نشده است.");
                return(View(addTemplateViewModel));
            }

            TemplateManager templateManager = new TemplateManager();

            templateManager.Add(addTemplateViewModel.template);
            templateManager.saveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public HamlTest()
 {
     _mgr.Add("haml", _generator);
 }
Exemplo n.º 5
0
        public int AddTemplate(TemplateEntity templateEntity)
        {
            TemplateManager mgr = new TemplateManager();

            return(mgr.Add(templateEntity));
        }