当前位置: 首页>>代码示例>>C#>>正文


C# RestVerbs类代码示例

本文整理汇总了C#中RestVerbs的典型用法代码示例。如果您正苦于以下问题:C# RestVerbs类的具体用法?C# RestVerbs怎么用?C# RestVerbs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RestVerbs类属于命名空间,在下文中一共展示了RestVerbs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NewToken

        object NewToken(RestVerbs verbs, IParameterCollection parameters)
        {
            var user = verbs["username"];
            var pass = verbs["password"];

            RestObject obj = null;
            if (Verify != null)
                obj = Verify(user, pass);

            if (obj == null)
                obj = new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };

            if (obj.Error != null)
                return obj;

            string hash;
            var rand = new Random();
            var randbytes = new byte[32];
            do
            {
                rand.NextBytes(randbytes);
                hash = randbytes.Aggregate("", (s, b) => s + b.ToString("X2"));
            } while (Tokens.ContainsKey(hash));

            Tokens.Add(hash, user);

            obj["token"] = hash;
            return obj;
        }
开发者ID:pfchrono,项目名称:Toaria,代码行数:29,代码来源:SecureRest.cs

示例2: RestRequestArgs

		public RestRequestArgs(RestVerbs verbs, IParameterCollection param, IRequest request, SecureRest.TokenData tokenData, IHttpContext context)
		{
			Verbs = verbs;
			Parameters = param;
			Request = request;
			TokenData = tokenData;
			Context = context;
		}
开发者ID:sliekasirdis79,项目名称:TShock,代码行数:8,代码来源:Rest.cs

示例3: DestroyToken

 object DestroyToken(RestVerbs verbs, IParameterCollection parameters)
 {
     var token = verbs["token"];
     try
     {
         Tokens.Remove(token);
     }
     catch (Exception)
     {
         return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified token queued for destruction failed to be deleted." } };
     }
     return new Dictionary<string, string> { { "status", "200" }, { "response", "Requested token was successfully destroyed." } };
 }
开发者ID:pfchrono,项目名称:Toaria,代码行数:13,代码来源:SecureRest.cs

示例4: ExecuteCommand

        protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
        {
            if (cmd.RequiresToken)
            {
                var strtoken = parms["token"];
                if (strtoken == null)
                    return new Dictionary<string, string> { { "status", "401" }, { "error", "Not authorized. The specified API endpoint requires a token." } };

                object token;
                if (!Tokens.TryGetValue(strtoken, out token))
                    return new Dictionary<string, string> { { "status", "403" }, { "error", "Not authorized. The specified API endpoint requires a token, but the provided token was not valid." } };
            }
            return base.ExecuteCommand(cmd, verbs, parms);
        }
开发者ID:pfchrono,项目名称:Toaria,代码行数:14,代码来源:SecureRest.cs

示例5: GetInventory

        private object GetInventory(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            List<TSPlayer> players = TShock.Utils.FindPlayer(verbs["user"]);
            if (players.Count > 1)
            {
                return new RestObject("400") {Response = "Found more than one match."};
            }
            else if (players.Count < 1)
            {
                return new RestObject("400") {Response = "Found no matches."};
            }

            string inventory = players[0].PlayerData.inventory.ToString();
            return new RestObject{{"inventory", inventory}};
        }
开发者ID:NyxStudios,项目名称:serverside-terraria,代码行数:15,代码来源:ServerSideExtensions.cs

示例6: BanCreate

        object BanCreate(RestVerbs verbs, IParameterCollection parameters)
        {
            var returnBlock = new Dictionary<string, string>();
            var ip = parameters["ip"];
            var name = parameters["name"];
            var reason = parameters["reason"];

            if (ip == null && name == null)
            {
                returnBlock.Add("status", "400");
                returnBlock.Add("error", "Required parameters were missing from this API endpoint.");
                return returnBlock;
            }

            if (ip == null)
            {
                ip = "";
            }

            if (name == null)
            {
                name = "";
            }

            if (reason == null)
            {
                reason = "";
            }

            try
            {
                TShock.Bans.AddBan(ip, name, reason);
            }
            catch (Exception)
            {
                returnBlock.Add("status", "400");
                returnBlock.Add("error", "The specified ban was unable to be created.");
                return returnBlock;
            }
            returnBlock.Add("status", "200");
            returnBlock.Add("response", "Ban created successfully.");
            return returnBlock;
        }
开发者ID:pfchrono,项目名称:Toaria,代码行数:43,代码来源:RestManager.cs

示例7: WorldRead

 private object WorldRead(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject()
     {
         {"name", Main.worldName},
         {"size", Main.maxTilesX + "*" + Main.maxTilesY},
         {"time", Main.time},
         {"daytime", Main.dayTime},
         {"bloodmoon", Main.bloodMoon},
         {"invasionsize", Main.invasionSize}
     };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:12,代码来源:RestManager.cs

示例8: WorldChangeSaveSettings

        private object WorldChangeSaveSettings(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            bool autoSave;
            if (!bool.TryParse(verbs["bool"], out autoSave))
                return RestInvalidParam("state");
            TShock.Config.AutoSave = autoSave;

            return RestResponse("AutoSave has been set to " + autoSave);
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:9,代码来源:RestManager.cs

示例9: WorldBloodmoon

        private object WorldBloodmoon(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            bool bloodmoon;
            if (!bool.TryParse(verbs["bool"], out bloodmoon))
                return RestInvalidParam("bloodmoon");
            Main.bloodMoon = bloodmoon;

            return RestResponse("Blood Moon has been set to " + bloodmoon);
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:9,代码来源:RestManager.cs

示例10: UserListV2

 private object UserListV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject() { { "users", TShock.Users.GetUsers().Select(p => new Dictionary<string,object>(){
         {"name", p.Name},
         {"id", p.ID},
         {"group", p.Group},
     }) } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:8,代码来源:RestManager.cs

示例11: UserDestroyV2

        private object UserDestroyV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            var ret = UserFind(parameters);
            if (ret is RestObject)
                return ret;

            try
            {
                TShock.Users.RemoveUser((User)ret);
            }
            catch (Exception e)
            {
                return RestError(e.Message);
            }

            return RestResponse("User deleted successfully");
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:17,代码来源:RestManager.cs

示例12: UserActiveListV2

 private object UserActiveListV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject() { { "activeusers", string.Join("\t", TShock.Players.Where(p => null != p && null != p.UserAccountName && p.Active).Select(p => p.UserAccountName)) } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:4,代码来源:RestManager.cs

示例13: PlayerReadV2

        private object PlayerReadV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            var ret = PlayerFind(parameters);
            if (ret is RestObject)
                return ret;

            TSPlayer player = (TSPlayer)ret;
            var activeItems = player.TPlayer.inventory.Where(p => p.active).ToList();
            return new RestObject()
            {
                {"nickname", player.Name},
                {"username", null == player.UserAccountName ? "" : player.UserAccountName},
                {"ip", player.IP},
                {"group", player.Group.Name},
                {"position", player.TileX + "," + player.TileY},
                {"inventory", string.Join(", ", activeItems.Select(p => (p.name + ":" + p.stack)))},
                {"buffs", string.Join(", ", player.TPlayer.buffType)}
            };
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:19,代码来源:RestManager.cs

示例14: PlayerListV2

 private object PlayerListV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     var playerList = new ArrayList();
     foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p))
     {
         var p = PlayerFilter(tsPlayer, parameters);
         if (null != p)
             playerList.Add(p);
     }
     return new RestObject() { { "players", playerList } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:11,代码来源:RestManager.cs

示例15: PlayerList

 private object PlayerList(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     var activeplayers = Main.player.Where(p => null != p && p.active).ToList();
     return new RestObject() { { "players", string.Join(", ", activeplayers.Select(p => p.name)) } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:5,代码来源:RestManager.cs


注:本文中的RestVerbs类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。