コード例 #1
0
        public async Task <SeafSession> GetSession()
        {
            if (!string.IsNullOrEmpty(Token))
            {
                return(await SeafSession.FromToken(ServerUri, Token));
            }

            return(await SeafSession.Establish(ServerUri, Username, Password.ToCharArray()));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Loop3/SeafClient-NetCore
        static async Task Test()
        {
            try
            {
                var serverUri = new Uri("", UriKind.Absolute);
                var username  = "";
                var password  = "".ToCharArray();
                // authenticate with the Seafile server and retrieve a Session
                var session = await SeafSession.Establish(serverUri, username, password);

                var ping = await session.Ping();

                Console.WriteLine(session.ServerVersion);
                Console.WriteLine(ping);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: maikebing/SeafileClient
        private static async Task SeafClientDemo(Uri host, string user, char[] pw)
        {
            try
            {
                // if the seafile server uses a self-signed certificate we accept it
                // for demonstration purposes
                ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, errors) => true;

                // try to connect to the seafile server using the given credentials
                Console.Write("Connecting...");
                var session = await SeafSession.Establish(host, user, pw);

                Console.WriteLine("OK");
                Console.WriteLine();

                // ping the server
                Console.Write("Pinging the server...");
                if (await session.Ping())
                {
                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("Failed");
                }

                // retrieve user account info
                var info = await session.CheckAccountInfo();

                Console.WriteLine("Account info: ");
                Console.WriteLine("User name: " + info.Name);
                Console.WriteLine("Space used: " + MiscUtils.FormatByteSize(info.Usage));
                Console.WriteLine("Space total: " +
                                  (info.HasUnlimitedSpace ? "unlimited" : MiscUtils.FormatByteSize(info.Quota)));
                Console.WriteLine("");

                // create a test library
                // Console.Write("Creating library...");
                // var newLib = await session.CreateLibrary("TestLib", "123");
                // Console.WriteLine("OK");

                // groups
                Console.WriteLine("Groups:");
                var groupList = await session.ListGroups();

                foreach (var g in groupList)
                {
                    Console.WriteLine(String.Format("{0:d} {1}", g.Id, g.Name));
                }

                if (groupList.Count > 0)
                {
                    var group = groupList.First();

                    //await session.AddGroupMember(group, "*****@*****.**");
                    //Console.WriteLine("added user to group");

                    var request = new ListGroupMembersRequest(session.AuthToken, group.Id, 120);
                    var members = await session.SendRequest(request);

                    Console.WriteLine("Group members:");
                    foreach (var m in members)
                    {
                        Console.WriteLine("  " + m.Name + " " + m.Email);
                    }

                    //await session.RemoveGroupMember(group, "*****@*****.**");
                    //Console.WriteLine("removed user from group");

                    //await session.DeleteGroup(group);
                    //Console.WriteLine("deleted group: " + group.Name);
                    //await session.RenameGroup(group, "changed name");
                    //Console.WriteLine("renamed group");
                }
                else
                {
                    var group = await session.AddGroup("new group");

                    Console.WriteLine("added group: " + group.Id + " - " + group.Name);
                }

                // default library
                var defLib = await session.GetDefaultLibrary();

                Console.WriteLine("Default library: " + defLib.Name);


                // retrieve user's libraries & shared libraries
                var libs = await session.ListLibraries();

                libs = libs.Union(await session.ListSharedLibraries()).ToList();
                Console.WriteLine("Libraries:");

                IList <string[]> lines = new List <string[]>();
                lines.Add(new[] { "Modified", "Permission", "Name", "Owner" });

                foreach (var lib in libs)
                {
                    var permission = lib.Permission == SeafPermission.ReadOnly ? "r" : "rw";
                    lines.Add(new[] { lib.Timestamp.ToString(), permission, lib.Name, lib.Owner });
                }
                Console.WriteLine(MiscUtils.PadElementsInLines(lines, 2));

                // list directories recursively
                var listDirsRequest = new ListDirectoryEntriesRequest(session.AuthToken, defLib.Id, "/", true);
                var dirs            = await session.SendRequest(listDirsRequest);

                foreach (var d in dirs)
                {
                    Console.WriteLine(d.Path);
                }
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException != null)
                {
                    throw ex.InnerException;
                }
            }
            catch (SeafException ex)
            {
                Console.WriteLine("Failed");
                Console.WriteLine("Request failed: " + ex.Message);
            }
        }