コード例 #1
0
        public static List <string> PrepareUploadInfo(string apiKey, string username = null, string password = null)
        {
            SendSpace sendSpace = new SendSpace(apiKey);

            try
            {
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
                {
                    AccountType = AccountType.Anonymous;

                    UploadInfo = sendSpace.AnonymousUploadGetInfo();
                    if (UploadInfo == null)
                    {
                        throw new Exception("UploadInfo is null.");
                    }
                }
                else
                {
                    AccountType = AccountType.User;
                    Username    = username;
                    Password    = password;

                    if (string.IsNullOrEmpty(Token))
                    {
                        Token = sendSpace.AuthCreateToken();
                        if (string.IsNullOrEmpty(Token))
                        {
                            throw new Exception("Token is null or empty.");
                        }
                    }
                    if (string.IsNullOrEmpty(SessionKey) || (DateTime.Now - LastSessionKey).TotalMinutes > 30)
                    {
                        SessionKey = sendSpace.AuthLogin(Token, username, password).SessionKey;
                        if (string.IsNullOrEmpty(SessionKey))
                        {
                            throw new Exception("SessionKey is null or empty.");
                        }
                        LastSessionKey = DateTime.Now;
                    }
                    UploadInfo = sendSpace.UploadGetInfo(SessionKey);
                    if (UploadInfo == null)
                    {
                        throw new Exception("UploadInfo is null.");
                    }
                }
            }
            catch (Exception e)
            {
                if (sendSpace.Errors.Count > 0)
                {
                    DebugHelper.WriteException(new Exception(sendSpace.ToErrorString()));
                }
                else
                {
                    DebugHelper.WriteException(e);
                }
            }

            return(sendSpace.Errors);
        }
コード例 #2
0
ファイル: SendSpaceManager.cs プロジェクト: raymondle/ShareX
        public static List<string> PrepareUploadInfo(string apiKey, string username = null, string password = null)
        {
            SendSpace sendSpace = new SendSpace(apiKey);

            try
            {
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
                {
                    AccountType = AccountType.Anonymous;

                    UploadInfo = sendSpace.AnonymousUploadGetInfo();
                    if (UploadInfo == null) throw new Exception("UploadInfo is null.");
                }
                else
                {
                    AccountType = AccountType.User;
                    Username = username;
                    Password = password;

                    if (string.IsNullOrEmpty(Token))
                    {
                        Token = sendSpace.AuthCreateToken();
                        if (string.IsNullOrEmpty(Token)) throw new Exception("Token is null or empty.");
                    }
                    if (string.IsNullOrEmpty(SessionKey) || (FastDateTime.Now - LastSessionKey).Minutes > 30)
                    {
                        SessionKey = sendSpace.AuthLogin(Token, username, password).SessionKey;
                        if (string.IsNullOrEmpty(Token)) throw new Exception("SessionKey is null or empty.");
                        LastSessionKey = FastDateTime.Now;
                    }
                    UploadInfo = sendSpace.UploadGetInfo(SessionKey);
                    if (UploadInfo == null) throw new Exception("UploadInfo is null.");
                }
            }
            catch (Exception e)
            {
                if (sendSpace.Errors.Count > 0)
                {
                    DebugHelper.WriteException(new Exception(sendSpace.ToErrorString()));
                }
                else
                {
                    DebugHelper.WriteException(e);
                }
            }

            return sendSpace.Errors;
        }