加入和服务器交互,必须登录服务器账号才能允许加入飞机

飞机数量控制以前的ini方式去掉,改为仅仅账号控制
加入登录登出服务器日志
加入飞行任务服务器日志
加入修改密码功能
用户级别也只能用账号方式控制
超级用户硬编码到代码里,不用登录服务器:admin 密码 fxmf0622
This commit is contained in:
xu 2020-02-25 03:50:34 +08:00
parent 6cb44d5401
commit 92044ae56b
13 changed files with 601 additions and 64 deletions

View File

@ -69,7 +69,7 @@ namespace Plane.FormationCreator
}; };
//new Test().Prepare().Run(); //new Test().Prepare().Run();
VersionControl.GetVersionFromIni(); VersionControl.GetSettingFromIni();
} }
private ILogger _logger; private ILogger _logger;
@ -177,16 +177,19 @@ namespace Plane.FormationCreator
{ {
await Dispatcher.BeginInvoke(new Action(() => await Dispatcher.BeginInvoke(new Action(() =>
{ {
copter = new Copter(Connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng) if (_copterManager.EnAddCopter_Real())
{ {
Id = ip, copter = new Copter(Connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng)
Name = ip.Substring(ip.LastIndexOf('.') + 1) {
Id = ip,
Name = ip.Substring(ip.LastIndexOf('.') + 1)
}; };
int _index; int _index;
_index=copters.AddCopter(copter); _index = copters.AddCopter(copter);
copterStatus.Insert(_index,false); copterStatus.Insert(_index, false);
copter.TextReceived += Copter_TextReceived; copter.TextReceived += Copter_TextReceived;
}
})); }));
} }
else else
@ -243,17 +246,21 @@ namespace Plane.FormationCreator
var copter = _copterManager.Copters.FirstOrDefault(c => c.Id == id.ToString()); var copter = _copterManager.Copters.FirstOrDefault(c => c.Id == id.ToString());
if (copter == null) if (copter == null)
{ {
var copterStatus = _copterManager.CopterStatus; if (_copterManager.EnAddCopter_Real())
var connection = new CommConnection();
copter = new Copter(connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng)
{ {
Id = id.ToString(),
Name = id.ToString(), var copterStatus = _copterManager.CopterStatus;
}; var connection = new CommConnection();
int _index; copter = new Copter(connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng)
_index = _copterManager.Copters.AddCopter(copter); {
copterStatus.Insert(_index, false); Id = id.ToString(),
copter.TextReceived += Copter_TextReceived; Name = id.ToString(),
};
int _index;
_index = _copterManager.Copters.AddCopter(copter);
copterStatus.Insert(_index, false);
copter.TextReceived += Copter_TextReceived;
}
} }
} }
})); }));

View File

@ -8,12 +8,25 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Plane.FormationCreator.Util; using Plane.FormationCreator.Util;
using Microsoft.Practices.ServiceLocation;
using Plane.FormationCreator.ViewModels;
using System.Threading;
using Plane.Communication;
using Plane.Util;
using System.Windows;
using Plane.Windows.Messages;
namespace Plane.FormationCreator.Formation namespace Plane.FormationCreator.Formation
{ {
public class CopterCollection : ObservableCollection<ICopter> public class CopterCollection : ObservableCollection<ICopter>
{ {
public int EnCopterNumber = 0;
public int EnVCopterNumber = 0;
/// <summary> /// <summary>
/// 实现排序插入 /// 实现排序插入
/// </summary> /// </summary>
@ -33,12 +46,39 @@ namespace Plane.FormationCreator.Formation
throw new NotImplementedException(); throw new NotImplementedException();
} }
/*
if (this.Count >= VersionControl.CopterUpperLimit) if (this.Count >= VersionControl.CopterUpperLimit)
{ {
return 0; return 0;
} }
//网络登录限制
// if (!VersionControl.IsFullVersion)
{
if (entityObject is FakeCopter)
{
if (this.Count >= EnVCopterNumber)
{
return 0;
}
}
else
{
if (this.Count >= EnCopterNumber)
{
return 0;
}
}
}
*/
int _index = 0; int _index = 0;
if (this.Count == 0) if (this.Count == 0)
{ {
@ -88,6 +128,16 @@ namespace Plane.FormationCreator.Formation
public class CopterManager : ObservableObject public class CopterManager : ObservableObject
{ {
const string supername = "admin";
const string superpass = "fxmf0622";
//服务器地址
const string strUrlPre = "http://111.229.174.37:81/login/checkforapp.php";
//用户级别
const int LEVEL_NORMAL = 1;
const int LEVEL_ADMIN = 0;
private string superDispname = "超级用户";
public CopterManager() public CopterManager()
{ {
AppEx.Current.AppModeChanged += (sender, e) => AppEx.Current.AppModeChanged += (sender, e) =>
@ -112,9 +162,12 @@ namespace Plane.FormationCreator.Formation
set { Set(nameof(scale3d), ref _scale3d, value); } set { Set(nameof(scale3d), ref _scale3d, value); }
} }
public delegate void NetStatusChanged(bool Logined, string status);
public event NetStatusChanged netStatusChanged;
public CopterCollection Copters { get;} = new CopterCollection(); public CopterCollection Copters { get;} = new CopterCollection();
//标记某飞机是否需要跳过
public ArrayList CopterStatus = new ArrayList(); public ArrayList CopterStatus = new ArrayList();
//public ObservableCollection<ICopter> Copters //public ObservableCollection<ICopter> Copters
//{ //{
@ -134,6 +187,295 @@ namespace Plane.FormationCreator.Formation
// } // }
//} //}
private string _Loginstate = "未登录";
public string Loginstate
{
get { return _Loginstate; }
set
{
Set(nameof(Loginstate), ref _Loginstate, value);
netStatusChanged(Logined,Loginstate);
}
}
private int _EnCopterNumber = 0;
public int EnCopterNumber
{
get { return _EnCopterNumber; }
set
{
Set(nameof(EnCopterNumber), ref _EnCopterNumber, value);
Copters.EnCopterNumber = EnCopterNumber;
}
}
private int _EnVCopterNumber = 0;
public int EnVCopterNumber
{
get { return _EnVCopterNumber; }
set
{
Set(nameof(EnVCopterNumber), ref _EnVCopterNumber, value);
Copters.EnVCopterNumber = EnVCopterNumber;
}
}
private bool _Logined = false;
public bool Logined
{
get { return _Logined; }
set
{
Set(nameof(Logined), ref _Logined, value);
netStatusChanged(Logined, Loginstate);
}
}
private string _UserName = "";
private string _UserDisplayName = "";
public void NetLogined(string UserName,string UserDisplayName,int vEnCopterNumber,int vEnVCopterNumber,int userlever=1)
{
_UserName = UserName;
EnCopterNumber = vEnCopterNumber;
EnVCopterNumber = vEnVCopterNumber;
_UserDisplayName = UserDisplayName;
string dis_EnCopterNumber ="<"+ EnCopterNumber.ToString()+">";
string dis_EnVCopterNumber = "<" + EnVCopterNumber.ToString() + ">";
if (EnCopterNumber == -1) dis_EnCopterNumber = "<无限>";
if (EnVCopterNumber == -1) dis_EnVCopterNumber = "<无限>";
Loginstate ="["+ UserDisplayName + "]已登录,模拟飞机:"+ dis_EnVCopterNumber + "架,真实飞机:"+ dis_EnCopterNumber + "架";
Logined = true;
VersionControl.SetUserLever(userlever);
if (UserName != supername)
{
Task.Run(async () =>
{
while (Logined)
{
NetActivePost();
//30秒一次保持活跃
await Task.Delay(30 * 1000).ConfigureAwait(false);
}
}).ConfigureAwait(false);
}
}
private void NetActivePost()
{
// 发送请求
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
sbUrl.Append(strUrlPre);
sbUrl.Append("?");
sbUrl.Append("username=" + _UserName);
sbUrl.Append("&type=Active");
String strUrl = sbUrl.ToString();
string errorstr;
new AsynDataUtils().AsynGetData(strUrl, null,out errorstr);
}
private void NetLogoutPost()
{
// 发送请求
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
sbUrl.Append(strUrlPre);
sbUrl.Append("?");
sbUrl.Append("username=" + _UserName);
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
sbUrl.Append("&type=Logout");
String strUrl = sbUrl.ToString();
string errorstr;
new AsynDataUtils().AsynGetData(strUrl, null, out errorstr);
}
public void NetLogout()
{
if (Logined)
NetLogoutPost();
Logined = false;
EnCopterNumber = 0;
EnVCopterNumber = 0;
_UserDisplayName = "";
_UserName = "";
VersionControl.SetUserLever(LEVEL_NORMAL);
Loginstate = "未登录";
}
//提交飞行记录
public void Net_PostStartMission(DateTime MissionTime,double OriginLng, double OriginLat)
{
// 发送请求
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
sbUrl.Append(strUrlPre);
sbUrl.Append("?");
sbUrl.Append("username=" + _UserName);
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
sbUrl.Append("&type=StartMission");
sbUrl.Append("&mtime="+ MissionTime.ToString());
sbUrl.Append("&orgLng="+ OriginLng.ToString());
sbUrl.Append("&orgLat="+ OriginLat.ToString());
sbUrl.Append("&coptercount=" + Copters.Count().ToString());
String strUrl = sbUrl.ToString();
string errorstr;
new AsynDataUtils().AsynGetData(strUrl, null, out errorstr);
}
private string tempuser;
private string tempPassword;
private bool tempSavePassword;
//在这个方法里面接收回调的返回信息
private void DataResultCallBack(string data,bool haveerror)
{
if (haveerror)
{
Loginstate = "登录失败,"+ data;
return;
}
if (data == "")
{
Loginstate = "登录失败,请检查网络连接";
return;
}
string[] arr = data.Split(';');
string loginret = arr[0];
if (loginret == "Login ok")
{
if (arr.Length!= 5)
{
Alert.Show("系统版本不正确!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
string UserDisplayName = arr[1];
int vEnCopterNumber = int.Parse(arr[2]);
int vEnVCopterNumber = int.Parse(arr[3]);
int userlevel = int.Parse(arr[4]);
NetLogined(tempuser, UserDisplayName, vEnCopterNumber, vEnVCopterNumber, userlevel);
VersionControl.SaveLogininfoToIni(tempuser, tempPassword, tempSavePassword);
//MessageBox.Show(UserDisplayName + " 登录成功!", "登录提示");
}
else
if (loginret == "username error")
{
NetLogout();
Alert.Show("账号错误!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
if (loginret == "password error")
{
NetLogout();
Alert.Show("密码错误!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
if (loginret == "replogin error")
{
NetLogout();
Alert.Show("该账号已在其他地方登录!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
public void NetLogoin(string username,string password,bool savepassword)
{
Logined = false;
//超级用户,无限制
if ((username== supername) && (password== superpass))
{
NetLogined(supername, superDispname, -1, -1, LEVEL_ADMIN);
return;
}
tempuser = username;
tempPassword = password;
tempSavePassword = savepassword;
// 发送请求
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
sbUrl.Append(strUrlPre);
sbUrl.Append("?");
sbUrl.Append("username=" + username);
sbUrl.Append("&" + "password=" + password);
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
String strUrl = sbUrl.ToString();
string errorstr;
if (new AsynDataUtils().AsynGetData(strUrl, DataResultCallBack, out errorstr))
Loginstate = "登录中...";
else Loginstate = "登录失败,"+ errorstr;
}
//在这个方法里面接收回调的返回信息
private void DataResultCallBack_changepassword(string data, bool haveerror)
{
if (haveerror)
{
MessageBox.Show("更改失败," + data, "提示");
return;
}
if (data == "")
{
MessageBox.Show("更改失败,请检查网络", "提示");
return;
}
string[] arr = data.Split(';');
string loginret = arr[0];
if (loginret == "chpassword ok")
{
MessageBox.Show( "密码更改成功!", "提示");
}
else
if (loginret == "username error")
{
MessageBox.Show("账号错误!", "提示");
}
else
if (loginret == "password error")
{
MessageBox.Show("原密码错误!", "提示");
}
}
public void NetChangePassword(string username, string oldpassword, string newpassword)
{
tempuser = username;
tempPassword = oldpassword;
// 发送请求
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
sbUrl.Append(strUrlPre);
sbUrl.Append("?");
sbUrl.Append("username=" + username);
sbUrl.Append("&password=" + oldpassword);
sbUrl.Append("&clientname=" + System.Net.Dns.GetHostName());
sbUrl.Append("&type=Chpassword");
sbUrl.Append("&newpassword=" + newpassword);
String strUrl = sbUrl.ToString();
string errorstr;
if (!new AsynDataUtils().AsynGetData(strUrl, DataResultCallBack_changepassword, out errorstr))
MessageBox.Show("更改失败," + errorstr, "提示");
}
public bool shiftkeydown; public bool shiftkeydown;
public IEnumerable<ICopter> SelectedCopters { get { return _selectedCoptersGetter().Cast<ICopter>(); } } public IEnumerable<ICopter> SelectedCopters { get { return _selectedCoptersGetter().Cast<ICopter>(); } }
@ -166,10 +508,28 @@ namespace Plane.FormationCreator.Formation
SeletedCopterCount = SelectedCopters.Count(); SeletedCopterCount = SelectedCopters.Count();
} }
public bool EnAddCopter_Real()
{
if (EnCopterNumber == -1) return true;
else
return Copters.Count < EnCopterNumber;
}
public bool EnAddCopter_Fake()
{
if (EnVCopterNumber == -1) return true;
else
return Copters.Count < EnVCopterNumber;
}
/// <summary> /// <summary>
/// 选择飞机 /// 选择飞机
/// </summary> /// </summary>
/// <param name="copter">Null表示清除所有选择</param> /// <param name="copter">Null表示清除所有选择</param>
public void Select(ICopter copter) public void Select(ICopter copter)
{ {
_selectCopterAction(copter); _selectCopterAction(copter);

View File

@ -18,7 +18,9 @@
PreviewKeyUp="MetroWindow_PreviewKeyUp" PreviewKeyUp="MetroWindow_PreviewKeyUp"
Style="{StaticResource VSWindowStyleKey}" Style="{StaticResource VSWindowStyleKey}"
Width="1920" Width="1920"
Height="1080" > Height="1080"
Closing="Window_Closing"
>
<c:MetroWindow.Resources> <c:MetroWindow.Resources>
<Style TargetType="Separator" <Style TargetType="Separator"
@ -43,7 +45,7 @@
<c:MetroWindow.RightWindowCommands> <c:MetroWindow.RightWindowCommands>
<c:WindowCommands> <c:WindowCommands>
<Button Content="登陆" <Button Content="{Binding LoginDisp}"
Command="{Binding LoginCommand}" /> Command="{Binding LoginCommand}" />
<Button Content="{Binding AppEx.ShowModifyTaskView, Converter={StaticResource ShowModifyTaskViewButtonContentConverter}}" <Button Content="{Binding AppEx.ShowModifyTaskView, Converter={StaticResource ShowModifyTaskViewButtonContentConverter}}"
@ -237,6 +239,7 @@
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Text="{Binding Loginstate}" Margin="0,4,14,0"/>
<TextBlock Text="通信连接:" Margin="4"/> <TextBlock Text="通信连接:" Margin="4"/>
<ContentPresenter Margin="0,4,14,0" Content="{Binding CommunicationModuleConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" /> <ContentPresenter Margin="0,4,14,0" Content="{Binding CommunicationModuleConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" />
</StackPanel> </StackPanel>

View File

@ -35,9 +35,10 @@ namespace Plane.FormationCreator
InitializeComponent(); InitializeComponent();
this.DataContext = ServiceLocator.Current.GetInstance<MainViewModel>(); this.DataContext = ServiceLocator.Current.GetInstance<MainViewModel>();
// this.OnClosing += Window_Closing;
//改到设置窗口显示版本信息 //改到设置窗口显示版本信息
// var version = Assembly.GetExecutingAssembly().GetName().Version; // var version = Assembly.GetExecutingAssembly().GetName().Version;
// Title = "飞行魔方无人机编队控制系统 V" + version.ToString() + "编译时间[" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString() + "]"; // Title = "飞行魔方无人机编队控制系统 V" + version.ToString() + "编译时间[" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString() + "]";
//ShowConnectDialog(); //ShowConnectDialog();
@ -59,7 +60,17 @@ namespace Plane.FormationCreator
} }
loginWindow.ShowDialog (); loginWindow.ShowDialog ();
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
_copterManager.NetLogout();
/*
MessageBoxResult result = MessageBox.Show("Do you really want to exit?", "", MessageBoxButton.YesNo);
if (result == MessageBoxResult.No)
{
e.Cancel = true;
}
*/
}
private void btnLogin_Click(object sender, RoutedEventArgs e) private void btnLogin_Click(object sender, RoutedEventArgs e)
{ {
var loginWindow = new ConnectWindow var loginWindow = new ConnectWindow
@ -485,7 +496,7 @@ namespace Plane.FormationCreator
{ {
MainViewModel vm = DataContext as MainViewModel; MainViewModel vm = DataContext as MainViewModel;
LogWindow logWindows = new LogWindow(vm.Messages); LogWindow logWindows = new LogWindow(vm.Messages);
logWindows.Show(); logWindows.ShowDialog();
} }
private void LogShowHide(object sender, MouseButtonEventArgs e) private void LogShowHide(object sender, MouseButtonEventArgs e)

View File

@ -195,6 +195,7 @@
<Compile Include="Util\ICommsSerial.cs" /> <Compile Include="Util\ICommsSerial.cs" />
<Compile Include="Util\ICorrections.cs" /> <Compile Include="Util\ICorrections.cs" />
<Compile Include="Util\ParamFile.cs" /> <Compile Include="Util\ParamFile.cs" />
<Compile Include="Util\PasswordBoxHelper.cs" />
<Compile Include="Util\rtcm3.cs" /> <Compile Include="Util\rtcm3.cs" />
<Compile Include="Util\VersionControl.cs" /> <Compile Include="Util\VersionControl.cs" />
<Compile Include="ViewModels\CalibrationViewModel.cs" /> <Compile Include="ViewModels\CalibrationViewModel.cs" />
@ -203,6 +204,8 @@
<Compile Include="ViewModels\ControlPanelViewModel.cs" /> <Compile Include="ViewModels\ControlPanelViewModel.cs" />
<Compile Include="ViewModels\CopterListViewModel.cs" /> <Compile Include="ViewModels\CopterListViewModel.cs" />
<Compile Include="ViewModels\GroupsViewModel.cs" /> <Compile Include="ViewModels\GroupsViewModel.cs" />
<Compile Include="ViewModels\ChangePasswordView.cs" />
<Compile Include="ViewModels\LoginViewModel.cs" />
<Compile Include="ViewModels\MainViewModel.cs" /> <Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\MapViewModel.cs" /> <Compile Include="ViewModels\MapViewModel.cs" />
<Compile Include="ViewModels\ModifyTaskViewModel.cs" /> <Compile Include="ViewModels\ModifyTaskViewModel.cs" />
@ -234,6 +237,12 @@
<Compile Include="Views\ConnectWindow.xaml.cs"> <Compile Include="Views\ConnectWindow.xaml.cs">
<DependentUpon>ConnectWindow.xaml</DependentUpon> <DependentUpon>ConnectWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\ChangePasswordView.xaml.cs">
<DependentUpon>ChangePasswordView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\LoginView.xaml.cs">
<DependentUpon>LoginView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\LogWindow.xaml.cs"> <Compile Include="Views\LogWindow.xaml.cs">
<DependentUpon>LogWindow.xaml</DependentUpon> <DependentUpon>LogWindow.xaml</DependentUpon>
</Compile> </Compile>
@ -373,6 +382,14 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\ChangePasswordView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\LoginView.xaml">
<SubType>Form</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\LogWindow.xaml"> <Page Include="Views\LogWindow.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -34,6 +34,8 @@ namespace Plane.FormationCreator
_container.Register<View3DViewModel>(); _container.Register<View3DViewModel>();
_container.Register<ModifyTaskViewModel>(); _container.Register<ModifyTaskViewModel>();
_container.Register<CalibrationViewModel>(); _container.Register<CalibrationViewModel>();
_container.Register<LoginViewModel>();
_container.Register<ChangePasswordViewModel>();
_container.Register<GroupsViewModel>(); _container.Register<GroupsViewModel>();
_container.Register<RtcmInfoViewModel>(); _container.Register<RtcmInfoViewModel>();
_container.Register<ConfigVirtualIdViewModel>(); _container.Register<ConfigVirtualIdViewModel>();

View File

@ -7,10 +7,14 @@ namespace Plane.Util
{ {
public class AsynDataUtils public class AsynDataUtils
{ {
public delegate void DataResultCallBack(string data); public delegate void DataResultCallBack(string data,bool haveerror);
DataResultCallBack _callback; DataResultCallBack _callback;
public void AsynGetData(string tagUrl, DataResultCallBack callback) bool haveerror;
string errorstr;
public bool AsynGetData(string tagUrl, DataResultCallBack callback, out string verrorstr)
{ {
haveerror = false;
errorstr = "";
try try
{ {
_callback = callback; _callback = callback;
@ -18,8 +22,13 @@ namespace Plane.Util
} }
catch (Exception ex) catch (Exception ex)
{ {
errorstr += ex.Message;
haveerror = true;
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
} }
verrorstr = errorstr;
return !haveerror;
} }
private void ReadCallback(IAsyncResult asynchronousResult) private void ReadCallback(IAsyncResult asynchronousResult)
@ -39,12 +48,17 @@ namespace Plane.Util
Console.WriteLine(resultString); Console.WriteLine(resultString);
if (_callback != null) if (_callback != null)
{ {
_callback(resultString); _callback(resultString,false);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
if (_callback != null)
{
_callback(ex.Message, true);
}
Console.WriteLine(ex.Message);
} }

View File

@ -20,13 +20,30 @@ namespace Plane.FormationCreator.Util
/// </summary> /// </summary>
public static int CopterUpperLimit = 50; public static int CopterUpperLimit = 50;
public static void GetVersionFromIni() public static string Username = "";
public static string Password = "";
public static bool IssavePassword = false;
public static void SetUserLever(int vuserlever)
{
if (vuserlever==0)
//管理员
IsFullVersion = true;
else
IsFullVersion = false;
}
public static void GetSettingFromIni()
{ {
IniFiles iniFiles = new IniFiles(); IniFiles iniFiles = new IniFiles();
int intTemp; int intTemp;
bool boolTemp;
string readvalue; string readvalue;
//完整版本和更多飞机数量通过网络授权或者超级用户得到
/*
readvalue = iniFiles.IniReadvalue("Version", "Version"); readvalue = iniFiles.IniReadvalue("Version", "Version");
if (readvalue != "" && int.TryParse(readvalue, out intTemp)) if (readvalue != "" && int.TryParse(readvalue, out intTemp))
Version = int.Parse(readvalue); Version = int.Parse(readvalue);
@ -35,6 +52,42 @@ namespace Plane.FormationCreator.Util
readvalue = iniFiles.IniReadvalue("Version", "CopterUpperLimit"); readvalue = iniFiles.IniReadvalue("Version", "CopterUpperLimit");
if (readvalue != "" && int.TryParse(readvalue, out intTemp)) if (readvalue != "" && int.TryParse(readvalue, out intTemp))
CopterUpperLimit = int.Parse(readvalue); CopterUpperLimit = int.Parse(readvalue);
*/
readvalue = iniFiles.IniReadvalue("Login", "Username");
if (readvalue != "")
Username = readvalue;
readvalue = iniFiles.IniReadvalue("Login", "Password");
if (readvalue != "")
Password = readvalue;
readvalue = iniFiles.IniReadvalue("Login", "issavePassword");
if (readvalue != "" && bool.TryParse(readvalue, out boolTemp))
IssavePassword = bool.Parse(readvalue);
} }
public static void SaveLogininfoToIni(string username,string password,bool issavepassword)
{
Username = username;
Password = password;
IssavePassword = issavepassword;
IniFiles iniFiles = new IniFiles();
iniFiles.IniWritevalue("Login", "Username", username);
if (issavepassword)
iniFiles.IniWritevalue("Login", "Password", password);
else
iniFiles.IniWritevalue("Login", "Password", "");
iniFiles.IniWritevalue("Login", "issavepassword", issavepassword.ToString());
}
} }
} }

View File

@ -24,6 +24,7 @@ using Plane.CommunicationManagement;
using Plane.Protocols; using Plane.Protocols;
using Microsoft.Practices.ServiceLocation; using Microsoft.Practices.ServiceLocation;
using System.Windows.Media; using System.Windows.Media;
using Plane.FormationCreator.Views;
namespace Plane.FormationCreator.ViewModels namespace Plane.FormationCreator.ViewModels
{ {
@ -229,7 +230,18 @@ namespace Plane.FormationCreator.ViewModels
})); }));
} }
} }
private ICommand _ChangepasswordCommand;
public ICommand ChangepasswordCommand
{
get
{
return _ChangepasswordCommand ?? (_ChangepasswordCommand = new RelayCommand( () =>
{
ChangePasswordView changePasswordView = new ChangePasswordView();
changePasswordView.ShowDialog();
}));
}
}
private ICommand _CommDataAsync; private ICommand _CommDataAsync;
public ICommand CommDataAsync public ICommand CommDataAsync
{ {

View File

@ -1148,17 +1148,16 @@ namespace Plane.FormationCreator.ViewModels
Alert.Show("作为参照的原点未设置,无法开始任务!", "提示"); Alert.Show("作为参照的原点未设置,无法开始任务!", "提示");
return; return;
} }
int utchour = DateTime.UtcNow.AddSeconds(5).Hour;
int utcminute = DateTime.UtcNow.AddSeconds(5).Minute; DateTime MissionTime = DateTime.UtcNow.AddSeconds(5);
int utcsecond = DateTime.UtcNow.AddSeconds(5).Second; Message.Show("开始任务"+ MissionTime.ToString());
Message.Show("开始任务");
//循环3次 发送起飞命令 避免通信问题 //循环3次 发送起飞命令 避免通信问题
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
await _commModuleManager.DoMissionStartAsync(_copterManager.Copters, await _commModuleManager.DoMissionStartAsync(_copterManager.Copters,
utchour, MissionTime.Hour,
utcminute, MissionTime.Minute,
utcsecond, MissionTime.Second,
_flightTaskManager.OriginLng, _flightTaskManager.OriginLng,
_flightTaskManager.OriginLat _flightTaskManager.OriginLat
); );
@ -1176,7 +1175,9 @@ namespace Plane.FormationCreator.ViewModels
*/ */
await Task.Delay(10).ConfigureAwait(false); await Task.Delay(10).ConfigureAwait(false);
} }
_copterManager.Net_PostStartMission(MissionTime, _flightTaskManager.OriginLng, _flightTaskManager.OriginLat);
Alert.Show("所有飞机开始执行航点任务。请勿多次开始任务!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Alert.Show("所有飞机开始执行航点任务。请勿多次开始任务!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
})); }));
} }

View File

@ -270,10 +270,10 @@ namespace Plane.FormationCreator.ViewModels
return _AddVirtualCopterCommand ?? (_AddVirtualCopterCommand = new RelayCommand<int>(async addcount => return _AddVirtualCopterCommand ?? (_AddVirtualCopterCommand = new RelayCommand<int>(async addcount =>
{ {
//给第三方时候限制数量用 //给第三方时候限制数量用
if (_copterManager.Copters.Count() >= VersionControl.CopterUpperLimit) // if (_copterManager.Copters.Count() >= VersionControl.CopterUpperLimit)
{ /// {
return; // return;
} // }
var center = _mapManager.Center; var center = _mapManager.Center;
string id; string id;
@ -352,19 +352,20 @@ namespace Plane.FormationCreator.ViewModels
*/ */
if (_copterManager.EnAddCopter_Fake())
{
var copter = new FakeCopter(SynchronizationContext.Current); var copter = new FakeCopter(SynchronizationContext.Current);
copter.SetProperties( copter.SetProperties(
latitude: _lastVirtualCopterLocation.Value.Lat, latitude: _lastVirtualCopterLocation.Value.Lat,
longitude: _lastVirtualCopterLocation.Value.Lng, longitude: _lastVirtualCopterLocation.Value.Lng,
id: id, id: id,
name: id name: id
); );
await copter.ConnectAsync(); await copter.ConnectAsync();
await copter.GetCopterDataAsync(); await copter.GetCopterDataAsync();
_copterManager.Copters.AddCopter(copter); _copterManager.Copters.AddCopter(copter);
_copterManager.CopterStatus.Add(false); _copterManager.CopterStatus.Add(false);
}
} }
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0) if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
_flightTaskManager.SetOriginal(); _flightTaskManager.SetOriginal();

View File

@ -14,6 +14,8 @@ using Microsoft.Practices.ServiceLocation;
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Plane.Geography; using Plane.Geography;
using Plane.FormationCreator.Views;
using System.Windows;
namespace Plane.FormationCreator.ViewModels namespace Plane.FormationCreator.ViewModels
{ {
@ -33,6 +35,7 @@ namespace Plane.FormationCreator.ViewModels
this.SwitchVelocityModeButtonContent = GetSwitchVelocityModeButtonContent(); this.SwitchVelocityModeButtonContent = GetSwitchVelocityModeButtonContent();
AppEx.Current.PropertyChanged += AppEx_PropertyChanged; AppEx.Current.PropertyChanged += AppEx_PropertyChanged;
_copterManager.netStatusChanged += CopterManagernetStatusChanged;
} }
private CopterListViewModel _copterListViewModel; private CopterListViewModel _copterListViewModel;
@ -43,6 +46,8 @@ namespace Plane.FormationCreator.ViewModels
public AppEx AppEx { get; } = AppEx.Current; public AppEx AppEx { get; } = AppEx.Current;
private void AppEx_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void AppEx_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
switch (e.PropertyName) switch (e.PropertyName)
@ -55,6 +60,14 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
private void CopterManagernetStatusChanged(bool Logined, string status)
{
Loginstate = status;
if (Logined)
LoginDisp = "注销";
else LoginDisp = "登录";
}
private string _SwitchVelocityModeButtonContent; private string _SwitchVelocityModeButtonContent;
public string SwitchVelocityModeButtonContent public string SwitchVelocityModeButtonContent
{ {
@ -160,6 +173,20 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
private string _Loginstate = "未登录";
public string Loginstate
{
get { return _copterManager.Loginstate ; }
set
{
Set(nameof(Loginstate), ref _Loginstate, value);
}
}
private ICommand _LoginCommand; private ICommand _LoginCommand;
public ICommand LoginCommand public ICommand LoginCommand
{ {
@ -167,7 +194,26 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _LoginCommand ?? (_LoginCommand = new RelayCommand(() => return _LoginCommand ?? (_LoginCommand = new RelayCommand(() =>
{ {
// AppEx.Current.ShowModifyTaskView = !AppEx.Current.ShowModifyTaskView;
if (!_copterManager.Logined)
{
LoginView loginview = new LoginView();
loginview.ShowDialog();
}
else
{
if (_copterManager.Copters.Count() > 0)
{
if (Alert.Show("注销将导致飞机全部清除,您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
== MessageBoxResult.Cancel)
return;
}
_copterListViewModel.ClearCoptersCommand.Execute(null);
_copterManager.NetLogout();
}
})); }));
} }
} }
@ -199,6 +245,15 @@ namespace Plane.FormationCreator.ViewModels
} }
private string _LoginDisp = "登录";
public string LoginDisp
{
get { return _LoginDisp; }
set { Set(nameof(LoginDisp), ref _LoginDisp, value); }
}
private ICommand _ChangeMapModeCommand; private ICommand _ChangeMapModeCommand;
public ICommand ChangeMapModeCommand public ICommand ChangeMapModeCommand
{ {

View File

@ -56,6 +56,7 @@
<Button Content="立体缩放" Width="90" Margin="5,5,5,5" Command="{Binding UpdateAllCopterCommand}"></Button> <Button Content="立体缩放" Width="90" Margin="5,5,5,5" Command="{Binding UpdateAllCopterCommand}"></Button>
<TextBlock Margin="5" VerticalAlignment="Center" Text="比例:" /> <TextBlock Margin="5" VerticalAlignment="Center" Text="比例:" />
<TextBox Width="30" VerticalContentAlignment="Center" Text="{Binding scale3d}" Margin="5,5,5,5" /> <TextBox Width="30" VerticalContentAlignment="Center" Text="{Binding scale3d}" Margin="5,5,5,5" />
<Button Content="更改密码" Width="90" Margin="5,5,5,5" Command="{Binding ChangepasswordCommand}"></Button>
</StackPanel> </StackPanel>