示例#1
0
        public void Check()
        {
            ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition();
            Evidence e = null;

            Assert.IsFalse(ad.Check(e), "Check (null)");
            e = new Evidence();
            Assert.IsFalse(ad.Check(e), "Check (empty)");
            e.AddHost(new Zone(SecurityZone.MyComputer));
            Assert.IsFalse(ad.Check(e), "Check (zone)");

            string codebase           = Assembly.GetExecutingAssembly().CodeBase;
            Url    u                  = new Url(codebase);
            ApplicationDirectory adir = new ApplicationDirectory(codebase);

            e.AddHost(u);
            Assert.IsFalse(ad.Check(e), "Check (url-host)");               // not enough
            e.AddAssembly(adir);
            Assert.IsFalse(ad.Check(e), "Check (url-host+adir-assembly)");

            e = new Evidence();
            e.AddHost(adir);
            Assert.IsFalse(ad.Check(e), "Check (adir-host)");               // not enough
            e.AddAssembly(u);
            Assert.IsFalse(ad.Check(e), "Check (url-assembly+adir-host)");

            e = new Evidence();
            e.AddHost(u);
            e.AddHost(adir);
            Assert.IsTrue(ad.Check(e), "Check (url+adir host)");               // both!!
        }
        protected string CreateArchive(RunningDeployment deployment, PackageMetadata packageMetadata)
        {
            var applicationDirectory = ApplicationDirectory.GetApplicationDirectory(
                packageMetadata,
                deployment.Variables,
                fileSystem);

            var customPackageFileName = deployment.Variables.Get(SpecialVariables.Package.CustomPackageFileName);

            if (!string.IsNullOrWhiteSpace(customPackageFileName))
            {
                Log.Verbose($"Using custom package file-name: '{customPackageFileName}'");
            }

            var targetFileName = !string.IsNullOrWhiteSpace(customPackageFileName)
                ? customPackageFileName
                : $"{packageMetadata.Id}.{packageMetadata.Version}{packageMetadata.FileExtension}";

            var targetFilePath = Path.Combine(applicationDirectory, targetFileName);

            var stagingDirectory = deployment.CurrentDirectory;

            jarTool.CreateJar(stagingDirectory, targetFilePath);
            Log.Info($"Re-packaging archive: '{targetFilePath}'");

            return(targetFilePath);
        }
        protected override void Seed(UserDataContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            UserProfileEntity profile = new UserProfileEntity()
            {
                Username        = "******",
                Organization    = "BIT",
                UserGroup       = UserGroup.Administrators,
                ProfileFileName = ApplicationDirectory.GetAppSubDirectory("Users") + "\\Lancern",
            };

            using (SHA512 hash = SHA512.Create())
            {
                profile.PasswordHash = hash.ComputeHash(Encoding.Unicode.GetBytes("Lancern"));
            }

            context.UserProfiles.AddOrUpdate(profile);
        }
示例#4
0
        public RemoteApplication(ApplicationDirectory applicationDirectory)
        {
            lock (_thisLock)
            {
                _applicationDirectory = applicationDirectory;

                if (_applicationDirectory.CertificateFile != null)
                {
                    string filename = _applicationDirectory.CertificateFile;
                    if (!(filename.StartsWith(@"\") || (filename.Length > 2 && filename.Substring(1, 2) == @":\")))
                    {
                        filename = HttpContext.Current.Server.MapPath(filename);
                    }

                    _certificate = new X509Certificate(filename);
                }

                TraceScope.Current.TraceData(TraceEventType.Start, (int)Event.CreateRemoteApplication,
                                             String.Format("RemoteApplication created for RootUrl={0}",
                                                           _applicationDirectory.FullTargetPath));
                _httpAppicationRootLength = HttpContext.Current.Request.ApplicationPath.Length;

                _pvpInformationHandling = applicationDirectory.PvpInformationHandling;
                _logTraffic             = applicationDirectory.LogTraffic;
                _isolateCookies         = applicationDirectory.IsolateCookies;
            }
        }
示例#5
0
        public void RightSideUrl()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PathMap));
            PathMap       mapping    = (PathMap)serializer.Deserialize(
                new System.IO.StreamReader(
                    @"MappingTest\Mapping.xml"));

            Directory dir1 = mapping.GetDirectory("/zmrsoap");

            Assert.IsNotNull(dir1, "dir1 not found.");
            Assert.AreEqual("zmrsoap", dir1.Name);
            Assert.AreEqual(
                "https://portals-test.bmi.gv.at/bmi.gv.at/soapv2/soaphttpengine/soapv2%23pvp1?dest=ZMR&opzone=test",
                dir1.GetFullTargetPath("/zmrsoap/"));

            ApplicationDirectory appStatistik = mapping.GetApplication("/statistik.at/vis.test.extern/");

            Assert.IsNotNull(appStatistik, "appStatistik not found.");
            Assert.AreEqual("vis.test.extern", appStatistik.Name);
            Assert.AreEqual("https://awp.statistik.at/statistik.at/vis.test.extern/", appStatistik.RootUrl);
            Assert.AreEqual("https://awp.statistik.at/statistik.at/vis.test.extern/einFile.txt",
                            appStatistik.GetFullTargetPath("/statistik.at/vis.test.extern/einFile.txt"));

            ApplicationDirectory withPort = mapping.GetApplication("/withport/");

            Assert.IsNotNull(withPort, "withport not found.");
            Assert.AreEqual("https://egora:8443/test", withPort.FullTargetPath);
            Assert.AreEqual("https://egora:8443/test/hello.htm", withPort.GetFullTargetPath("/withport/hello.htm"));

            ApplicationDirectory defaultApp = mapping.GetApplication("/someunknownurl/");

            Assert.IsNotNull(defaultApp, "defaultApp not found.");
            Assert.AreEqual(string.Empty, defaultApp.Name);
        }
示例#6
0
        public static RemoteApplication GetRemoteApplication(HttpRequest leftSideRequest)
        {
            string path = leftSideRequest.Path.Substring(leftSideRequest.ApplicationPath.Length);

            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }

            ApplicationDirectory appDir = s_map.GetApplication(path);

            if (appDir != null)
            {
                RemoteApplication app;
                lock (s_remoteApplications)
                {
                    if (s_remoteApplications.ContainsKey(appDir))
                    {
                        app = s_remoteApplications[appDir];
                    }
                    else
                    {
                        app = new RemoteApplication(appDir);
                        s_remoteApplications.Add(appDir, app);
                    }
                }
                TraceScope.Current.TraceEvent(TraceEventType.Verbose, (int)Event.AssociateApplication,
                                              "Found RemoteApplication {0} for path {1}.", app.RootUrl, path);
                return(app);
            }
            return(null);
        }
示例#7
0
 private static void ConfigureAndStartLogging()
 {
     Log.Logger = new LoggerConfiguration()
                  .WriteTo.File(ApplicationDirectory.CreateAbsolutePath("log.txt"))
                  .WriteTo.ApplicationLog()
                  .CreateLogger();
 }
        protected string CreateArchive(RunningDeployment deployment)
        {
            var packageMetadata      = PackageName.FromFile(deployment.PackageFilePath);
            var applicationDirectory = ApplicationDirectory.GetApplicationDirectory(
                packageMetadata,
                deployment.Variables,
                fileSystem);

            var customPackageFileName = deployment.Variables.Get(PackageVariables.CustomPackageFileName);

            if (!string.IsNullOrWhiteSpace(customPackageFileName))
            {
                Log.Verbose($"Using custom package file-name: '{customPackageFileName}'");
            }

            var targetFilePath = Path.Combine(applicationDirectory, customPackageFileName ?? Path.GetFileName(deployment.PackageFilePath));

            var stagingDirectory = deployment.CurrentDirectory;

            var enableCompression = deployment.Variables.GetFlag(PackageVariables.JavaArchiveCompression, true);

            jarTool.CreateJar(stagingDirectory, targetFilePath, enableCompression);
            log.Info($"Re-packaging archive: '{targetFilePath}'");

            return(targetFilePath);
        }
示例#9
0
        public void ExtractToApplicationDirectory(PathToPackage pathToPackage, IPackageExtractor customPackageExtractor = null)
        {
            var metadata   = PackageName.FromFile(pathToPackage);
            var targetPath = ApplicationDirectory.GetApplicationDirectory(metadata, variables, fileSystem);

            Extract(pathToPackage, targetPath, customPackageExtractor);
        }
示例#10
0
 public static void ApplicationDirectoryCallMethods()
 {
     ApplicationDirectory ad = new ApplicationDirectory("test");
     object obj   = ad.Copy();
     bool   check = ad.Equals(new object());
     int    hash  = ad.GetHashCode();
     string str   = ad.ToString();
 }
示例#11
0
        public void ToString_()
        {
            ApplicationDirectory ad = new ApplicationDirectory("file://MONO");
            string ts = ad.ToString();

            Assert.IsTrue(ts.StartsWith("<System.Security.Policy.ApplicationDirectory"), "Tag");
            Assert.IsTrue(ts.IndexOf("version=\"1\"") > 0, "Directory");
            Assert.IsTrue(ts.IndexOf("<Directory>file://MONO</Directory>") > 0, "Directory");
        }
示例#12
0
        public void ApplicationDirectory_String()
        {
            ApplicationDirectory ad = new ApplicationDirectory("mono");

#if NET_2_0
            Assert.AreEqual("mono", ad.Directory, "Directory");
#else
            Assert.AreEqual("file://MONO", ad.Directory, "Directory");
#endif
        }
        public void ApplicationDirectory_GetRequiredSize()
        {
            ApplicationDirectory ad = new ApplicationDirectory("file://MONO");

            Assert.AreEqual(14, GetRequiredSize(ad, true), "GetRequiredSize-true");
            Assert.AreEqual(12, GetRequiredSize(ad, false), "GetRequiredSize-false");
            ad = new ApplicationDirectory("file://NOVELL/mono");
            Assert.AreEqual(21, GetRequiredSize(ad, true), "GetRequiredSize-true-2");
            Assert.AreEqual(19, GetRequiredSize(ad, false), "GetRequiredSize-false-2");
        }
示例#14
0
        public void Copy()
        {
            ApplicationDirectory ad = new ApplicationDirectory("novell");

            Assert.AreEqual("novell", ad.Directory, "Directory");
            ApplicationDirectory copy = (ApplicationDirectory)ad.Copy();

            Assert.IsTrue(ad.Equals(copy), "ad.Equals(copy)");
            Assert.IsTrue(copy.Equals(ad), "copy.Equals(ad)");
            Assert.IsFalse(Object.ReferenceEquals(ad, copy), "Copy");
            Assert.AreEqual(ad.GetHashCode(), copy.GetHashCode(), "GetHashCode");
            Assert.AreEqual(ad.ToString(), copy.ToString(), "ToString");
        }
示例#15
0
        // Determine if two objects are equal.
        public override bool Equals(Object obj)
        {
            ApplicationDirectory other = (obj as ApplicationDirectory);

            if (other != null)
            {
                return(other.parser.URL == parser.URL);
            }
            else
            {
                return(false);
            }
        }
示例#16
0
        public void GetHashCode_()
        {
            string linux             = "/unix/path/mono";
            ApplicationDirectory ad1 = new ApplicationDirectory(linux);

            Assert.AreEqual(linux, ad1.Directory);
            Assert.AreEqual(linux.GetHashCode(), ad1.GetHashCode(), "GetHashCode-Linux");

            string windows           = "\\windows\\path\\mono";
            ApplicationDirectory ad2 = new ApplicationDirectory(windows);

            Assert.AreEqual(windows, ad2.Directory);
            Assert.AreEqual(windows.GetHashCode(), ad2.GetHashCode(), "GetHashCode-Windows");
        }
示例#17
0
        public void LoadActionPlugins()
        {
            var dir = new DirectoryInfo(Path.Combine(Application.StartupPath, Settings.Default.PluginFolder));

            IEnumerable <FileInfo> dlls = dir.EnumerateFiles(@"*.dll", SearchOption.AllDirectories);

            List <Type> actions = new List <Type>();

            foreach (FileInfo fi in dlls)
            {
                var evidence = new Evidence();
                var appDir   = new ApplicationDirectory(Assembly.GetEntryAssembly().CodeBase);
                evidence.AddAssemblyEvidence(appDir);
                Assembly asm;
                try
                {
                    asm = Assembly.LoadFrom(fi.FullName);
                }
                catch (BadImageFormatException)
                {
                    continue;
                }

                Type[] typesInFile = asm.GetExportedTypes();

                var actionTypes = (from type in typesInFile
                                   where !type.IsAbstract
                                   where type.GetCustomAttributes(typeof(ActionCategoryAttribute), true).Any()
                                   select type);

                List <Type> actionTypeList = actionTypes.ToList();
                if (!actionTypeList.Any())
                {
                    continue;
                }

                this.PluginFiles.Add(fi, actionTypeList);

                var customDataTypes = from type in typesInFile
                                      where !type.IsAbstract
                                      where type.IsAssignableFrom(typeof(ICentipedeDataType))
                                      select type;

                foreach (Type t in customDataTypes)
                {
                    CentipedeSerializer.RegisterSerializableType(t);
                }
            }
        }
示例#18
0
        public void Equals()
        {
            ApplicationDirectory ad1 = new ApplicationDirectory("mono");

            Assert.IsFalse(ad1.Equals(null), "Equals(null)");
            Assert.IsFalse(ad1.Equals(String.Empty), "Equals(String.Empty)");
            Assert.IsFalse(ad1.Equals("mono"), "Equals(mono)");
            Assert.IsTrue(ad1.Equals(ad1), "Equals(self)");
            ApplicationDirectory ad2 = new ApplicationDirectory(ad1.Directory);

            Assert.IsTrue(ad1.Equals(ad2), "Equals(ad2)");
            Assert.IsTrue(ad2.Equals(ad1), "Equals(ad2)");
            ApplicationDirectory ad3 = new ApplicationDirectory("..");

            Assert.IsFalse(ad2.Equals(ad3), "Equals(ad3)");
        }
示例#19
0
        public void ByPassTest()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PathMap));
            PathMap       mapping    = (PathMap)serializer.Deserialize(
                new System.IO.StreamReader(
                    @"MappingTest\Mapping.xml"));

            ApplicationDirectory zmrres = (ApplicationDirectory)mapping.GetDirectory("/zmrres");

            Assert.IsTrue(zmrres.ByPass("someStylesheet.css"));
            Assert.IsTrue(zmrres.ByPass("someStylesheet.css?somQueryPar"));
            Assert.IsFalse(zmrres.ByPass("anUrlwithcsswithin.txt"));
            Assert.IsFalse(zmrres.ByPass("anUrlwith.csswithin.txt"));

            Assert.IsTrue(zmrres.ByPass("(/images/somePicture.png"));
        }
示例#20
0
        public void Equals_Invalid()
        {
            // funny one
            string appdir = Invalid(true);
            // constructor is ok with an invalid path...
            ApplicationDirectory ad = new ApplicationDirectory(appdir);
            // we can copy it...
            ApplicationDirectory copy = (ApplicationDirectory)ad.Copy();

            // we can't get it's hash code
            Assert.AreEqual(appdir.GetHashCode(), ad.GetHashCode(), "GetHashCode");
            // we can convert it to string...
            Assert.IsTrue(ad.ToString().IndexOf(appdir) > 0, "ToString");
            // ... but it throws in Equals - with self!
            Assert.IsTrue(ad.Equals(ad), "Equals(self)");
        }
示例#21
0
        static UserManager()
        {
            ms_default = null;
            ms_lock    = new object();

            // 加载用户信息文件目录信息。
            FileSystemSettingProvider settings = new FileSystemSettingProvider();

            if (settings.Contains(ms_userDirectorySettingName))
            {
                ms_userDirectory = settings.Get <string>(ms_userDirectorySettingName);
            }
            else
            {
                // 加载默认目录名称。
                ms_userDirectory = ApplicationDirectory.GetAppSubDirectory("Users");
            }
        }
示例#22
0
        static ProblemArchieveManager()
        {
            ms_default = null;
            ms_sync    = new object();

            // 初始化本地主题目库根目录。
            FileSystemSettingProvider settings = new FileSystemSettingProvider();

            if (!settings.Contains(ArchieveDiretcorySettingName))
            {
                // 设置集中无根目录设置。设置为默认目录。
                ms_archieveDirectory = ApplicationDirectory.GetAppSubDirectory("ProblemArchieve");
            }
            else
            {
                ms_archieveDirectory = settings.Get <string>(ArchieveDiretcorySettingName);
            }
        }
示例#23
0
        static ContestManager()
        {
            ms_default  = null;
            ms_syncLock = new object();

            // 加载比赛目录信息。
            using (FileSystemSettingProvider settings = new FileSystemSettingProvider())
            {
                if (settings.Contains(ContestDirectorySettingName))
                {
                    ContestDirectory = settings.Get <string>(ContestDirectorySettingName);
                }
                else
                {
                    // 加载默认比赛目录。
                    ContestDirectory = ApplicationDirectory.GetAppSubDirectory("Contests");
                }
            }
        }
示例#24
0
        static SubmissionManager()
        {
            ms_default  = null;
            ms_syncLock = new object();

            // 加载用户提交代码文件目录信息。
            using (FileSystemSettingProvider settings = new FileSystemSettingProvider())
            {
                if (settings.Contains(SubmissionCodeFileDirectorySettingName))
                {
                    SubmissionCodeFilesDirectory = settings.Get <string>(SubmissionCodeFileDirectorySettingName);
                }
                else
                {
                    // 加载默认设置。
                    SubmissionCodeFilesDirectory = ApplicationDirectory.GetAppSubDirectory("Submissions");
                }
            }
        }
示例#25
0
        /// <summary>
        /// Remove every file inside application directory.
        /// </summary>
        protected void ClearApplicationDirectory()
        {
            try
            {
                GRoggle.Write("Try to clear application directory", RoggleLogLevel.Debug);

                foreach (var file in ApplicationDirectory.EnumerateFiles())
                {
                    if (file.Name != ApplicationReleaseFileName)
                    {
                        GRoggle.Write($"Delete {file.Name}", RoggleLogLevel.Debug);

                        file.Delete();
                    }
                }
            }
            catch (Exception e)
            {
                GRoggle.Write("Something goes wrong while clearing application directory", e);
            }
        }
        protected string CreateArchive(RunningDeployment deployment, PackageMetadata packageMetadata)
        {
            var applicationDirectory = ApplicationDirectory.GetApplicationDirectory(
                packageMetadata,
                deployment.Variables,
                fileSystem);

            var customPackageFileName = deployment.Variables.Get(SpecialVariables.Package.CustomPackageFileName);

            if (!string.IsNullOrWhiteSpace(customPackageFileName))
            {
                Log.Verbose($"Using custom package file-name: '{customPackageFileName}'");
            }

            var targetFileName = !string.IsNullOrWhiteSpace(customPackageFileName)
                ? customPackageFileName
                : new StringBuilder()
                                 .Append(packageMetadata.PackageId)

                                 /*
                                  * If this package uses the maven version format, we use the # char as a delimiter between
                                  * the package id and the version. If it is not a maven version, we use the default of
                                  * a period.
                                  */
                                 .Append(packageMetadata.VersionFormat == VersionFormat.Maven ? JavaConstants.MavenFilenameDelimiter : '.')
                                 .Append(packageMetadata.Version)
                                 .Append(packageMetadata.FileExtension)
                                 .ToString();

            var targetFilePath = Path.Combine(applicationDirectory, targetFileName);

            var stagingDirectory = deployment.CurrentDirectory;

            jarTool.CreateJar(stagingDirectory, targetFilePath);
            Log.Info($"Re-packaging archive: '{targetFilePath}'");

            return(targetFilePath);
        }
示例#27
0
        public void GetHashCode_()
        {
            string linux             = "/unix/path/mono";
            ApplicationDirectory ad1 = new ApplicationDirectory(linux);

#if NET_2_0
            Assert.AreEqual(linux, ad1.Directory);
            Assert.AreEqual(linux.GetHashCode(), ad1.GetHashCode(), "GetHashCode-Linux");
#else
            Assert.AreEqual("file://UNIX/PATH/mono", ad1.Directory);
            Assert.AreEqual("file://UNIX/PATH/mono".GetHashCode(), ad1.GetHashCode(), "GetHashCode-Linux");
#endif

            string windows           = "\\windows\\path\\mono";
            ApplicationDirectory ad2 = new ApplicationDirectory(windows);
#if NET_2_0
            Assert.AreEqual(windows, ad2.Directory);
            Assert.AreEqual(windows.GetHashCode(), ad2.GetHashCode(), "GetHashCode-Windows");
#else
            Assert.AreEqual("file://WINDOWS/PATH/mono", ad2.Directory);
            Assert.AreEqual("file://WINDOWS/PATH/mono".GetHashCode(), ad2.GetHashCode(), "GetHashCode-Windows");
#endif
        }
示例#28
0
        public void ApplicationDirectory_FileUrl()
        {
            ApplicationDirectory ad = new ApplicationDirectory("file://MONO");

            Assert.AreEqual("file://MONO", ad.Directory, "Directory");
        }
示例#29
0
        public void ApplicationDirectory_String()
        {
            ApplicationDirectory ad = new ApplicationDirectory("mono");

            Assert.AreEqual("mono", ad.Directory, "Directory");
        }
示例#30
0
        public void ApplicationDirectory_HttpUrl()
        {
            ApplicationDirectory ad = new ApplicationDirectory("http://www.go-mono.com/");

            Assert.AreEqual("http://www.go-mono.com/", ad.Directory, "Directory");
        }