//public MongoContext(string connectionString, string dbName) //{ // _client = new MongoClient(connectionString); // _database = _client.GetDatabase(dbName); //} public MongoContextBase() { string connectionString = ConfigGetter.GetSectionFromJson("MongoSettings:ConnectionString"); string dbName = ConfigGetter.GetSectionFromJson("MongoSettings:DbName"); _client = new MongoClient(connectionString); _database = _client.GetDatabase(dbName); }
public void AddNote(Models.Note note) { List <Models.Note> Notes = GetNote(); Notes.Add(note); using var writer = File.CreateText(ConfigGetter.GetNotePath()); writer.Write(JsonConvert.SerializeObject(Notes, Formatting.Indented)); }
public static void AddWelcome(Models.Welcome welcome) { List <Models.Welcome> Welcomes = GetWelcome(); Welcomes.Add(welcome); using var writer = File.CreateText(ConfigGetter.GetWelcomePath()); writer.Write(JsonConvert.SerializeObject(Welcomes, Formatting.Indented)); }
public static void AddFilter(Models.Filter filter) { List <Models.Filter> Filters = GetFilter(); Filters.Add(filter); using var writer = File.CreateText(ConfigGetter.GetFilterPath()); writer.Write(JsonConvert.SerializeObject(Filters, Formatting.Indented)); }
private void OpenConfigItem_Click(object sender, EventArgs e) { ConfigGetter cg = new ConfigGetter(); if (cg.ShowDialog() != DialogResult.OK && string.IsNullOrEmpty(cg.Dev)) { return; } string Auther = cg.Dev; Auther = Auther.Replace(' ', '_'); if (Auther.Length > 25) { Auther = Auther.Remove(25); } string AutherPath = Path.Combine(LocalAppData, Auther); try { string[] ConfigPaths = Directory.GetFiles( AutherPath , "user.config", SearchOption.AllDirectories); //辞書リセットと作成 od.Clear(); ConfigList.Items.Clear(); foreach (string FullPath in ConfigPaths) { Uri LocalDataPath = new Uri(AutherPath), ConfigPath; DirectoryInfo di = Directory.GetParent(FullPath); ConfigPath = new Uri(di.ToString()); string relatepath = HttpUtility.UrlDecode( LocalDataPath.MakeRelativeUri(ConfigPath).ToString()).Replace('/', '\\'); od.Add(relatepath, FullPath); ConfigList.Items.Add(relatepath); } } catch (DirectoryNotFoundException) { MessageBox.Show("設定ファイルが見つからなかったよ。(´・ω・)", "ねぇよwww", MessageBoxButtons.OK, MessageBoxIcon.Stop); } catch (Exception b) { StringBuilder sb = new StringBuilder(); sb.AppendLine("別の原因で処理が継続できないみたい。"); sb.AppendLine("下に診断書みたいなの書いておくから自己解決できるなら自己解決を、出来ないなら開発者に問い合わせてね。"); sb.AppendLine(); sb.AppendLine(b.ToString()); MessageBox.Show(sb.ToString(), "処理が継続不能", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { vozBot = new TelegramBotClient(ConfigGetter.GetAPI()); var me = vozBot.GetMeAsync().Result; Console.WriteLine($"Hello, World! I am user {me.Id} and my name is {me.FirstName}."); vozBot.OnMessage += Bot_OnMessage; vozBot.StartReceiving(); Thread.Sleep(int.MaxValue); }
public async Task <UserAccountBO> CheckUserAccount(string email, string password) { var encryptedPassword = Crypto.Encrypt(password, ConfigGetter.GetSectionFromJson("CryptoKey")); Task <User> userTask = _userRepository.GetAsync(u => u.Email == email && u.Password == encryptedPassword); User user = await userTask; if (user != null) { return(_mapper.Map <UserAccountBO>(user)); } else { return(null); } }
public static void AddBio(Models.Bio bio) { List <Models.Bio> Bios = GetBio(); foreach (var existedBio in Bios) { if (existedBio.UserId == bio.UserId) { Bios.Remove(existedBio); break; } } Bios.Add(bio); using var writer = File.CreateText(ConfigGetter.GetBioPath()); writer.Write(JsonConvert.SerializeObject(Bios, Formatting.Indented)); }
public string Authenticate(UserAccountBO userAccount) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(ConfigGetter.GetSectionFromJson("SecretKey")); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Email, userAccount.Email), new Claim(ClaimTypes.Role, UserRoleNames.GetRoleName(userAccount.RoleId)) }), Expires = DateTime.UtcNow.AddDays(Convert.ToInt32(ConfigGetter.GetSectionFromJson("TokenExpiresDay"))), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenStr = tokenHandler.WriteToken(token); return(tokenStr); }
static void Main() { if (!mutex.WaitOne(TimeSpan.FromSeconds(1), false)) { MessageBox.Show("Application is already running!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Helpers.DataBaseHelper.CreateDatabase(); Application.ThreadException += Application_ThreadException; if (!ConfigGetter.GetConfigDetails()) { MessageBox.Show("[Config Getter] Unable to load configuration details."); return; } GenerateReport.GenerateUngeneratedReport(); Application.Run(new MainForm()); mutex.ReleaseMutex(); }
public static List <Models.Admin> GetAdmin() { using var reader = File.OpenText(ConfigGetter.GetAdminPath()); return(JsonConvert.DeserializeObject <List <Models.Admin> >(reader.ReadToEnd())); }
public static void UpdateAdmin(List <Models.Admin> admins) { using var writer = File.CreateText(ConfigGetter.GetAdminPath()); writer.Write(JsonConvert.SerializeObject(admins, Formatting.Indented)); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(ConfigGetter.GetSectionFromJson(_connectionStringName)); }
private static Func <string, object, ConfigurationSafeHandle, object> GetRetriever <T>(ConfigGetter <T> getter) { return((key, defaultValue, handle) => { T value; var res = getter(out value, handle, key); if (res == (int)GitErrorCode.GIT_ENOTFOUND) { return defaultValue; } Ensure.Success(res); return value; }); }
public string Decrypt(CryptoModel model) { return(Crypto.Decrypt(model.Encrypted, ConfigGetter.GetSectionFromJson("CryptoKey"))); }