示例#1
0
        protected virtual void Process(HierarchyNamespace parent, ApiInterface iface)
        {
            var hierarchyInterface = CreateHierarchyElementInternal <HierarchyInterface> (parent);

            hierarchyInterface.Init(iface);

            AddLocationComment(iface, hierarchyInterface);
            Helpers.ForEachNotNull(iface.ChildElements, (ApiElement e) => {
                switch (e)
                {
                case ApiField field:
                    Process(hierarchyInterface, field);
                    break;

                case ApiMethod method:
                    Process(hierarchyInterface, method);
                    break;

                case ApiImplements implements:
                    Process(hierarchyInterface, implements);
                    break;

                case ApiTypeParameter typeParameter:
                    Process(hierarchyInterface, typeParameter);
                    break;

                default:
                    Logger.Warning($"Unexpected member type for ApiInterface: '{e.GetType ().FullName}'");
                    break;
                }
            });

            parent.AddMember(hierarchyInterface);
            TypeIndex.Add(hierarchyInterface);
        }
        public string Resolve(ApiInterface source, object destination, string destMember, ResolutionContext context)
        {
            if (!source.IsUseEnvelop)
            {
                try
                {
                    var result = JToken.Parse(source.ResponseResult);
                    return(JsonConvert.SerializeObject(result, Formatting.Indented));
                }
                catch (System.Exception)
                {
                    return("Json内容格式不正确, 通过编辑修复之后再查看");
                }
            }

            var envelop = new EnvelopMessage <object>()
            {
                Code            = 200,
                Tid             = GuidGenerator.GenerateDigitalUUID(),
                FriendlyMessage = "返回成功",
                ErrorMessage    = string.Empty
            };

            try
            {
                envelop.Data = JToken.Parse(source.ResponseResult);
            }
            catch (System.Exception)
            {
                envelop.Data = "Json内容格式不正确, 通过编辑修复之后再查看";
            }
            return(JsonConvert.SerializeObject(envelop, Formatting.Indented));
        }
示例#3
0
        /// <summary>
        /// 发送私聊消息
        /// </summary>
        /// <param name="userId">发送目标用户id</param>
        /// <param name="message">消息</param>
        /// <returns>
        /// <para><see cref="APIStatusType"/> API执行状态</para>
        /// <para><see langword="messageId"/> 消息ID</para>
        /// </returns>
        public async ValueTask <(APIStatusType apiStatus, int messageId)> SendPrivateMessage(long userId, params object[] message)
        {
            if (userId < 10000)
            {
                throw new ArgumentOutOfRangeException($"{nameof(userId)} too small");
            }
            if (message.Length == 0)
            {
                throw new NullReferenceException(nameof(message));
            }
            //消息段列表
            List <CQCode> msgList = new List <CQCode>();

            foreach (object msgObj in message)
            {
                if (msgObj is CQCode cqCode)
                {
                    msgList.Add(cqCode);
                }
                else if (msgObj is IEnumerable <CQCode> cqCodes)
                {
                    msgList.AddRange(cqCodes);
                }
                else
                {
                    msgList.Add(CQCode.CQText(msgObj.ToString()));
                }
            }
            return(((APIStatusType apiStatus, int messageId)) await ApiInterface.SendPrivateMessage(this.ConnectionGuid, userId, msgList));
        }
示例#4
0
        static void Main(string[] args)
        {
            var targetSys = ConfigurationManager.AppSettings["TargetSystem"];

            ApiInterface app = new ApiInterface();

            switch (targetSys)
            {
            case "ConsoleApp":
                app.setTarget(new ConsoleSys());
                app.GetMsg("Hello World");
                app.WriteMsg();
                break;

            case "Database":
                app.setTarget(new DatabaseSys());
                app.GetMsg("Hello World");
                app.WriteMsg();
                break;

            default:
                app.GetMsg("Hello World");
                app.WriteMsg();
                break;
            }

            Console.ReadKey();
        }
示例#5
0
 /// <summary>
 /// 退出群
 /// </summary>
 /// <param name="groupId">群号</param>
 public async ValueTask LeaveGroup(long groupId)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException(nameof(groupId));
     }
     await ApiInterface.SetGroupLeave(this.ConnectionGuid, groupId, false);
 }
示例#6
0
 /// <summary>
 /// 设置群管理员
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">成员id</param>
 public async ValueTask EnableGroupAdmin(long groupId, long userId)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} out of range");
     }
     await ApiInterface.SetGroupAdmin(this.ConnectionGuid, userId, groupId, true);
 }
示例#7
0
 /// <summary>
 /// 群组全员禁言
 /// </summary>
 /// <param name="groupId">群号</param>
 public async ValueTask EnableGroupMute(long groupId)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException(nameof(groupId));
     }
     await ApiInterface.SetGroupWholeBan(this.ConnectionGuid, groupId, true);
 }
示例#8
0
 /// <summary>
 /// 设置群组成员禁言
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">用户id</param>
 /// <param name="duration">
 /// <para>禁言时长(s)</para>
 /// <para>至少60s</para>
 /// </param>
 public async ValueTask EnableGroupMemberMute(long groupId, long userId, long duration)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} or {nameof(duration)} out of range");
     }
     await ApiInterface.SetGroupBan(this.ConnectionGuid, groupId, userId, duration);
 }
示例#9
0
 /// <summary>
 /// 群组踢人
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">用户id</param>
 /// <param name="rejectRequest">拒绝此人的加群请求</param>
 public async ValueTask KickGroupMember(long groupId, long userId, bool rejectRequest)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} out of range");
     }
     await ApiInterface.SetGroupKick(this.ConnectionGuid, groupId, userId, rejectRequest);
 }
示例#10
0
 /// <summary>
 /// 设置群成员专属头衔
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">用户id</param>
 /// <param name="specialTitle">专属头衔(为空时清空)</param>
 public async ValueTask SetGroupMemberSpecialTitle(long groupId, long userId, string specialTitle)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} out of range");
     }
     await ApiInterface.SetGroupSpecialTitle(this.ConnectionGuid, groupId, userId, specialTitle);
 }
示例#11
0
 /// <summary>
 /// 设置群名片
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">用户id</param>
 /// <param name="card">
 /// <para>新名片</para>
 /// <para>当值为 <see langword="null"/> 或 <see cref="string"/>.<see langword="Empty"/> 时为清空名片</para>
 /// </param>
 public async ValueTask SetGroupCard(long groupId, long userId, string card)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} out of range");
     }
     await ApiInterface.SetGroupCard(this.ConnectionGuid, groupId, userId, card);
 }
示例#12
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 重启客户端
 /// </summary>
 /// <param name="delay">延迟(ms)</param>
 public async ValueTask <APIStatusType> RebootClient(int delay = 0)
 {
     if (delay < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(delay));
     }
     return((APIStatusType)await ApiInterface.Restart(this.ConnectionGuid, delay));
 }
示例#13
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 取消群管理员
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">成员id</param>
 public async ValueTask <APIStatusType> DisableGroupAdmin(long groupId, long userId)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} out of range");
     }
     return((APIStatusType)await ApiInterface.SetGroupAdmin(this.ConnectionGuid, userId, groupId, false));
 }
示例#14
0
 /// <summary>
 /// 获取中文分词
 /// </summary>
 /// <param name="text">内容</param>
 /// <returns>
 /// <para><see cref="APIStatusType"/> API执行状态</para>
 /// <para><see langword="wordList"/> 分词列表</para>
 /// </returns>
 public async ValueTask <(APIStatusType apiStatus, List <string> wordList)> GetWordSlices(string text)
 {
     if (string.IsNullOrEmpty(text))
     {
         throw new NullReferenceException(nameof(text));
     }
     return(((APIStatusType apiStatus, List <string> wordList)) await ApiInterface.GetWordSlices(this.ConnectionGuid, text));
 }
示例#15
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 解散群
 /// </summary>
 /// <param name="groupId">群号</param>
 public async ValueTask <APIStatusType> DismissGroup(long groupId)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException(nameof(groupId));
     }
     return((APIStatusType)await ApiInterface.SetGroupLeave(this.ConnectionGuid, groupId, true));
 }
示例#16
0
 /// <summary>
 /// 重启客户端
 /// </summary>
 /// <param name="delay">延迟(ms)</param>
 public async ValueTask RebootClient(int delay = 0)
 {
     if (delay < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(delay));
     }
     await ApiInterface.Restart(this.ConnectionGuid, delay);
 }
示例#17
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 解除群组全员禁言
 /// </summary>
 /// <param name="groupId">群号</param>
 public async ValueTask <APIStatusType> DisableGroupMute(long groupId)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException(nameof(groupId));
     }
     return((APIStatusType)await ApiInterface.SetGroupWholeBan(this.ConnectionGuid, groupId, false));
 }
示例#18
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 处理加好友请求
 /// </summary>
 /// <param name="flag">请求flag</param>
 /// <param name="approve">是否同意</param>
 /// <param name="remark">好友备注</param>
 public async ValueTask <APIStatusType> SetFriendAddRequest(string flag, bool approve,
                                                            string remark = null)
 {
     if (string.IsNullOrEmpty(flag))
     {
         throw new NullReferenceException(nameof(flag));
     }
     return((APIStatusType)await ApiInterface.SetFriendAddRequest(this.ConnectionGuid, flag, approve, remark));
 }
示例#19
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 群组踢人
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="userId">用户id</param>
 /// <param name="rejectRequest">拒绝此人的加群请求</param>
 public async ValueTask <APIStatusType> KickGroupMember(long groupId, long userId, bool rejectRequest)
 {
     if (groupId is < 100000 || userId is < 10000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(userId)} out of range");
     }
     return((APIStatusType)await ApiInterface.KickGroupMember(this.ConnectionGuid, groupId, userId,
                                                              rejectRequest));
 }
示例#20
0
 /// <summary>
 /// 获取群成员列表
 /// </summary>
 /// <param name="groupId"></param>
 /// <returns>
 /// <para><see cref="APIStatusType"/> API执行状态</para>
 /// <para><see cref="List{T}"/> 群成员列表</para>
 /// </returns>
 public async ValueTask <(APIStatusType apiStatus, List <GroupMemberInfo> groupMemberList)> GetGroupMemberList(long groupId)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} out of range");
     }
     return(((APIStatusType apiStatus, List <GroupMemberInfo> groupMemberList))
            await ApiInterface.GetGroupMemberList(this.ConnectionGuid, groupId));
 }
示例#21
0
 /// <summary>
 /// 获取群信息
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="useCache">是否使用缓存</param>
 /// <returns>
 /// <para><see cref="APIStatusType"/> API执行状态</para>
 /// <para><see cref="GroupInfo"/> 群信息列表</para>
 /// </returns>
 public async ValueTask <(APIStatusType apiStatus, GroupInfo groupInfo)> GetGroupInfo(long groupId, bool useCache = true)
 {
     if (groupId is < 100000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} out of range");
     }
     return(((APIStatusType apiStatus, GroupInfo groupInfo))
            await ApiInterface.GetGroupInfo(this.ConnectionGuid, groupId, useCache));
 }
示例#22
0
文件: SoraApi.cs 项目: nidbCN/Sora
 public async ValueTask <(APIStatusType apiStatus, VipInfo vipInfo)> GetVipInfo(long userId)
 {
     if (userId < 10000)
     {
         throw new ArgumentOutOfRangeException(nameof(userId));
     }
     return(((APIStatusType apiStatus, VipInfo vipInfo))
            await ApiInterface.GetVipInfo(this.ConnectionGuid, userId));
 }
示例#23
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 获取用户信息
 /// </summary>
 /// <param name="userId">用户ID</param>
 /// <param name="useCache"></param>
 /// <returns>
 /// <para><see cref="APIStatusType"/> API执行状态</para>
 /// <para><see cref="UserInfo"/> 群成员信息</para>
 /// <para><see cref="string"/> qid</para>
 /// </returns>
 public async ValueTask <(APIStatusType apiStatus, UserInfo userInfo, string qid)> GetUserInfo(
     long userId, bool useCache = true)
 {
     if (userId < 10000)
     {
         throw new ArgumentOutOfRangeException(nameof(userId));
     }
     return(((APIStatusType apiStatus, UserInfo userInfo, string qid))
            await ApiInterface.GetUserInfo(this.ConnectionGuid, userId, useCache));
 }
示例#24
0
文件: SoraApi.cs 项目: nidbCN/Sora
        /// <summary>
        /// 获取合并转发消息
        /// </summary>
        /// <param name="forwardId"></param>
        /// <returns>
        /// <para><see cref="APIStatusType"/> API执行状态</para>
        /// <para><see langword="nodeArray"/> 消息节点列表</para>
        /// </returns>
        public async ValueTask <(APIStatusType apiStatus, List <Node> nodeArray)> GetForwardMessage(string forwardId)
        {
            if (string.IsNullOrEmpty(forwardId))
            {
                throw new NullReferenceException(nameof(forwardId));
            }
            var(retCode, nodeArray) = await ApiInterface.GetForwardMessage(this.ConnectionGuid, forwardId);

            return((APIStatusType)retCode, nodeArray.NodeMsgList);
        }
示例#25
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 获取图片信息
 /// </summary>
 /// <param name="cacheFileName">缓存文件名</param>
 /// <returns>
 /// <para><see cref="APIStatusType"/> API执行状态</para>
 /// <para><see langword="size"/> 文件大小(Byte)</para>
 /// <para><see langword="fileName"/> 文件名</para>
 /// <para><see langword="url"/> 文件链接</para>
 /// </returns>
 public async ValueTask <(APIStatusType apiStatus, int size, string fileName, string url)> GetImage(
     string cacheFileName)
 {
     if (string.IsNullOrEmpty(cacheFileName))
     {
         throw new ArgumentOutOfRangeException(nameof(cacheFileName));
     }
     return(((APIStatusType apiStatus, int size, string fileName, string url))
            await ApiInterface.GetImage(this.ConnectionGuid, cacheFileName));
 }
示例#26
0
 /// <summary>
 /// 处理加群请求/邀请
 /// </summary>
 /// <param name="flag">请求flag</param>
 /// <param name="requestType">请求类型</param>
 /// <param name="approve">是否同意</param>
 /// <param name="reason">拒绝理由</param>
 public async ValueTask SetGroupAddRequest(string flag,
                                           GroupRequestType requestType,
                                           bool approve,
                                           string reason = null)
 {
     if (string.IsNullOrEmpty(flag))
     {
         throw new NullReferenceException(nameof(flag));
     }
     await ApiInterface.SetGroupAddRequest(this.ConnectionGuid, flag, requestType, approve, reason);
 }
示例#27
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 设置群名
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="newName">新群名</param>
 public async ValueTask <APIStatusType> SetGroupName(long groupId, string newName)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException(nameof(groupId));
     }
     if (string.IsNullOrEmpty(newName))
     {
         throw new NullReferenceException(nameof(newName));
     }
     return((APIStatusType)await ApiInterface.SetGroupName(this.ConnectionGuid, groupId, newName));
 }
示例#28
0
 /// <summary>
 /// 群组匿名用户禁言
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="anonymousFlag">匿名用户Flag</param>
 /// <param name="duration">禁言时长, 单位秒</param>
 public async ValueTask EnableGroupAnonymousMute(long groupId, string anonymousFlag, long duration)
 {
     if (groupId is < 100000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(duration)} out of range");
     }
     if (anonymousFlag == null)
     {
         throw new NullReferenceException("anonymousFlag is null");
     }
     await ApiInterface.SetAnonymousBan(this.ConnectionGuid, groupId, anonymousFlag, duration);
 }
示例#29
0
 /// <summary>
 /// 发送合并转发(群)
 /// 但好像不能用的样子
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="nodeList">
 /// 节点(<see cref="Node"/>)消息段列表
 /// </param>
 public async ValueTask SendGroupForwardMsg(long groupId, List <CustomNode> nodeList)
 {
     if (groupId < 100000)
     {
         throw new ArgumentOutOfRangeException(nameof(groupId));
     }
     if (nodeList == null || nodeList.Count == 0)
     {
         throw new NullReferenceException(nameof(nodeList));
     }
     await ApiInterface.SendGroupForwardMsg(this.ConnectionGuid, groupId, nodeList);
 }
示例#30
0
文件: SoraApi.cs 项目: nidbCN/Sora
 /// <summary>
 /// 群组匿名用户禁言
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="anonymous">匿名用户对象</param>
 /// <param name="duration">禁言时长, 单位秒</param>
 public async ValueTask <APIStatusType> EnableGroupAnonymousMute(long groupId, Anonymous anonymous, long duration)
 {
     if (groupId is < 100000 || duration < 60)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(duration)} out of range");
     }
     if (anonymous == null)
     {
         throw new NullReferenceException("anonymous is null");
     }
     return((APIStatusType)await ApiInterface.SetAnonymousBan(this.ConnectionGuid, groupId, anonymous,
                                                              duration));
 }