Files
lserp_cs_6.0/插件库/Lskj.Push/Push/Mode/Platform.cs
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

118 lines
3.5 KiB
C#

using Lskj.Push.Common;
using Lskj.Push.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Mode
{
public class Platform
{
private const String ALL = "all";
[JsonProperty(PropertyName = "winphone")]
public string allPlatform{get;set;}
private HashSet<string> _deviceTypes;
public HashSet<string> deviceTypes
{
get
{
return _deviceTypes;
}
set
{
if (value != null)
{
allPlatform = null;
}
_deviceTypes = value;
}
}
private Platform()
{
allPlatform = ALL;
deviceTypes = null;
}
private Platform(bool all, HashSet<string> deviceTypes)
{
//用来判断all=true时deviceTypes必须为空,反之当all=false时deviceTypes有值,不然json序列化会出错
Debug.Assert(all && deviceTypes == null || !all && deviceTypes != null);
if (all)
{
allPlatform = ALL;
}
this.deviceTypes = deviceTypes;
}
public static Platform all()
{
return new Platform(true, null).Check();
}
public static Platform ios()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.ios.ToString());
return new Platform(false,types).Check();
}
public static Platform android()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.android.ToString());
return new Platform(false, types).Check();
}
public static Platform winphone()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.winphone.ToString());
return new Platform(false, types).Check();
}
public static Platform android_ios()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.android.ToString());
types.Add(DeviceType.ios.ToString());
return new Platform(false, types).Check();
}
public static Platform android_winphone()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.android.ToString());
types.Add(DeviceType.winphone.ToString());
return new Platform(false, types).Check();
}
public static Platform ios_winphone()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.ios.ToString());
types.Add(DeviceType.winphone.ToString());
return new Platform(false, types).Check();
}
public bool isAll()
{
return allPlatform != null;
}
public void setAll(bool all)
{
if (all)
{
allPlatform = ALL;
}
else
{
allPlatform = null;
}
}
public Platform Check()
{
Preconditions.checkArgument(!(isAll() && null != deviceTypes), "Since all is enabled, any platform should not be set.");
Preconditions.checkArgument(!(!isAll() && null == deviceTypes), "No any deviceType is set.");
return this;
}
}
}