void Initialize() { Logger.Write("[程序设定]插件目录:{0}", PluginDir); var files = Directory.GetFiles(PluginDir, PLUGIN_PATTERN); foreach (var file in files) { AssemblyAdd(null, new FileSystemEventArgs(WatcherChangeTypes.Created, PluginDir, Path.GetFileName(file))); } foreach (var plugin in plugins) { AppSetting appSetting = new AppSetting(plugin.Key); var interval = int.Parse(appSetting.Get("interval", "1")); if (appSetting.Get("interval").IsNullOrWhiteSpace()) { appSetting.Set("interval", "1"); } DispatcherTimer pluginTimer = new DispatcherTimer(); pluginTimer.Interval = TimeSpan.FromHours(interval); pluginTimer.IsEnabled = true; pluginTimer.Tick += delegate { ExecutePluginEvent(plugin.Key); }; pluginTimer.Start(); Logger.Write("{0}定时器启动,时间间隔为{1}小时", plugin.Key, interval); } }
public ControlRoomMongoContext() { var connection = AppSetting.Get <string>("MongoDBConnection"); var mongoClient = new MongoClient(connection); _database = mongoClient.GetDatabase("ControlRoom"); }
public static void FormLoad(object sender) { ModuleConfig.TranslationEnabled = AppSetting.Get("Translation Enabled").Value.ToInt32().ToBoolean(); activeForm.ParentForm = ParentFormList.Instance.GetParentForm((sender as Form).Name, (sender as Form).GetType().Namespace); Translatable.Instance.InitializeAll(sender as Form); Translator.Translate(sender as Form); }
public static string GetMessageFromQueue() { string apibaseurl = AppSetting.Get("ApiUrl"); WebClient wc = new WebClient(); var Vehicle_Id = wc.DownloadString(apibaseurl + "api/Queue/GetQueue"); return(Vehicle_Id); }
public static int GetQueueCount() { string apibaseurl = AppSetting.Get("ApiUrl"); WebClient wc = new WebClient(); var countstr = wc.DownloadString(apibaseurl + "api/Queue/GetQueueCount"); int cnt = Convert.ToInt32(countstr); return(cnt); }
public void 透過AppSetting物件讀取設定檔() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); var config = builder.Build(); var appSetting = AppSetting.Get(config); Console.WriteLine($"AppId = {appSetting.Player.AppId}"); Console.WriteLine($"Key = {appSetting.Player.Key}"); Console.WriteLine($"Connection String = {appSetting.ConnectionStrings.DefaultConnectionString}"); }
public FileContent GetFileAttachment(Guid fileId) { var result = fileAttachmentRepository.GetAll().Where(t => t.Id == fileId) .Select(t => new FileContent() { Id = t.Id, AttachmentType = (FileAttachmentType)t.AttachmentTypeValue, Extension = t.Extension, FileName = t.FileName, Path = t.Path, PhysicalName = t.PhysicalName, RelatedId = t.RelatedId, }).FirstOrDefault(); if (result == null) { return(null); } var uploadPath = AppSetting.Get <string>("FileUploadPath"); if (!string.IsNullOrWhiteSpace(result.Path)) { if (result.Path != "upload") { uploadPath = Path.Combine(uploadPath, result.Path); } } var filePath = Path.Combine(uploadPath, result.PhysicalName); result.MimeType = MimeTypeMapping.GetMimeType(result.Extension ?? ""); if (!System.IO.File.Exists(filePath)) { throw new ResourceNotFoundException(); } var stream = System.IO.File.OpenRead(filePath); result.FileStream = stream; return(result); }
public Guid SaveFileAttach(Stream fileStream, string fileName, FileAttachmentType attachmentType, Guid?relatedId = null, string path = null) { var uploadPath = AppSetting.Get <string>("FileUploadPath"); if (!Directory.Exists(uploadPath)) { throw new DirectoryNotFoundException(uploadPath); } if (!string.IsNullOrWhiteSpace(path)) { uploadPath = Path.Combine(uploadPath, path); } var id = Guid.NewGuid(); var fileExt = Path.GetExtension(fileName); var physicalName = id.ToString() + fileExt; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } var filePath = Path.Combine(uploadPath, physicalName); using (var saveStream = System.IO.File.Create(filePath)) { fileStream.Seek(0, SeekOrigin.Begin); fileStream.CopyTo(saveStream); } var file = new FileAttachment(); file.Id = id; file.FileName = fileName; file.PhysicalName = physicalName; file.Extension = fileExt; file.Path = path; file.RelatedId = relatedId; file.AttachmentType = attachmentType; fileAttachmentRepository.Add(file); unitOfWork.SaveChanges(); return(file.Id); }
public void RemoveFileAttachment(Guid fileAttachmentId) { var fileAtt = fileAttachmentRepository.Get(fileAttachmentId); if (fileAtt != null) { var uploadPath = AppSetting.Get <string>("FileUploadPath"); if (!string.IsNullOrWhiteSpace(fileAtt.Path)) { uploadPath = Path.Combine(uploadPath, fileAtt.Path); } var filePath = Path.Combine(uploadPath, fileAtt.PhysicalName); fileAttachmentRepository.Remove(fileAtt); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } unitOfWork.SaveChanges(); } }
private async Task InitialConnections() { var key = AppSetting.Get <string>("Key"); var siteServiceId = AppSetting.Get <Guid>("SiteServiceId"); try { var connection = await apiService.GetAsync <ConnectionModel>($"/site-services/{siteServiceId}/connection"); var pumps = await apiService.GetAsync <IEnumerable <ControlPumpModel> >($"/site-services/{siteServiceId}/pumps"); pumpConections.Clear(); foreach (var pump in pumps.Where(t => t.PumpModelId.HasValue).ToList()) { if (string.IsNullOrWhiteSpace(pump.DatabaseNaming) && pump.PumpModelId.HasValue) { var sb = new SqlConnectionStringBuilder(); sb.DataSource = connection.LocalServer; sb.InitialCatalog = connection.DatabaseName; sb.IntegratedSecurity = false; sb.UserID = connection.Username; sb.Password = CryptoHelper.DecryptText(connection.Password); var connectionString = sb.ConnectionString; pumpConections.Add(new PumpConnectionData { ConnectionString = connectionString, DatabaseNaming = pump.DatabaseNaming, PumpId = pump.Id, PumpName = pump.Name, PumpModelId = pump.PumpModelId.Value, PumpModelCode = pump.PumpModelCode }); } } } catch (Exception ex) { logger.Error(ex, "Error while getting pump data"); } }
public SqlHelper() { oledb = new OleDbHelper(); oledb.Url = AppSetting.Get("ConnectionString"); }
public void Execute(string[] args) { var url = AppSetting.Get <string>("ApiUrl"); var key = AppSetting.Get <string>("Key"); var siteServiceId = AppSetting.Get <Guid>("SiteServiceId"); int interval; try { interval = int.Parse(args[0]) * 1000; } catch (Exception) { Console.WriteLine("Invalid parameters"); return; } if (!apiService.AuthenSiteService(siteServiceId, key)) { Console.WriteLine("Authen Faild"); return; } connection = new HubConnectionBuilder() .WithUrl(url + "/ControlHub") .WithAutomaticReconnect() .Build(); InitialConnections().Wait(); connection.Reconnected += async(msg) => { await Register(apiService.GetToken()); }; connection.StartAsync().Wait(); Register(apiService.GetToken()).Wait(); timer.Interval = interval; loadPumpTimer.Interval = 180000; loadPumpTimer.Elapsed += LoadPumpTimer_Elapsed; timer.Elapsed += Timer_Elapsed; timer.Start(); loadPumpTimer.Start(); Console.Clear(); Console.WriteLine("Notify pump state to clients."); Console.WriteLine("Running..."); Console.WriteLine("Enter command \"exit\" for terminate jobs."); Console.Write("Command : "); var cmd = Console.ReadLine(); while (cmd.ToLower() != "exit") { Console.Clear(); Console.WriteLine("Notify pump state to clients."); Console.WriteLine("Running..."); Console.WriteLine("Enter command \"exit\" for terminate jobs."); Console.Write("Command : "); cmd = Console.ReadLine(); } this.Dispose(); }
public static void AddInQueueCount(string Vehicle_Id) { string apibaseurl = AppSetting.Get("ApiUrl"); WebClient wc = new WebClient(); var countstr = wc.DownloadString(apibaseurl + "api/Queue/AddQueue?Vehicle_Id=" + Vehicle_Id); }
public ApiService() { baseUrl = AppSetting.Get <string>("ApiUrl"); }
public void Execute(string[] args) { var url = AppSetting.Get <string>("ApiUrl"); var username = AppSetting.Get <string>("ApiUserName"); var password = AppSetting.Get <string>("ApiPassword"); var token = ""; var refreshToken = ""; int interval; try { interval = int.Parse(args[0]) * 1000; } catch (Exception) { Console.WriteLine("Invalid parameters"); return; } connection = new HubConnectionBuilder() .WithUrl(url + "/ControlHub") .WithAutomaticReconnect() .Build(); LoadPumps(); var json = JsonConvert.SerializeObject(new { userName = username, password = password }); HttpClient httpClient = new HttpClient(); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); connection.Reconnected += async(msg) => { json = JsonConvert.SerializeObject(new { token = token, refreshToken = refreshToken }); var refreshTokenResult = httpClient.PostAsync(url + "/token/refresh", httpContent).Result.Content.ReadAsStringAsync().Result; dynamic resultObj = JsonConvert.DeserializeObject(refreshTokenResult); if (resultObj.success == true) { token = resultObj.token; refreshToken = resultObj.refreshToken; } await Register(token); }; connection.StartAsync().Wait(); var authenResult = httpClient.PostAsync(url + "/authen", httpContent).Result.Content.ReadAsStringAsync().Result; dynamic resultObj = JsonConvert.DeserializeObject(authenResult); if (resultObj.success != true) { Console.WriteLine("Authen Faild"); return; } token = resultObj.token; refreshToken = resultObj.refreshToken; Register(token).Wait(); timer.Interval = interval; loadPumpTimer.Interval = 180000; loadPumpTimer.Elapsed += LoadPumpTimer_Elapsed; timer.Elapsed += Timer_Elapsed; timer.Start(); loadPumpTimer.Start(); Console.Clear(); Console.WriteLine("Notify pump state to clients."); Console.WriteLine("Running..."); Console.WriteLine("Enter command \"exit\" for terminate jobs."); Console.Write("Command : "); var cmd = Console.ReadLine(); while (cmd.ToLower() != "exit") { Console.Clear(); Console.WriteLine("Notify pump state to clients."); Console.WriteLine("Running..."); Console.WriteLine("Enter command \"exit\" for terminate jobs."); Console.Write("Command : "); cmd = Console.ReadLine(); } this.Dispose(); }
public static void UpdateStatus(int Vehicle_Id, bool status) { string apibaseurl = AppSetting.Get("ApiUrl"); WebClient wc = new WebClient(); string response = wc.DownloadString(apibaseurl + "api/VehicleData/VehicleStatusUpdate?Vehicle_Id=" + Vehicle_Id + "&Status=" + status); }