/// <summary> /// 主要测试函数 /// </summary> /// <param name="config"></param> static void Func(MConfig config) { var master = ModBus4.ModBusMasterFactor.CreateMaster(config); ushort addr = 6; new Thread(() => { while (true) { try { var res = master.ReadHoldingRegisters(1, addr, 1); if (res != null && res.Length >= 1) { Console.WriteLine(string.Format("Read:{0},Value:{1}", addr, res[0])); } var addr2 = (ushort)(addr + 4); var v = new Random().Next(1, 500); master.WriteSingleRegister(1, addr2, (ushort)v); Console.WriteLine(string.Format("Write:{0},Value:{1}", addr2, v)); } catch (Exception ex) { } Thread.Sleep(500); } }) { IsBackground = true }.Start(); }
private void InitConfig() { Config = new MConfig(); Config.DUILITE_MODE = "both"; Config.CLOUD_ASR_RES_MODULE = "aienglish"; Config.ENABLE_NATIVE_VAD = "true"; Config.NATIVE_VAD_NEWCFG = new MRes() { resBinPath = "./res/vad/vad_aihome_v0.7.bin", pauseTime = 2 * 1000 }; }
public Crawler Fetch() { if (!IsExternalIPAddress(this.SourceUrl)) { State = "INVALID_URL"; return(this); } var request = HttpWebRequest.Create(this.SourceUrl) as HttpWebRequest; using (var response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { State = "Url returns " + response.StatusCode + ", " + response.StatusDescription; return(this); } if (response.ContentType.IndexOf("image") == -1) { State = "Url is not an image"; return(this); } ServerUrl = PathFormatter.Format(Path.GetFileName(this.SourceUrl), MConfig.GetString("catcherPathFormat")); var savePath = Server.MapPath(ServerUrl); if (!Directory.Exists(Path.GetDirectoryName(savePath))) { Directory.CreateDirectory(Path.GetDirectoryName(savePath)); } try { var stream = response.GetResponseStream(); var reader = new BinaryReader(stream); byte[] bytes; using (var ms = new MemoryStream()) { byte[] buffer = new byte[4096]; int count; while ((count = reader.Read(buffer, 0, buffer.Length)) != 0) { ms.Write(buffer, 0, count); } bytes = ms.ToArray(); } File.WriteAllBytes(savePath, bytes); State = "SUCCESS"; } catch (Exception e) { State = "抓取错误:" + e.Message; } return(this); } }
public ActionResult Index(string target, string action) { lock (_lock) { if (!string.IsNullOrEmpty(target)) { string method = Request.HttpMethod.ToLower(); //if (!string.IsNullOrEmpty(action)) //{ // method = action.ToLower().Trim(); //} StringBuilder urlBuilder = new StringBuilder(); urlBuilder.Append(MConfig.Get <String>("remoteRoot")); urlBuilder.Append(MConfig.Get <string>(target.Trim().ToLower())); urlBuilder.AppendFormat("userId={0}", UserInfo.UserSysNo); switch (method) { case "get": { NameValueCollection keyValuePair = Request.QueryString; foreach (string key in keyValuePair.Keys) { urlBuilder.AppendFormat("&{0}={1}", key, keyValuePair[key]); } break;; } case "post": { NameValueCollection keyValuePair = Request.Form; foreach (string key in keyValuePair.Keys) { urlBuilder.AppendFormat("&{0}={1}", key, keyValuePair[key]); } break; } } var proxy = OpenRequest.Create(urlBuilder.ToString(), method); var resp = proxy.GetResponse(); return(Content(resp.ResponseText)); } return(new EmptyResult()); } }
public static ModbusMaster CreateMaster(MConfig config) { if (config != null) { var s = config.GetType(); if (s.FullName == typeof(SerialConfig).FullName) { var conf = config as SerialConfig; if (conf != null) { var port = conf.CreateSerialPort(); if (!port.IsOpen) { port.Open(); } return(CreateSerialMaster(port, conf.Mode)); } } else if (s.FullName == typeof(IPConfig).FullName) { var con = config as IPConfig; if (con != null) { if (con.Mode == IPMode.Tcp) { var client = new TcpClient(con.Address, con.Port); if (!client.Connected) { client.Connect(con.Address, con.Port); } return(ModbusIpMaster.CreateIp(client)); } else if (con.Mode == IPMode.Udp) { var client = new UdpClient(); client.Connect(con.CreateIPEndPoint()); return(ModbusIpMaster.CreateIp(client)); } } } } return(null); }
public override void Process() { try { Start = String.IsNullOrEmpty(Request["start"]) ? 0 : Convert.ToInt32(Request["start"]); Size = String.IsNullOrEmpty(Request["size"]) ? MConfig.GetInt("imageManagerListSize") : Convert.ToInt32(Request["size"]); } catch (FormatException) { State = ResultState.InvalidParam; WriteResult(); return; } var buildingList = new List <String>(); try { var localPath = Server.MapPath(PathToList); buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories) .Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower())) .Select(x => PathToList + x.Substring(localPath.Length).Replace("\\", "/"))); Total = buildingList.Count; FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray(); } catch (UnauthorizedAccessException) { State = ResultState.AuthorizError; } catch (DirectoryNotFoundException) { State = ResultState.PathNotFound; } catch (IOException) { State = ResultState.IOError; } finally { WriteResult(); } }
private MDB() { connection = new NpgsqlConnection(MConfig.Get().GetDbConnectionString()); connection.Open(); }
public void ProcessRequest(HttpContext context) { IUser user = UserContext.CurrentUser; if (user == null) { context.Response.Redirect(SiteUrls.Instance().Login()); } MHandler action = null; switch (context.Request["action"]) { case "config": action = new MConfigHandler(context); break; case "uploadimage": action = new MUploadHandler(context, new MUploadConfig() { MAllowExtensions = MConfig.GetStringList("imageAllowFiles"), MPathFormat = MConfig.GetString("imagePathFormat"), MSizeLimit = MConfig.GetInt("imageMaxSize"), MUploadFieldName = MConfig.GetString("imageFieldName") }); break; case "uploadscrawl": action = new MUploadHandler(context, new MUploadConfig() { MAllowExtensions = new string[] { ".png" }, MPathFormat = MConfig.GetString("scrawlPathFormat"), MSizeLimit = MConfig.GetInt("scrawlMaxSize"), MUploadFieldName = MConfig.GetString("scrawlFieldName"), MBase64 = true, MBase64Filename = "scrawl.png" }); break; case "uploadvideo": action = new MUploadHandler(context, new MUploadConfig() { MAllowExtensions = MConfig.GetStringList("videoAllowFiles"), MPathFormat = MConfig.GetString("videoPathFormat"), MSizeLimit = MConfig.GetInt("videoMaxSize"), MUploadFieldName = MConfig.GetString("videoFieldName") }); break; case "uploadfile": action = new MUploadHandler(context, new MUploadConfig() { MAllowExtensions = MConfig.GetStringList("fileAllowFiles"), MPathFormat = MConfig.GetString("filePathFormat"), MSizeLimit = MConfig.GetInt("fileMaxSize"), MUploadFieldName = MConfig.GetString("fileFieldName") }); break; case "listimage": action = new MListFileManager(context, MConfig.GetString("imageManagerListPath"), MConfig.GetStringList("imageManagerAllowFiles")); break; case "listfile": action = new MListFileManager(context, MConfig.GetString("fileManagerListPath"), MConfig.GetStringList("fileManagerAllowFiles")); break; case "catchimage": action = new MCrawlerHandler(context); break; default: action = new MNotSupportedHandler(context); break; } action.Process(); }