public HttpResponseMessage FileSystem()
        {
            FileSystemCommand command;

            Enum.TryParse(CurrentContext.Request["command"], out command);
            string arguments = CurrentContext.Request["arguments"];
            var    config    = new FileSystemConfiguration {
                Request            = new HttpContextWrapper(CurrentContext).Request,
                FileSystemProvider = new PhysicalFileSystemProvider(CurrentContext.Server.MapPath("~/Scripts")),
                //uncomment the code below to enable file/folder management
                //AllowCopy = true,
                //AllowCreate = true,
                //AllowMove = true,
                //AllowDelete = true,
                //AllowRename = true,
                //AllowUpload = true,
                AllowDownload         = true,
                AllowedFileExtensions = new[] { ".js", ".json", ".css" },
                TempDirectory         = TempDirectoryPath
            };
            var processor     = new FileSystemCommandProcessor(config);
            var commandResult = processor.Execute(command, arguments);
            var result        = commandResult.GetClientCommandResult();

            return(command == FileSystemCommand.Download && commandResult.Success ? CreateDownloadResponse(result) : Request.CreateResponse(result));
        }
Exemple #2
0
        public object FileSystem()
        {
            var request = new HttpContextWrapper(HttpContext.Current).Request;
            FileSystemCommand command;

            Enum.TryParse(request["command"], out command);
            string arguments = request["arguments"];
            var    config    = new FileSystemConfiguration {
                Request            = request,
                FileSystemProvider = new PhysicalFileSystemProvider(
                    Path.Combine(HostingEnvironment.ApplicationPhysicalPath, SampleImagesRelativePath),
                    (fileSystemItem, clientItem) => {
                    if (!clientItem.IsDirectory)
                    {
                        clientItem.CustomFields["url"] = GetFileItemUrl(fileSystemItem);
                    }
                }
                    ),
                //uncomment the code below to enable file/directory management
                //AllowCopy = true,
                //AllowCreate = true,
                //AllowMove = true,
                //AllowDelete = true,
                //AllowRename = true,
                //AllowUpload = true,
                AllowDownload = true,
                TempDirectory = HttpContext.Current.Server.MapPath("~/App_Data/UploadTemp")
            };
            var processor     = new FileSystemCommandProcessor(config);
            var commandResult = processor.Execute(command, arguments);
            var result        = commandResult.GetClientCommandResult();

            return(command == FileSystemCommand.Download && commandResult.Success ? CreateDownloadResponse(result) : Request.CreateResponse(result));
        }
Exemple #3
0
        public HttpResponseMessage Process()
        {
            FileSystemCommand command;

            Enum.TryParse(CurrentContext.Request["command"], out command);
            string arguments = CurrentContext.Request["arguments"];

            AzureStorageAccount account = AzureStorageAccount.FileManager.Value;
            var provider = new AzureBlobFileProvider(account.AccountName, account.AccessKey, account.ContainerName, TempDirectoryPath);

            var config = new FileSystemConfiguration {
                Request            = new HttpContextWrapper(CurrentContext).Request,
                FileSystemProvider = provider,
                //uncomment the code below to enable file/folder management
                //AllowCopy = true,
                //AllowCreate = true,
                //AllowMove = true,
                //AllowDelete = true,
                //AllowRename = true,
                //AllowUpload = true,
                AllowDownload       = true,
                UploadConfiguration = new UploadConfiguration {
                    MaxFileSize = 1048576
                },
                TempDirectory = TempDirectoryPath
            };
            var processor     = new FileSystemCommandProcessor(config);
            var commandResult = processor.Execute(command, arguments);
            var result        = commandResult.GetClientCommandResult();

            return(command == FileSystemCommand.Download && commandResult.Success ? CreateDownloadResponse(result) : Request.CreateResponse(result));
        }
Exemple #4
0
        public IActionResult FileSystem(FileSystemCommand command, string arguments)
        {
            try
            {
                var config = new FileSystemConfiguration
                {
                    Request = Request,
                    //FileSystemProvider = new DefaultFileProvider(CreateGlavnaFolder()),
                    //AllowCopy = true,
                    //AllowCreate = true,
                    //AllowMove = true,
                    //AllowRemove = true,
                    //AllowRename = true,
                    //AllowUpload = true
                };
                var processor = new FileSystemCommandProcessor(config);
                var result    = processor.Execute(command, arguments);

                return(Ok(result.GetClientCommandResult()));
            }
            catch (Exception)
            {
            }

            return(Ok());
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conf            = Configuration.GetSection("CoreBrowser").Get <CoreBrowserConfiguration>();
            var filesRootFolder = conf.FilesRootFolder;

            if (filesRootFolder.StartsWith(ApplicationConstants.WWWROOT_PLACEHOLDER))
            {
                var removedPlaceholder = filesRootFolder.Remove(0, ApplicationConstants.WWWROOT_PLACEHOLDER.Length);
                filesRootFolder = $"{HostingEnvironment.WebRootPath}{removedPlaceholder}";
            }

            _fileSystemConfiguration = new FileSystemConfiguration(filesRootFolder)
                                       .AddExcludedFileNames(conf.ExcludedFileNames)
                                       .AddExcludedFileExtensions(conf.ExcludedFileExtensions)
                                       .SetDirectoryHeaderFileName(conf.DirectoryHeaderFileName)
                                       .Build();

            services.AddTransient <IFileSystemService>(x => new FileSystemService(_fileSystemConfiguration));
            services.AddTransient <IConfiguration>(x => Configuration);
            services.AddTransient <ICoreBrowserRazorView, CoreBrowserRazorView>();

            // Add framework services.
            services.AddMvc();

            services.Configure <CoreBrowserConfiguration>(Configuration.GetSection("CoreBrowser"));
        }
        public object FileSystem(FileSystemCommand command, string arguments)
        {
            var config = new FileSystemConfiguration {
                Request            = Request,
                FileSystemProvider = new PhysicalFileSystemProvider(
                    Path.Combine(HostingEnvironment.WebRootPath, SampleImagesRelativePath),
                    (fileSystemItem, clientItem) => {
                    if (!clientItem.IsDirectory)
                    {
                        clientItem.CustomFields["url"] = GetFileItemUrl(fileSystemItem);
                    }
                }
                    ),
                //uncomment the code below to enable file/directory management
                //AllowCopy = true,
                //AllowCreate = true,
                //AllowMove = true,
                //AllowDelete = true,
                //AllowRename = true,
                //AllowUpload = true,
                AllowDownload = true
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(result.GetClientCommandResult());
        }
		public StronglyTypedRavenSettings(NameValueCollection settings)
		{
			Replication = new ReplicationConfiguration();
			Voron = new VoronConfiguration();
			Prefetcher = new PrefetcherConfiguration();
            FileSystem = new FileSystemConfiguration();
			Encryption = new EncryptionConfiguration();
			
			this.settings = settings;
		}
        public StronglyTypedRavenSettings(NameValueCollection settings)
        {
            Replication = new ReplicationConfiguration();
            Voron       = new VoronConfiguration();
            Prefetcher  = new PrefetcherConfiguration();
            FileSystem  = new FileSystemConfiguration();
            Encryption  = new EncryptionConfiguration();

            this.settings = settings;
        }
        public FileSystemServiceTests()
        {
            var conf = new FileSystemConfiguration(_rootDir)
                       .AddExcludedFileExtensions(_excludedExtensions)
                       .AddExcludedFileNames(_excludedFilenames)
                       .Build();

            _configuration = conf;

            _fileService = new FileSystemService(_configuration);
        }
        public StronglyTypedRavenSettings(NameValueCollection settings)
        {
            Replication = new ReplicationConfiguration();
            Voron       = new VoronConfiguration();
            Esent       = new EsentConfiguration();
            Prefetcher  = new PrefetcherConfiguration();
            FileSystem  = new FileSystemConfiguration();
            Encryption  = new EncryptionConfiguration();
            Indexing    = new IndexingConfiguration();
            WebSockets  = new WebSocketsConfiguration();

            this.settings = settings;
        }
        public void GetDirectory_GivenTxtHeaderContent_ReturnsTextFileContent()
        {
            var conf = new FileSystemConfiguration(_rootDir)
                       .SetDirectoryHeaderFileName("_headerContent.txt")
                       .Build();

            var fileService = new FileSystemService(conf);

            var contents = fileService.GetDirectory();
            var header   = contents.HeaderContent;

            Assert.Equal("Title", header);
        }
        public StronglyTypedRavenSettings(NameValueCollection settings)
        {
            Replication = new ReplicationConfiguration();
            Voron = new VoronConfiguration();
            Esent = new EsentConfiguration();
            Prefetcher = new PrefetcherConfiguration();
            FileSystem = new FileSystemConfiguration();
            Encryption = new EncryptionConfiguration();
            Indexing = new IndexingConfiguration();
            WebSockets = new WebSocketsConfiguration();

            this.settings = settings;
        }
Exemple #13
0
        static void Main(string[] args)
        {
            DbSettings dbSettings = new DbSettings();

            dbSettings.Server   = "192.168.2.101";
            dbSettings.Database = "garmin_toolbox_net";
            dbSettings.Username = "******";
            dbSettings.Password = "******";

            FileSystemConfiguration fileSystem = new FileSystemConfiguration();

            fileSystem.GpxFileDownloadDirectory = "U:\\";

            DirectoryInfo gpxOutputDir = new DirectoryInfo(@"C:\Temp\OrderedGpx");

            if (!gpxOutputDir.Exists)
            {
                gpxOutputDir.Create();
            }

            IUnityContainer container = new UnityContainer();

            new DBConfiguration(container, dbSettings);
            container.RegisterType <IActivityArchiveService, ActivityArchiveService>();
            container.RegisterType <IActivityMetadataDao, ActivityMetadataDao>();

            IActivityArchiveService  archive    = container.Resolve <IActivityArchiveService>();
            IList <ActivityMetadata> allWithGpx = archive.GetAllWithGpx();

            foreach (ActivityMetadata activityMetadata in allWithGpx)
            {
                FileInfo gpxFile = new FileInfo(Path.Combine(fileSystem.GpxFileDownloadDirectory,
                                                             $"{activityMetadata.ActivityId}.gpx"));
                if (gpxFile.Exists && activityMetadata.Start.HasValue)
                {
                    DirectoryInfo destinationFolder = new DirectoryInfo(Path.Combine(gpxOutputDir.FullName,
                                                                                     activityMetadata.Start.Value.Year.ToString(),
                                                                                     activityMetadata.Start.Value.Month.ToString("D2")));
                    if (!destinationFolder.Exists)
                    {
                        destinationFolder.Create();
                    }

                    string destinationFile =
                        $"{activityMetadata.Start.Value:yyyy-MM-dd-HH-mm-ss}-{activityMetadata.ActivityType}-{activityMetadata.ActivityId}{gpxFile.Extension}";

                    gpxFile.CopyTo(Path.Combine(destinationFolder.FullName, destinationFile));
                }
            }
        }
        public IActionResult Process(FileSystemCommand command, string arguments)
        {
            var config = new FileSystemConfiguration {
                Request               = Request,
                FileSystemProvider    = DBFileProvider,
                AllowCopy             = true,
                AllowCreate           = true,
                AllowMove             = true,
                AllowRemove           = true,
                AllowRename           = true,
                AllowedFileExtensions = new string[0]
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(Ok(result.GetClientCommandResult()));
        }
Exemple #15
0
        public StronglyTypedRavenSettings(NameValueCollection settings)
        {
            Replication = new ReplicationConfiguration();
            Voron       = new VoronConfiguration();
            Esent       = new EsentConfiguration();
            Prefetcher  = new PrefetcherConfiguration();
            FileSystem  = new FileSystemConfiguration();
            Counter     = new CounterConfiguration();
            TimeSeries  = new TimeSeriesConfiguration();
            Encryption  = new EncryptionConfiguration();
            Indexing    = new IndexingConfiguration();
            WebSockets  = new WebSocketsConfiguration();
            Cluster     = new ClusterConfiguration();
            Monitoring  = new MonitoringConfiguration();
            Studio      = new StudioConfiguration();

            this.settings = settings;
        }
Exemple #16
0
        public object Process(FileSystemCommand command, string arguments)
        {
            var request = new HttpContextWrapper(HttpContext.Current).Request;
            var config  = new FileSystemConfiguration {
                Request               = request,
                FileSystemProvider    = new DbFileProvider(),
                AllowCopy             = true,
                AllowCreate           = true,
                AllowMove             = true,
                AllowDelete           = true,
                AllowRename           = true,
                AllowedFileExtensions = new string[0]
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(Ok(result.GetClientCommandResult()));
        }
        public void SyncGpx(FileSystemConfiguration fileSystemConfiguration)
        {
            IList <ActivityMetadata> activitiesWithoutOriginalFile = _activityMetadataDao.FindAllWithoutGpxAndNotFailed();

            foreach (ActivityMetadata metadata in activitiesWithoutOriginalFile)
            {
                try
                {
                    Export(metadata.ActivityId, fileSystemConfiguration.GpxFileDownloadDirectory + metadata.ActivityId + ".gpx", ExportFileType.Gpx);
                    metadata.UpdateHasGpx();
                    _activityMetadataDao.Update(metadata);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " | " + metadata.ActivityId);
                }
            }
        }
Exemple #18
0
        public IActionResult FileSystem(FileSystemCommand command, string arguments)
        {
            var rootPath = Path.Combine(Environment.WebRootPath, "ContentFolder");
            var config   = new FileSystemConfiguration {
                Request            = Request,
                FileSystemProvider = new DefaultFileProvider(rootPath, ThumbnailGenerator.AssignThumbnailUrl),
                AllowCopy          = true,
                AllowCreate        = true,
                AllowMove          = true,
                AllowRemove        = true,
                AllowRename        = true,
                AllowUpload        = true
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(Ok(result.GetClientCommandResult()));
        }
        public IActionResult FileSystem(FileSystemCommand command, string arguments)
        {
            var config = new FileSystemConfiguration
            {
                Request            = Request,
                FileSystemProvider = new AzureBlobFileProvider(),
                AllowCopy          = true,
                AllowCreate        = true,
                AllowMove          = true,
                AllowRemove        = true,
                AllowRename        = true,
                AllowUpload        = true,
                UploadTempPath     = _hostingEnvironment.ContentRootPath + "/wwwroot/UploadTemp"
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(Ok(result.GetClientCommandResult()));
        }
        public IActionResult FileSystem(FileSystemCommand command, string arguments)
        {
            var rootPath = Path.Combine(Environment.WebRootPath, "ContentFolder");
            var config   = new FileSystemConfiguration {
                Request            = Request,
                FileSystemProvider = new PhysicalFileSystemProvider(rootPath, ThumbnailGenerator.AssignThumbnailUrl),
                AllowCopy          = true,
                AllowCreate        = true,
                AllowMove          = true,
                AllowDelete        = true,
                AllowRename        = true,
                AllowUpload        = true
            };

            config.AllowedFileExtensions = new[] { ".png", ".gif", ".jpg", ".jpeg", ".ico", ".bmp" };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(Ok(result.GetClientCommandResult()));
        }
        public object FileSystem(FileSystemCommand command, string arguments)
        {
            var config = new FileSystemConfiguration {
                Request               = Request,
                FileSystemProvider    = new PhysicalFileSystemProvider(Path.Combine(HostingEnvironment.WebRootPath, "SampleDocs")),
                AllowCopy             = true,
                AllowCreate           = true,
                AllowMove             = true,
                AllowDelete           = true,
                AllowRename           = true,
                AllowUpload           = true,
                AllowDownload         = true,
                AllowedFileExtensions = new string[] { ".xlsx", ".rtf", ".txt", ".docx", ".json", ".jpg" }
            };

            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(result.GetClientCommandResult());
        }
Exemple #22
0
        public object FileSystem(FileSystemCommand command, string arguments)
        {
            var config = new FileSystemConfiguration {
                Request            = Request,
                FileSystemProvider = new DefaultFileProvider(_hostingEnvironment.ContentRootPath + "/wwwroot"),
                //uncomment the code below to enable file/folder management
                //AllowCopy = true,
                //AllowCreate = true,
                //AllowMove = true,
                //AllowRemove = true,
                //AllowRename = true,
                //AllowUpload = true,
                AllowDownload         = true,
                AllowedFileExtensions = new[] { ".js", ".json", ".css" }
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(result.GetClientCommandResult());
        }
        public object FileSystem(FileSystemCommand command, string arguments)
        {
            var config = new FileSystemConfiguration {
                Request            = Request,
                FileSystemProvider = AzureFileProvider,
                //uncomment the code below to enable file/folder management
                //AllowCopy = true,
                //AllowCreate = true,
                //AllowMove = true,
                //AllowRemove = true,
                //AllowRename = true,
                //AllowUpload = true,
                AllowDownload         = true,
                AllowedFileExtensions = new string[0],
                MaxUploadFileSize     = 1048576,
                UploadTempPath        = HostingEnvironment.ContentRootPath + "/UploadTemp"
            };
            var processor = new FileSystemCommandProcessor(config);
            var result    = processor.Execute(command, arguments);

            return(result.GetClientCommandResult());
        }
Exemple #24
0
        public static void Init(FileSystemConfiguration config)
        {
            if (_initialized)
            {
                throw new InvalidOperationException($"{nameof(FileSystem)} has already been initialized.");
            }
            Logger.Trace($"Init the file system with base path: {config.BasePath}", typeof(FileSystem));

            var assetsPath = Path.GetFullPath(config.BasePath);

            if (!Directory.Exists(assetsPath))
            {
                Logger.Warning($"Asset path '{assetsPath}' does not exist, this could be because the project is running inside visual studio or with dotnet run. Trying to find the root folder.", typeof(FileSystem));

                var maxDepth = 5;
                var path     = Directory.GetCurrentDirectory();

                var basePathIdentifier = config.BasePathIdentifierPattern ?? "*.csproj";
                do
                {
                    path = Directory.GetParent(path)?.FullName;
                } while (--maxDepth > 0 && path != null && Directory.GetFiles(path, basePathIdentifier, SearchOption.TopDirectoryOnly).Length == 0);

                if (path == null)
                {
                    Logger.Error("Could not find the root folder.", typeof(FileSystem));
                    throw new InvalidOperationException("Failed to locate the assets folder.");
                }

                assetsPath = Path.Combine(path, config.BasePath);
                if (!Directory.Exists(assetsPath))
                {
                    Logger.Error($"Asset path '{assetsPath}' does not exist. ", typeof(FileSystem));
                    throw new InvalidOperationException("Failed to locate the assets folder.");
                }
            }
            _basePath    = assetsPath;
            _initialized = true;
        }
        public RavenConfiguration()
        {
            Settings = new NameValueCollection(StringComparer.OrdinalIgnoreCase);

            Core = new CoreConfiguration(this);

            FileSystem = new FileSystemConfiguration(Core);
            Counter    = new CounterConfiguration(Core);
            TimeSeries = new TimeSeriesConfiguration(Core);

            Replication = new ReplicationConfiguration();
            Prefetcher  = new PrefetcherConfiguration();
            Storage     = new StorageConfiguration();
            Encryption  = new EncryptionConfiguration();
            Indexing    = new IndexingConfiguration();
            WebSockets  = new WebSocketsConfiguration();
            Cluster     = new ClusterConfiguration();
            Monitoring  = new MonitoringConfiguration();
            Queries     = new QueryConfiguration();
            Patching    = new PatchingConfiguration();
            BulkInsert  = new BulkInsertConfiguration();
            Server      = new ServerConfiguration();
            Memory      = new MemoryConfiguration();
            Expiration  = new ExpirationBundleConfiguration();
            Versioning  = new VersioningBundleConfiguration();
            Studio      = new StudioConfiguration();
            Tenants     = new TenantConfiguration();
            Licensing   = new LicenseConfiguration();
            Quotas      = new QuotasBundleConfiguration();

            IndexingClassifier = new DefaultIndexingClassifier();

            Catalog = new AggregateCatalog(CurrentAssemblyCatalog);

            Catalog.Changed += (sender, args) => ResetContainer();
        }
        public void CleanGpxFiles(FileSystemConfiguration fileSystemConfiguration)
        {
            IList <ActivityMetadata> metadatas = _activityMetadataDao.GetAll();

            foreach (ActivityMetadata metadata in metadatas.Where(x => x.HasGpx))
            {
                FileInfo file = new FileInfo(fileSystemConfiguration.GpxFileDownloadDirectory + metadata.ActivityId + ".gpx");
                if (!file.Exists)
                {
                    metadata.UpdateHasGpx(false);
                    _activityMetadataDao.Update(metadata);
                }
                else
                {
                    if (file.Length == 0)
                    {
                        file.Delete();
                        metadata.UpdateHasGpx(false);
                        metadata.UpdateGpxDownloadFailed(true);
                        _activityMetadataDao.Update(metadata);
                    }
                }
            }
        }
Exemple #27
0
        public static async Task Main(string[] args)
        {
            IConfigurationRoot config = new ConfigurationBuilder()
                                        .SetBasePath(Directory.GetCurrentDirectory())
                                        .AddJsonFile(args[0], optional: true, reloadOnChange: true)
                                        .Build();

            DbSettings dbSettings = new DbSettings();

            config.GetSection("DbSettings").Bind(dbSettings);

            GarminConfiguration garminSettings = new GarminConfiguration();

            config.GetSection("GarminSettings").Bind(garminSettings);

            Console.WriteLine($"Garmin-User: {garminSettings.Username}");

            MailConfiguration mailSettings = new MailConfiguration();

            config.GetSection("MailSettings").Bind(mailSettings);

            FileSystemConfiguration fileSystemSettings = new FileSystemConfiguration();

            config.GetSection("FileSystem").Bind(fileSystemSettings);

            IUnityContainer unity = new UnityContainer();

            new DBConfiguration(unity, dbSettings);
            unity.RegisterType <IActivityMetadataDao, ActivityMetadataDao>();
            unity.RegisterType <ISessionService, SessionService>(new ContainerControlledLifetimeManager());
            unity.RegisterType <IActivitySearchService, ActivitySearchService>();
            unity.RegisterType <IActivityService, ActivityService>();
            unity.RegisterType <IReportService, ReportService>();
            unity.RegisterType <IMailService, MailService>();
            unity.RegisterType <IActivityArchiveService, ActivityArchiveService>();

            ISessionService sessionService = unity.Resolve <ISessionService>();

            try
            {
                sessionService.SignOut();
            }
            catch (Exception ex)
            {
            }
            sessionService.SignIn(garminSettings);
            IActivityService activityService = unity.Resolve <IActivityService>();

            activityService.SyncLatestMetadata();
            activityService.SyncFiles(fileSystemSettings);
            activityService.CleanGpxFiles(fileSystemSettings);
            try
            {
                sessionService.SignOut();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            IReportService resportService = unity.Resolve <IReportService>();
            string         report         = resportService.CreateTextReportForLastSevenDays();
            IMailService   mailService    = unity.Resolve <IMailService>();
            await mailService.SendMailAsync(mailSettings, report);
        }
 public void SyncFiles(FileSystemConfiguration fileSystemConfiguration)
 {
     SyncOriginalFiles(fileSystemConfiguration);
     SyncGpx(fileSystemConfiguration);
 }