コード例 #1
0
        public static Boolean SendAuthority(string file_path, string authority_number)
        {
            bool isRequest = false;
            var  thread    = new Thread(() =>
            {
                var request = (HttpWebRequest)WebRequest.Create(MyKeys.SENDURL);

                string source = "file_path=" + file_path
                                + "&authority_number=" + authority_number;
                source = Encrypt(source);

                var postData = "model=" + PostOptions.SENDAUTHORITY;
                postData    += "&user_id=" + UrlEncode(MyKeys.USER_ID, Encoding.UTF8);
                postData    += "&guid=" + UrlEncode(MyKeys.GUID, Encoding.UTF8);
                postData    += source;

                var data = Encoding.UTF8.GetBytes(postData);

                request.Method        = "POST";
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                var response       = (HttpWebResponse)request.GetResponse();
                var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                responseString     = Decrypt(responseString);
                Console.WriteLine("responseString:" + responseString);

                string[] sourceStrArray = responseString.Split('&');
                string status           = sourceStrArray[0].Split('=')[1].ToString();
                Console.WriteLine("status:" + status);

                if (status.Equals("OK"))
                {
                    File.AppendAllText("C:\\Windows\\System32\\drivers\\elocklist.lock", file_path.Replace("/", "\\") + "\r\n");
                    CFunction.UpdateFiles();
                    Console.WriteLine("SEND");
                    isRequest = true;
                }

                Thread.Sleep(TimeSpan.FromMilliseconds(1000));
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            return(isRequest);
        }
コード例 #2
0
        public static string GetRealPath(string path)
        {
            string        realPath        = path;
            StringBuilder pathInformation = new StringBuilder(250);
            string        driveLetter     = System.IO.Path.GetPathRoot(realPath).Replace("\\", "");

            CFunction.QueryDosDevice(driveLetter, pathInformation, 250);

            // If drive is substed, the result will be in the format of "\??\C:\RealPath\".

            // Strip the \??\ prefix.
            string realRoot = pathInformation.ToString();

            //Combine the paths.
            realPath = System.IO.Path.Combine(realRoot, realPath.Replace(System.IO.Path.GetPathRoot(realPath), ""));


            return(realPath);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: lrh12580/elock
        private void requestMethod()
        {
            thread = new Thread(() =>
            {
                ulong temp         = 0;
                StringBuilder path = new StringBuilder(256);
                while (true)
                {
                    bool isGet = CFunction.SimpleGetMessage(ref temp, path, 256);
                    if (isGet == true && temp != 0)
                    {
                        StringBuilder devicepath    = ChangePath.ChangePaths(path).Replace("\\", "/");
                        Dictionary <int, bool> dict = new Dictionary <int, bool>();
                        dict = isContain(devicepath);
                        if (dict[1])
                        {
                            if (dict[2])
                            {
                                CFunction.SimpleReplyMessage(temp, true);
                            }
                            else
                            {
                                CFunction.SimpleReplyMessage(temp, false);
                            }
                        }
                        else
                        {
                            //Window1 window = new Window1(devicepath, temp);
                            //window.Show();

                            //if (System.Windows.MessageBox.Show("请通过手机验证", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                            if (createMessageBox(path))
                            {
                                if (MainWindow.isSigined)
                                {
                                    if (Post.SendCheck(devicepath.ToString(), "1"))
                                    {
                                        DateTime date = DateTime.Now;
                                        CFunction.SimpleReplyMessage(temp, true);
                                        permissions.Add(new Mypermission(devicepath, true, date));
                                    }
                                    else
                                    {
                                        DateTime date = DateTime.Now;
                                        CFunction.SimpleReplyMessage(temp, false);
                                        permissions.Add(new Mypermission(devicepath, false, date));
                                    }
                                }
                                else
                                {
                                    System.Windows.MessageBox.Show("您还未登录!", "e-lock", MessageBoxButton.OK);
                                }
                            }

                            else
                            {
                                DateTime date = DateTime.Now;
                                CFunction.SimpleReplyMessage(temp, false);
                                permissions.Add(new Mypermission(devicepath, false, date));
                            }
                        }
                        Thread.Sleep(TimeSpan.FromMilliseconds(10));
                    }
                    else
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(1000));
                    }
                }
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
コード例 #4
0
ファイル: PageMain.xaml.cs プロジェクト: lrh12580/elock
        private void DecreaseButton_Click(object sender, RoutedEventArgs e)
        {
            Authority emp = mylistview.SelectedItem as Authority;

            if (emp != null)
            {
                Dispatcher.Invoke(new Action(() =>  //BeginInvoke是异步操作,Invoke是同步操作。
                {
                    if (CMessageBox.Show("确认删除吗?", "e-Lock消息", CMessageBoxButton.YesNO, CMessageBoxImage.None, CMessageBoxDefaultButton.Yes) == CMessageBoxResult.Yes)
                    {
                        if (MainWindow.isSigined)
                        {
                            //网络请求
                            string filepath = emp.File_Path;
                            if (Post.SendCheck(filepath.Replace("\\", "/"), "0") == true)
                            {
                                string filelist = File.ReadAllText("C:\\Windows\\System32\\drivers\\elocklist.lock");
                                filelist        = filelist.Replace("\r", "");
                                string[] array  = filelist.Split('\n');
                                string result   = "";
                                for (int i = 0; i < array.Length; i++)
                                {
                                    if (array[i].Equals(""))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        if (array[i].Equals(filepath))
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            result += array[i] + "\r\n";
                                        }
                                    }
                                }
                                File.WriteAllText("C:\\Windows\\System32\\drivers\\elocklist.lock", result);
                                CFunction.UpdateFiles();

                                thelist.Clear();
                                ObservableCollection <Authority> mainlist = Post.GetAuthorityList();
                                foreach (Authority item in mainlist)
                                {
                                    item.File_Name = item.File_Path.Split('/').Last();
                                    item.File_Path = item.File_Path.Replace("/", "\\");
                                    thelist.Add(item);
                                }
                            }
                        }
                        else
                        {
                            System.Windows.MessageBox.Show("您还未登录!", "e-lock", MessageBoxButton.OK);
                        }
                    }
                }));
            }

            //DeleteGrid.Visibility = Visibility.Visible;
        }