private void _ic_Notified(CVResult result, object obj) { if (result == CVResult.ResourceOperationResponded) { if (obj is ResourcePt) { ResourcePt r = obj as ResourcePt; if (r.service == 4) { if (r.success == 0) { string tempPathfile = Kits.GetTempPathfile(r.name); string pathfile = _dc.GetFtpPathfileWithoutRemoteDirectory(r.pathfile); DownloadDataItem ddi = new DownloadDataItem() { Source = pathfile, Target = tempPathfile, Id = r.objectid, Crc = r.crc }; _dc.Add(ddi); } else { Notified?.Invoke(CVResRequestResult.SourceNotFound, r.msg); } } } } }
public static void Notify(params byte[][] messages) { messages.ToList().ForEach(x => Console.Write(string.Concat(x.AsString(), "|"))); Console.WriteLine(); Notified?.Invoke(messages); }
private void _timer_Elapsed(object sender, ElapsedEventArgs e) { _timeout = true; _timer.Stop(); Notified?.Invoke(CVRTableResult.OperationTimeout, Token); }
/// <summary> /// 启动队列、检查目录 /// </summary> public void Start() { try { //链接&改变目录 Connect(); //检查目录 if (!Directory.Exists(LocalDirectory)) { Notified?.Invoke(CVResult.LocalDirectoryException, LocalDirectory); throw new Exception("没有找到本地目录 " + LocalDirectory); } _dataOpQue = new DataOpQue(this); //启动操作队列 Begin(); Notified?.Invoke(CVResult.DatacenterReady, this); } catch (IOException ioe) { Notified?.Invoke(CVResult.RemoteException, ioe.Message); } catch (Exception ex) { Notified?.Invoke(CVResult.DatacenterNotConnected, ex.Message); } }
internal void NotifyAll() { Notify(() => Token); Notify(() => PropertyLabel); Notified?.Invoke(); }
private void ParseMinaQueueThread() { try { while (true) { byte[] body = _minaQueue.Dequeue(); if (body != null) { _parser.Do(RC4.Convert(body, 4)); } Thread.Sleep(10); } } catch (SocketException ex) { Shutdown(); Notified?.Invoke(CVResult.ReceiveCallbackFailed, ex); } catch (ObjectDisposedException) { _connected = false; Notified?.Invoke(CVResult.InfocenterNotConnected, this); } catch (Exception ex) { Notified?.Invoke(CVResult.ExceptionHappened, ex); } }
static void OnPeripheralUpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e) { if (e.Characteristic.Value == null) { return; } Notified?.Invoke(null, new NotificationEventArgs()); }
/// <summary> /// 发送信息给id /// </summary> /// <param name="message"></param> /// <param name="i"></param> public void Send(string message, int i) { if (_user != null) { _ieo.Send(_user.Id, _user.Name, i.ToString(), message); } else { Notified?.Invoke(CVRInfoExResult.CurrentUserHappened, "没有用户信息"); } }
internal void NotifyAll() { Notify(() => Token); Notify(() => IsGroupKey); Notify(() => GroupByEnabled); Notify(() => GroupByChecked); Notify(() => GroupByVisible); Notify(() => PropertyLabel); Notified?.Invoke(); }
private void DownloadDirectory(object o) { string pathname = o as string; //获取当前目录所有文件 GetFilesItem gfi = new GetFilesItem { Target = _dc.GetFtpPathfile(pathname) }; _dc.Execute(gfi); if (gfi.Success == false) { Notified?.Invoke(CVRDownloadResult.SourceHappened, gfi.Target); return; } foreach (FileInfoItem fii in gfi.Files) { if (_excludedItems.Contains(fii.Name)) { continue; } string remote = _dc.GetFtpPathfile(Path.Combine(pathname, fii.Name)); DownloadDataItem ddi = new DownloadDataItem { Source = remote, Target = _dc.GetDrivePathfile(Path.Combine(_temp, Path.Combine(pathname, fii.Name))) }; string dir = (new FileInfo(ddi.Target)).DirectoryName; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } _requestedCount++; _dc.Add(ddi); } //获取当前目录所有子目录 GetDirectoriesItem gdi = new GetDirectoriesItem { Target = _dc.GetFtpPathfile(pathname) }; _dc.Execute(gdi); foreach (FileInfoItem fii in gdi.Directories) { DownloadDirectory(Path.Combine(pathname, fii.Name)); } }
private void _dc_Ended(IDataOpItem item) { if (item is DownloadDataItem) { DownloadDataItem ddi = item as DownloadDataItem; if (ddi.Success) { if (_excludedItems.Contains(Kits.GetFilename(ddi.Target))) { return; } _downedCount++; //unpackage string target = ddi.Target.Replace(@"\" + _temp, ""); string dir = (new FileInfo(target)).DirectoryName; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } try { int l = ResourcePackage.Unpackage(ddi.Target, target); Notified?.Invoke(CVRDownloadResult.Finished, new FinishedItem { Name = target, Length = l }); } catch { Notified?.Invoke(CVRDownloadResult.UnpackageHappened, target); } if (_requestedCount == _downedCount) { string targetemp = Path.Combine(Target, _temp); if (Directory.Exists(targetemp)) { Kits.DeleteDirectory(targetemp); } Notified?.Invoke(CVRDownloadResult.Completed, _downedCount); } } else { Notified?.Invoke(CVRDownloadResult.DownloadHappened, ddi.Source); } } }
/// <summary> /// 下载资源集文件内容 /// </summary> /// <param name="pathfile"></param> public void DownloadResXml(string pathfile) { if (File.Exists(pathfile)) { ResXmlReader rxr = new ResXmlReader(pathfile); foreach (XmlNode xn in rxr.Root.ChildNodes) { ResXmlItem rxi = new ResXmlItem(xn); Download(rxi.Id); } } else { Notified?.Invoke(CVResRequestResult.XmlNotExisted, pathfile); } }
/// <summary> /// 发送信息给多个id /// </summary> /// <param name="message"></param> /// <param name="ids"></param> public void Send(string message, params int[] ids) { if (_user != null) { string sentId = string.Empty; foreach (int i in ids) { sentId += i + ","; } _ieo.Send(_user.Id, _user.Name, sentId, message); } else { Notified?.Invoke(CVRInfoExResult.CurrentUserHappened, "没有用户信息"); } }
private void _ic_Notified(CVResult r, object o) { if (r == CVResult.TableQueryReceived) { if (o is QueryResultPt) { QueryResultPt qrp = o as QueryResultPt; if (qrp.success == 0) { if (qrp.resultFmart == "xml") { _txw = new TableXmlWrapper(qrp); Notified?.Invoke(CVRTableResult.SelectXmlReceived, _txw); } else if (qrp.resultFmart == "json") { _cjp = new CVRJsonParser(qrp.result) { Token = qrp.token, Count = qrp.count }; Notified?.Invoke(CVRTableResult.SelectJsonReceived, _cjp); } } else { Notified?.Invoke(CVRTableResult.SelectFailed, qrp.msg); } } } else if (r == CVResult.TableUpdateReceived) { if (o is ExecuteResultPt) { ExecuteResultPt erp = o as ExecuteResultPt; _ui = new UpdateItem { Id = erp.token, Succeed = erp.success == 0, Msg = erp.msg }; Notified?.Invoke(CVRTableResult.UpdateResultReceived, _ui); } } }
private void _dc_Ended(IDataOpItem item) { if (item is DownloadDataItem) { DownloadDataItem ddi = item as DownloadDataItem; if (ddi.Success) { string crc = FileMD5.Create(ddi.Target); if (crc == ddi.Crc) { string localPathfile = _dc.GetLocalPathfile(ddi.Source); try { if (LocalFile) { ResourcePackage.Unpackage(ddi.Target, localPathfile); Notified?.Invoke(CVResRequestResult.RequestFileSucceed, localPathfile); } else { byte[] buff = ResourcePackage.Unpackage(File.ReadAllBytes(ddi.Target)); Notified?.Invoke(CVResRequestResult.RequestDataSucceed, buff); } } catch (NullReferenceException) { Notified?.Invoke(CVResRequestResult.UnpackageFailed, localPathfile); } catch (IOException) { Notified?.Invoke(CVResRequestResult.WriteFailed, localPathfile); } } else { Notified?.Invoke(CVResRequestResult.CrcFailded, ddi.Message); } } else { Notified?.Invoke(CVResRequestResult.DownloadFailed, ddi.Message); } } }
/// <summary> /// 条件下载 /// </summary> /// <param name="where">下载条件</param> public void Download(string where, int pageSize = 20, int pageNo = 0) { _pageNo = pageNo; _pageSize = pageSize; _pageCount = 0; _curIndex = 0; _curNum = 0; if (Directory.Exists(_dc.LocalDirectory)) { _sqlString = "SELECT objectid,pathfile,name,folder,version,versionname,lastwrite,remark,crc FROM " + _resTable + (where.Length == 0 ? "" : " WHERE " + where); _to.Token = _token = Guid.NewGuid().ToString("N"); _to.Select(_sqlString, _pageSize, _pageNo); } else { Notified?.Invoke(CVResDownloadResult.TargetDirectoryFailed, _dc.LocalDirectory); } }
internal void ProcessNotifications() { // handle notify events var notifys = _pendingNotifys.ToArray(); _pendingNotifys.Clear(); foreach (var notify in notifys) { Notified?.Invoke(notify.Ent, notify.Type, notify.Parameters); if (_notifyHandlers.ContainsKey(notify.Type)) { var handlers = _notifyHandlers[notify.Type]; foreach (var handler in handlers) { try { var parameters = handler.Method.GetParameters(); if (parameters.Length > 0 && parameters[0].ParameterType == typeof(Entity)) { var newParameters = new object[notify.Parameters.Length + 1]; newParameters[0] = (this is Entity) ? (Entity)this : null; Array.Copy(notify.Parameters, 0, newParameters, 1, notify.Parameters.Length); handler.DynamicInvoke(newParameters); } else { handler.DynamicInvoke(notify.Parameters); } } catch (Exception ex) { Log.Write(LogLevel.Error, "Exception during handling of notify event {0} on {1}: {2}", notify.Type, this, (ex.InnerException != null) ? ex.InnerException.ToString() : ex.ToString()); } } } } }
/// <summary> /// 删除 /// </summary> /// <param name="target">远程全路径文件名</param> public void DeleteFile(DeleteDataItem ddi) { try { string filename = ddi.Target.Replace(CurrentRemotePath + Path.AltDirectorySeparatorChar, ""); Delete(filename); ddi.Success = true; if (ddi.Replied) { Ended?.Invoke(ddi); } } catch (IOException ex) { ddi.Message = ex.Message; ddi.Success = false; Notified?.Invoke(CVResult.DeleteFileExceptionHappened, ddi); } }
/// <summary> /// 删除远程目录 /// </summary> /// <param name="rdi"></param> public void RemoveDirectory(RemoveDirectoryItem rdi) { string ipfolder = rdi.Target.Replace(CurrentRemotePath + Path.AltDirectorySeparatorChar, ""); try { RmDir(ipfolder); rdi.Success = true; if (rdi.Replied) { Ended?.Invoke(rdi); } } catch (IOException ex) { rdi.Message = ex.Message; rdi.Success = false; Notified?.Invoke(CVResult.MakeDirectoryExceptionHappened, rdi); } }
private void _ic_Notified(CVResult result, object obj) { if (result == CVResult.ResourceOperationResponded) { if (obj is ResourcePt) { ResourcePt r = obj as ResourcePt; if (r.service == 1) { if (r.success == 0) { Notified?.Invoke(CVReSubmitResult.SubmitSucceed, r.pathfile); } else { Notified?.Invoke(CVReSubmitResult.UploadFailed, r.msg); } } } } }
/// <summary> /// 发送数据 /// </summary> /// <param name="buff"></param> internal void Send(byte[] buff) { try { if (_client == null) { throw new NullReferenceException("未连接"); } _client.BeginSend(buff, 0, buff.Length, 0, new AsyncCallback(SendCallback), _client); } catch (SocketException sex) { _connected = false; Notified?.Invoke(CVResult.SendFailed, sex); } catch (NullReferenceException) { _connected = false; Notified?.Invoke(CVResult.InfocenterNotConnected, this); } }
/// <summary> /// 重命名 /// </summary> /// <param name="ri"></param> public void Rename(RenameItem ri) { string remotePathfile = ri.Source.Replace(CurrentRemotePath + Path.AltDirectorySeparatorChar, ""); string filename = ri.Target; try { Rename(remotePathfile, filename); ri.Success = true; if (ri.Replied) { Ended?.Invoke(ri); } } catch (IOException ex) { ri.Message = ex.Message; ri.Success = false; Notified?.Invoke(CVResult.RenameExceptionHappened, ri); } }
/// <summary> /// 关闭 /// </summary> public void Shutdown() { try { if (_client == null) { throw new NullReferenceException("尚未连接信息中心"); } Bye(); if (_parser != null) { _parser.Notified -= _parser_Info; } _client.Shutdown(SocketShutdown.Both); _client.Close(); Notified?.Invoke(CVResult.InfocenterDisconnected, this); } catch (NullReferenceException) { Notified?.Invoke(CVResult.InfocenterNotConnected, this); } catch (SocketException ex) { Notified?.Invoke(CVResult.SocketExceptionHappened, ex); } catch (ObjectDisposedException) { Notified?.Invoke(CVResult.InfocenterDisconnected, this); } finally { Reset(); } }
/// <summary> /// 上传 /// </summary> /// <param name="localPathfile">本地全路径文件名</param> /// <param name="version"></param> /// <param name="group"></param> /// <param name="remark"></param> public void Upload(string localPathfile, string version = "", int group = 0, string remark = "") { try { string tempPathfile = Kits.GetTempPathfile(Kits.GetFilename(localPathfile)); ResourcePackage.Package(localPathfile, tempPathfile); UploadDataItem ud = new UploadDataItem() { Source = tempPathfile, Target = _dc.GetRemotePathfile(localPathfile), Version = version, Group = group, Remark = remark, Tag = localPathfile }; _dc.Add(ud); } catch (IOException ioe) { Notified?.Invoke(CVReSubmitResult.SourceNotFound, ioe.Message); } }
/// <summary> /// 发送信息给所有 /// </summary> /// <param name="message"></param> public void Send(string message) { if (_user != null) { string sentId = string.Empty; foreach (KeyValuePair <int, UserItem> kvp in _users) { sentId += kvp.Key + ","; } if (sentId != string.Empty) { _ieo.Send(_user.Id, _user.Name, sentId, message); } else { Notified?.Invoke(CVRInfoExResult.NoneUsersHappened, "没有其他用户信息"); } } else { Notified?.Invoke(CVRInfoExResult.CurrentUserHappened, "没有用户信息"); } }
/// <summary> /// 获取远程文件大小 /// </summary> /// <param name="dsi"></param> /// <returns>-1:则获取失败</returns> public long GetFileSize(DataSizeItem dsi) { dsi.Size = -1; try { string filename = dsi.Target.Replace(CurrentRemotePath + Path.AltDirectorySeparatorChar, ""); dsi.Size = GetFileSize(filename); dsi.Success = true; if (dsi.Replied) { Ended?.Invoke(dsi); } } catch (IOException ex) { dsi.Message = ex.Message; dsi.Success = false; Notified?.Invoke(CVResult.GetFileSizeExceptionHappened, dsi); } return(dsi.Size); }
private void ConnectCallback(IAsyncResult ar) { try { Socket client = (Socket)ar.AsyncState; client.EndConnect(ar); //连接成功,创建剖析器 _parser = new InfocenterParser(this); _parser.Notified += _parser_Info; //创建日志读写操作 _logTableOp = OpFactory <TableOp> .Create(_instance); while (true) { if (_client != null) { byte[] buff = new byte[_bufferSize]; int bytesRead = _client.Receive(buff); _minaQueue.Enqueue(buff, bytesRead); } else { break; } Thread.Sleep(10); } } catch (SocketException ex) { Reset(); Notified?.Invoke(ex.SocketErrorCode == SocketError.TimedOut ? CVResult.ServerConnectTimeouted : CVResult.ConnectFailed, ex); } }
/// <summary> /// 客户端实例 /// </summary> /// <param name="ip">信息中心ip,应保证其合法性</param> /// <param name="port"></param> private Infocenter(string ip, int port, string user, string pwd) { _ip = ip; _port = port; _user = user; _pwd = pwd; if (string.IsNullOrEmpty(_ip) || string.IsNullOrEmpty(_user) || string.IsNullOrEmpty(_pwd) || _port == 0 ) { Notified?.Invoke(CVResult.InfocenterParameterHappened, "服务器参数配置问题"); } _connected = false; _remoteEP = new IPEndPoint(IPAddress.Parse(ip), port); //本机特征 _localIp = Kits.GetIp(); _localName = Environment.MachineName; Log.Added += AddLog; }
private void _dc_Ended(IDataOpItem item) { if (item is UploadDataItem) { UploadDataItem udi = item as UploadDataItem; if (udi.Success) { string source = udi.Tag as string; string crc = FileMD5.Create(udi.Source); string name = Kits.GetFilename(source); string pathname = _dc.GetPathfileByRemotePathfile(udi.Target); ResourceOp rop = OpFactory <ResourceOp> .Create(_ic); rop.Add(pathname, name, udi.Group, 0, udi.Version, Kits.GetLastWriteTime(source), udi.Remark, "cvraddresource", crc); } else { Notified?.Invoke(CVReSubmitResult.UploadFailed, udi.Message); } } }
protected void Notify(CVResult result, object obj) { Notified?.Invoke(result, obj); }