public PersonalCloudRootFileSystem(PersonalCloud personalCloud, Microsoft.Extensions.Logging.ILogger l) { Logger = l; // RootFs = personalCloud.RootFS; // return; //_PersonalCloud = personalCloud; var dic = new Dictionary <string, IFileSystem>(); dic["Files"] = personalCloud.RootFS; var aif = new AppInFs(l); aif.GetApps = () => personalCloud.Apps; aif.GetUrl = (x) => { try { var uri = personalCloud.GetWebAppUri(x); if (uri == null) { Logger.LogError($"personalCloud.GetWebAppUri return null."); return(null); } return(uri.AbsoluteUri); } catch (Exception e) { Logger.LogError(e, $"Exception when calling GetWebAppUri"); throw; } }; dic["Apps"] = aif; RootFs = new FileSystemContainer(dic, Logger); }
public void CreateMultiple() { int count = 50; using (var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Trace).AddFile("Logs/{Date}.txt", LogLevel.Trace))) { var l = loggerFactory.CreateLogger <LocalServiceTest>(); var t = DateTime.Now; var inf = new HostPlatformInfo[count]; var srv = new PCLocalService[count]; var ports = new int[count]; var pcs = new PersonalCloud[count]; for (int i = 0; i < count; i++) { inf[i] = new HostPlatformInfo(); srv[i] = new PCLocalService(inf[i], loggerFactory, Getfs(inf[i].GetConfigFolder()), null); ports[i] = 2000 + i; } Parallel.For(0, count, new ParallelOptions { MaxDegreeOfParallelism = 3 }, i => { srv[i].TestSetUdpPort(ports[i], ports); srv[i].StartService(); l.LogInformation($"StartService {i}"); }); } }
private static void CreateAndSharePC() { var my = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var dic = Path.Combine(my, "TestConsoleApp", "webapps"); var t1 = new SimpleConfigStorage( Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TestConsoleApp", Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))); pcservice = new PCLocalService(t1, loggerFactory, new VirtualFileSystem(t1.RootPath), dic); Directory.CreateDirectory(dic); pcservice.InstallApps().Wait(); pcservice.StartService(); pc = pcservice.CreatePersonalCloud("test", "test1").Result; pcservice.SetAlbumConfig(pc.Id, new System.Collections.Generic.List <AlbumConfig>() { new AlbumConfig { MediaFolder = @"F:\pics", Name = "test", ThumbnailFolder = @"D:\Projects\out" } }); if (pc.Apps?.Count != 1) { Console.WriteLine($"Install app failed. exit"); return; } var ret = pcservice.SharePersonalCloud(pc).Result; Console.WriteLine($"Share code is {ret}"); }
private static void CreateAndSharePC() { var my = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var dic = Path.Combine(my, "TestConsoleApp", "webapps"); var t1 = new SimpleConfigStorage( Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TestConsoleApp", Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))); var fs = new PhysicalFileSystem(); var subfs = new SubFileSystem(fs, fs.ConvertPathFromInternal(t1.RootPath), true); pcservice = new PCLocalService(t1, loggerFactory, subfs, dic); Directory.CreateDirectory(dic); pcservice.InstallApps().Wait(); pcservice.StartService(); pc = pcservice.CreatePersonalCloud("test", "test1"); var ret = pcservice.SharePersonalCloud(pc); Console.WriteLine($"Share code is {ret}"); }
public static void RemoveMountPoint(this SQLiteConnection database, PersonalCloud cloud) { if (cloud is null) { throw new ArgumentNullException(nameof(cloud)); } database.RemoveMountPoint(new Guid(cloud.Id)); }
static private void SimapleShareCheckContent(PersonalCloud pc, int expectedCount, int nodes) { var fs2 = pc.RootFS.EnumerateChildrenAsync("/").AsTask().Result; Assert.AreEqual(nodes, fs2.Count); foreach (var item in fs2) { var f = pc.RootFS.EnumerateChildrenAsync($"/{item.Name}").AsTask().Result; Assert.AreEqual(expectedCount, f.Count); } }
public void ShareToMultiple() { int count = 20; using (var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Trace).AddFile("Logs/{Date}.txt", LogLevel.Trace))) { var l = loggerFactory.CreateLogger <LocalServiceTest>(); var t = DateTime.Now; var inf = new HostPlatformInfo[count]; var srv = new PCLocalService[count]; var ports = new int[count]; var pcs = new PersonalCloud[count]; for (int i = 0; i < count; i++) { inf[i] = new HostPlatformInfo(); srv[i] = new PCLocalService(inf[i], loggerFactory, Getfs(inf[i].GetConfigFolder()), null); ports[i] = 2000 + i; } Parallel.For(0, count, new ParallelOptions { MaxDegreeOfParallelism = 3 }, i => { srv[i].TestSetUdpPort(ports[i], ports); Thread.Sleep(500); srv[i].StartService(); l.LogInformation($"guid {srv[i].NodeId} is test{i}"); }); pcs[0] = srv[0].CreatePersonalCloud("test", "test0"); var ret = srv[0].SharePersonalCloud(pcs[0]); l.LogInformation("srv0 is sharing"); Thread.Sleep(2000 * count / 2); var fret = Parallel.For(1, count, new ParallelOptions { MaxDegreeOfParallelism = 2 }, i => { pcs[i] = srv[i].JoinPersonalCloud(int.Parse(ret, CultureInfo.InvariantCulture), $"test{i}").Result; }); while (!fret.IsCompleted) { Thread.Sleep(500); } Thread.Sleep(5000 * count / 10); l.LogInformation("Exam the result"); for (int i = 0; i < count; i++) { SimpleShareCheckContent(pcs[i], 2, count); } } }
public PersonalCloudRootFileSystem(PersonalCloud personalCloud, Microsoft.Extensions.Logging.ILogger l) { Logger = l; // RootFs = personalCloud.RootFS; // return; //_PersonalCloud = personalCloud; var dic = new Dictionary <string, IFileSystem>(); dic["Files"] = personalCloud.RootFS; var aif = new AppInFs(); aif.GetApps = () => personalCloud.Apps; aif.GetUrl = (x) => personalCloud.GetWebAppUri(x).ToString(); dic["Apps"] = aif; RootFs = new FileSystemContainer(dic, Logger); }
private static void JoinPersonalCloud() { var t2 = new SimpleConfigStorage( Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TestConsoleApp", Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))); pcservice = new PCLocalService(t2, loggerFactory, new VirtualFileSystem(t2.RootPath), null); //pcservice.SetUdpPort(2330, new[] { 2330 }); pcservice.StartService(); Console.Write("Input share code:"); var input = Console.ReadLine(); Console.WriteLine(); pc = pcservice.JoinPersonalCloud(int.Parse(input), "test2").Result; }
public override void ViewDidLoad() { base.ViewDidLoad(); HomeItem = new UIBarButtonItem(UIImage.FromBundle("Home"), UIBarButtonItemStyle.Bordered, GoHome); NewFolderItem = new UIBarButtonItem(UIImage.FromBundle("NewFolder"), UIBarButtonItemStyle.Bordered, CreateFolder); NewFileItem = new UIBarButtonItem(UIImage.FromBundle("NewFile"), UIBarButtonItemStyle.Bordered, UploadFile); HelpItem = new UIBarButtonItem(UIImage.FromBundle("Help"), UIBarButtonItemStyle.Bordered, ShowHelp); AddDeviceItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, AddDeviceOrService); lastNotificationTime = new DateTime(2020, 3, 1, 0, 0, 0, DateTimeKind.Local); Globals.CloudManager.OnError += OnPersonalCloudError; cloud = Globals.CloudManager.PersonalClouds[0]; fileSystem = cloud.RootFS; RefreshControl = new UIRefreshControl(); RefreshControl.ValueChanged += RefreshDirectory; GoHome(this, EventArgs.Empty); }
private void WaitForPath(PersonalCloud cloud, string path) { var pathsegs = path.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries); if (pathsegs?.Length > 0) { var rootnodetofind = pathsegs[0]; for (int i = 0; i < 3 * 60; i++) { var nodes = cloud.RootFS.EnumerateChildrenAsync("/").AsTask().Result; if (nodes.Any(x => string.Compare(x.Name, rootnodetofind, true, CultureInfo.InvariantCulture) == 0)) { return; } Thread.Sleep(1000); } } throw new InvalidDataException("Couldn't backup images to personal cloud root, which is readonly"); }
public PersonalCloudRootFileSystem(PersonalCloud personalCloud) { _PersonalCloud = personalCloud; }
public static string GetMountPoint(this SQLiteConnection database, PersonalCloud cloud) => database.GetMountPoint(new Guid(cloud.Id));