Example #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);
        }
Example #2
0
        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;
        }