// See ILockIt API documentation private async Task <bool> Authenticate(LockKey key, IDevice device) { var result = new TaskCompletionSource <bool>(); var lockControlService = await device.GetKnownService(LockControlServiceGuid); { var authStatus = await lockControlService.GetKnownCharacteristics(AuthenticationStatusGuid); authStatus.WhenNotificationReceived() .Take(1) .Timeout(MaxAuthDuration) .Subscribe(notification => { result.TrySetResult(notification.Data[0] == 0); }, exception => { result.TrySetResult(false); }); await authStatus.EnableNotifications(); } var authenticationCharacteristic = await lockControlService.GetKnownCharacteristics(AuthenticationGuid); authenticationCharacteristic.WhenNotificationReceived().Take(1).Subscribe(async notification => { var challenge = notification.Data; var crypto = CreateAes(key); challenge = crypto.CreateDecryptor().TransformFinalBlock(challenge, 0, challenge.Length); challenge[^ 1] += 1;
public void ShowLockState(LockKey lockKey, bool state) { if ((lockKey == LockKey.Num && showNum) || (lockKey == LockKey.Caps && showCaps) || (lockKey == LockKey.Scroll && showScroll)) { ShowMessage(lockKey.ToString() + ": " + (state ? "On" : "Off")); } }
//post to keys public void Test(LockKey value) { using (var conn = new SqlConnection(this.connString)) { string sQuery = "INSERT INTO LockKeys (LockID, KeyID)" + " VALUES(@LockID,@KeyID)"; conn.Open(); conn.Execute(sQuery, value); } }
private void DeleteKeySaveTODataCenterBase(int KeyIDNumber) { //从数据库删除 //ConnectionStringSettings CloudLockConnectString = ConfigurationManager.ConnectionStrings["CloudLockConnectString"]; // LockKeyManager MyLockKeyManager = new LockKeyManager(CloudLockConnectString.ConnectionString); LockKeyManager MyLockKeyManager = new LockKeyManager(); LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = MyLockIDStr; AnyLockKey.LockKeyID = KeyIDNumber; MyLockKeyManager.DeleteLockKey(AnyLockKey); //--切底删除--- }
private void AddKeyUpdateTODataCenterBase(int KeyIDNumber) { //更改数据库 //ConnectionStringSettings CloudLockConnectString = ConfigurationManager.ConnectionStrings["CloudLockConnectString"]; //LockKeyManager MyLockKeyManager = new LockKeyManager(CloudLockConnectString.ConnectionString); LockKeyManager MyLockKeyManager = new LockKeyManager(); LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = MyLockIDStr; AnyLockKey.LockKeyID = KeyIDNumber; MyLockKeyManager.UpdateLockKey(AnyLockKey); }
public virtual bool Open(LockKey key) { if (key == this.key) { IsOn = false; return(true); } else { return(false); } }
public void ExploreStudent() { Destroy(BtnExplore); Destroy(PanelNotice); FpsController.gameObject.SetActive(true); DummyCamera.gameObject.SetActive(false); MobileController.SetActive(true); if (SceneManager.GetActiveScene().name != "SceneDoer") { LockKey.SetActive(true); LockKeyCount.SetActive(true); } }
private void AddKeySaveTODataCenterBase(int KeyIDNumber, string NameIDStr) { //插入数据库 //ConnectionStringSettings CloudLockConnectString = ConfigurationManager.ConnectionStrings["CloudLockConnectString"]; LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = MyLockIDStr; AnyLockKey.LockKeyID = KeyIDNumber; AnyLockKey.OwerName = NameIDStr; AnyLockKey.KeyString = "******"; AnyLockKey.CreateTime = DateTime.Now; LockKeyManager MyLockKeyManager = new LockKeyManager(); //CloudLockConnectString.ConnectionString MyLockKeyManager.InsertLockKey(AnyLockKey); }
private string GetKeyDateStrFromODataBase() { LockKeyManager MyLockKeyManager = new LockKeyManager(); //LockKey AnyLockKey = new LockKey(); //AnyLockKey.LockID = this.MyLockIDStr; //AnyLockKey..OwerName = this.NameIDStr; //AnyLockKey.KeyDateStr = this.DateTimeStr; LockKey AnyLockKey = MyLockKeyManager.FindOneLockKey(this.MyLockIDStr, int.Parse(KeyNumberIDStr)); if (AnyLockKey != null) { return(MyLockKeyManager.FindOneLockKey(this.MyLockIDStr, int.Parse(KeyNumberIDStr)).KeyDateStr); } else { return(null); } }
/// <summary> /// Controls the concurrent / multi-threaded calls to a single Func /// by queuing multi-threaded calls to it and /// bouncing off (not executing) extra calls that exceed its queue_length parameter /// </summary> /// <typeparam name="T">Result value of the the Func.</typeparam> /// <param name="func">The Func delegate to be called</param> /// <param name="defaultValue">Default value of T that gets returned in the event of a calls is bounced off the queue</param> /// <param name="key">By default, this extension method could automatically tell /// the unique signature of the Func to determine whether or not /// another thread is currently executing it. /// However, when the Func has input variable that aren't final /// (e.g. SomeFunc(5,2) <= final values, SomeFunc(x,y) <= non final), /// then a unique key is needed to identify the Func signature, /// as otherwise this extension method would always default to allowing unlimited multi-threaded calls to /// execute the Func if it couldn't identify its unique signature. /// </param> /// <param name="queueLength"></param> /// <returns></returns> public static T QueueCall <T>(Func <T> func, T defaultValue = default, int queueLength = 1, object key = null ) { var localCount = Interlocked.Increment(ref lockCount); if (key == null) { key = func; } LockKey lockKey = null; lock (lockObj) { lockKey = locks.FirstOrDefault(x => x.Key.Equals(key)); if (lockKey != null && lockKey.Count > queueLength) { return(defaultValue); } if (lockKey == null) { lockKey = new LockKey() { Key = key, Count = 1 } } ; else { lockKey.Count++; } } T result = func(); lock (lockObj) { locks.Remove(lockKey); return(result); } }
private int AddKeySaveTODataCenterBaseEx() { //-----插入数据库---------------------------------- //int KeyIDNumberID=0; //ConnectionStringSettings CloudLockConnectString = ConfigurationManager.ConnectionStrings["CloudLockConnectString"]; //LockKeyManager MyLockKeyManager = new LockKeyManager(CloudLockConnectString.ConnectionString); //LockKeyManager MyLockKeyManager = new LockKeyManager(); LockKeyManager MyLockKeyManager = new LockKeyManager(); LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = this.MyLockIDStr; AnyLockKey.LockKeyID = this.KeyIDNumber; AnyLockKey.OwerName = this.NameIDStr; AnyLockKey.KeyDateStr = this.DateTimeStr; //return MyLockKeyManager.InsertLockKeyEx(AnyLockKey); return(MyLockKeyManager.InsertLockKeyEx(AnyLockKey)); }
private void AddKeySynchProc() { string CreateDateStr; int KeyCount; int KeyID; //--密钥部分------------------------------------------------------------------------------------------------------------- KeyCount = this.MyReadBuffers[22]; //MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("当前有效密钥数[{0}]", KeyCount)); int ReturnCode; LockKeyManager MyLockKeyManager = new LockKeyManager(); for (int i = 0; i < KeyCount; i++) { int Index = 23 + 17 * i; KeyID = this.MyReadBuffers[Index]; CreateDateStr = null; CreateDateStr = Encoding.ASCII.GetString(this.MyReadBuffers, Index + 2, 15); //CreateDateStr = CreateDateStr.Insert(4, "-"); //CreateDateStr = CreateDateStr.Insert(7, "-"); //CreateDateStr = CreateDateStr.Insert(10, " "); //CreateDateStr = CreateDateStr.Insert(13, ":"); //CreateDateStr = CreateDateStr.Insert(16, ":"); //MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]号密钥创建日期[{1}]", KeyID, CreateDateStr)); //LockKeyManager MyLockKeyManager = new LockKeyManager(); //LockKeyManager MyLockKeyManager = new LockKeyManager(this.MyAsynchLockServerSocketService.MySqlConnection); LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = this.MyLockIDStr; AnyLockKey.LockKeyID = KeyID; AnyLockKey.OwerName = "XXX" + string.Format("{0:D2}", KeyID); AnyLockKey.CreateTime = this.GetCreateDateFromStr(CreateDateStr); AnyLockKey.KeyDateStr = CreateDateStr; //ReturnCode = MyLockKeyManager.SynchAddLockKey(AnyLockKey); ReturnCode = MyLockKeyManager.SynchAddLockKey(AnyLockKey); MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]保存[{1}]号密钥到数据库[{2}]", MyLockIDStr, KeyID, ReturnCode)); } }
public static void Run(LockKey key, Action action) { using (var db = Factory.Instance.CreateDbContext()) { try { db.Session.CommandTimeout = 60; db.Session.BeginTransaction(); db.Session.ExecuteScalar(@" select `key` from t_lock where `key` = @key FOR UPDATE;", new DbParam[] { new DbParam("key", key.ToString()) }); action(); db.Session.CommitTransaction(); } catch (Exception ex) { db.Session.RollbackTransaction(); throw ex; } } }
/// <summary> /// Controls the concurrent / multi-threaded calls to a single Action /// by queuing multi-threaded calls to it and /// bouncing off (not executing) extra calls that exceed its queueLength parameter /// </summary> /// <param name="action"></param> /// <param name="key">By default, this extension method could automatically tell /// the unique signature of the Action to determine whether or not /// another thread is currently executing it. /// However, when the Action has input variable that aren't final /// (e.g. SomeAction(5,2) <= final values, SomeAction(x,y) <= non final), /// then a unique key is needed to identify the Action signature, /// otherwise this extension method would always default to allowing unlimited multi-threaded calls to /// execute the Action if it couldn't identify its unique signature. </param> /// <param name="queueLength">Maximum queue length, default is 1 (i.e. only one call is allowed, any extra concurrent calls are ignored)</param> public static void QueueCall(Action action, int queueLength = 1, object key = null) { //var localCount = Interlocked.Increment(ref lockCount); if (key == null) { key = action; } LockKey lockKey = null; lock (lockObj) { lockKey = locks.FirstOrDefault(x => x.Key.Equals(key)); if (lockKey != null && lockKey.Count > queueLength) { return; } if (lockKey == null) { lockKey = new LockKey() { Key = key, Count = 1 } } ; else { lockKey.Count++; } } action(); lock (lockObj) { locks.Remove(lockKey); } }
private void DeleteKeySynchProc() { string CreateDateStr; int KeyCount; int KeyID; //--密钥部分------------------------------------------------------------------------------------------------------------- KeyCount = this.MyReadBuffers[22]; //MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("当前有效密钥数[{0}]", KeyCount)); //----------------------------------------------------------------------------------------------------------------------- LockKeyManager MyLockKeyManager = new LockKeyManager(); for (int i = 0; i < KeyCount; i++) { int Index = 23 + 17 * i; KeyID = this.MyReadBuffers[Index]; CreateDateStr = null; CreateDateStr = Encoding.ASCII.GetString(this.MyReadBuffers, Index + 2, 15); //CreateDateStr = CreateDateStr.Insert(4, "-"); //CreateDateStr = CreateDateStr.Insert(7, "-"); //CreateDateStr = CreateDateStr.Insert(10, " "); //CreateDateStr = CreateDateStr.Insert(13, ":"); //CreateDateStr = CreateDateStr.Insert(16, ":"); //MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]号密钥创建日期[{1}]", KeyID, CreateDateStr)); //LockKeyManager MyLockKeyManager = new LockKeyManager(); LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = MyLockIDStr; AnyLockKey.LockKeyID = KeyID; //MyLockKeyManager.DeleteLockKeyEx(AnyLockKey);//--采用标志删除-- MyLockKeyManager.DeleteLockKeyEx(AnyLockKey); //--采用标志删除-- MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]删除[{1}]号密钥从数据库", MyLockIDStr, KeyID)); } }
private static Aes CreateAes(LockKey key) => new AesManaged { Key = key.UserKey, Mode = CipherMode.ECB, Padding = PaddingMode.Zeros, };
private void AllInforSynchProc() { string MasterKey = null; string CreateDateStr; int KeyCount; int KeyID; //---母码部分-------------------------------------------------------------------------------------------------------------- for (int i = 0; i < 6; i++) { MasterKey = MasterKey + this.MyReadBuffers[22 + i].ToString(); } CreateDateStr = Encoding.ASCII.GetString(this.MyReadBuffers, 28, 15); //CreateDateStr = CreateDateStr.Insert(4, "-"); //CreateDateStr = CreateDateStr.Insert(7, "-"); //CreateDateStr = CreateDateStr.Insert(10, " "); //CreateDateStr = CreateDateStr.Insert(13, ":"); //CreateDateStr = CreateDateStr.Insert(16, ":"); MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]母码修改为[{1}]", MyLockIDStr, MasterKey)); //LockManager MyLockManager = new LockManager(); //MyLockManager.UpdateMasterKey(MyLockIDStr, MasterKey);//--保存数据库 LockManager MyLockManager = new LockManager(); MyLockManager.UpdateMasterKey(MyLockIDStr, MasterKey); //--保存新母码到数据库 //--密钥部分------------------------------------------------------------------------------------------------------------- KeyCount = this.MyReadBuffers[43]; //MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("当前有效密钥数[{0}]", KeyCount)); //-------------------------------------------------------------------------------------------------- int ReturnCode; LockKeyManager MyLockKeyManager = new LockKeyManager(); for (int i = 0; i < KeyCount; i++) { int Index = 44 + 17 * i; KeyID = this.MyReadBuffers[Index]; CreateDateStr = null; CreateDateStr = Encoding.ASCII.GetString(this.MyReadBuffers, Index + 2, 15); //CreateDateStr = CreateDateStr.Insert(4, "-"); //CreateDateStr = CreateDateStr.Insert(7, "-"); // CreateDateStr = CreateDateStr.Insert(10, " "); // CreateDateStr = CreateDateStr.Insert(13, ":"); // CreateDateStr = CreateDateStr.Insert(16, ":"); // MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]号密钥创建日期[{1}]", KeyID, CreateDateStr)); //------------------------------------------------------------------------------------------------- //LockKeyManager MyLockKeyManager = new LockKeyManager(); LockKey AnyLockKey = new LockKey(); AnyLockKey.LockID = this.MyLockIDStr; AnyLockKey.LockKeyID = KeyID; AnyLockKey.OwerName = "XXX" + string.Format("{0:D2}", KeyID); AnyLockKey.CreateTime = this.GetCreateDateFromStr(CreateDateStr); AnyLockKey.KeyDateStr = CreateDateStr; //ReturnCode=MyLockKeyManager.SynchAddLockKey(AnyLockKey); ReturnCode = MyLockKeyManager.SynchAddLockKey(AnyLockKey); MyAsynchLockServerSocketService.DisplayResultInfor(1, string.Format("[{0}]保存[{1}]号密钥到数据库[{2}]", MyLockIDStr, KeyID, ReturnCode)); } }
public static void Run(LockKey key, Action action) { DAL.LockAction.Run(key, action); }
// static public string GetMap(string dwsUrl, string docName, string mapName, int level, int row, int col, int size, string format) { string FolderPath = ConfigurationManager.AppSettings["CachePath"].ToString() + "\\" + size + "\\" + docName + "\\" + mapName + "\\" + level; string path = FolderPath + "\\" + row + "_" + col + ".png"; //查找缓存 FileInfo f = new FileInfo(path); if (f.Exists) { if (f.Length == 0 || f.Length == 1275) { return("empty"); } return(path); } //计算绘制等级,行列号,和范围 int uplevel = UP_LEVLE; int drawLevel = level - uplevel; double drawSize = LEVEL0_TILE_SIZE / Math.Pow(2, level); int drawPixelSize = size; int drawRow = row; int drawCol = col; while (uplevel-- > 0) { drawRow /= 2; drawCol /= 2; drawSize *= 2; drawPixelSize *= 2; } //构造绘制块Key string drawKey = "/DCSMap/" + size + "/" + docName + "/" + mapName + "/" + drawLevel + "/" + drawRow + "/" + drawCol; // string filepath = null; // try { LockKey.Lock(drawKey); //计算范围 double xmin = -180 + (drawCol * drawSize); double ymin = -90 + (drawRow * drawSize); double xmax = xmin + drawSize; double ymax = ymin + drawSize; // string box = xmin + "," + ymin + "," + xmax + "," + ymax; // DWS.dwService dws = new DWS.dwService(); dws.Url = dwsUrl; //DWS.MapQuery query = new DWS.MapQuery(); //query.box = box; //query.format = format; //query.classPath = ""; //query.mapDoc = docName; //query.mapName = mapName; //query.col = -1; //query.row = -1; //query.level = 0; //query.useTile = false; //query.width = drawPixelSize; //query.height = drawPixelSize; DWS.MapQuery query = new DWS.MapQuery(); query.format = "png"; query.classPath = ""; query.mapDoc = docName; query.mapName = mapName; query.col = col; query.row = row; query.level = (short)level; query.useTile = true; query.width = 256; query.height = 256; //开始绘制 DWS.MapInfo mi = dws.getMap(query); //创建文件夹 if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } //绘制成功 if (mi.isSuccess && mi.image != null) { //开始的行列号 int sRow = drawRow; int sCol = drawCol; //瓦块行列数目 int rowNum = 1; int colNum = 1; uplevel = UP_LEVLE; while (uplevel-- > 0) { sRow *= 2; sCol *= 2; rowNum *= 2; colNum *= 2; } // hack, 850 byte and 6120 byte is empty if (mi.image.Length == 850 && mi.image.Length == 24072) { // 记录缓存 for (int nr = 0; nr < rowNum; ++nr) { for (int nc = 0; nc < colNum; ++nc) { //string tilepath = FolderPath + "/" + row + "_" + col + ".png"; string tilepath = FolderPath + "/" + (sRow + nr) + "_" + (sCol + nc) + ".png"; FileStream fs = File.Open(tilepath, FileMode.CreateNew); fs.Close(); } } } else { //请求到的图片 MemoryStream stream = new MemoryStream(mi.image); Bitmap fullimage = new Bitmap(stream); // Bitmap bmp = new Bitmap(size, size); Graphics g = Graphics.FromImage(bmp); // Rectangle destRect = new Rectangle(0, 0, size, size); Rectangle srcRect = new Rectangle(0, 0, size, size); //分割图片 for (int nr = 0; nr < rowNum; ++nr) { for (int nc = 0; nc < colNum; ++nc) { g.Clear(System.Drawing.Color.Transparent); srcRect.X = nc * size; srcRect.Y = drawPixelSize - (nr * size) - size; g.DrawImage(fullimage, destRect, srcRect, GraphicsUnit.Pixel); // string tilepath = FolderPath + "/" + (sRow + nr) + "_" + (sCol + nc) + ".png"; try { File.Delete(tilepath); bmp.Save(tilepath); } catch (Exception) { } } } } filepath = path; } else { // error filepath = null; } } catch (Exception) { filepath = null; } finally { LockKey.UnLock(drawKey); } return(filepath); }
static public string GetTDT(string layer, int level, int row, int col) { //过滤平面8-13列的请求 int maxCol = 8 * (int)Math.Pow(2, level); if (col >= maxCol) { return(null); } int tdtlevel = level + 3; string tdtlayer = layer; //string tdtlayer = GetTDTLayerName(layer, tdtlevel); if (tdtlayer == null) { return(null); } // string FolderPath = ConfigurationManager.AppSettings["CachePath"] + "\\256\\TDTSource" + "\\" + layer + "\\" + level; string path = FolderPath + "\\" + row + "_" + col + ".png"; if (File.Exists(path)) { return(path); } //构造绘制块Key string drawKey = "/TDTImage/256" + "/" + layer + "/" + level + "/" + row + "/" + col; try { // LockKey.Lock(drawKey); //创建文件夹 if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } //天地图第3级行列号 int tdtrownum = 4; int tdtcolnum = 8; int tl = level; while (tl-- > 0) { tdtrownum *= 2; tdtcolnum *= 2; } int tdtrow = tdtrownum - row - 1; int tdtcol = col; Random r = new Random(); int ser = r.Next(8); //string url1 = "http://tile" + ser + ".tianditu.com/DataServer?T=" + tdtlayer + "&X=" + tdtcol + "&Y=" + tdtrow + "&L=" + tdtlevel; string url1 = ""; switch (tdtlayer) { case "img_c": url1 = "http://t" + ser + ".tianditu.cn/" + tdtlayer + "/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=c&TILEMATRIX=" + tdtlevel + "&TILEROW=" + tdtrow + "&TILECOL=" + tdtcol + "&FORMAT=tiles"; break; case "vec_c": url1 = "http://t" + ser + ".tianditu.cn/" + tdtlayer + "/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=c&TILEMATRIX=" + tdtlevel + "&TILEROW=" + tdtrow + "&TILECOL=" + tdtcol + "&FORMAT=tiles"; break; case "cva_c": url1 = "http://t" + ser + ".tianditu.cn/" + tdtlayer + "/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=c&TILEMATRIX=" + tdtlevel + "&TILEROW=" + tdtrow + "&TILECOL=" + tdtcol + "&FORMAT=tiles"; break; case "X0110_ZL_GJ": case "X0110_ZL_SJ": url1 = "http://t" + ser + ".tianditu.cn/DataServer?T=bou_c&X=" + tdtcol + "&Y=" + tdtrow + "&L=" + tdtlevel + ""; break; case "W1103_TMap": url1 = "http://t" + ser + ".tianditu.cn/DataServer?T=wat_c&X=" + tdtcol + "&Y=" + tdtrow + "&L=" + tdtlevel + ""; break; } try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url1); request.Timeout = Timeout; HttpWebResponse response = null; using (response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.OK) { int len = (int)response.ContentLength; if (len == 2407) { path = null; //return "empty"; } else { using (Stream responseStream = response.GetResponseStream()) { BinaryReader reader = new BinaryReader(responseStream); byte[] byteArry = reader.ReadBytes(len); FileStream fs = File.Open(path, FileMode.Create); fs.Write(byteArry, 0, byteArry.Length); fs.Close(); } } } } } catch (Exception) { path = null; } } catch (Exception) { path = null; } finally { LockKey.UnLock(drawKey); } return(path); }
static public string GetAltitude(string dwsUrl, string classpath, string filter) { string path = null; try { string[] tmp = filter.Split(','); string level = tmp[2].Split(':')[1]; string row = tmp[0].Split(':')[1]; string col = tmp[1].Split(':')[1]; string sample = tmp[7].Split(':')[1]; string xmax = tmp[3].Split(':')[1]; string xmin = tmp[4].Split(':')[1]; string ymin = tmp[5].Split(':')[1]; string ymax = tmp[6].Split(':')[1]; filter = "row:" + row + ",col:" + col + ",level:" + level + ",xmax:" + xmax + ",xmin:" + xmin + ",ymin:" + ymin + ",ymax:" + ymax + ",sample:" + sample; string safeclasspath = Uri.EscapeDataString(classpath); string FolderPath = ConfigurationManager.AppSettings["DEMCachePath"].ToString() + "/" + sample + "/" + safeclasspath + "/" + level; path = FolderPath + "/" + row + "_" + col + ".db"; if (File.Exists(path)) { return(path); } //创建文件夹 if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } string getKey = "/DCSDem/" + sample + "/" + classpath + "/" + level + "/" + row + "/" + col; LockKey.Lock(getKey); try { byte[] dem = GetTDData(dwsUrl, "altitude", classpath, filter); if (dem != null) { FileStream fs = File.Open(path, FileMode.Create); fs.Write(dem, 0, dem.Length); fs.Close(); return(path); } else { return(null); } } catch (Exception) { path = null; } finally { LockKey.UnLock(getKey); } } catch (Exception) { path = null; } return(path); }
public void Post([FromBody] LockKey value) { lockKeyDataRepository.Test(value); }
public KeylockChangeArgs(LockKey lockKey, bool isOn) { this.LockKey = lockKey; this.IsOn = isOn; }
public virtual void OnKeyboardEvent(KeyboardEvent keyEvent) { m_lockKey = keyEvent.LockKey; }
public void ClearLockKey() { m_lockKey = 0; }
/// <summary> /// Compares two LockKey's keyID string /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool CompareId(LockKey a, LockKey b) { if (a.keyId == b.keyId) return true; else return false; }
public KeyboardEvent(EventState state, TKey key, LockKey lockKey) { m_state = state; m_key = key; m_lockKey = lockKey; }
private async Task <IDevice?> Initialize(Lock @lock, LockKey key) { if (_adapter.Status != AdapterStatus.PoweredOn) { if (!(_adapter.CanControlAdapterState() && await TurnOnBle())) { await _dialogService.ShowError("Bluetooth anschalten", "Schalten Sie Bluetooth ein, um das Schloss zu bedienen"); return(null); } Task <bool> TurnOnBle() { TaskCompletionSource <bool> bleResult = new TaskCompletionSource <bool>(); _adapter.WhenStatusChanged() .Timeout(MaxTurnOnBluetoothDuration) .Subscribe(status => { if (status == AdapterStatus.PoweredOn) { bleResult.TrySetResult(true); } }, exception => { bleResult.TrySetResult(false); }); try { _adapter.SetAdapterState(true); } catch (Exception) { return(Task.FromResult(false)); } return(bleResult.Task); } } var result = new TaskCompletionSource <IDevice?>(); _adapter.ScanUntilDeviceFound(@lock.Name) .Take(1) .Timeout(MaxScanDuration) .Subscribe(device => { device.WhenConnected().Take(1).Subscribe(async _ => { var success = await Authenticate(key, device); if (success) { result.TrySetResult(device); } else { result.TrySetResult(null); await _dialogService.ShowError("Authentifizierung fehlgeschlagen", "Das Schloss konnte aufgrund eines Fehlers mit der Authentifizierung nicht geöffnet werden."); } }, async exception => { result.TrySetResult(null); await _dialogService.ShowError("Verbindung fehlgeschlagen", "Die Verbindung zum Schloss ist fehlgeschlagen, obwohl das Schloss gefunden wurde."); }); device.Connect(new ConnectionConfig { AutoConnect = false }); }, async exception => { await _dialogService.ShowError("Schloss wurde nicht gefunden", "Das Schloss konnte nicht gefunden werden."); result.TrySetResult(null); }); return(await result.Task); }