Ejemplo n.º 1
0
        /// <summary>
        /// 构造函数。
        /// </summary>
        /// <param name="sci"></param>
        /// <param name="userInfo"></param>
        /// <param name="ports"></param>
        public HostListenService(StartClassInfo sci,UserInfo userInfo, PortSettings ports)
        {
            this.sci = sci;
            this.userInfo = userInfo;
            this.ports = ports;

            this.udpSocket = new UDPSocket(this.ports.ClientCallback);
            this.udpSocket.Changed += this.RaiseChanged;
            this.udpSocket.DataArrival += new SocketDataArrivalEventHandler<Msg>(delegate(Msg sender)
            {
                try
                {
                    Thread thread = new Thread(new ThreadStart(delegate()
                    {
                        this.ReceiveClientData(sender);
                    }));
                    thread.IsBackground = true;
                    thread.Start();
                }
                catch (Exception e)
                {
                    UtilTools.OnExceptionRecord(e, typeof(UDPSocket));
                }
            });
            this.workUpTcpService = new WorkUpTcpService(this.ports.FileUpTransfer);
            this.workUpTcpService.Changed += this.RaiseChanged;
            this.workUpTcpService.DataArrival += new SocketDataArrivalEventHandler<FileMSG>(delegate(FileMSG sender)
            {
                this.ReceiveClientData(sender as UploadFileMSG);
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 序列化。
 /// </summary>
 /// <param name="conf"></param>
 public static void Serializer(PortSettings data)
 {
     if (data != null)
     {
         string path = FolderStructure.NetPortSettingsFile;
         UtilTools.Serializer<PortSettings>(data, path);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 反序列化。
 /// </summary>
 /// <returns></returns>
 public static PortSettings DeSerializer()
 {
     string path = FolderStructure.NetPortSettingsFile;
     PortSettings cfg = UtilTools.DeSerializer<PortSettings>(path);
     if (cfg == null)
         cfg = new PortSettings();
     return cfg;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sci"></param>
        /// <param name="hostAddress"></param>
        /// <param name="ports"></param>
        public void Start(StartClassInfo sci, HostAddress hostAddress, PortSettings ports)
        {
            try
            {
                if (sci == null || ports == null || hostAddress == null) return;
                int broadcastPort = ports.HostBroadcast;

                Thread thread = HostBroadcastService.PortThreadCache[broadcastPort] as Thread;

                #region 如果当前广播未关闭,强制关闭。
                if (thread != null)
                {
                    try
                    {
                        this.Stop();
                        thread.Abort();
                    }
                    finally
                    {
                        thread = null;
                    }
                }
                #endregion

                this.RaiseChanged("开启主机广播...");

                IPEndPoint broadcastAddr = new IPEndPoint(hostAddress.BroadcastAddress, broadcastPort);

                HostBroadcast data = new HostBroadcast();
                data.SName = string.Format("{0}[{1}]{2}({3})", this.info.UserName, sci.ClassInfo.ClassName, sci.CatalogInfo.CatalogName, sci.CatalogInfo.TypeName);
                data.Ports = ports;
                data.UID = this.info.UserID;
                data.Time = DateTime.Now;

                int interval = ports.BroadcastInterval;

                thread = new Thread(new ThreadStart(delegate()
                {
                    this.isStart = true;
                    //主机广播。
                    this.sendHostBroadcast(data, broadcastAddr, interval);
                    //发送主机关闭广播。
                    this.sendHostCloseBroadcast(broadcastAddr);
                    //移除缓存。
                    HostBroadcastService.PortThreadCache[broadcastPort] = null;
                }));
                thread.IsBackground = true;
                HostBroadcastService.PortThreadCache[broadcastPort] = thread;
                thread.Start();
            }
            catch (Exception x)
            {
                this.OnExceptionRecord(x, this.GetType());
                this.RaiseChanged(x.Message);
                MessageBox.Show(x.Message, "循环广播时发生异常:", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// 反序列化。
        /// </summary>
        /// <returns></returns>
        public static PortSettings DeSerializer()
        {
            PortSettings result = null;
            if (File.Exists(path))
                result = UtilTools.DeSerializer<PortSettings>(path);

            if (result == null)
                result = new PortSettings();
            return result;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="service"></param>
 public StudentLoginWindow(ICoreService service)
     : base(service)
 {
     this.hostIP = IPAddress.Parse(string.Format("{0}", service["host_ip"]));
     this.prots = service["portsettings"] as PortSettings;
     this.socket = new UDPSocket(this.prots.HostOrder);
     this.socket.DataArrival += this.receiveHostData;
     this.socket.Changed += this.showMessage;
     InitializeComponent();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 private HostNetService(ICoreService service, StartClassInfo sci)
 {
     this.info = service["userinfo"] as UserInfo;
     this.ports = service["portsettings"] as PortSettings;
     this.hostAddress = service["hostaddress"] as HostAddress;
     //主机广播。
     this.hostBroadcast = new HostBroadcastService(info);
     this.hostBroadcast.Changed += this.OnRaiseChanged;
     //主机侦听。
     this.hostListenService = new HostListenService(this.sci = sci, this.info, this.ports);
     this.hostListenService.Changed += this.OnRaiseChanged;
     this.hostListenService.UpdateControls += this.OnUpdateControls;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UCLogin_Load(object sender, EventArgs e)
        {
            try
            {
                this.OnMessageEvent(MessageType.Normal, string.Empty);
                if (this.loginMethod != EnumLoginMethod.UnifiedLogin)
                {
                    this.txtUsername.DropDownStyle = ComboBoxStyle.DropDownList;
                    if (this.students != null)
                    {
                        foreach (Student stu in this.students)
                        {
                            string code = stu.StudentCode;
                            if (!string.IsNullOrEmpty(code) && code.Length > 2)
                            {
                                code = code.Substring(code.Length - 2);
                            }
                            stu.StudentName = string.Format("[{0}]{1}", code, stu.StudentName);
                        }
                        this.txtUsername.BeginUpdate();
                        this.txtUsername.DataSource = this.students;
                        this.txtUsername.DisplayMember = "StudentName";
                        this.txtUsername.ValueMember = "StudentID";
                        this.txtUsername.EndUpdate();
                    }
                    this.panelWork.Visible = (this.loginMethod == EnumLoginMethod.Password);
                }
                else
                {
                    this.panelWork.Visible = true;
                }

                #region 建立UDP监听。
                this.ports = this.CoreService["portsettings"] as PortSettings;
                this.hostIP = IPAddress.Parse(string.Format("{0}", this.CoreService["host_ip"]));

                this.socket = new UDPSocket(this.ports.HostOrder);
                this.socket.Changed += new Yaesoft.SFIT.Client.RaiseChangedHandler(delegate(string content)
                {
                    this.OnMessageEvent(MessageType.Normal, content);
                });
                this.socket.DataArrival += this.ReceiveHostData;
                this.socket.Start();
                #endregion
            }
            catch (Exception x)
            {
                this.OnMessageEvent(MessageType.Normal | MessageType.PopupWarn, "发生异常:" + x.Message);
            }
        }
        private void SystemSettingsWindow_Load(object sender, EventArgs e)
        {
            this.portSettings = this.CoreService["portsettings"] as PortSettings;
            if (this.portSettings == null)
            {
                this.portSettings = NetPortSettingsMgr.DeSerializer();
            }

            this.colorSettings = this.CoreService["monitoruicolorsettings"] as MonitorUIColorSettings;
            if (this.colorSettings == null)
            {
                this.colorSettings = MonitorUIColorSettings.DeSerializer();
            }

            this.SetTextBoxValue(this.txtHostBroadcast, this.portSettings.HostBroadcast);
            this.SetTextBoxValue(this.txtBroadcastInterval, this.portSettings.BroadcastInterval);
            this.SetTextBoxValue(this.txtHostOrder, this.portSettings.HostOrder);
            this.SetTextBoxValue(this.txtClientCallback, this.portSettings.ClientCallback);
            this.SetTextBoxValue(this.txtFileUpTransfer, this.portSettings.FileUpTransfer);
            this.SetTextBoxValue(this.txtFileDownTransfer, this.portSettings.FileDownTransfer);
            this.SetTextBoxValue(this.txtMaxFileSize, this.portSettings.MaxFileSize);

            this.SetTextBoxColor(this.txtOnlineColor, this.colorSettings.OnlineColor);
            this.SetTextBoxColor(this.txtOfflineColor, this.colorSettings.OfflineColor);
            this.SetTextBoxColor(this.txtUploadColor, this.colorSettings.UploadColor);
            this.SetTextBoxColor(this.txtOfflineUploadColor, this.colorSettings.OfflineUploadColor);
            this.SetTextBoxColor(this.txtMoveColor, this.colorSettings.MoveColor);
            this.SetTextBoxColor(this.txtReviewColor, this.colorSettings.ReviewColor);
        }
 /// <summary>
 /// 序列化。
 /// </summary>
 /// <param name="conf"></param>
 public static void Serializer(PortSettings data)
 {
     if (data != null)
         UtilTools.Serializer<PortSettings>(data, path);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 protected override void BeginRun()
 {
     if ((this.ports = this["portsettings"] as PortSettings) != null)
     {
         (this.udpBroadcast = new UDPSocket(this.ports.HostBroadcast)).Start();
     }
 }