public static void Initialize() { if (!Configuration.LoadedConfiguration.FirstRunCompleted) { throw new Exception("Cannot initialize FileCache if the first run is not complete"); } // Create a ByamlSerializer ByamlSerializer byamlSerializer = new ByamlSerializer(new ByamlSerializerSettings() { ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian, SupportPaths = false, Version = ByamlVersion.Version1 }); // Create the FestivalSettings dictionary FestivalSettings = new Dictionary <RomType, List <FestivalSetting> >(); // Populate the FestivalSettings dictionary with RomTypes and lists foreach (RomType romType in Program.BcatPairs.Keys) { // Create a list for this RomType FestivalSettings[romType] = new List <FestivalSetting>(); // Get all FestivalSetting byamls for this RomType string[] festPaths = Directory.GetFiles(Path.Combine(LOCAL_DIRECTORY, "Festival", romType.ToString()), "*.byaml"); // Loop over every path foreach (string festPath in festPaths) { // Deserialize the byaml FestivalSetting festivalSetting = byamlSerializer.Deserialize <FestivalSetting>(festPath); // Add this to the list FestivalSettings[romType].Add(festivalSetting); } // Sort in ascending order FestivalSettings[romType].Sort((x, y) => x.Times.Start.CompareTo(y.Times.Start)); } // Create the VersusSettings dictionary VersusSettings = new Dictionary <RomType, VersusSetting>(); // Get all VersusSetting byamls string[] versusPaths = Directory.GetFiles(Path.Combine(LOCAL_DIRECTORY, "VSSetting")); // Loop over every path foreach (string versusPath in versusPaths) { // Get the RomType RomType romType = (RomType)EnumUtil.GetEnumValueFromString(typeof(RomType), Path.GetFileNameWithoutExtension(versusPath)); // Deserialize the byaml VersusSettings[romType] = byamlSerializer.Deserialize <VersusSetting>(versusPath); } // Deserialize the CoopSetting byaml CoopSetting = byamlSerializer.Deserialize <CoopSetting>(COOP_SETTING_PATH); }
public static void SetCoopSetting(CoopSetting coopSetting, byte[] rawSetting) { CoopSetting = coopSetting; // Write out the local file File.WriteAllBytes(COOP_SETTING_PATH, rawSetting); }
public CoopMessage(IUser user, Language lang) : base(user) { // Get the current CoopSetting CoopSetting coopSetting = FileCache.GetCoopSetting(); // Get the current DateTime in UTC DateTime utcNow = DateTime.UtcNow; // Find the current and future phases phases = coopSetting.Phases.Where(x => { return(x.EndDateTime >= utcNow || // is in future (x.StartDateTime <= utcNow && x.EndDateTime > utcNow)); // is happening now }).ToList(); // Set the Language language = lang; }
public static Task HandleCoop(RomType romType, Dictionary <string, byte[]> data, CoopSetting previousSetting, CoopSetting newSetting, byte[] rawFile) { // Only do this once if (romType != RomType.NorthAmerica) { return(Task.FromResult(0)); } lock (WebFileHandler.Lock) { // Get the WebConfig JelonzoBotWebConfig webConfig = ((JelonzoBotConfiguration)Configuration.LoadedConfiguration).WebConfig; // Connect to the remote server if needed WebFileHandler.Connect(webConfig); // Deserialize the CoopSetting dynamically dynamic settingDynamic = ByamlLoader.GetByamlDynamic(rawFile); // Upload to the server WebFileHandler.WriteSerializedJson(webConfig.CoopSettingPath, settingDynamic); // Disconnect WebFileHandler.Disconnect(); } return(Task.FromResult(0)); }
public static Task HandleCoop(RomType romType, Dictionary <string, byte[]> data, CoopSetting previousSetting, CoopSetting newSetting, byte[] rawFile) { // Only do this once if (romType != RomType.NorthAmerica) { return(Task.FromResult(0)); } // Update CoopSetting FileCache.SetCoopSetting(newSetting, rawFile); return(Task.FromResult(0)); }