public void GetTouchedCellsTest(float givenX, float givenY, int expetedCount) { var cells = PathMapper.GetTouchedCells(new GpsCoordinate() { x = givenX, y = givenY, z = 10 }, 10.0f); Assert.AreEqual(expetedCount, cells.Count); }
public static void Upload(string tenant, Guid contactId, HttpPostedFileBase file) { if (file == null) { throw new AttachmentException(Resources.NoFileWasUploaded); } string path = $"/Tenants/{tenant}/Areas/Frapid.AddressBook/avatars"; path = PathMapper.MapPath(path); if (path == null) { Log.Warning("Could not upload resource because the path to avatar directory is illegal."); throw new AttachmentException("CouldNotFindAvatarDirectory"); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileName = Path.GetFileName(file.FileName); if (fileName == null) { Log.Warning("Could not upload resource because the posted avatar file name is null or invalid."); throw new AttachmentException("Resources.InvalidFileName"); } var allowed = FrapidConfig.GetAllowedUploadExtensions(tenant); string extension = Path.GetExtension(fileName); if (!allowed.Contains(extension)) { Log.Warning("Could not upload avatar resource because the uploaded file {file} has invalid extension.", fileName); throw new AttachmentException("Resources.AccessIsDenied"); } var dir = new DirectoryInfo(path); foreach ( var f in dir.GetFiles().Where(f => Path.GetFileNameWithoutExtension(f.Name).Equals(contactId.ToString()))) { f.Delete(); } var stream = file.InputStream; path = Path.Combine(path, contactId + extension); using (var fileStream = File.Create(path)) { stream.CopyTo(fileStream); } }
private void RemoveFile(string path) { string file = PathMapper.MapPath(path); if (file != null) { File.Delete(file); } }
public Registration(Asset asset) { this.Asset = asset; string path = PathMapper.MapPath(Configs.AssetsDirectory); this.AssetDirectory = path; this.EnsureDirectoryExists(path); }
public void PathMapper_MapPathUsingCustomPattern() { var record = new CustomTestRecord(TestContext); var sut = new PathMapper(record.Expression, record.Replacement); var output = sut.MapPath(record.Input); Assert.AreEqual(record.Expected, output, "Unexpected output for expression '{0}' and replacement '{1}' on input '{2}'", record.Expression, record.Replacement, record.Input); }
public Deserializer(string tenant, AreaRegistration area, int width, int height, string path) { this.Tenant = tenant; this.Width = width; this.Height = height; this.Path = path; this.ImagePath = PathMapper.MapPath($"/Tenants/{tenant}/Areas/{area.AreaName}/attachments/" + path); }
private void CleanupTenantDirectory() { string pathToTenant = PathMapper.MapPath($"/Tenants/{this.Tenant}"); if (Directory.Exists(pathToTenant)) { Directory.Delete(pathToTenant, true); } }
private static PathMapper Init(string input) { PathMapper.ResetInstance(); var pathMapper = input.Contains('\\') ? new PathMapper(@"C:\o", @"C:\o\e\f") : new PathMapper("/o", "/o/e/f"); return(pathMapper); }
private void CleanupTenantDirectory() { string pathToTenant = PathMapper.MapPath($"/Tenants/{this.Tenant}"); if (Directory.Exists(pathToTenant)) { FileHelper.DeleteDirectoryRecursively(pathToTenant); } }
public void PathMapper_MapPathUsingDefaultPattern() { var record = new DefaultTestRecord(TestContext); var sut = new PathMapper(null, record.Replacement); var output = sut.MapPath(record.Input); Assert.AreEqual(record.Expected, output, "Unexpected output for replacement '{0}' on input '{1}'", record.Replacement, record.Input); }
public async Task SanitiseCache() { IList <string> stale = new List <string>(); bool hasStale = false; foreach (var url in Urls) { var file = PathMapper.PathForUrl(url, false); if (!File.Exists(file)) { stale.Add(url); } } foreach (var url in stale) { Urls.Remove(url); Removed?.Invoke(url, new EventArgs()); hasStale = true; } if (hasStale) { FlushUrls(); } foreach (var url in Urls) { var localUrl = RemovePortFromUrl(url); var file = PathMapper.PathForUrl(localUrl, false); if (!File.Exists(file)) { continue; } var lastModified = File.GetLastWriteTime(file); SpeedWagonContent content; bool inCache = this._customCache.TryGetValue(localUrl, out content); if (inCache) { if (content.CacheTime != null && DateTime.Compare(content.CacheTime.Value, lastModified) < 0) { content = await base.GetContent(localUrl); PlaceInCache(localUrl, content); } } } }
public void CellByPointTest(float givenX, float givenY, float expectedX, float expectedY) { var cell = PathMapper.GetCellByPoint(new GpsCoordinate() { x = givenX, y = givenY, z = 10 }); Assert.AreEqual(expectedX, cell.x); Assert.AreEqual(expectedY, cell.y); }
public static int GetPageSize(string tenant) { string configFile = PathMapper.MapPath($"~/Tenants/{tenant}/Configs/Frapid.config"); int pageSize = !File.Exists(configFile) ? 0 : ConfigurationManager.ReadConfigurationValue(configFile, "WebApiPageSize").To <int>(); pageSize = pageSize == 0 ? 10 : pageSize; pageSize = pageSize > 100 ? 100 : pageSize; return(pageSize); }
public string Generate(Report report) { if (!report.HasHeader) { return(string.Empty); } string pathToHeader = PathMapper.MapPath("~/Reports/Assets/Header.html"); return(File.ReadAllText(pathToHeader, Encoding.UTF8)); }
protected string GetContent(string fileName) { string pathToFile = PathMapper.MapPath(fileName); if (File.Exists(pathToFile)) { return(File.ReadAllText(pathToFile, Encoding.UTF8)); } return(string.Empty); }
public static void WriteHtml(string path, string html) { var destination = new FileInfo(PathMapper.MapPath(path)); if (!destination.Directory.Exists) { destination.Directory.Create(); } File.WriteAllText(destination.FullName, html, new UTF8Encoding(false)); }
private static string GetVersionFile(string tenant, string schema) { string versionFile = VersionFile.Replace("{tenant}", tenant).Replace("{schema}", schema); var file = new FileInfo(PathMapper.MapPath(versionFile)); if (!file.Directory.Exists) { file.Directory.Create(); } return(file.FullName); }
public void AddTenantDataToBackup() { string source = PathMapper.MapPath($"/Tenants/{this.Tenant}"); string destination = Path.Combine(this.BackupPath, this.FileName); this.BackupDirectory = destination; if (source != null) { FileSystem.CopyDirectory(source, destination); } }
private void PrepareNewBuild(string projectName, string action = "build") { // keep as a separate method so we cn make sure to register the msbuild assemblies first. PathMapper.ResetInstance(); Directory.SetCurrentDirectory(_execRoot); var lastProject = _context?.ProjectFile; var configId = typeof(BuildManager).GetField("s_nextBuildRequestConfigurationId", BindingFlags.Static | BindingFlags.NonPublic); configId !.SetValue(null, 0); if (Path.IsPathRooted(projectName)) { projectName = projectName[(_execRoot.Length + 1)..];
public static string GetUploadDirectory(string tenant) { string path = $"/Tenants/{tenant}/Areas/MixERP.Social/uploads/"; path = PathMapper.MapPath(path); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return(path); }
public static string GetNotificationEmailTemplate(string tenant) { string file = $"/Tenants/{tenant}/Areas/Frapid.Calendar/Templates/Email.html"; file = PathMapper.MapPath(file); if (!File.Exists(file)) { return(string.Empty); } return(File.ReadAllText(file, Encoding.UTF8)); }
public static string Get(string tenant, string key) { string configurationFile = $"/Tenants/{tenant}/Configs/Calendar.config"; configurationFile = PathMapper.MapPath(configurationFile); if (!File.Exists(configurationFile)) { return(string.Empty); } return(ConfigurationManager.ReadConfigurationValue(configurationFile, key)); }
public static void DeleteMy(string tenant, MyWidgetInfo info) { string container = PathMapper.MapPath($"{WidgetLocation.Replace("{tenant}", tenant)}/{info.Scope}/{info.Me}"); string filePath = Path.Combine(container, SanitizePath(info.Name) + ".json"); if (!File.Exists(filePath)) { return; } File.Delete(filePath); }
public static Asset FindByName(string name) { string assetsDirectory = PathMapper.MapPath(Configs.AssetsDirectory); string path = Path.Combine(assetsDirectory, name + ".json"); if (!File.Exists(path)) { return(null); } string contents = File.ReadAllText(path, Encoding.UTF8); return(JsonConvert.DeserializeObject <Asset>(contents)); }
public static FileManagerResource GetFiles(string tenant, string module) { string path = $"/Areas/{module}/Reports/"; path = PathMapper.MapPath(path).Replace("/", "\\"); if (!Directory.Exists(path)) { throw new ReportBrowserException($"Cannot find the module {module}."); } return(Discover(path, module)); }
public static Config Get(string tenant) { string path = ConfigFile.Replace("{tenant}", tenant); path = PathMapper.MapPath(path); if (!File.Exists(path)) { return(new Config()); } string contents = File.ReadAllText(path, Encoding.UTF8); return(string.IsNullOrWhiteSpace(contents) ? new Config() : JsonConvert.DeserializeObject <Config>(contents)); }
public void GetPathFragmentsFromTargetPathTest() { var mapper = new PathMapper(@"C:\dir1\dir2", @"D:\dir3\dir4"); var result = mapper.GetPathFragmentsFromTargetPath(@"D:\dir3\dir4\dir5\dir6\file1.txt"); Assert.Equal(new[] { @"D:\dir3\dir4\dir5", @"D:\dir3\dir4\dir5\dir6", @"D:\dir3\dir4\dir5\dir6\file1.txt", }, result); }
public static MessagingConfig Get(string tenant) { string path = $"/Tenants/{tenant}/Configs/Smtp.json"; path = PathMapper.MapPath(path); if (path != null && File.Exists(path)) { string contents = File.ReadAllText(path, Encoding.UTF8); return(JsonConvert.DeserializeObject <MessagingConfig>(contents)); } return(new MessagingConfig()); }
public void GetTouchedCellsNegativeValueTest() { var cells = PathMapper.GetTouchedCells(new GpsCoordinate() { x = -205, y = -295, z = 10 }, 10.0f); Assert.AreEqual(3, cells.Count); Assert.AreEqual(-300, cells[0].x); Assert.AreEqual(-300, cells[0].y); Assert.AreEqual(-300, cells[1].x); Assert.AreEqual(-400, cells[1].y); Assert.AreEqual(-200, cells[2].x); Assert.AreEqual(-300, cells[2].y); }
public string Generate(string tenant, Report report) { if (!report.HasHeader) { return(string.Empty); } string pathToHeader = PathMapper.MapPath($"~/Tenants/{tenant}/Areas/Frapid.Reports/Assets/Header.html"); if (!File.Exists(pathToHeader)) { pathToHeader = PathMapper.MapPath("~/Reports/Assets/Header.html"); } return(File.ReadAllText(pathToHeader, Encoding.UTF8)); }
protected override void BeginProcessing() { mapper = new PathMapper(Expression, Replacement); base.BeginProcessing(); }
protected override void EndProcessing() { mapper = null; }