Exemplo n.º 1
0
        public FileToken()
        {
            this.Token = string.Empty;
            this.Path  = string.Empty;

            this.Encoding = EncodingType.ANSI;
            this.Type     = FileTokenType.ReadRandomLine;
        }
        private int FileToken(out string token, out string endpoint, FileTokenType tokenType, long xid, int timeout = 0)
        {
            token    = "";
            endpoint = "";

            TCPClient client = GetCoreClient();

            if (client == null)
            {
                return(fpnn.ErrorCode.FPNN_EC_CORE_INVALID_CONNECTION);
            }

            Quest quest = new Quest("filetoken");

            switch (tokenType)
            {
            case FileTokenType.P2P:
                quest.Param("cmd", "sendfile");
                quest.Param("to", xid);
                break;

            case FileTokenType.Group:
                quest.Param("cmd", "sendgroupfile");
                quest.Param("gid", xid);
                break;

            case FileTokenType.Room:
                quest.Param("cmd", "sendroomfile");
                quest.Param("rid", xid);
                break;
            }

            Answer answer = client.SendQuest(quest, timeout);

            if (answer.IsException())
            {
                return(answer.ErrorCode());
            }

            try
            {
                token    = answer.Want <string>("token");
                endpoint = answer.Want <string>("endpoint");
                return(fpnn.ErrorCode.FPNN_EC_OK);
            }
            catch (Exception)
            {
                return(fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE);
            }
        }
        //===========================[ File Token ]=========================//
        //-- Action<token, endpoint, errorCode>
        private bool FileToken(Action <string, string, int> callback, FileTokenType tokenType, long xid, int timeout = 0)
        {
            TCPClient client = GetCoreClient();

            if (client == null)
            {
                return(false);
            }

            Quest quest = new Quest("filetoken");

            switch (tokenType)
            {
            case FileTokenType.P2P:
                quest.Param("cmd", "sendfile");
                quest.Param("to", xid);
                break;

            case FileTokenType.Group:
                quest.Param("cmd", "sendgroupfile");
                quest.Param("gid", xid);
                break;

            case FileTokenType.Room:
                quest.Param("cmd", "sendroomfile");
                quest.Param("rid", xid);
                break;
            }

            return(client.SendQuest(quest, (Answer answer, int errorCode) => {
                string token = "";
                string endpoint = "";
                if (errorCode == fpnn.ErrorCode.FPNN_EC_OK)
                {
                    try
                    {
                        token = answer.Want <string>("token");
                        endpoint = answer.Want <string>("endpoint");
                    }
                    catch (Exception)
                    {
                        errorCode = fpnn.ErrorCode.FPNN_EC_CORE_INVALID_PACKAGE;
                    }
                }
                callback(token, endpoint, errorCode);
            }, timeout));
        }