Beispiel #1
0
        private FileInfo GetFileInfo(Uri requestUrl)
        {
            var requestPath = requestUrl.LocalPath;

            if (!requestPath.StartsWith(localPath))
            {
                return(null);
            }

            var path     = requestPath.Substring(localPath.Length);
            var fullpath = Path.GetFullPath(Path.Combine(root, path));

            //Don't hack me!
            if (!fullpath.StartsWith(root))
            {
                return(null);
            }

            var fileInfo = new FileInfo(fullpath);

            if (fullpath == root || !fileInfo.Exists)
            {
                var filepath = DefaultFiles.Select(filename => Path.Combine(root, filename)).FirstOrDefault(File.Exists);
                if (filepath != null)
                {
                    fileInfo = new FileInfo(filepath);
                }
            }
            return(!fileInfo.Exists ? null : fileInfo);
        }
Beispiel #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseCors("CorsPolicy");
            if (env.IsDevelopment()) //Is Development mode
            {
                Swagger.StartUpSwaggerConfigure(app);
                app.UseDeveloperExceptionPage();
            }
            else if (env.IsProduction()) //Is Production mode
            {
                app.UseHsts();
            }
            else if (env.IsStaging()) //Is Staging mode
            {
                app.UseHsts();
            }
            app.UseAuthentication();


            DefaultFiles.DefaultFilesConfigure(app, env);
            SignalRMapHub.SignalRMapHubConfigure(app);

            app.UseHttpsRedirection();
            app.UseMvc();
        }
Beispiel #3
0
        public void Execution_Unpack()
        {
            // ARRANGE
            var xml = new XmlDocument();

            //manifests.Add(@"Q:\WebApp1\Admin\Package1\manifest.xml", xml);
            xml.LoadXml(@"<Package type='Product' level='Tool'>
  <Name>Sense/Net ECM</Name>
  <ReleaseDate>2016-12-21</ReleaseDate>
  <Description>|package description|</Description>
  <Steps>
    <Trace>Original message</Trace>
  </Steps>
</Package>");

            var files = DefaultFiles.ToList();

            files.Add(@"Q:\WebApp1\Admin\Package1.zip");
            var manifests = DefaultManifests.ToDictionary(x => x.Key, x => x.Value);

            manifests.Add(@"Q:\WebApp1\Admin\Package1.zip\manifest.xml", xml);

            var disk = new TestDisk(DefaultDirs, files, manifests);

            Disk.Instance = disk;
            var activator = new TestActivator(1);

            ProcessActivator.Instance = activator;
            var unpacker = new TestUnpacker();

            Unpacker.Instance = unpacker;
            var args    = new[] { "Package1", "LOGLEVEL:Console" };
            var console = new StringWriter();

            SnAdmin.Output = console;

            // ACT
            var result = SnAdmin.Main(args);

            // ASSERT
            var consoleText = console.GetStringBuilder().ToString();

            Assert.AreEqual(0, result);

            Assert.IsTrue(disk.Manifests.ContainsKey(@"Q:\WebApp1\Admin\Package1\manifest.xml"));
            Assert.IsTrue(consoleText.Contains("Extracting ..."));

            Assert.AreEqual(1, activator.ExePaths.Count);
            Assert.AreEqual(1, activator.Args.Count);
            Assert.IsTrue(activator.Args[0].Contains("Package1"));
            Assert.IsTrue(activator.Args[0].Contains("PHASE:0"));
        }
        /// <summary>
        /// Loads and fixes up configuration values from the configuraton.
        /// </summary>
        /// <remarks>
        /// Note we're custom loading this to allow for not overly string command line syntax
        /// </remarks>
        /// <param name="Configuration">.NET Core Configuration Provider</param>
        public bool LoadFromConfiguration(IConfiguration Configuration)
        {
            Current = this;

            WebRoot = Configuration["WebRoot"];
            if (string.IsNullOrEmpty(WebRoot))
            {
                // if not set but the first arg does not start with the - it's the folder
                var args = Environment.GetCommandLineArgs();
                if (args.Length > 1 && !args[1].StartsWith("-"))
                {
                    WebRoot = args[1];
                }
            }
            if (string.IsNullOrEmpty(WebRoot))
            {
                WebRoot = Environment.CurrentDirectory;
            }
            else
            {
                var expandedPath = FileUtils.ExpandPathEnvironmentVariables(WebRoot);
                WebRoot = Path.GetFullPath(expandedPath, Environment.CurrentDirectory);
            }

            Port         = Helpers.GetIntegerSetting("Port", Configuration, Port);
            UseSsl       = Helpers.GetLogicalSetting("UseSsl", Configuration, UseSsl);
            Host         = Helpers.GetStringSetting("Host", Configuration, Host);
            DefaultFiles = Helpers.GetStringSetting("DefaultFiles", Configuration, DefaultFiles);
            Extensions   = Helpers.GetStringSetting("Extensions", Configuration, Extensions);

            UseLiveReload = Helpers.GetLogicalSetting("UseLiveReload", Configuration, UseLiveReload);
            UseRazor      = Helpers.GetLogicalSetting("UseRazor", Configuration);
            ShowUrls      = Helpers.GetLogicalSetting("ShowUrls", Configuration, ShowUrls);

            OpenBrowser         = Helpers.GetLogicalSetting("OpenBrowser", Configuration, OpenBrowser);
            OpenEditor          = Helpers.GetLogicalSetting("OpenEditor", Configuration, OpenEditor);
            EditorLaunchCommand = Helpers.GetStringSetting("EditorLaunchCommand", Configuration, EditorLaunchCommand);


            DetailedErrors = Helpers.GetLogicalSetting("DetailedErrors", Configuration, DetailedErrors);

            FolderNotFoundFallbackPath = Helpers.GetStringSetting("FolderNotFoundFallbackPath", Configuration, null);

            // Enables Markdown Middleware and optionally copies Markdown Templates into output folder
            UseMarkdown = Helpers.GetLogicalSetting("UseMarkdown", Configuration, false);
            if (UseMarkdown)
            {
                // defaults to true but only if Markdown is enabled!
                CopyMarkdownResources = Helpers.GetLogicalSetting("CopyMarkdownResources", Configuration, CopyMarkdownResources);
            }
            MarkdownTemplate    = Helpers.GetStringSetting("MarkdownTemplate", Configuration, MarkdownTemplate);
            MarkdownTheme       = Helpers.GetStringSetting("MarkdownTheme", Configuration, MarkdownTheme);
            MarkdownSyntaxTheme = Helpers.GetStringSetting("MarkdownSyntaxTheme", Configuration, MarkdownSyntaxTheme);


            // Fix ups
            if (Extensions is null)
            {
                Extensions = string.Empty;
            }

            if (UseMarkdown)
            {
                if (!Extensions.Contains(".md"))
                {
                    Extensions += ",.md";
                }
                if (!Extensions.Contains(".markdown"))
                {
                    Extensions += ",.markdown";
                }

                if (!DefaultFiles.Contains(".md"))
                {
                    DefaultFiles = DefaultFiles.Trim(',') + ",README.md,index.md";
                }
            }

            return(true);
        }
Beispiel #5
0
        static void SetDefaultFile(ScriptExecutionContext executionContext, DefaultFiles file, FileUserDataBase fileHandle)
        {
            Table R = executionContext.GetScript().Registry;

            R.Set("853BEAAF298648839E2C99D005E1DF94_" + file.ToString(), UserData.Create(fileHandle));
        }
Beispiel #6
0
        static FileUserDataBase GetDefaultFile(ScriptExecutionContext executionContext, DefaultFiles file)
        {
            Table R = executionContext.GetScript().Registry;

            DynValue ff = R.Get("853BEAAF298648839E2C99D005E1DF94_" + file.ToString());

            if (ff.IsNil())
            {
                switch (file)
                {
                case DefaultFiles.In:
                    return(stdin);

                case DefaultFiles.Out:
                    return(stdout);

                case DefaultFiles.Err:
                    return(stderr);

                default:
                    throw new InternalErrorException("DefaultFiles value defaulted");
                }
            }
            else
            {
                return(ff.CheckUserDataType <FileUserDataBase>("getdefaultfile(" + file.ToString() + ")"));
            }
        }
Beispiel #7
0
        private static DynValue HandleDefaultStreamSetter(ScriptExecutionContext executionContext, CallbackArguments args, DefaultFiles defaultFiles)
        {
            if (args.Count == 0 || args[0].IsNil())
            {
                var file = GetDefaultFile(executionContext, defaultFiles);
                return(UserData.Create(file));
            }

            FileUserDataBase inp = null;

            if (args[0].Type == DataType.String || args[0].Type == DataType.Number)
            {
                string fileName = args[0].CastToString();
                inp = Open(fileName, GetUTF8Encoding(), defaultFiles == DefaultFiles.In ? "r" : "w");
            }
            else
            {
                inp = args.AsUserData <FileUserDataBase>(0, defaultFiles == DefaultFiles.In ? "input" : "output", false);
            }

            SetDefaultFile(executionContext, defaultFiles, inp);

            return(UserData.Create(inp));
        }