Quellcode durchsuchen

boss增加发送邮件命令

tanghai vor 13 Jahren
Ursprung
Commit
21bf9b6ace

+ 35 - 0
CSharp/App/BossBase/Messages.cs

@@ -255,4 +255,39 @@ namespace BossBase
 		[DataMember(Order = 2, IsRequired = false)]
 		public string Content { get; set; }
 	}
+
+	[DataContract]
+	public class BossMailItem
+	{
+		[DataMember(Order = 1, IsRequired = false)]
+		public uint item_id { get; set; }
+
+		[DataMember(Order = 2, IsRequired = false)]
+		public uint item_count { get; set; }
+	}
+
+	[DataContract]
+	public class BossMail
+	{
+		[DataMember(Order = 1, IsRequired = true)]
+		public string sender_name { get; set; }
+
+		[DataMember(Order = 2, IsRequired = true)]
+		public ulong receiver_guid { get; set; }
+
+		[DataMember(Order = 3, IsRequired = true)]
+		public string subject { get; set; }
+
+		[DataMember(Order = 4, IsRequired = true)]
+		public string content { get; set; }
+
+		[DataMember(Order = 5, IsRequired = false)]
+		public uint free_gold { get; set; }
+
+		[DataMember(Order = 6, IsRequired = false)]
+		public uint silver { get; set; }
+
+		[DataMember(Order = 7, IsRequired = false)]
+		public Dictionary<int, int> item_dict { get; set; }
+	}
 }

+ 2 - 0
CSharp/App/BossCommand/ABossCommand.cs

@@ -15,6 +15,8 @@ namespace BossCommand
 			this.IMessageChannel.SendMessage(MessageOpcode.CMSG_BOSS_GM, cmsgBossGm);
 		}
 
+		public string CommandString { get; set; }
+
 		protected async Task<T> RecvMessage<T>()
 		{
 			var result = await this.IMessageChannel.RecvMessage();

+ 4 - 4
CSharp/App/BossCommand/BCForbidLogin.cs

@@ -8,16 +8,16 @@ namespace BossCommand
 		public string Command { get; set; }
 		public string Content { get; set; }
 		public string ForbiddenLoginTime { get; set; }
+
 		public BCForbidLogin(IMessageChannel iMessageChannel): base(iMessageChannel)
 		{
 		}
 
 		public override async Task<object> DoAsync()
 		{
-			this.SendMessage(new CMSG_Boss_Gm
-			{
-				Message = string.Format("{0} {1} {2}", this.Command, this.Content, this.ForbiddenLoginTime)
-			});
+			this.CommandString = string.Format(
+				"{0} {1} {2}", this.Command, this.Content, this.ForbiddenLoginTime);
+			this.SendMessage(new CMSG_Boss_Gm { Message = this.CommandString });
 			var smsgBossCommandResponse = await RecvMessage<SMSG_Boss_Command_Response>();
 			return smsgBossCommandResponse.ErrorCode;
 		}

+ 5 - 6
CSharp/App/BossCommand/BCForbiddenCharacter.cs

@@ -5,20 +5,19 @@ namespace BossCommand
 {
 	public class BCForbiddenCharacter: ABossCommand
 	{
-		public BCForbiddenCharacter(IMessageChannel iMessageChannel): base(iMessageChannel)
+		public BCForbiddenCharacter(IMessageChannel iMessageChannel): 
+			base(iMessageChannel)
 		{
 		}
 
 		public string Guid { get; set; }
 		public string Command { get; set; }
 		public string ForbiddenTime { get; set; }
+
 		public override async Task<object> DoAsync()
 		{
-			this.SendMessage(new CMSG_Boss_Gm
-			{
-				Message = string.Format("{0} {1} {2}", this.Command, this.Guid, this.ForbiddenTime)
-			});
-
+			this.CommandString = string.Format("{0} {1} {2}", this.Command, this.Guid, this.ForbiddenTime);
+			this.SendMessage(new CMSG_Boss_Gm { Message = CommandString });
 			var smsgBossCommandResponse = await this.RecvMessage<SMSG_Boss_Command_Response>();
 			return smsgBossCommandResponse.ErrorCode;
 		}

+ 2 - 5
CSharp/App/BossCommand/BCGetCharacterInfo.cs

@@ -19,11 +19,8 @@ namespace BossCommand
 
 		public override async Task<object> DoAsync()
 		{
-			this.SendMessage(new CMSG_Boss_Gm
-			{
-				Message = string.Format(
-					"get_character_info {0} {1} ", this.FindTypeIndex, this.FindType)
-			});
+			this.CommandString = string.Format("get_character_info {0} {1} ", this.FindTypeIndex, this.FindType);
+			this.SendMessage(new CMSG_Boss_Gm { Message = CommandString });
 			var smsgBossCommandResponse = await this.RecvMessage<SMSG_Boss_Command_Response>();
 			if (smsgBossCommandResponse.ErrorCode != ErrorCode.RESPONSE_SUCCESS)
 			{

+ 27 - 0
CSharp/App/BossCommand/BCSendMail.cs

@@ -0,0 +1,27 @@
+
+using System.Threading.Tasks;
+using BossBase;
+using Helper;
+using Log;
+
+namespace BossCommand
+{
+	public class BCSendMail: ABossCommand
+	{
+		public BossMail BossMail { get; set; }
+
+		public BCSendMail(IMessageChannel iMessageChannel): base(iMessageChannel)
+		{
+		}
+
+		public override async Task<object> DoAsync()
+		{
+			this.CommandString = string.Format(
+				"send_mail --json {0} ", JsonHelper.ToString(this.BossMail));
+			Logger.Trace(this.CommandString);
+			this.SendMessage(new CMSG_Boss_Gm { Message = CommandString });
+			var smsgBossCommandResponse = await this.RecvMessage<SMSG_Boss_Command_Response>();
+			return smsgBossCommandResponse.ErrorCode;
+		}
+	}
+}

+ 1 - 0
CSharp/App/BossCommand/BossCommand.csproj

@@ -41,6 +41,7 @@
     <Compile Include="BCForbidLogin.cs" />
     <Compile Include="BCCommand.cs" />
     <Compile Include="BCGetCharacterInfo.cs" />
+    <Compile Include="BCSendMail.cs" />
     <Compile Include="BCServerInfo.cs" />
     <Compile Include="BCReloadWorld.cs" />
     <Compile Include="BCForbiddenCharacter.cs" />

+ 27 - 0
CSharp/App/Modules/Robot/NumValidation.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Globalization;
+using System.Windows.Controls;
+
+namespace Modules.Robot
+{
+	public class NumValidation : ValidationRule
+	{
+		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+		{
+			if ((string) value == "")
+			{
+				return new ValidationResult(true, null);
+			}
+			try
+			{
+				int.Parse((string) value);
+			}
+			catch (Exception e)
+			{
+				return new ValidationResult(false, string.Format("Illegal characters or {0}", e.Message));
+			}
+
+			return new ValidationResult(true, null);
+		}
+	}
+}

+ 1 - 0
CSharp/App/Modules/Robot/Robot.csproj

@@ -60,6 +60,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ComboBoxForbiddenType.cs" />
+    <Compile Include="NumValidation.cs" />
     <Compile Include="Robot.cs" />
     <Compile Include="RobotModule.cs" />
     <Compile Include="RobotViewModel.cs" />

+ 69 - 16
CSharp/App/Modules/Robot/RobotView.xaml

@@ -17,6 +17,21 @@
 			<Robot:ComboBoxForbiddenType Name="匹配" Value="forbid_match"></Robot:ComboBoxForbiddenType>
 			<Robot:ComboBoxForbiddenType Name="聊天" Value="forbid_chat"></Robot:ComboBoxForbiddenType>
 		</x:Array>
+
+		<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
+			<Style.Triggers>
+				<Trigger Property="Validation.HasError" Value="true">
+					<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
+                        Path=(Validation.Errors)[0].ErrorContent}"/>
+				</Trigger>
+			</Style.Triggers>
+		</Style>
+		<ControlTemplate x:Key="numberValidationTemplate">
+			<DockPanel>
+				<AdornedElementPlaceholder DockPanel.Dock="Left"/>
+				<TextBlock Foreground="Red" FontSize="20" >请输入数字!</TextBlock>
+			</DockPanel>
+		</ControlTemplate>
 	</UserControl.Resources>
 	<Grid>
 		<DockPanel x:Name="dock" Visibility="{Binding DockPanelVisiable}">
@@ -57,7 +72,7 @@
 						</TabItem>
 						<TabItem Header="角色">
 							<Canvas>
-								<GroupBox Header="角色信息" Canvas.Left="10" Height="723" Width="734" BorderBrush="BurlyWood">
+								<GroupBox Header="角色信息" Canvas.Left="10" Height="667" Width="837" BorderBrush="BurlyWood">
 									<Canvas>
 										<ComboBox x:Name="cbFindType" SelectedIndex="{Binding FindTypeIndex}" Canvas.Left="32" Canvas.Top="23" Height="25">
 											<ComboBoxItem Content="帐 号"/>
@@ -72,9 +87,51 @@
 										<TextBox Text="{Binding Name}" Grid.Row="2" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="84" Width="204"/>
 										<Label Content="GUID:" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" Canvas.Left="32" Canvas.Top="114" />
 										<TextBox Text="{Binding Guid}" Grid.Row="3" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="114" Width="204"/>
-										<TabControl Name="tcCharacterInfo" Height="541" Canvas.Top="160" Width="722" IsEnabled="False">
-											<TabItem Header="信息">
-												<Grid Margin="0,0,8,36"/>
+										<TabControl Name="tcCharacterInfo" Height="475" Canvas.Top="160" Width="815" IsEnabled="False">
+											<TabItem Header="邮件">
+												<Canvas>
+													<GroupBox Header="发送邮件" Canvas.Left="10" Canvas.Top="10" Height="279" Width="323">
+														<Canvas>
+															<Label Content="主   题:" Canvas.Left="10" Canvas.Top="7" />
+															<TextBox Text="{Binding Subject}" Height="23" Canvas.Left="63" Canvas.Top="10" Width="154" />
+															<TextBox Text="{Binding Content}" Height="124" Canvas.Left="10" Canvas.Top="38" Width="291" />
+															<Label Content="邮件内容:" Canvas.Left="222" Canvas.Top="7"/>
+															<Label Content="免费元宝:" Canvas.Left="10" Canvas.Top="164"/>
+															<Label Content="银   两:" Canvas.Left="160" Canvas.Top="167" />
+															<Label Content="物品ID:" Canvas.Left="10" Canvas.Top="198"/>
+															<TextBox Height="23" Canvas.Left="63" Canvas.Top="167" Width="92" Validation.ErrorTemplate="{StaticResource numberValidationTemplate}" Style="{StaticResource textBoxInError}">
+																<Binding Path="FreeGold" UpdateSourceTrigger="PropertyChanged" >
+																	<Binding.ValidationRules>
+																		<Robot:NumValidation />
+																	</Binding.ValidationRules>
+																</Binding>
+															</TextBox>
+															<TextBox Height="23" Canvas.Left="213" Canvas.Top="167" Width="92" Validation.ErrorTemplate="{StaticResource numberValidationTemplate}" Style="{StaticResource textBoxInError}">
+																<Binding Path="Silver" UpdateSourceTrigger="PropertyChanged" >
+																	<Binding.ValidationRules>
+																		<Robot:NumValidation />
+																	</Binding.ValidationRules>
+																</Binding>
+															</TextBox>
+															<TextBox Height="23" Canvas.Left="64" Canvas.Top="198" Width="92" Validation.ErrorTemplate="{StaticResource numberValidationTemplate}" Style="{StaticResource textBoxInError}">
+																<Binding Path="ItemID" UpdateSourceTrigger="PropertyChanged" >
+																	<Binding.ValidationRules>
+																		<Robot:NumValidation />
+																	</Binding.ValidationRules>
+																</Binding>
+															</TextBox>
+															<TextBox Height="23" Canvas.Left="213" Canvas.Top="198" Width="92" Validation.ErrorTemplate="{StaticResource numberValidationTemplate}" Style="{StaticResource textBoxInError}">
+																<Binding Path="ItemCount" UpdateSourceTrigger="PropertyChanged" >
+																	<Binding.ValidationRules>
+																		<Robot:NumValidation />
+																	</Binding.ValidationRules>
+																</Binding>
+															</TextBox>
+															<Label Content="数   量:" Canvas.Left="160" Canvas.Top="198"/>
+															<Button Name="btnSendMail" Content="发送" Canvas.Left="10" Canvas.Top="229" Width="75" Click="btnSendMail_Click" />
+														</Canvas>
+													</GroupBox>
+												</Canvas>
 											</TabItem>
 											<TabItem Header="包裹">
 												<Grid/>
@@ -85,19 +142,15 @@
 											<TabItem Header="装备">
 												<Canvas/>
 											</TabItem>
-											<TabItem Header="GM">
-												<Canvas>
-													<Button x:Name="btnForbiddenBuy" Content="禁止" Canvas.Left="186" Canvas.Top="40" Width="75" Click="btnForbidCharacter_Click" />
-													<Button x:Name="btnAllowBuy" Content="允许" Canvas.Left="186" Canvas.Top="10" Width="75" Click="btnAllowCharacter_Click" />
-													<ComboBox Name="cbForbiddenType" SelectedIndex="0" Canvas.Left="61" Canvas.Top="11" Width="120" 
-															ItemsSource="{StaticResource ResourceKey=ComboBoxCharacterForbiddenTypeKey}" 
-															DisplayMemberPath="Name" SelectedValuePath="Value" />
-													<TextBox Name="tbForbiddenTime" Height="23" Canvas.Left="61" Canvas.Top="40" Width="120"/>
-													<Label Content="类型:" Canvas.Left="10" Canvas.Top="11"/>
-													<Label Content="时间:" Canvas.Left="10" Canvas.Top="37"/>
-												</Canvas>
-											</TabItem>
 										</TabControl>
+										<Button Name="btnForbidCharacter" IsEnabled="False" Content="禁止" Canvas.Left="495" Canvas.Top="55" Width="75" Click="btnForbidCharacter_Click" />
+										<Button Name="btnAllowCharacter" IsEnabled="False" Content="允许" Canvas.Left="495" Canvas.Top="25" Width="75" Click="btnAllowCharacter_Click" />
+										<ComboBox x:Name="cbForbiddenType" SelectedIndex="0" Canvas.Left="370" Canvas.Top="26" Width="120" 
+											ItemsSource="{StaticResource ResourceKey=ComboBoxCharacterForbiddenTypeKey}" 
+											DisplayMemberPath="Name" SelectedValuePath="Value" />
+										<TextBox x:Name="tbForbiddenTime" Height="23" Canvas.Left="370" Canvas.Top="55" Width="120"/>
+										<Label Content="类型:" Canvas.Left="319" Canvas.Top="26"/>
+										<Label Content="时间:" Canvas.Left="319" Canvas.Top="52"/>
 									</Canvas>
 								</GroupBox>
 							</Canvas>

+ 9 - 0
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -38,6 +38,8 @@ namespace Modules.Robot
 		{
 			await this.ViewModel.GetCharacterInfo();
 			this.tcCharacterInfo.IsEnabled = true;
+			this.btnForbidCharacter.IsEnabled = true;
+			this.btnAllowCharacter.IsEnabled = true;
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}
@@ -92,5 +94,12 @@ namespace Modules.Robot
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}
+
+		private async void btnSendMail_Click(object sender, RoutedEventArgs e)
+		{
+			await this.ViewModel.SendMail();
+			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
+			this.tbLog.ScrollToEnd();
+		}
 	}
 }

+ 173 - 19
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel.Composition;
 using System.Globalization;
@@ -26,7 +27,14 @@ namespace Modules.Robot
 		private string name = "";
 		private string guid = "";
 		private string command = "";
-		private bool isGMEnable;
+
+		private string subject = "";
+		private string content = "";
+		private string freeGold = "";
+		private string silver = "";
+		private string itemID = "";
+		private string itemCount = "";
+
 		private Visibility dockPanelVisiable = Visibility.Hidden;
 		private readonly BossClient.BossClient bossClient = new BossClient.BossClient();
 		private readonly ObservableCollection<ServerViewModel> serverInfos = 
@@ -178,6 +186,108 @@ namespace Modules.Robot
 			}
 		}
 
+		public string Subject
+		{
+			get
+			{
+				return this.subject;
+			}
+			set
+			{
+				if (this.subject == value)
+				{
+					return;
+				}
+				this.subject = value;
+				this.RaisePropertyChanged("Subject");
+			}
+		}
+
+		public string Content
+		{
+			get
+			{
+				return this.content;
+			}
+			set
+			{
+				if (this.content == value)
+				{
+					return;
+				}
+				this.content = value;
+				this.RaisePropertyChanged("Content");
+			}
+		}
+
+		public string FreeGold
+		{
+			get
+			{
+				return this.freeGold;
+			}
+			set
+			{
+				if (this.freeGold == value)
+				{
+					return;
+				}
+				this.freeGold = value;
+				this.RaisePropertyChanged("FreeGold");
+			}
+		}
+
+		public string Silver
+		{
+			get
+			{
+				return this.silver;
+			}
+			set
+			{
+				if (this.silver == value)
+				{
+					return;
+				}
+				this.silver = value;
+				this.RaisePropertyChanged("Silver");
+			}
+		}
+
+		public string ItemID
+		{
+			get
+			{
+				return this.itemID;
+			}
+			set
+			{
+				if (this.itemID == value)
+				{
+					return;
+				}
+				this.itemID = value;
+				this.RaisePropertyChanged("ItemID");
+			}
+		}
+
+		public string ItemCount
+		{
+			get
+			{
+				return this.itemCount;
+			}
+			set
+			{
+				if (this.itemCount == value)
+				{
+					return;
+				}
+				this.itemCount = value;
+				this.RaisePropertyChanged("ItemCount");
+			}
+		}
+
 		[ImportingConstructor]
 		public RobotViewModel(IEventAggregator eventAggregator)
 		{
@@ -213,6 +323,16 @@ namespace Modules.Robot
 			this.eventAggregator.GetEvent<ReLoginEvent>().Publish(null);
 		}
 
+		public void ShowErrorInfo(uint errorCode, string commandString)
+		{
+			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
+			{
+				this.ErrorInfo = string.Format("{0} Succeed!", commandString);
+				return;
+			}
+			this.ErrorInfo = string.Format("{0} Fail, error code: {1}", commandString, errorCode);
+		}
+
 		public async Task Servers()
 		{
 			ABossCommand bossCommand = new BCServerInfo(this.IMessageChannel);
@@ -243,21 +363,21 @@ namespace Modules.Robot
 		{
 			ABossCommand bossCommand = new BCGetCharacterInfo(this.IMessageChannel)
 			{
-				FindTypeIndex = this.FindTypeIndex, 
+				FindTypeIndex = this.FindTypeIndex,
 				FindType = this.FindType
 			};
 			var result = await bossCommand.DoAsync();
 			if (result == null)
 			{
-				this.ErrorInfo = string.Format("获取玩家信息失败");
+				this.ErrorInfo = string.Format("{0} Fail!", bossCommand.CommandString);
 				return;
 			}
 			var characterInfo = (CharacterInfo)result;
 
-			this.ErrorInfo = "获取玩家信息成功";
 			this.Account = characterInfo.Account;
 			this.Name = characterInfo.Name;
 			this.Guid = characterInfo.Guid.ToString();
+			this.ErrorInfo = string.Format("{0} Succeed!", bossCommand.CommandString);
 		}
 
 		public async Task ForbidCharacter(string forbiddenCommand, string forbiddenTime)
@@ -267,7 +387,13 @@ namespace Modules.Robot
 				this.ErrorInfo = "请先指定玩家";
 				return;
 			}
-
+			ulong ulongGuid = 0;
+			if (!ulong.TryParse(this.Guid, out ulongGuid))
+			{
+				this.ErrorInfo = "Guid必须是数字";
+				return;
+			}
+			
 			int time = 0;
 			if (!int.TryParse(forbiddenTime, out time))
 			{
@@ -277,21 +403,15 @@ namespace Modules.Robot
 
 			ABossCommand bossCommand = new BCForbiddenCharacter(this.IMessageChannel)
 			{
-				Guid = this.Guid,
 				Command = forbiddenCommand,
+				Guid = this.Guid,
 				ForbiddenTime = forbiddenTime
 			};
 			var result = await bossCommand.DoAsync();
 
 			var errorCode = (uint)result;
 
-			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
-			{
-				this.ErrorInfo = string.Format(
-					"{0} {1} {2} Succeed!", forbiddenCommand, this.Guid, forbiddenTime);
-				return;
-			}
-			this.ErrorInfo = string.Format("{0} Fail, error code: {1}", forbiddenCommand, errorCode);
+			ShowErrorInfo(errorCode, bossCommand.CommandString);
 		}
 
 		public async Task ForbiddenLogin(
@@ -306,21 +426,55 @@ namespace Modules.Robot
 
 			ABossCommand bossCommand = new BCForbidLogin(this.IMessageChannel)
 			{
-				Command = forbiddenCommand,
-				Content = forbiddenContent,
+				Command = forbiddenCommand, 
+				Content = forbiddenContent, 
 				ForbiddenLoginTime = forbiddenTime
 			};
 			var result = await bossCommand.DoAsync();
 
 			var errorCode = (uint)result;
 
-			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
+			ShowErrorInfo(errorCode, bossCommand.CommandString);
+		}
+
+		public async Task SendMail()
+		{
+			BossMail bossMail = null;
+			try
 			{
-				this.ErrorInfo = string.Format(
-					"{0} {1} {2} Succeed!", forbiddenCommand, forbiddenContent, forbiddenTime);
+				bossMail = new BossMail
+				{
+					sender_name = "系统",
+					receiver_guid = ulong.Parse(this.Guid),
+					subject = this.Subject,
+					content = this.Content,
+					free_gold = uint.Parse(this.FreeGold),
+					silver = uint.Parse(this.Silver),
+					item_dict = new Dictionary<int, int>()
+				};
+
+				if (this.ItemID != "")
+				{
+					bossMail.item_dict.Add(int.Parse(this.ItemID), int.Parse(this.ItemCount));
+				}
+			}
+			catch (Exception e)
+			{
+				Logger.Trace(e.ToString());
+				this.ErrorInfo = "输入错误!";
 				return;
 			}
-			this.ErrorInfo = string.Format("{0}, error code: {1}", forbiddenCommand, errorCode);
+
+			ABossCommand bossCommand = new BCSendMail(this.IMessageChannel)
+			{
+				BossMail = bossMail
+			};
+
+			var result = await bossCommand.DoAsync();
+
+			var errorCode = (uint) result;
+
+			ShowErrorInfo(errorCode, bossCommand.CommandString);
 		}
 
 		public async Task SendCommand()

+ 3 - 0
CSharp/Platform/Helper/Helper.csproj

@@ -32,6 +32,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Newtonsoft.Json">
+      <HintPath>..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="protobuf-net, Version=2.0.0.621, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\..\packages\protobuf-net.2.0.0.621\lib\net40\protobuf-net.dll</HintPath>

+ 4 - 17
CSharp/Platform/Helper/JsonHelper.cs

@@ -1,30 +1,17 @@
-using System.IO;
-using System.Runtime.Serialization.Json;
-using System.Text;
+using Newtonsoft.Json;
 
 namespace Helper
 {
 	public static class JsonHelper
 	{
-		public static string ToString<T>(T obj)
+		public static string ToString(object obj)
 		{
-			var serializer = new DataContractJsonSerializer(typeof (T));
-			using (var ms = new MemoryStream())
-			{
-				serializer.WriteObject(ms, obj);
-				string str = Encoding.UTF8.GetString(ms.ToArray());
-				return str;
-			}
+			return JsonConvert.SerializeObject(obj);
 		}
 
 		public static T FromString<T>(string str)
 		{
-			var serializer = new DataContractJsonSerializer(typeof (T));
-			using (var ms = new MemoryStream(Encoding.Default.GetBytes(str)))
-			{
-				var obj = (T) serializer.ReadObject(ms);
-				return obj;
-			}
+			return JsonConvert.DeserializeObject<T>(str);
 		}
 	}
 }

+ 1 - 0
CSharp/Platform/Helper/Packages.config

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
   <package id="protobuf-net" version="2.0.0.621" targetFramework="net45" />
 </packages>