/// <summary> /// 查询设备状态 /// 设备状态,目前取值如下: /// 0:未授权 1:已经授权(尚未被用户绑定) 2:已经被用户绑定 3:属性未设置 /// </summary> /// <param name="device_id"></param> /// <returns></returns> public ActionResult CheckDeviceStatus(string device_id) { if (!VerifyParam("device_id")) { return(ErrMsg()); } // var result = new AccessJsonView(); // TODO:向微信服务器发送查询设备状态请求 var weChatConfig = GetWechatConfig(); var ret = DeviceApi.DeviceStatus(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, device_id); if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", status = ret.status, success = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 验证二维码 /// 微信硬件接口返回的deviceType 字段目前为服务号原始ID,SIM系统目前忽略了这个字段 /// </summary> /// <param name="qrticket"></param> /// <returns></returns> public ActionResult Verify(string qrticket) { // TODO:向微信服务器发送二维码验证请求 if (!VerifyParam("qrticket")) { return(ErrMsg()); } var weChatConfig = GetWechatConfig(); var ret = DeviceApi.VerifyQRCode(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, qrticket); if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", device_type = ret.device_type, mac = ret.mac, device_id = ret.device_id, success = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } }
public string DelDevice(int appId, string deviceId) { var rst = new ReturnResult <bool>(); var api = new DeviceApi(); var delRst = api.DelDevice(appId, deviceId); if (delRst.Status == "NoContent") { rst.Result = true; rst.Message = "删除成功"; var bll = new UserDeviceBll(); var del = bll.Delete(new UserDevice() { DeviceId = deviceId }); } else { rst.Message = "删除失败"; } return(JsonHelper.Instance.Serialize(rst)); }
public string RegDevice(RegDeviceRequest model) { var rst = new ReturnResult <RegDeviceResult>(); var api = new DeviceApi(); var apiRst = api.RegDevice(model); if (apiRst.Result && !string.IsNullOrEmpty(apiRst.Data.deviceId)) { //根据设备型号查找profile var bll = new ProfileBll(); var profileRst = bll.GetOneByModel(new Profile() { Model = model.model }); if (profileRst.Result) { var profile = profileRst.Data; //修改设备 var updateRst = api.UpdateDevice(model.appId, apiRst.Data.deviceId, model.name, profile, "CoAP"); if (updateRst.Result && updateRst.Status == "NoContent") { rst.Result = true; rst.Data = apiRst.Data; rst.Message = "注册成功"; } else { rst.Message = "注册失败"; } } else { rst.Message = "设备型号不存在"; } //插入用户设备表 var device = new UserDevice() { DeviceId = apiRst.Data.deviceId, DeviceName = model.name, VerifyCode = model.verifyCode, NodeId = model.nodeId, ProfileId = profileRst.Data?.Id, UserId = model.userId }; var addDeviceRst = new UserDeviceBll().AddOrUpdate(device); if (addDeviceRst.Result) { rst.Result = true; rst.Message = "注册成功"; } } else { rst.Message = "注册失败"; } return(JsonHelper.Instance.Serialize(rst)); }
public static CudaStructures.CudaDeviceProperties GetDeviceProperties(int device) { var ret = new CudaStructures.CudaDeviceProperties(); DeviceApi.GetDeviceProperties(ref ret, device); return(ret); }
public static void CheckDeviceSanity() { DeviceApi.ThreadSynchronize(); int err = DeviceApi.GetDeviceStatus(); if (err != 0) { throw new InvalidProgramException("GPU is in a non-valid state: " + err); } }
private void InitGameObjects() { _client = new ApiClient(ApiUrl); _client.AddDefaultHeader("api-key", _apiKey); _deviceApi = new DeviceApi(_client); _obj = new GameObject("MatchMoreObject"); if (_config.LoggingEnabled) { MatchmoreLogger.Context = _obj; } _coroutine = _obj.AddComponent <CoroutineWrapper>(); }
/// <summary> /// 绑定设备,解绑设备接口 /// </summary> /// <returns></returns> public ActionResult BindDevice() { // var result = new AccessJsonView(); if (!VerifyParam("ticket,device_id,simuid,action")) { return(ErrMsg()); } var ticket = Request["ticket"]; var deviceId = Request["device_id"]; var simuid = int.Parse(Request["simuid"]); var action = Request["action"]; var weChatConfig = GetWechatConfig(); var list = _BaseService.GetList <WechatMPUserView>(0, a => a.Id == simuid, null); if (list == null || list.Count == 0) { return(ErrMsg("simuid 没有找到!")); } // TODO:绑定设备 if (action.Equals("bind")) { var ret = DeviceApi.DeviceBindUnbind(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, true, ticket, deviceId, list[0].OpenId); if (ret.errcode != Weixin.ReturnCode.请求成功) { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } // 解绑设备 } else if (action.Equals("unbind")) { var ret = DeviceApi.DeviceBindUnbind(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, true, ticket, deviceId, list[0].OpenId); if (ret.errcode != Weixin.ReturnCode.请求成功) { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = true, message = "" }, JsonRequestBehavior.AllowGet)); }
public PollingMatchMonitor(Device device, DeviceApi _deviceApi, CoroutineWrapper coroutine, Action<string> closedCallback) { if (device == null || string.IsNullOrEmpty(device.Id)) { throw new ArgumentException("Device null or invalid id"); } _device = device; _coroutine = coroutine; _closedCallback = closedCallback; _coroutine.SetupContinuousRoutine(device.Id, () => { var matches = _deviceApi.GetMatches(device.Id); OnMatchReceived(new MatchReceivedEventArgs(device, Matchmore.MatchChannel.polling, matches)); }); }
public void PageInit() { contextMenuStrip.Renderer = new Helpers.ClassicalMenuRender(Handle); item_ramuseage = new PerformanceInfos.PerformanceInfoSpeicalItem(); item_ramcanuse = new PerformanceInfos.PerformanceInfoSpeicalItem(); item_sended = new PerformanceInfos.PerformanceInfoSpeicalItem(); item_cached = new PerformanceInfos.PerformanceInfoSpeicalItem(); item_pagepool = new PerformanceInfos.PerformanceInfoSpeicalItem(); item_nopagepool = new PerformanceInfos.PerformanceInfoSpeicalItem(); item_ramuseage.Name = LanuageMgr.GetStr("MemUsing"); item_ramcanuse.Name = LanuageMgr.GetStr("MenCanUse"); item_sended.LineSp = true; item_sended.Name = LanuageMgr.GetStr("Submited"); item_cached.Name = LanuageMgr.GetStr("Cached"); item_pagepool.LineSp = true; item_pagepool.Name = LanuageMgr.GetStr("PagedPool"); item_nopagepool.Name = LanuageMgr.GetStr("NonPagedPool"); performanceInfos.SpeicalItems.Add(item_ramuseage); performanceInfos.SpeicalItems.Add(item_ramcanuse); performanceInfos.SpeicalItems.Add(item_sended); performanceInfos.SpeicalItems.Add(item_cached); performanceInfos.SpeicalItems.Add(item_pagepool); performanceInfos.SpeicalItems.Add(item_nopagepool); all_ram = MSystemMemoryPerformanctMonitor.GetAllMemory(); performanceGridGlobal.RightText = FormatFileSize(all_ram); DeviceApi.MDEVICE_GetMemoryDeviceInfo(); performanceTitle.SmallTitle = Marshal.PtrToStringUni(DeviceApi.MDEVICE_GetMemoryDeviceName()); performanceInfos.StaticItems.Add(new PerformanceInfos.PerformanceInfoStaticItem(LanuageMgr.GetStr("Speed"), DeviceApi.MDEVICE_GetMemoryDeviceSpeed().ToString() + " MHz")); performanceInfos.StaticItems.Add(new PerformanceInfos.PerformanceInfoStaticItem(LanuageMgr.GetStr("FormFactor"), DeviceApi.MDEVICE_MemoryFormFactorToString(DeviceApi.MDEVICE_GetMemoryDeviceFormFactor()) )); UInt16 used = 0, all = 0; if (DeviceApi.MDEVICE_GetMemoryDeviceUsed(ref all, ref used)) { performanceInfos.StaticItems.Add(new PerformanceInfos.PerformanceInfoStaticItem(LanuageMgr.GetStr("DeviceLocator"), used + "/" + all)); } fTipVauleFree = LanuageMgr.GetStr("MemTipFree"); fTipVauleModified = LanuageMgr.GetStr("MemTipModifed"); fTipVauleStandby = LanuageMgr.GetStr("MemTipStandby"); fTipVauleUsing = LanuageMgr.GetStr("MemTipUsing"); }
public ThreadedPollingMatchMonitor(Device device, DeviceApi deviceApi, CoroutineWrapper coroutine, Action<string> closedCallback) { if (device == null || string.IsNullOrEmpty(device.Id)) { throw new ArgumentException("Device null or invalid id"); } _deviceApi = deviceApi; _device = device; _coroutine = coroutine; _closedCallback = closedCallback; _running = true; Start(); _coroutine.SetupContinuousRoutine(device.Id, () => { OnMatchReceived(new MatchReceivedEventArgs(device, Matchmore.MatchChannel.threadedPolling, _matches)); }); }
public MatrixApi(Uri url) { if (url != null && url.IsWellFormedOriginalString() && !url.IsAbsoluteUri) { throw new MatrixException(Resources.InvalidUrl); } _isAppservice = false; Backend = new HttpBackend(url, UserId); BaseUrl = url; Rng = new Random(DateTime.Now.Millisecond); Room = new RoomApi(this); LoginEndpoint = new LoginEndpoint(this); VersionsEndpoint = new VersionsEndpoint(this); Device = new DeviceApi(this); Media = new MediaApi(this); Profile = new ProfileApi(this); Sync = new SyncEndpoint(this); RoomDirectory = new RoomDirectoryApi(this); }
/// <summary> /// 获取用户绑定的所有设备 /// /// </summary> /// <param name="qrticket"></param> /// <returns></returns> public ActionResult GetDeviceList(string simuid) { // TODO:向微信服务器发送二维码验证请求 if (!VerifyParam("simuid")) { return(ErrMsg()); } //查询用户 var userid = int.Parse(simuid); var user = _BaseService.Repository.Entities.FirstOrDefault(a => a.Id == userid); if (user == null) { return(ErrMsg("simuid 不存在!")); } //查询设备列表 var weChatConfig = GetWechatConfig(); var ret = DeviceApi.DeviceList(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, user.OpenId); if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", success = true, device_list = ret.device_list, simuid = simuid }, JsonRequestBehavior.AllowGet)); } else { return(ErrMsg(ret.errmsg)); } }
public WebsocketMatchMonitor(Device device, Matchmore.Config config, DeviceApi deviceApi, CoroutineWrapper coroutine, Action<string> closedCallback) { if (device == null || string.IsNullOrEmpty(device.Id)) { throw new ArgumentException("Device null or invalid id"); } _device = device; _deviceApi = deviceApi; _coroutine = coroutine; _closedCallback = closedCallback; var worldId = Utils.ExtractWorldId(config.ApiKey); MatchmoreLogger.Debug("Starting websocket for device {0}", device.Id); var protocol = config.UseSecuredCommunication ? "wss" : "ws"; var port = config.PusherPort == null ? "" : ":" + config.PusherPort; var url = string.Format("{3}://{0}{4}/pusher/{1}/ws/{2}", config.Environment, Matchmore.API_VERSION, _device.Id, protocol, port); _ws = new WebSocket(url, "api-key", worldId); _ws.OnOpen += (sender, e) => MatchmoreLogger.Debug("WS opened for device {0}", device.Id); _ws.OnClose += (sender, e) => MatchmoreLogger.Debug("WS closing {0} for device {1}", e.Code, device.Id); _ws.OnError += (sender, e) => MatchmoreLogger.Debug("Error in WS {0} for device {1}", e.Message, device.Id); _ws.OnMessage += (sender, e) => { var data = e.Data; if (data == "ping") { _ws.Send("pong"); } else { _coroutine.RunOnce(Id, GetMatch(data)); } }; _ws.Connect(); }
public static int GetDeviceCount() { return(DeviceApi.GetDeviceCount()); }
public void Init() { instance = new DeviceApi(); }
public static void SetBestDevice() { SetDevice(DeviceApi.GetBestDevice()); }
public static void SetDevice(int i) { DeviceApi.SetDevice(i); CheckDeviceSanity(); }
/// <summary> /// 利用deviceid更新设备属性 (包括获取deviceid和二维码) /// </summary> /// <returns></returns> public ActionResult RegisterDevice(string action, string data) { // var result = new AccessJsonView(); if (!VerifyParam("action,data")) { return(ErrMsg()); } // var action = Request["action"]; // var data = Request["data"]; var weChatConfig = GetWechatConfig(); // TODO:注册设备 if (action.Equals("register")) { var ret = DeviceApi.DeviceRegister(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, data); if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", success = true, resp = ret.resp }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } } // 设备授权验证 else if (action.Equals("auth")) { //product_id 是绑定到账号的 var ret = DeviceApi.DeviceAuthority(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, weChatConfig.ProductID); if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", deviceid = ret.deviceid, qrticket = ret.qrticket, success = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } } return(Json(new { message = "action 参数错误!", success = false }, JsonRequestBehavior.AllowGet)); }