用webServices维护用户列表

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace userlist
{
 /// <summary>
 /// Service1 的摘要说明。
 /// </summary>
 [WebService(Namespace="http://www.ehang.com.cn/webservices/")]
 public class EhangMember : System.Web.Services.WebService
 {
  public EhangMember()
  {
   //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
   InitializeComponent();
  }

  private System.Timers.Timer timer1;

  #region 组件设计器生成的代码
  
  //Web 服务设计器所必需的
  private IContainer components = null;
    
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.timer1 = new System.Timers.Timer();
   ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
   //
   // timer1
   //
   this.timer1.Enabled = true;
   this.timer1.Interval = 10000;
   this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
   ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if(disposing && components != null)
   {
    components.Dispose();
   }
   base.Dispose(disposing);  
  }
  
  #endregion
  [WebMethod]
  public void Clear(){
   base.Application.Lock();
   base.Application.Clear();
   base.Application .UnLock();
  }

  [WebMethod]
  public String[] getUsers(){
   base.Application.Lock();
   string[] user=new string[base.Application.Count];
   user=base.Application.AllKeys;
   base.Application.UnLock();
   return user;
  }
  [WebMethod]
  public FYZ.Information.users getUser(string uid){
   base.Application.Lock();
   FYZ.Information.users userInfo=new FYZ.Information.users();
   userInfo=(FYZ.Information.users)base.Application[uid];
   base.Application.UnLock();
   return userInfo;
  }
  [WebMethod]
  public bool insertUser(string uid)
  {
   try
   {
    base.Application.Lock();
    FYZ.Information.users userinfo=new FYZ.Information.users();
    userinfo.LasstTime =DateTime.Now.ToString();
    userinfo.name=uid;
    base.Application.Add(uid,userinfo);
    base.Application.UnLock();
    return true;
   }
   catch
   {
    return false;
   }
  }

  [WebMethod]
  public bool insertUser(FYZ.Information.users UserInfo)
  {
   try
   {
    base.Application.Lock();
    UserInfo.LasstTime =DateTime.Now.ToString();
    base.Application.Add(UserInfo.name,UserInfo);
    base.Application.UnLock();
    return true;
   }
   catch
   {
    return false;
   }
  }
  [WebMethod]
  public int Onlines(){
   return base.Application.Count;
  }

  private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  {
   base.Application.Remove("RM");
   for(int i=0; i<base.Application.Count;i++)
   {
    if(DateTime.Compare(DateTime.Now.AddMinutes(-2),DateTime.Parse(((FYZ.Information.users)base.Application[i]).LasstTime))==1){
     base.Application.Lock();
     base.Application.RemoveAt(i);
     base.Application.UnLock();
    }
   }
  }
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值