/// <summary> 启动云平台服务 /// </summary> /// <param name="state"></param> private void _StartCloundService(object state) { //鉴权码、授权码、公司名称、机器码 DataTable dt = DBHelper.GetTable("获取注册信息", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.CommAccCode, "tb_signing_info", "*", "", "", ""); if (dt != null && dt.Rows.Count > 0) { if (dt.Columns.Contains("authentication")) { GlobalStaticObj_Server.Instance.LicenseCode = dt.Rows[0]["authentication"].ToString(); } if (dt.Columns.Contains("sign_id")) { GlobalStaticObj_Server.Instance.StationID = dt.Rows[0]["sign_id"].ToString(); } if (dt.Columns.Contains("s_user")) { GlobalStaticObj_Server.Instance.Cloud_UserId = dt.Rows[0]["s_user"].ToString(); } if (dt.Columns.Contains("s_pwd")) { GlobalStaticObj_Server.Instance.Cloud_Password = dt.Rows[0]["s_pwd"].ToString(); } } if (ServiceAgent.ServiceTest() || FileAgent.ServiceTest()) { AutoTask.Start(); } this.Invoke(this.uiHandler); }
/// <summary> 操作数据 /// </summary> /// <param name="dt">数据表</param> /// <param name="operation">操作类别</param> /// <param name="dbName">帐套</param> private static void Operation(DataTable dt, string operation, string dbName) { if (dt == null) { return; } string path = string.Empty; foreach (DataRow dr in dt.Rows) { FileProtocol protocol = GetProtocol(dr, dbName); if (protocol != null) { protocol.Operation = operation; if (operation == DataSources.EnumOperationType.Add.ToString("d") || operation == DataSources.EnumOperationType.Update.ToString("d")) { FileModel file = FileModel.CreateModel(dr); protocol.FileId = file.Id; protocol.FileType = file.FileType; path = GlobalStaticObj_Server.Instance.FilePath + "\\" + file.Path; //上传文件信息 byte[] files = FileHelper.GetFileInByte(path); if (files == null) { continue; } protocol.File = ProtocolTranslator.ByteToHex(files); } FileAgent.AddSendQueue(protocol); } } }
/// <summary> /// 对单个文件进行处理 /// </summary> /// <param name="source">来源文件(根据后缀决定是否需要翻译)</param> /// <param name="target">目标文件(如果目录不存在则自动创建)</param> /// <param name="data">语言包</param> /// <param name="language">当前需要翻译的语种</param> /// <param name="undone">词库中没有的词汇</param> private void BuildTranslate(string source, string target, Dictionary <string, Dictionary <Language, string> > data, Language language, Dictionary <Language, List <string> > undone) { string fileType = source.Substring(source.LastIndexOf('.') + 1); //#1 创建目标目录 string targetDirectory = target.Substring(0, target.LastIndexOf('\\')); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } //#2 不需要翻译的文件,判断文件是否更新,进行复制覆盖处理。 如果没有更新则跳过 if (!new[] { "html", "htm", "js", "css", "txt", "json" }.Contains(fileType)) { if (!File.Exists(target) || FileAgent.GetMD5(source) != FileAgent.GetMD5(target)) { File.Copy(source, target, true); } return; } //#3 进行文件翻译 string targetContent = File.Exists(target) ? File.ReadAllText(target, Encoding.UTF8) : string.Empty; string sourceContent = File.ReadAllText(source, Encoding.UTF8); Regex regex = new Regex(@"~.{1,50}?~", RegexOptions.Multiline); string content = regex.Replace(sourceContent, match => { string key = GetKey(match.Value); if (data.ContainsKey(key) && data[key].ContainsKey(language)) { return(data[key][language]); } if (!Regex.IsMatch(match.Value, @"[\u4e00-\u9fa5]")) { return(match.Value); } string keyword = match.Value.Replace("~", ""); if (!undone.ContainsKey(language)) { undone.Add(language, new List <string>()); } if (!undone[language].Contains(keyword)) { undone[language].Add(keyword); } return(keyword); }); if (targetContent.GetHashCode() != content.GetHashCode()) { File.WriteAllText(target, content, Encoding.UTF8); } }
private void btnLink_Click(object sender, EventArgs e) { if (this.tbIp.Text.Trim().Length == 0 || this.tbIp.Text.Trim().Length == 0) { MessageBox.Show("IP and Port is required!"); return; } int port = 0; if (!int.TryParse(this.tbPort.Text.Trim(), out port)) { MessageBox.Show("Port must be number!"); return; } ServiceAgent.SetParas(this.tbIp.Text.Trim(), port); if (int.TryParse(this.tbFilePort.Text.Trim(), out port)) { FileAgent.SetParas(this.tbIp.Text.Trim(), port); } GlobalStaticObj_Server.Instance.StationID = this.tbSendMsg.Text.Split('$')[0]; if (ServiceAgent.ServiceTest() || FileAgent.ServiceTest()) { if (this.startFlag) { this.startFlag = false; AutoTask.StartTest(this.dateTimePicker1.Value.Ticks); } else { AutoTask.Continue(); } this.btnLink.Text = "已连接"; this.btnLink.Enabled = false; this.btnClose.Enabled = true; } }
private void SendMessage(object state) { string[] arrays = state.ToString().Split('$'); if (arrays.Length != 8) { return; } LoginProtocol lp = new LoginProtocol(); lp.StationId = arrays[0]; lp.SerialNumber = arrays[1]; lp.MessageId = arrays[2]; lp.SubMessageId = arrays[3]; lp.TimeSpan = arrays[4]; lp.UserId = arrays[5]; lp.Password = arrays[6]; lp.PermissionCode = arrays[7]; ServiceAgent.AddSendQueue(lp); FileAgent.AddSendQueue(lp); }
/// <summary> /// 附件登录 /// </summary> /// <returns></returns> public static bool FileLogin() { LoginProtocol protocol = GetLoginProtocol(); MessageProtocol mp = FileAgent.SendAndReceiveMessage(protocol); if (mp != null && mp.GetRealProtocol() is ResultProtocol) { ResultProtocol result = mp.GetRealProtocol() as ResultProtocol; if (result.Result == DataSources.EnumResultType.Success.ToString("d")) { Log.writeCloudLog("云平台文件通讯-登录成功!"); return(true); } else { string msg = "登录消息(附件端口):" + DataSources.GetDescription(typeof(DataSources.EnumResultType), result.Result); //写入日志 Log.writeLog(msg); } } return(false); }
public void Save(string aUnitFilename) { FileAgent.Save(aUnitFilename); }
/// <summary> /// 解析并且保存安卓文件 /// </summary> /// <returns></returns> private Result SaveApk(IFormFile file) { string localFile = @$ "{Directory.GetCurrentDirectory()}/temp/{DateTime.Now.Ticks}.apk"; using (FileStream fileStream = new FileStream(localFile, FileMode.Create)) { file.CopyTo(fileStream); } string fileMD5 = FileAgent.GetMD5(localFile).Substring(0, 4); byte[] AndroidManifest, resources, iconData; try { using (ZipArchive zip = ZipFile.OpenRead(localFile)) { ZipArchiveEntry entry = zip.GetEntry("AndroidManifest.xml"); AndroidManifest = new byte[entry.Length]; entry.Open().Read(AndroidManifest, 0, AndroidManifest.Length); ZipArchiveEntry ascr = zip.GetEntry("resources.arsc"); resources = new byte[ascr.Length]; ascr.Open().Read(resources, 0, resources.Length); ApkReader apkReader = new ApkReader(); ApkInfo info = apkReader.extractInfo(AndroidManifest, resources); string iconFile = info.iconFileName.Where(t => t.EndsWith(".png")).LastOrDefault(); ZipArchiveEntry iconEntry = zip.GetEntry(iconFile); iconData = new byte[iconEntry.Length]; iconEntry.Open().Read(iconData, 0, iconData.Length); // 上传文件至OSS string version = this.GetVersion(info.versionName); string fileName = $"app/{info.label.ToPinYinAbbr().ToLower()}_{version}_{fileMD5}.apk"; string iconPath = $"app/{Encryption.toMD5(iconData).Substring(0, 16).ToLower()}.png"; string ossMessage; if (!OSSAgent.Upload(_ossSetting, fileName, localFile, out ossMessage)) { return(new Result(false, ossMessage, new { fileName, localFile })); } if (!OSSAgent.Upload(_ossSetting, iconPath, iconData, null, out ossMessage)) { return(new Result(false, ossMessage)); } string configFile = $"app/{DateTime.Now.ToString("yyyyMMHHmmss")}.json"; string json = new { Name = info.label, File = fileName, Version = version, Icon = iconPath, Config = configFile, UpdateAt = DateTime.Now }.ToJson(); if (!OSSAgent.Upload(_ossSetting, configFile, Encoding.UTF8.GetBytes(json), null, out ossMessage)) { return(new Result(false, ossMessage)); } return(new Result(true, fileName, json)); } } catch (Exception ex) { return(new Result(false, ex.Message)); } finally { File.Delete(localFile); } }
public override Result Invote() { if (string.IsNullOrEmpty(_path)) { return(new Result(false, "not configured file save path")); } // 是否是需要向前兼容的版本(旧版本如果出错则返回空值) bool isBackward = context.Request.Path.StartsWithSegments("/imageupload.ashx"); string uploadFolder = null; string fileFolder = null; try { // 自定义的后缀名 string type = !this.context.Request.Headers.ContainsKey("x-type") ? null : this.context.Request.Headers["x-type"].ToString(); byte[] data = this.context.GetData(); if (data == null || data.Length < 2) { return(isBackward ? new Result("") : new Result(false, "Content is Empty")); } string fileName = Encryption.toMD5(data).Substring(0, 16).ToLower(); // 相对路径 fileFolder = "upload/" + DateTime.Now.ToString("yyyyMM"); // 绝对路径 uploadFolder = _path + DateTime.Now.ToString("yyyyMM"); if (!Directory.Exists(uploadFolder)) { Directory.CreateDirectory(uploadFolder); } string contentType = FileAgent.GetContentType(data); if (string.IsNullOrEmpty(contentType) && string.IsNullOrEmpty(type)) { return(isBackward ? new Result("") : new Result(false, "文件类型未知")); } string ext = type ?? Regex.Match(contentType, @"/(?<Type>\w+)$").Groups["Type"].Value; if (!fileType.Contains(ext)) { return(isBackward ? new Result("") : new Result(false, $"文件类型{ext}不支持")); } // 需要保存的绝对路径 string filePath = $"{uploadFolder}/{ fileName}.{ ext}"; // 对外输出的相对路径 fileName = $"{fileFolder}/{fileName}.{ext}"; if (!OSSAgent.Upload(_ossSetting, fileName, data, null, out string message)) { return(new Result(false, message)); } if (!File.Exists(filePath)) { File.WriteAllBytes(filePath, data); } if (isBackward) { return(new Result(ContentType.TEXT, $"/{fileName}")); } else { return(new Result(true, "Success", new { fileName = $"/{fileName}" })); } } catch (Exception ex) { if (isBackward) { return(new Result("")); } else { return(new Result(false, $"{ex.Message}\nfileFolder:{fileFolder}\nuploadFolder:{uploadFolder}")); } } }
public void Save(string iProjectName) { FileAgent.Save(iProjectName); }