public SingleTypeCollection <T> FetchAsRepo <T>() where T : class, IGuidProvider { SLogger.Debug("Fetching all " + typeof(T).FullName + " from " + DBFilename); SingleTypeCollection <T> repo = new SingleTypeCollection <T>(_config, _slice); return(repo); }
/// <summary> /// 获取未被加载过的包装类 /// </summary> /// <param name="types"></param> /// <returns></returns> protected virtual IEnumerable <IExtensionWrapper> GetNewWrappersFrom(IEnumerable <Type> types) { List <IExtensionWrapper> newWrappers = new List <IExtensionWrapper>(); foreach (var type in types) { try { var tmp = GetWrapperFor(type); if (tmp.Check()) { tmp.Ready(); newWrappers.Add(tmp); } else { SLogger.Debug($"{ManagedAssembly.GetName().Name} 's librarian", "Check result is false"); tmp.Destory(); } } catch (WrapperAlreadyCreatedOnceException) { SLogger.Debug($"{ManagedAssembly.GetName().Name} 's librarian", $"{type.Name}'s wrappers was created once,skip it"); } catch (Exception ex) { SLogger.Debug($"{ManagedAssembly.GetName().Name} 's librarian", $"an exception threw on create wappers for {type.Name}", ex); } } return(newWrappers); }
private IEnumerable <Assembly> GetAssemblies(IEnumerable <FileInfo> files) { var result = new List <Assembly>(); foreach (var file in files) { try { if (file.Extension == PATTERN_OEXT.Substring(1)) { SLogger <DreamLibManager> .Info($"{file} is an aoext"); result.Add(Assembly.LoadFile(file.FullName)); } else { result.Add(Assembly.Load(File.ReadAllBytes(file.FullName))); } } catch (Exception e) { SLogger <DreamLibManager> .Warn($"can not load extension: {file.Name}", e); } } SLogger <DreamLibManager> .Debug($"There are {result.Count()} assemblies"); return(result); }
/// <summary> /// 结束一个进程(不用Process.Kill的原因是其不够高效) /// </summary> /// <param name="pid"></param> private void Kill(int pid) { new WindowsCmdCommand($"taskkill /F /PID {pid}") .To((e) => { SLogger <HestExecutor> .Debug(e.Text); }) .Execute(); }
private IEnumerable <FileInfo> GetFiles() { var extDir = new DirectoryInfo(BuildInfo.DEFAULT_EXTENSION_PATH); var files = new List <FileInfo>() .Concat(extDir.GetFiles(PATTERN_DEFAULT)) .Concat(extDir.GetFiles(PATTERN_ATMBEXT)) .Concat(extDir.GetFiles(PATTERN_OEXT)); SLogger <DreamLibManager> .Debug($"There are {files.Count()} extension file"); return(files); }
/// <summary> /// 进行加载 /// </summary> private void Load() { var objAttrs = classExtensionType.GetCustomAttributes(typeof(ExtTextAttribute), true); SLogger <ClassTextManagerImpl> .Debug($"There are {objAttrs.Length} ExtTextAttribute on {classExtensionType.Name}"); var attrs = (ExtTextAttribute[])objAttrs; foreach (var attr in attrs) { ResourceCollection.Add(attr.Key, attr); } }
/// <summary> /// 获取信息 /// </summary> /// <param name="key"></param> /// <returns></returns> public object this[string key] { get { try { return(Informations[key].Value); } catch (Exception e) { SLogger.Debug(Name, $"InfoReader: can not get info '{key}' ", e); return(null); } } }
public void SendSignal(string signal, object value = null) { if (string.IsNullOrWhiteSpace(signal)) { throw new ArgumentException("message", nameof(signal)); } try { SLogger <ExtensionThread> .Debug($"sending signal {signal} to {Wrapper.Info.Name}"); instance.ReceiveSignal(signal, value); } catch (Exception e) { SLogger <ExtensionThread> .Debug($"a exception was thrown when {Wrapper.Info.Name} handling signal: {signal}", e); } }
/// <summary> /// 重启程序 /// </summary> /// <param name="asAdmin"></param> public static void Restart(bool asAdmin) { ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine("..", "AutumnBox-秋之盒.exe")); var args = new List <string> { $"-waitfor {Process.GetCurrentProcess().Id}" }; if (asAdmin) { args.Add("-tryadmin"); } startInfo.Arguments = string.Join(" ", args); SLogger.Debug("Self", startInfo.FileName + " " + startInfo.Arguments); Process.Start(startInfo); App.Current.Shutdown(0); }
public static void Check() { SLogger.Debug(TAG, "doing banned-check"); new VersionBanInfoGetter().Advance().ContinueWith((task) => { SLogger.Debug(TAG, "the banned-check task is over"); SLogger.Debug(TAG, $"tsuc:{task.IsCompleted} trst:{(task?.Result?.Json ?? "null")}"); if (task.IsCompleted) { var result = task.Result; if (result.Banned) { Reason = result.Reason; App.Current.Dispatcher.Invoke(() => { App.Current.Shutdown(App.ERR_BANNED_VERSION); }); } } }); }
public List <T> Fetch <T>() { int count = 0; while (IsThisInTransaction()) { string fn = _transactionSetters[DBFilename]; SLogger.Info("Waiting for transaction for 0.5s, caller was " + fn); Thread.Sleep(500); count++; if (count > 240 * 2) { throw new FlaException("Waited more than 240s"); } } SLogger.Debug("Fetching all " + typeof(T).FullName + " from " + DBFilename); lock (Dblock) { return(_database.Fetch <T>() ?? throw new FlaException("Fetch failed")); } }
public static void Check() { new VersionBanInfoGetter().Advance().ContinueWith((task) => { SLogger.Debug(TAG, "the banned-check task is over"); SLogger.Debug(TAG, $"tsuc:{task.IsCompleted} trst:{(task?.Result?.Json ?? "null")}"); if (task.IsCompleted) { var result = task.Result; if (result.Banned) { App.Current.Dispatcher.Invoke(() => { string banned = App.Current.Resources["CurrentVersionHasBeenBanned"].ToString(); string message = $"{banned}{Environment.NewLine}{Reason}"; MessageBox.Show(message, banned, MessageBoxButton.OK, MessageBoxImage.Warning); Reason = result.Reason; App.Current.Shutdown(App.ERR_BANNED_VERSION); }); } } }); }
private IEnumerable <FileInfo> GetFiles() { var extDir = BuildInfo.ExtensionStore; if (!extDir.Exists) { extDir.Create(); } List <FileInfo> files = new List <FileInfo>(); foreach (var file in extDir.GetFiles()) { SLogger <DreamLibManager> .Info($"{file.Name}{file.Extension}"); } var extensionFiles = from file in extDir.GetFiles() where file.Extension == ".dll" select file; files.AddRange(extensionFiles); SLogger <DreamLibManager> .Debug($"There are {files.Count()} extension file"); return(files); }
static LeafUIHelper() { text = OpenApiFactory.SGet <IClassTextManager>(typeof(LeafUIHelper)); SLogger.Debug(nameof(LeafUIHelper), $"{typeof(LeafUIHelper)}'s IClassTextManager created"); }
/// <summary> /// 当摧毁时被调用 /// </summary> public virtual void Destory() { SLogger.Debug(Info.Name, "Good bye"); }
/// <summary> /// 同步POST请求 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="D"></typeparam> /// <param name="url"></param> /// <param name="param"></param> /// <param name="timeout"></param> /// <returns></returns> public static HttpResponse PostSync <T, D>(string url, T param = null, double?timeout = null) where T : class, new() where D : class { // 单机测试,使用FakeData生成随机测试数据模拟网络访问 if (AppRunConfigs.Instance.IsSingleTestMode) { var genType = typeof(D); int genNum = -1; if (genType.IsAssignableFrom(typeof(BaseOpResult))) { genNum = 1; } // 生成随机等待时间,模拟网络请求耗时 var randomGenDataCostTime = FakeDataHelper.Instance.GenRandomInt(AppRunConfigs.Instance.DefaultRequestTimeout); // 模拟1/2的请求是要等待长时间,而另外1/2的请求等待短时间 if (randomGenDataCostTime <= AppRunConfigs.Instance.DefaultRequestTimeout / 2) { randomGenDataCostTime = 300; } Thread.Sleep(randomGenDataCostTime); return(ClientFakeDataHelper.Instance.CreateFakeDataNetResponse(genType, genNum)); } HttpContent requestContent = null; if (null != param) { var strJson = JsonHelper.SerializeTo(param); requestContent = new StringContent(strJson); requestContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); } url = NetHelper.FormatRequestUrl(url); HttpResponse responseMsg = null; var requestDTO = new WebReqResStatisticsDTO() { RequestFullUrl = url, Method = "POST", InTime = DateTime.Now, RequestBody = requestContent?.ToString(), }; try { //SetNetDALTimeout(timeout); var httpResponseTask = s_syncWebClient.PostAsync(url, requestContent); httpResponseTask.Wait(); var httpResponse = httpResponseTask.Result; string responseContent = null; if (httpResponse.IsSuccessStatusCode) { string resultStr = httpResponse.Content.ReadAsStringAsync().Result; responseContent = resultStr; } requestDTO.ResponseBody = responseContent; requestDTO.OutTime = DateTime.Now; requestDTO.Cost = (long)(requestDTO.OutTime - requestDTO.InTime).TotalMilliseconds; responseMsg = new HttpResponse(responseContent, httpResponse.StatusCode); } catch (HttpRequestException ex) { //responseMsg = new HttpResponse(ex.ToString(), HttpStatusCode.ExpectationFailed); responseMsg = new HttpResponse("网络请求异常", HttpStatusCode.ExpectationFailed); responseMsg.ResponseMsg = ex.ToString(); } catch (Exception ex) { //responseMsg = new HttpResponse(ex.ToString(), HttpStatusCode.ExpectationFailed); responseMsg = new HttpResponse("系统异常", HttpStatusCode.ExpectationFailed); responseMsg.ResponseMsg = ex.ToString(); } finally { SLogger.Debug(JsonHelper.SerializeTo(requestDTO)); } return(responseMsg); }
/// <summary> /// 异步POST请求 /// TOFIX:待添加超时逻辑 /// </summary> /// <param name="url"></param> /// <param name="content"></param> /// <param name="callBack"></param> /// <param name="timeout"></param> public static async Task PostContentAsync(string url, HttpContent content, HttpResponseHandler callBack, double?timeout = null) { url = NetHelper.FormatRequestUrl(url); HttpResponse responseMsg = null; var requestDTO = new WebReqResStatisticsDTO() { RequestFullUrl = url, Method = "POST", InTime = DateTime.Now, RequestBody = content?.ToString(), }; try { //SetNetDALTimeout(timeout); if (null == callBack) { // 无回调请求,可以优化成发送之后就不管了 await s_asyncWebClient.PostAsync(url, content); return; } var httpResponse = await s_asyncWebClient.PostAsync(url, content); string responseContent = null; if (httpResponse.IsSuccessStatusCode) { string resultStr = await httpResponse.Content.ReadAsStringAsync(); responseContent = resultStr; } requestDTO.ResponseBody = responseContent; requestDTO.OutTime = DateTime.Now; requestDTO.Cost = (long)(requestDTO.OutTime - requestDTO.InTime).TotalMilliseconds; responseMsg = new HttpResponse(responseContent, httpResponse.StatusCode); } catch (HttpRequestException ex) { //responseMsg = new HttpResponse(ex.ToString(), HttpStatusCode.ExpectationFailed); responseMsg = new HttpResponse("网络请求异常", HttpStatusCode.ExpectationFailed); responseMsg.ResponseMsg = ex.ToString(); } catch (Exception ex) { //responseMsg = new HttpResponse(ex.ToString(), HttpStatusCode.ExpectationFailed); responseMsg = new HttpResponse("系统异常", HttpStatusCode.ExpectationFailed); responseMsg.ResponseMsg = ex.ToString(); } finally { SLogger.Debug(JsonHelper.SerializeTo(requestDTO)); callBack?.Invoke(responseMsg, null); } }
static LeafUIHelper() { text = LakeProvider.Lake.Get <IClassTextReader>().Read((typeof(LeafUIHelper))); SLogger.Debug(nameof(LeafUIHelper), $"{typeof(LeafUIHelper)}'s IClassTextManager created"); }