Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        private void RemoveFile(string path)
        {
            string file = PathMapper.MapPath(path);

            if (file != null)
            {
                File.Delete(file);
            }
        }
Ejemplo n.º 4
0
        public Registration(Asset asset)
        {
            this.Asset = asset;
            string path = PathMapper.MapPath(Configs.AssetsDirectory);

            this.AssetDirectory = path;

            this.EnsureDirectoryExists(path);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private void CleanupTenantDirectory()
        {
            string pathToTenant = PathMapper.MapPath($"/Tenants/{this.Tenant}");

            if (Directory.Exists(pathToTenant))
            {
                Directory.Delete(pathToTenant, true);
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        private void CleanupTenantDirectory()
        {
            string pathToTenant = PathMapper.MapPath($"/Tenants/{this.Tenant}");

            if (Directory.Exists(pathToTenant))
            {
                FileHelper.DeleteDirectoryRecursively(pathToTenant);
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        protected string GetContent(string fileName)
        {
            string pathToFile = PathMapper.MapPath(fileName);

            if (File.Exists(pathToFile))
            {
                return(File.ReadAllText(pathToFile, Encoding.UTF8));
            }

            return(string.Empty);
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
            }
        }
Ejemplo n.º 19
0
        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)..];
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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));
        }
Ejemplo n.º 22
0
        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));
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 25
0
        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));
        }
Ejemplo n.º 26
0
        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));
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
        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());
        }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
0
        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;
 }