コード例 #1
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
        /// <summary>
        /// Get the region with a int ip address with memory binary search algorithm.
        /// </summary>
        private DataBlock MemorySearch(long ip)
        {
            int blen = IndexBlock.LENGTH;

            if (_dbBinStr == null)
            {
                _dbBinStr = new byte[(int)_raf.Length];
                _raf.Seek(0L, SeekOrigin.Begin);
                _raf.Read(_dbBinStr, 0, _dbBinStr.Length);

                //initialize the global vars
                _firstIndexPtr    = IpTool.GetIntLong(_dbBinStr, 0);
                _lastIndexPtr     = IpTool.GetIntLong(_dbBinStr, 4);
                _totalIndexBlocks = (int)((_lastIndexPtr - _firstIndexPtr) / blen) + 1;
            }

            //search the index blocks to define the data
            int  l = 0, h = _totalIndexBlocks;
            long sip = 0;

            while (l <= h)
            {
                int m = (l + h) >> 1;
                int p = (int)(_firstIndexPtr + m * blen);

                sip = IpTool.GetIntLong(_dbBinStr, p);

                if (ip < sip)
                {
                    h = m - 1;
                }
                else
                {
                    sip = IpTool.GetIntLong(_dbBinStr, p + 4);
                    if (ip > sip)
                    {
                        l = m + 1;
                    }
                    else
                    {
                        sip = IpTool.GetIntLong(_dbBinStr, p + 8);
                        break;
                    }
                }
            }

            //not matched
            if (sip == 0)
            {
                return(null);
            }

            //get the data
            int    dataLen = (int)((sip >> 24) & 0xFF);
            int    dataPtr = (int)((sip & 0x00FFFFFF));
            int    city_id = (int)IpTool.GetIntLong(_dbBinStr, dataPtr);
            string region  = Encoding.UTF8.GetString(_dbBinStr, dataPtr + 4, dataLen - 4);//new String(dbBinStr, dataPtr + 4, dataLen - 4, Encoding.UTF8);

            return(new DataBlock(city_id, region, dataPtr));
        }
コード例 #2
0
        public static IpInfo GetRemoteIpInfo(this HttpContext context)
        {
#if NETSTANDARD2_0
            return(IpTool.Search(context.Connection.RemoteIpAddress.ToString()));
#else
            return(IpTool.Search(context.Request.UserHostAddress));
#endif
        }
コード例 #3
0
 private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (userButton.ID.Equals("BtnSync"))
     {
         if (!AllowIpRange.Equals("") && !IpTool.CheckInNowWifi(AllowIpRange))
         {
             string courseOrMeeting_String = Settings.Default.CourseOrMeeting_String;
             AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", courseOrMeeting_String.Equals("課程") ? "教" : courseOrMeeting_String));
             return;
         }
         if (this.Home_ReturnSyncStatus_Event != null)
         {
             _003C_003Ec__DisplayClass6 _003C_003Ec__DisplayClass = new _003C_003Ec__DisplayClass6();
             _003C_003Ec__DisplayClass._003C_003E4__this = this;
             Tuple <bool, bool> tuple = this.Home_ReturnSyncStatus_Event();
             _003C_003Ec__DisplayClass.syncSwitch = false;
             if (!tuple.Item1)
             {
                 int       num       = 0;
                 DataTable dataTable = MSCE.GetDataTable("select count(ID) as FileNotFinished from NowLogin as nl\r\n                                                       inner join FileRow as fr on nl.UserID=fr.UserID and nl.MeetingID=fr.MeetingID\r\n                                                       where DownloadBytes=0 or DownloadBytes<TotalBytes");
                 if (dataTable.Rows.Count > 0)
                 {
                     num = (int)dataTable.Rows[0]["FileNotFinished"];
                 }
                 if (num > 0)
                 {
                     AutoClosingMessageBox.Show(string.Format("請將{0}資料下載完成後,再同步", Settings.Default.CourseOrMeeting_String));
                     return;
                 }
                 _003C_003Ec__DisplayClass.syncSwitch = true;
             }
             else
             {
                 _003C_003Ec__DisplayClass.syncSwitch = false;
             }
             btnImg.Source = ButtonTool.GetSyncButtonImage(tuple.Item1, tuple.Item2);
             Task.Factory.StartNew(new Action(_003C_003Ec__DisplayClass._003CUserControl_MouseLeftButtonDown_003Eb__4));
         }
     }
     else
     {
         if ((userButton.ID.Equals("BtnIndividualSign") || userButton.ID.Equals("BtnBroadcast")) && !AllowIpRange.Equals("") && !IpTool.CheckInNowWifi(AllowIpRange))
         {
             string courseOrMeeting_String2 = Settings.Default.CourseOrMeeting_String;
             AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", courseOrMeeting_String2.Equals("課程") ? "教" : courseOrMeeting_String2));
             return;
         }
         btnImg.Source = ButtonTool.GetButtonImage(userButton.ID, true);
         if (this.Home_PopUpButtons_Event != null)
         {
             this.Home_PopUpButtons_Event(userButton.ID);
         }
     }
     Task.Factory.StartNew(new Action(_003CUserControl_MouseLeftButtonDown_003Eb__5));
 }
コード例 #4
0
        /// <summary>
        /// get chinese ip infos
        /// </summary>
        /// <returns></returns>
        public static IpInfo GetCnIpInfo()
        {
            string ipAdd = GetLocalIPAddress();

            if (ipAdd.StartsWith("192.168") || ipAdd.StartsWith("127"))
            {
                return(null);
            }

            return(IpTool.Search(ipAdd));
        }
コード例 #5
0
ファイル: HeaderBlock.cs プロジェクト: lulzzz/Virgo
 /// <summary>
 /// Get the bytes for total storage
 /// </summary>
 /// <returns>
 /// Bytes gotten.
 /// </returns>
 public byte[] GetBytes()
 {
     /*
      * +------------+-----------+
      * | 4bytes     | 4bytes    |
      * +------------+-----------+
      *  start ip      index ptr
      */
     byte[] b = new byte[8];
     IpTool.WriteIntLong(b, 0, IndexStartIp);
     IpTool.WriteIntLong(b, 4, IndexPtr);
     return(b);
 }
コード例 #6
0
        private void btnYes_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (StackLines.Count < 1 || txtPLS.Visibility == Visibility.Visible)
            {
                if (!PicUrl.Equals(""))
                {
                    MessageBox.Show("已簽名,欲重新簽名請先按x清除");
                }
                else
                {
                    MessageBox.Show("請簽名後上傳");
                }
                return;
            }
            string    text      = "";
            DataTable dataTable = MSCE.GetDataTable("select AllowIpRange from NowLogin");

            if (dataTable.Rows.Count > 0)
            {
                text = dataTable.Rows[0]["AllowIpRange"].ToString();
            }
            if (!text.Equals("") && !IpTool.CheckInNowWifi(text))
            {
                string courseOrMeeting_String = Settings.Default.CourseOrMeeting_String;
                AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", courseOrMeeting_String.Equals("課程") ? "教" : courseOrMeeting_String));
                return;
            }
            string path = System.IO.Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.SignInFolder);

            path = System.IO.Path.Combine(path, MeetingID, UserID);
            Directory.CreateDirectory(path);
            string      str     = Guid.NewGuid().ToString();
            string      path2   = str + ".png";
            string      text2   = System.IO.Path.Combine(path, path2);
            Application current = Application.Current;

            CanvasTool.SaveCanvas(current.Windows[0], SignPad, 96, text2);
            MouseTool.ShowLoading();
            if (UserID.Equals("guest"))
            {
                UserID_Origin = UserID;
                UserID        = "";
            }
            else if (UserID.Equals("dept"))
            {
                UserID_Origin = UserID;
                UserID        = "";
            }
            GetSigninDataUpload.AsyncPOST(MeetingID, UserID, DeptID, text2, new Action <SigninDataUpload>(_003CbtnYes_MouseDown_003Eb__1f));
        }
コード例 #7
0
        private void txtUnSigned_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Home_GoBackTogSignPictureCT_Function home_GoBackTogSignPictureCT_Function  = null;
            Home_GoBackTogSignPictureCT_Function home_GoBackTogSignPictureCT_Function2 = null;
            _003C_003Ec__DisplayClasse           _003C_003Ec__DisplayClasse            = new _003C_003Ec__DisplayClasse();
            string    text      = "";
            DataTable dataTable = MSCE.GetDataTable("select AllowIpRange from NowLogin");

            if (dataTable.Rows.Count > 0)
            {
                text = dataTable.Rows[0]["AllowIpRange"].ToString();
            }
            if (!text.Equals("") && !IpTool.CheckInNowWifi(text))
            {
                AutoClosingMessageBox.Show("您不在會議室範圍內,無法使用此功能");
                return;
            }
            _003C_003Ec__DisplayClasse.Home_Window = Enumerable.FirstOrDefault(Enumerable.OfType <Home>(Application.Current.Windows));
            if (_003C_003Ec__DisplayClasse.Home_Window == null)
            {
                return;
            }
            string deptID = (signinDataUser.DeptID == null) ? "" : signinDataUser.DeptID;

            if (!signinDataUser.ID.Trim().Equals(""))
            {
                ContentControl cC        = _003C_003Ec__DisplayClasse.Home_Window.CC;
                string         iD        = signinDataUser.ID;
                string         name      = signinDataUser.Name;
                string         signedPic = signinDataUser.SignedPic;
                if (home_GoBackTogSignPictureCT_Function == null)
                {
                    home_GoBackTogSignPictureCT_Function = new Home_GoBackTogSignPictureCT_Function(_003C_003Ec__DisplayClasse._003CtxtUnSigned_MouseLeftButtonDown_003Eb__a);
                }
                cC.Content = new SignPadCT(iD, name, deptID, signedPic, home_GoBackTogSignPictureCT_Function);
            }
            else
            {
                ContentControl cC2        = _003C_003Ec__DisplayClasse.Home_Window.CC;
                string         userName   = string.Format("{0} 來賓", signinDataUser.Dept);
                string         signedPic2 = signinDataUser.SignedPic;
                if (home_GoBackTogSignPictureCT_Function2 == null)
                {
                    home_GoBackTogSignPictureCT_Function2 = new Home_GoBackTogSignPictureCT_Function(_003C_003Ec__DisplayClasse._003CtxtUnSigned_MouseLeftButtonDown_003Eb__b);
                }
                cC2.Content = new SignPadCT("dept", userName, deptID, signedPic2, home_GoBackTogSignPictureCT_Function2);
            }
        }
コード例 #8
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
        /// <summary>
        /// Get by index ptr.
        /// </summary>
        private DataBlock GetByIndexPtr(long ptr)
        {
            _raf.Seek(ptr, SeekOrigin.Begin);
            byte[] buffer = new byte[12];
            _raf.Read(buffer, 0, buffer.Length);
            long extra   = IpTool.GetIntLong(buffer, 8);
            int  dataLen = (int)((extra >> 24) & 0xFF);
            int  dataPtr = (int)((extra & 0x00FFFFFF));

            _raf.Seek(dataPtr, SeekOrigin.Begin);
            byte[] data = new byte[dataLen];
            _raf.Read(data, 0, data.Length);
            int    city_id = (int)IpTool.GetIntLong(data, 0);
            string region  = Encoding.UTF8.GetString(data, 4, data.Length - 4);

            return(new DataBlock(city_id, region, dataPtr));
        }
コード例 #9
0
        private void btnSign_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string    text      = "";
            DataTable dataTable = MSCE.GetDataTable("select AllowIpRange from NowLogin");

            if (dataTable.Rows.Count > 0)
            {
                text = dataTable.Rows[0]["AllowIpRange"].ToString();
            }
            if (!text.Equals("") && !IpTool.CheckInNowWifi(text))
            {
                string courseOrMeeting_String = Settings.Default.CourseOrMeeting_String;
                AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", courseOrMeeting_String.Equals("課程") ? "教" : courseOrMeeting_String));
            }
            else
            {
                this.Home_ChangeTogSignPadCT_Event(signinDataUser.ID, signinDataUser.Name);
            }
        }
コード例 #10
0
        public byte[] GetBytes()
        {
            /*
             * +------------+-----------+-----------+
             * | 4bytes     | 4bytes    | 4bytes    |
             * +------------+-----------+-----------+
             *  start ip      end ip      data ptr + len
             */
            byte[] b = new byte[12];

            IpTool.WriteIntLong(b, 0, StartIP);    //start ip
            IpTool.WriteIntLong(b, 4, EndIp);      //end ip

            //write the data ptr and the length
            long mix = DataPtr | ((DataLen << 24) & 0xFF000000L);

            IpTool.WriteIntLong(b, 8, mix);

            return(b);
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: jangocheng/IPTools
        static void Main(string[] args)
        {
            var       searcher = IpTool.Searcher;
            Stopwatch sw       = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 255; i++)
            {
                for (int j = 0; j < 255; j++)
                {
                    var info = searcher.Search($"171.{i}.{j}.163");
                }
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);

            var ipinfo = IpTool.Search("171.210.12.163");

            Console.WriteLine(ipinfo.Country);        // China
            Console.WriteLine(ipinfo.CountryCode);    // CN
            Console.WriteLine(ipinfo.Province);       // Sichuan
            Console.WriteLine(ipinfo.ProvinceCode);   // SC
            Console.WriteLine(ipinfo.City);           // Chengdu
            Console.WriteLine(ipinfo.Latitude);       // 30.6667
            Console.WriteLine(ipinfo.Longitude);      // 104.6667
            Console.WriteLine(ipinfo.AccuracyRadius); // 50

            Console.WriteLine();
            IpToolSettings.DefaultLanguage = "en";
            ipinfo = IpTool.SearchWithI18N("171.210.12.163");
            Console.WriteLine(ipinfo.Country);        // 中国
            Console.WriteLine(ipinfo.CountryCode);    // CN
            Console.WriteLine(ipinfo.Province);       // 四川省
            Console.WriteLine(ipinfo.ProvinceCode);   // SC
            Console.WriteLine(ipinfo.City);           // 成都
            Console.WriteLine(ipinfo.Latitude);       // 30.6667
            Console.WriteLine(ipinfo.Longitude);      // 104.6667
            Console.WriteLine(ipinfo.AccuracyRadius); // 50
            Console.Read();
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: zhoujianxiong/IPTools
        static void Main(string[] args)
        {
            IpToolSettings.LoadInternationalDbToMemory = true;

            Console.WriteLine("Default Searcher:" + IpTool.Search("171.210.12.163").City);

            Console.WriteLine("IPTools.International Searcher:" + IpTool.IpAllSearcher.Search("171.210.12.163").City);
            Console.WriteLine("IPTools.International Searcher with i18n:" + IpTool.IpAllSearcher.SearchWithI18N("171.210.12.163").City);

            Console.WriteLine("IPTools.China Searcher:" + IpTool.IpChinaSearcher.Search("171.210.12.163").City);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 255; i++)
            {
                for (int j = 0; j < 255; j++)
                {
                    var info = IpTool.Search($"171.{i}.{j}.163");
                }
            }
            sw.Stop();
            Console.WriteLine("Query 65025 ip spend " + sw.ElapsedMilliseconds + " ms.");

            sw.Restart();
            for (int i = 0; i < 255; i++)
            {
                for (int j = 0; j < 255; j++)
                {
                    var info = IpTool.IpAllSearcher.Search($"171.{i}.{j}.163");
                }
            }
            sw.Stop();
            Console.WriteLine("Complex query 65025 ip spend " + sw.ElapsedMilliseconds + " ms.");
            Console.Read();
        }
コード例 #13
0
        static void Main(string[] args)
        {
            var       searcher = IpTool.Searcher;
            Stopwatch sw       = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 255; i++)
            {
                for (int j = 0; j < 255; j++)
                {
                    var info = searcher.Search($"171.{i}.{j}.163");
                }
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);

            var ipinfo = IpTool.Search("171.210.12.163");

            Console.WriteLine(ipinfo.Country);         // 中国
            Console.WriteLine(ipinfo.Province);        // 四川省
            Console.WriteLine(ipinfo.City);            // 成都市
            Console.WriteLine(ipinfo.NetworkOperator); // 电信
            Console.Read();
        }
コード例 #14
0
        public ActionResult Loginon(LoginDto loginModel)
        {
            if (string.IsNullOrEmpty(loginModel.uname))
            {
                ModelState.AddModelError("err", "用户名不能为空");
            }
            if (string.IsNullOrEmpty(loginModel.pwd))
            {
                ModelState.AddModelError("err", "密码不能为空");
            }
            try
            {
                login_info loginInfo = new login_info();
                var        userAgent = RequestHelper.UserAgent();
                if (userAgent != null)
                {
                    loginInfo.login_name   = loginModel.uname.Trim();
                    loginInfo.browser      = userAgent.Browser;
                    loginInfo.device_info  = userAgent.Device;
                    loginInfo.osinfo       = userAgent.OS;
                    loginInfo.request_ip   = userAgent.Ip;
                    loginInfo.request_time = DateTime.Now;
                    if (NetHelper.IsIntranetIP(loginInfo.request_ip))
                    {
                        loginInfo.real_address = "本地局域网";
                    }
                    else
                    {
                        var ipInfo = IpTool.Search(loginInfo.request_ip);
                        if (ipInfo != null)
                        {
                            loginInfo.real_address = $"{ipInfo.Province}-{ipInfo.City}";
                        }
                        //string filePath = AppDomain.CurrentDomain.BaseDirectory + @"data\ip2region.db";
                        //DbSearcher dbSearcher = new DbSearcher(filePath);
                        //var dataBlock = dbSearcher.BtreeSearch("120.195.209.125");
                        //loginInfo.real_address = dataBlock.ToString();
                    }
                }
                var user         = _userApp.LoginValidate(loginModel.uname.Trim(), loginModel.pwd.Trim());
                var loginUserDto = new LoginUserDto();
                if (user != null)
                {
                    if (user.user_avatar.IsEmpty())
                    {
                        user.user_avatar = "/ui/images/profile.jpg";
                    }
                    loginUserDto.Id        = user.id;
                    loginUserDto.LoginName = user.login_name;
                    loginUserDto.UserName  = user.user_name;
                    loginUserDto.IsSuper   = user.is_super == 1;
                    loginUserDto.DeptId    = user.dept_id;
                    loginUserDto.Avatar    = user.user_avatar;
                    loginUserDto.RoleId    = user.role_id;
                    loginUserDto.DeptName  = user.dept_name;
                    loginUserDto.Gender    = user.gender;
                    loginUserDto.Phone     = user.mobile_phone;
                    loginUserDto.Email     = user.email;
                    if (user.role_id > 0)
                    {
                        sys_role role = _roleApp.GetRoleById(user.role_id);
                        if (role != null)
                        {
                            loginUserDto.RoleCode = role.role_code;
                            loginUserDto.RoleName = role.role_name;
                        }
                    }

                    //插入登录信息
                    loginInfo.login_status  = 1;
                    loginInfo.login_message = "登录成功";
                    loginInfoApp.InsertLoginInfo(loginInfo);

                    //设置cookie
                    // FormsAuthentication.SetAuthCookie(loginUserDto.AccountName, false);
                    string claimstr = loginUserDto.ToJson();
                    RequestHelper.SetCookie(claimstr);


                    return(Redirect("/admin/Home/Index"));
                }

                //插入登录信息
                loginInfo.login_message = "用户名或密码错误";
                loginInfoApp.InsertLoginInfo(loginInfo);
                ModelState.AddModelError("err", "用户名或密码错误");
            }
            catch (Exception e)
            {
                LoggerHelper.Exception(e);
                ModelState.AddModelError("err", "登录异常");
            }

            return(View("Index", loginModel));
        }
コード例 #15
0
        private void btnSign_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string    AllowIpRange = "";
            DataTable dt           = MSCE.GetDataTable("select AllowIpRange from NowLogin");

            if (dt.Rows.Count > 0)
            {
                AllowIpRange = dt.Rows[0]["AllowIpRange"].ToString();
            }
            if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false)
            {
                string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String;
                AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", CourseOrMeeting_String.Equals("課程") ? "教" : CourseOrMeeting_String));
                //AutoClosingMessageBox.Show("您不在會議室範圍內,無法使用此功能");
                return;
            }

            Home_ChangeTogSignPadCT_Event(signinDataUser.ID, signinDataUser.Name);
        }
コード例 #16
0
        private void txtUnSigned_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string    AllowIpRange = "";
            DataTable dt           = MSCE.GetDataTable("select AllowIpRange from NowLogin");

            if (dt.Rows.Count > 0)
            {
                AllowIpRange = dt.Rows[0]["AllowIpRange"].ToString();
            }

            if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false)
            {
                AutoClosingMessageBox.Show("您不在會議室範圍內,無法使用此功能");
                return;
            }

            if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false)
            {
                AutoClosingMessageBox.Show("您不在會議室範圍內,無法使用此功能");
                return;
            }


            Home Home_Window = Application.Current.Windows.OfType <Home>().FirstOrDefault();

            if (Home_Window != null)
            {
                string DeptID = signinDataUser.DeptID == null ? "" : signinDataUser.DeptID;
                if (signinDataUser.ID.Trim().Equals("") == false)
                {
                    Home_Window.CC.Content = new SignPadCT(signinDataUser.ID, signinDataUser.Name, DeptID, signinDataUser.SignedPic, (x, y) => { Home_Window.CC.Content = new SignListCT_Mix(); });
                }
                else
                {
                    Home_Window.CC.Content = new SignPadCT("dept", string.Format("{0} 來賓", signinDataUser.Dept), DeptID, signinDataUser.SignedPic, (x, y) => { Home_Window.CC.Content = new SignListCT_Mix(); });
                }
            }
        }
コード例 #17
0
ファイル: IpToolExtension.cs プロジェクト: jangocheng/IPTools
 public static IpInfo GetRemoteIpInfo(this HttpContext context)
 {
     return(IpTool.Search(context.Connection.RemoteIpAddress.ToString()));
 }
コード例 #18
0
        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (userButton.ID.Equals("BtnSync"))
            {
                if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false)
                {
                    string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String;
                    AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", CourseOrMeeting_String.Equals("課程")?"教":CourseOrMeeting_String));
                    return;
                }

                if (Home_ReturnSyncStatus_Event != null)
                {
                    Tuple <bool, bool> SyncStatus = Home_ReturnSyncStatus_Event();

                    bool syncSwitch = false;
                    // 沒同步,按下去要變成同步且不是主控
                    if (SyncStatus.Item1 == false)
                    {
                        int       FileNotFinished = 0;
                        DataTable dt = MSCE.GetDataTable(@"select count(ID) as FileNotFinished from NowLogin as nl
                                                       inner join FileRow as fr on nl.UserID=fr.UserID and nl.MeetingID=fr.MeetingID
                                                       where DownloadBytes=0 or DownloadBytes<TotalBytes");
                        if (dt.Rows.Count > 0)
                        {
                            FileNotFinished = (int)dt.Rows[0]["FileNotFinished"];
                        }
                        if (FileNotFinished > 0)
                        {
                            AutoClosingMessageBox.Show(string.Format("請將{0}資料下載完成後,再同步", PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String));
                            return;
                        }
                        syncSwitch = true;
                    }
                    else  //有同步,不是主控,按下去要變成沒有同步
                    {
                        syncSwitch = false;
                    }
                    btnImg.Source = ButtonTool.GetSyncButtonImage(SyncStatus.Item1, SyncStatus.Item2);

                    //string UserID = "";
                    //string UserName = "";
                    //string MeetingID = "";
                    //DataTable dt = MSCE.GetDataTable("select UserID,UserName,UserPWD,MeetingID from NowLogin");
                    //if (dt.Rows.Count > 0)
                    //{
                    //    UserID = dt.Rows[0]["UserID"].ToString();
                    //    UserName = dt.Rows[0]["UserName"].ToString();
                    //    MeetingID = dt.Rows[0]["MeetingID"].ToString();
                    //}


                    Task.Factory.StartNew(() =>
                    {
                        AutoClosingMessageBox.Show("連線中");
                        int i = 1;
                        while (i <= 10)
                        {
                            SocketClient socketClient = Singleton_Socket.GetInstance(MeetingID, UserID, UserName, syncSwitch);
                            Thread.Sleep(1);
                            if (socketClient != null && socketClient.GetIsConnected() == true)
                            {
                                socketClient.syncSwitch(syncSwitch);
                                break;
                            }
                            else
                            {
                                Singleton_Socket.ClearInstance();
                                if (i == 10)
                                {
                                    AutoClosingMessageBox.Show("同步伺服器尚未啟動,請聯絡議事管理員開啟同步");
                                }
                            }

                            Thread.Sleep(10);
                            i++;
                        }
                    });
                }
            }
            else
            {
                if (userButton.ID.Equals("BtnIndividualSign") || userButton.ID.Equals("BtnBroadcast"))
                {
                    if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false)
                    {
                        string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String;
                        AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", CourseOrMeeting_String.Equals("課程") ? "教" : CourseOrMeeting_String));
                        //AutoClosingMessageBox.Show("您不在會議室範圍內,無法使用此功能");
                        return;
                    }
                }

                btnImg.Source = ButtonTool.GetButtonImage(userButton.ID, true);

                if (Home_PopUpButtons_Event != null)
                {
                    Home_PopUpButtons_Event(userButton.ID);
                }
            }



            //if(userButton.ID.Equals("BtnQuit")==true)
            //{
            //        DataTable dt = MSCE.GetDataTable("select HomeUserButtonAryJSON from NowLogin");
            //        if (dt.Rows.Count > 0)
            //        {
            //           string HomeUserButtonAryJSON = dt.Rows[0]["HomeUserButtonAryJSON"].ToString();
            //           Task.Factory.StartNew(() =>
            //               {
            //                   Home_ChangeBtnSP_Event(JsonConvert.DeserializeObject<UserButton[]>(HomeUserButtonAryJSON), "BtnHome");
            //               });

            //        }
            //}

            //改變按鈕列表
            Task.Factory.StartNew(() =>
            {
                Home_ChangeCC_Event(userButton);
            });
        }
コード例 #19
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
 /// <summary>
 /// Get the region throught the ip address with binary search algorithm.
 /// </summary>
 public DataBlock BinarySearch(String ip)
 {
     return(BinarySearch(IpTool.Ip2long(ip)));
 }
コード例 #20
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
        /// <summary>
        /// Get the region with a int ip address with binary search algorithm.
        /// </summary>
        private DataBlock BinarySearch(long ip)
        {
            int blen = IndexBlock.LENGTH;

            if (_totalIndexBlocks == 0)
            {
                _raf.Seek(0L, SeekOrigin.Begin);
                byte[] superBytes = new byte[8];
                _raf.Read(superBytes, 0, superBytes.Length);
                //initialize the global vars
                _firstIndexPtr    = IpTool.GetIntLong(superBytes, 0);
                _lastIndexPtr     = IpTool.GetIntLong(superBytes, 4);
                _totalIndexBlocks = (int)((_lastIndexPtr - _firstIndexPtr) / blen) + 1;
            }

            //search the index blocks to define the data
            int l = 0, h = _totalIndexBlocks;

            byte[] buffer = new byte[blen];
            long   sip    = 0;

            while (l <= h)
            {
                int m = (l + h) >> 1;
                _raf.Seek(_firstIndexPtr + m * blen, SeekOrigin.Begin);    //set the file pointer
                _raf.Read(buffer, 0, buffer.Length);
                sip = IpTool.GetIntLong(buffer, 0);
                if (ip < sip)
                {
                    h = m - 1;
                }
                else
                {
                    sip = IpTool.GetIntLong(buffer, 4);
                    if (ip > sip)
                    {
                        l = m + 1;
                    }
                    else
                    {
                        sip = IpTool.GetIntLong(buffer, 8);
                        break;
                    }
                }
            }
            //not matched
            if (sip == 0)
            {
                return(null);
            }
            //get the data
            int dataLen = (int)((sip >> 24) & 0xFF);
            int dataPtr = (int)((sip & 0x00FFFFFF));

            _raf.Seek(dataPtr, SeekOrigin.Begin);
            byte[] data = new byte[dataLen];
            _raf.Read(data, 0, data.Length);
            int    city_id = (int)IpTool.GetIntLong(data, 0);
            String region  = Encoding.UTF8.GetString(data, 4, data.Length - 4);//new String(data, 4, data.Length - 4, "UTF-8");

            return(new DataBlock(city_id, region, dataPtr));
        }
コード例 #21
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
 /// <summary>
 /// Get the region throught the ip address with b-tree search algorithm.
 /// </summary>
 public DataBlock BtreeSearch(string ip)
 {
     return(BtreeSearch(IpTool.Ip2long(ip)));
 }
コード例 #22
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
        /// <summary>
        /// Get the region with a int ip address with b-tree algorithm.
        /// </summary>
        private DataBlock BtreeSearch(long ip)
        {
            //check and load the header
            if (_headerSip == null)
            {
                _raf.Seek(8L, SeekOrigin.Begin);    //pass the super block
                byte[] b = new byte[4096];
                _raf.Read(b, 0, b.Length);
                //fill the header
                int len = b.Length >> 3, idx = 0;  //b.lenght / 8
                _headerSip = new long[len];
                _headerPtr = new int[len];
                long startIp, dataPtrTemp;
                for (int i = 0; i < b.Length; i += 8)
                {
                    startIp     = IpTool.GetIntLong(b, i);
                    dataPtrTemp = IpTool.GetIntLong(b, i + 4);
                    if (dataPtrTemp == 0)
                    {
                        break;
                    }

                    _headerSip[idx] = startIp;
                    _headerPtr[idx] = (int)dataPtrTemp;
                    idx++;
                }
                _headerLength = idx;
            }

            //1. define the index block with the binary search
            if (ip == _headerSip[0])
            {
                return(GetByIndexPtr(_headerPtr[0]));
            }
            else if (ip == _headerPtr[_headerLength - 1])
            {
                return(GetByIndexPtr(_headerPtr[_headerLength - 1]));
            }
            int l = 0, h = _headerLength, sptr = 0, eptr = 0;
            int m = 0;

            while (l <= h)
            {
                m = (l + h) >> 1;
                //perfectly matched, just return it
                if (ip == _headerSip[m])
                {
                    if (m > 0)
                    {
                        sptr = _headerPtr[m - 1];
                        eptr = _headerPtr[m];
                    }
                    else
                    {
                        sptr = _headerPtr[m];
                        eptr = _headerPtr[m + 1];
                    }
                }
                //less then the middle value
                else if (ip < _headerSip[m])
                {
                    if (m == 0)
                    {
                        sptr = _headerPtr[m];
                        eptr = _headerPtr[m + 1];
                        break;
                    }
                    else if (ip > _headerSip[m - 1])
                    {
                        sptr = _headerPtr[m - 1];
                        eptr = _headerPtr[m];
                        break;
                    }
                    h = m - 1;
                }
                else
                {
                    if (m == _headerLength - 1)
                    {
                        sptr = _headerPtr[m - 1];
                        eptr = _headerPtr[m];
                        break;
                    }
                    else if (ip <= _headerSip[m + 1])
                    {
                        sptr = _headerPtr[m];
                        eptr = _headerPtr[m + 1];
                        break;
                    }
                    l = m + 1;
                }
            }
            //match nothing just stop it
            if (sptr == 0)
            {
                return(null);
            }
            //2. search the index blocks to define the data
            int blockLen = eptr - sptr, blen = IndexBlock.LENGTH;

            byte[] iBuffer = new byte[blockLen + blen];    //include the right border block
            _raf.Seek(sptr, SeekOrigin.Begin);
            _raf.Read(iBuffer, 0, iBuffer.Length);
            l = 0; h = blockLen / blen;
            long sip = 0;
            int  p   = 0;

            while (l <= h)
            {
                m   = (l + h) >> 1;
                p   = m * blen;
                sip = IpTool.GetIntLong(iBuffer, p);
                if (ip < sip)
                {
                    h = m - 1;
                }
                else
                {
                    sip = IpTool.GetIntLong(iBuffer, p + 4);
                    if (ip > sip)
                    {
                        l = m + 1;
                    }
                    else
                    {
                        sip = IpTool.GetIntLong(iBuffer, p + 8);
                        break;
                    }
                }
            }
            //not matched
            if (sip == 0)
            {
                return(null);
            }
            //3. get the data
            int dataLen = (int)((sip >> 24) & 0xFF);
            int dataPtr = (int)((sip & 0x00FFFFFF));

            _raf.Seek(dataPtr, SeekOrigin.Begin);
            byte[] data = new byte[dataLen];
            _raf.Read(data, 0, data.Length);
            int    city_id = (int)IpTool.GetIntLong(data, 0);
            String region  = Encoding.UTF8.GetString(data, 4, data.Length - 4);// new String(data, 4, data.Length - 4, "UTF-8");

            return(new DataBlock(city_id, region, dataPtr));
        }
コード例 #23
0
ファイル: DbSearcher.cs プロジェクト: lulzzz/Virgo
 /// <summary>
 /// Get the region throught the ip address with memory binary search algorithm.
 /// </summary>
 public DataBlock MemorySearch(string ip)
 {
     return(MemorySearch(IpTool.Ip2long(ip)));
 }
コード例 #24
0
ファイル: IpToolExtension.cs プロジェクト: jangocheng/IPTools
 /// <summary>
 /// Get ip info from request header.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="headerKey">request header key.</param>
 /// <returns></returns>
 public static IpInfo GetRemoteIpInfo(this HttpContext context, string headerKey)
 {
     return(IpTool.Search(context.Request.Headers[headerKey]));
 }
コード例 #25
0
        private void btnYes_MouseDown(object sender, MouseButtonEventArgs e)
        {
            //if (StackLines.Count < 1 || txtPLS.Visibility == Visibility.Visible)
            if (SignPad.Strokes.Count < 1 || txtPLS.Visibility == Visibility.Visible)
            {
                if (PicUrl.Equals("") == false)
                {
                    MessageBox.Show("已簽名,欲重新簽名請先按x清除");
                    return;
                }
                else
                {
                    MessageBox.Show("請簽名後上傳");
                    return;
                }
            }


            string    AllowIpRange = "";
            DataTable dt           = MSCE.GetDataTable("select AllowIpRange from NowLogin");

            if (dt.Rows.Count > 0)
            {
                AllowIpRange = dt.Rows[0]["AllowIpRange"].ToString();
            }
            if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false)
            {
                string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String;
                AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", CourseOrMeeting_String.Equals("課程") ? "教" : CourseOrMeeting_String));
                return;
            }

            // 系統暫存資料夾
            //string tempPath = System.IO.Path.GetTempPath(); //Environment.GetEnvironmentVariable("TEMP");
            string SignInFolder = System.IO.Path.Combine(ClickOnceTool.GetFilePath(), PaperLess_Emeeting.Properties.Settings.Default.SignInFolder);

            SignInFolder = System.IO.Path.Combine(SignInFolder, MeetingID, UserID);
            Directory.CreateDirectory(SignInFolder);
            string      GUID         = Guid.NewGuid().ToString();
            string      tempFileName = GUID + ".png";
            string      filePath     = System.IO.Path.Combine(SignInFolder, tempFileName);
            Application app          = Application.Current;

            //(1) Canvas
            CanvasTool.SaveCanvas(app.Windows[0], this.SignPad, 96, filePath);

            //(2) InkCanvas
            //double width = SignPad.ActualWidth;
            //double height = SignPad.ActualHeight;
            //RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
            //DrawingVisual dv = new DrawingVisual();
            //using (DrawingContext dc = dv.RenderOpen())
            //{
            //    VisualBrush vb = new VisualBrush(SignPad);
            //    dc.DrawRectangle(vb, null, new Rect(new System.Windows.Point(), new System.Windows.Size(width, height)));
            //}
            //bmpCopied.Render(dv);
            //System.Drawing.Bitmap bitmap;
            //using (MemoryStream outStream = new MemoryStream())
            //{
            //    // from System.Media.BitmapImage to System.Drawing.Bitmap
            //    BitmapEncoder enc = new BmpBitmapEncoder();
            //    enc.Frames.Add(BitmapFrame.Create(bmpCopied));
            //    enc.Save(outStream);
            //    bitmap = new System.Drawing.Bitmap(outStream);
            //}

            //EncoderParameter qualityParam =new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 85L);

            //// Jpeg image codec
            //ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg");

            //if (jpegCodec == null)
            //    return;

            //EncoderParameters encoderParams = new EncoderParameters(1);
            //encoderParams.Param[0] = qualityParam;
            //Bitmap btm = new Bitmap(bitmap);
            //bitmap.Dispose();
            //btm.Save(filePath, jpegCodec, encoderParams);
            //btm.Dispose();

            //SigninDataUpload sdu = GetSigninDataUpload.POST(MeetingID, "UserID", filePath);
            MouseTool.ShowLoading();

            if (UserID.Equals("guest") == true)
            {
                UserID_Origin = UserID;
                UserID        = "";
            }
            else if (UserID.Equals("dept") == true)
            {
                UserID_Origin = UserID;
                UserID        = "";
            }
            GetSigninDataUpload.AsyncPOST(MeetingID, UserID, DeptID, filePath, (sdu) => { GetSigninDataUpload_DoAction(sdu); });
        }