public async Task SimpleApp()
        {
            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)));

            Directory.CreateDirectory(dic);


            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 inf1 = new HostPlatformInfo();
                using (var srv1 = new PCLocalService(t1, loggerFactory, new VirtualFileSystem(t1.RootPath), dic))
                {
                    srv1.InstallApps().Wait();

                    var inf2 = new HostPlatformInfo();
                    using (var srv2 = new PCLocalService(inf2, loggerFactory, new VirtualFileSystem(inf2.GetConfigFolder()), null))
                    {
                        srv1.StartService();
                        srv2.StartService();

                        //l.LogInformation((DateTime.Now - t).TotalSeconds.ToString());
                        var pc1 = srv1.CreatePersonalCloud("test", "test1").Result;


                        await srv1.SetAlbumConfig(pc1.Id, new List <AlbumConfig>() {
                            new AlbumConfig {
                                MediaFolder     = @"F:\pics",
                                Name            = "test",
                                ThumbnailFolder = @"D:\Projects\out"
                            }
                        }).ConfigureAwait(false);

                        Assert.AreEqual(pc1.Apps?.Count, 1);

                        var ret = srv1.SharePersonalCloud(pc1).Result;
                        Thread.Sleep(3000);
                        var pc2 = srv2.JoinPersonalCloud(int.Parse(ret, CultureInfo.InvariantCulture), "test2").Result;
                        Thread.Sleep(1000);

                        Assert.AreEqual(pc2.Apps?.Count, 1);
                        foreach (var item in pc2.Apps)
                        {
                            var url = pc2.GetWebAppUri(item);
                            if (string.IsNullOrWhiteSpace(url?.AbsoluteUri))
                            {
                                Assert.Fail();
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        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}");
        }
Exemple #3
0
        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}");
        }
Exemple #4
0
        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;
        }
        private void FabOnClick(object sender, EventArgs eventArgs)
        {
            Task.Run(() => {
                try
                {
                    var my  = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
                    var dic = Path.Combine(my, "TestConsoleApp", "webapps");
                    Directory.CreateDirectory(dic);
                    var loggerFactory = LoggerFactory.Create(builder => {
                        builder
                        .AddFilter("System", LogLevel.Warning);
                    });

                    var t1 = new SimpleConfigStorage(
                        Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),
                                     "TestConsoleApp", Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)));
                    var pcservice = new PCLocalService(t1, loggerFactory, new VirtualFileSystem(t1.RootPath), dic);
                    Directory.CreateDirectory(dic);
                    pcservice.InstallApps().Wait();

                    pcservice.StartService();
                    var pc = pcservice.CreatePersonalCloud("test", "test1").Result;

                    Thread.Sleep(3000);
                    var routdir = pc.RootFS.EnumerateChildrenAsync("/").Result;
                    //using var mem = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("This is a test sentence."));
                    File.Delete(Path.Combine(dic, "content.txt"));
                    var fso    = new FileStream(Path.Combine(dic, "content.txt"), FileMode.OpenOrCreate);
                    byte[] buf = new byte[1024 * 1024];
                    for (int i = 0; i < 1; i++)
                    {
                        fso.Write(buf);
                    }
                    fso.Dispose();
                    //File.WriteAllText(Path.Combine(dic, "content.txt"), "This is a test sentence.");
                    using var fs = new FileStream(Path.Combine(dic, "content.txt"), FileMode.Open);
                    try
                    {
                        pc.RootFS.DeleteAsync("/test1/tex.txt").GetAwaiter().GetResult();
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    var fi = pc.RootFS.EnumerateChildrenAsync("/test1/").Result;

                    pc.RootFS.WriteFileAsync("/test1/tex.txt", fs).GetAwaiter().GetResult();

                    using var rfs = pc.RootFS.ReadFileAsync("/test1/tex.txt").Result;
                    for (int i = 0; i < 100; i++)
                    {
                        var read = rfs.Read(buf, 0, 1024 * 1024);
                        Console.WriteLine(read);
                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
        }