public static bool IsTemplateAvaliable() { try { var templatePath = DatabaseApi.GetTemplatePaths(); if (string.IsNullOrEmpty(templatePath)) { return(false); } if (!Directory.Exists(templatePath)) { Directory.CreateDirectory(templatePath); return(false); } var templatedir = Directory.CreateDirectory(templatePath); if (templatedir != null) { if (Directory.GetFiles(templatedir.FullName, "*.template").ToList().Count > 0) { return(true); } } return(false); } catch (Exception e) { Log.Error(e, "IsTemplateAvaliable"); return(false); } }
////private static Settings s_settings; public static Settings GetSettings() { var databasePath = DatabaseApi.GetActiveCompetition(); ////if (s_settings != null) ////{ //// return s_settings; ////} lock (syncLock) { ////if (s_settings != null) ////{ //// return s_settings; ////} var settingsfile = Path.Combine(databasePath, "FeltAdmin.xml"); if (File.Exists(settingsfile)) { var mySerializer = new XmlSerializer(typeof(Settings)); using (var myFileStream = new FileStream(settingsfile, FileMode.Open)) { return((Settings)mySerializer.Deserialize(myFileStream)); } } return(new Settings()); } }
public void AddNewRegistrations(List <LeonPerson> newRegistrations, bool save = true) { if (m_leonPersons == null) { m_leonPersons = new List <LeonPerson>(); } foreach (var newRegistration in newRegistrations) { var found = m_leonPersons.SingleOrDefault(p => p.Team == newRegistration.Team && p.Target == newRegistration.Target); if (found != null) { m_leonPersons.Remove(found); } if (!newRegistration.IsEmpty) { m_leonPersons.Add(newRegistration); } if (save) { DatabaseApi.Save(newRegistration); } } m_leonPersons = m_leonPersons.OrderBy(p => p.Team).ThenBy(p => p.Target).ToList(); this.BuildLists(); }
private List <Result> GetResults200m(string competition) { DatabaseApi.SelectCompetition200m(competition); var settings = SettingsHelper.GetSettings(); var rawResults = DatabaseApi.LoadCompetitionFromTable(TableName.OrionResult); var registrations = DatabaseApi.LoadCompetitionFromTable(TableName.LeonRegistration); var actualResults = this.AddNewResults(rawResults.OfType <OrionResult>().ToList(), settings); var results = BuildResultObjects(actualResults); foreach (var item in results) { if (registrations.Any()) { var registration = registrations.OfType <LeonPerson>().Last(r => r.ShooterId == item.ShooterId); if (registration != null) { item.Name = registration.Name; item.Class = registration.Class; item.ClubName = registration.ClubName; } } } return(results); }
internal static void CheckTmpFile(OrionSetupViewModel orionViewModel) { foreach (var orion in orionViewModel.OrionViewModels) { var path = orion.CommunicationSetup.SelectedPath; if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { return; } var tmpBasePath = DatabaseApi.GetActiveCompetition(); var tmpPath = Path.Combine(tmpBasePath, string.Format("Orion_{0}", orion.OrionId)); var filenameTmp = Path.Combine(tmpPath, ToOrionDataTmp); if (File.Exists(filenameTmp)) { var updFile = Path.Combine(path, ToOrionUPD); if (!File.Exists(updFile)) { var filename = Path.Combine(path, ToOrionData); var fileMoveError = false; try { File.Move(filenameTmp, filename); } catch (Exception ex) { Log.Error(ex, "Unable to move file " + filenameTmp + " to " + filename); fileMoveError = true; } if (!fileMoveError) { try { using (FileStream file = new FileStream(updFile, FileMode.Create, System.IO.FileAccess.Write)) { file.Write(s_updFileContent, 0, s_updFileContent.Length); file.Flush(true); file.Close(); } } catch (Exception ex) { Log.Error(ex, "Unable to create file " + updFile); try { File.Move(filename, filenameTmp); } catch (Exception ex1) { Log.Error(ex1, "Unable to move back file after UPD file create error " + filename + ", " + filenameTmp); } } } } } } }
private void AddNewRegistrations(List <MinneRegistration> newRegistrations, bool save) { if (m_minneRegistrations == null) { m_minneRegistrations = new List <MinneRegistration>(); } foreach (var newRegistration in newRegistrations) { var found = m_minneRegistrations.SingleOrDefault(p => p.ShooterId == newRegistration.ShooterId); if (found != null) { m_minneRegistrations.Remove(found); } if (!newRegistration.IsEmpty) { m_minneRegistrations.Add(newRegistration); } if (save) { DatabaseApi.Save(newRegistration); } } m_minneRegistrations = m_minneRegistrations.OrderBy(p => p.Team).ThenBy(p => p.Target).ToList(); ////this.BuildLists(); }
void ResetApi() { database = null; networkBroadcast = null; history = null; crypto = null; }
private IPromise DatabaseApiInitialized(DatabaseApi api) { return(api.GetChainId().Then(SetChainId).Then(() => Repository.SubscribeToNotice(api).Then(() => Repository.SubscribeToDynamicGlobalProperties(api).Then(() => { OnDatabaseApiInitialized.SafeInvoke(api); return Promise.Resolved(); })))); }
static IPromise Init(DatabaseApi api) { return(Promise.All( api.GetDynamicGlobalProperties().Then(AddInPromise), api.GetGlobalProperties().Then(AddInPromise), api.GetAsset().Then(AddInPromise) )); }
public void LoadFromCache_LeonRegistrations() { this.InitTestDatabase("TestStevne", new DateTime(2016, 2, 26)); this.SaveLeonPersons(10); var result = DatabaseApi.LoadCompetitionFromTable(TableName.LeonRegistration); Assert.IsTrue(result.Count == 10); }
private List <Result> GetResults100m(string competition) { DatabaseApi.SelectCompetition100m(competition); var settings = SettingsHelper.GetSettings(); var rawResults = DatabaseApi.LoadCompetitionFromTable(TableName.OrionResult); var actualResults = this.AddNewResults(rawResults.OfType <OrionResult>().ToList(), settings); return(BuildResultObjects(actualResults)); }
private void InitExistingDatabase() { var existing = DatabaseApi.GetAllCompetitions(); if (existing != null && existing.Any()) { DataBaseNames = new ObservableCollection <string>(existing); SelectedDatabase = DataBaseNames.First(); } }
public static void SaveSettings(Settings settings) { var databasePath = DatabaseApi.GetActiveCompetition(); var settingsfile = Path.Combine(databasePath, "FeltAdmin.xml"); var ser = new XmlSerializer(typeof(Settings)); using (var writer = new StreamWriter(settingsfile)) { ser.Serialize(writer, settings); } }
public List <string> GetCompetitions(RangeClass rangeClass) { if (rangeClass == RangeClass.Range100m) { return(DatabaseApi.GetAllCompetitions100m()); } else { return(DatabaseApi.GetAllCompetitions200m()); } }
IPromise DatabaseApiInitialized(DatabaseApi api) { return(api.GetChainId().Then((Action <string>)SetChainId).Then(result => { return Repository.SubscribeToNotice(api).Then(() => { if (!OnDatabaseApiInitialized.IsNull()) { OnDatabaseApiInitialized.Invoke(api); } return Promise.Resolved(); }); })); }
private void InitTestDatabase(string competitionName, DateTime date) { try { Directory.Delete(@"C:\FeltAdmin\TEST\Database", true); } catch (Exception ex) { Log.Error(ex, "Test"); } DatabaseApi.CreateNewCompetition("FeltAdmin", competitionName, date); }
public List <OrionResult> GetOrionResult(OrionViewModel orionViewModel) { if (this.CheckForNewFile() == false) { return(null); } var filename = GetFilename(); var updFile = this.GetUPDFilename(); var allLines = m_fileHandler.ReadAllLines(filename); var id = "NoId"; var result = new List <OrionResult>(); foreach (var line in allLines) { if (string.IsNullOrWhiteSpace(line)) { continue; } var or = OrionResult.ParseFromOrion(line, orionViewModel); id = or.OrionId.ToString(); if (or.ShooterId > 0) { DatabaseApi.Save(or); result.Add(or); } } var dbroot = DatabaseApi.GetActiveCompetition(); var backupPath = Path.Combine(dbroot, "Backup"); if (!Directory.Exists(backupPath)) { Directory.CreateDirectory(backupPath); } var bkupfilename = Path.Combine(backupPath, string.Format("{0}_Orion_{1}_kmonew.txt", DateTime.Now.ToString("yyyyMMdd-HHmmss"), id)); try { File.Move(filename, bkupfilename); File.Delete(updFile); } catch (Exception ex) { Log.Error(ex, "Unable to move to backup: " + filename); } return(result); }
public static string GetTemplateDir() { var templatePath = DatabaseApi.GetTemplatePaths(); if (string.IsNullOrEmpty(templatePath)) { return(string.Empty); } if (!Directory.Exists(templatePath)) { Directory.CreateDirectory(templatePath); } return(templatePath); }
public void CreateDatabaseExecute() { if (string.IsNullOrWhiteSpace(NewDatabaseName)) { MessageBox.Show("Du må angi navn på stevnet"); return; } if (NewDatabaseStartTime == DateTime.MinValue) { NewDatabaseStartTime = DateTime.Now; } DatabaseApi.CreateNewCompetition(SelectedAvailableTemplate, NewDatabaseName, NewDatabaseStartTime); this.InitExistingDatabase(); }
void OrionResultViewModel_NewOrionResults(object sender, Orion.OrionResultsEventArgs e) { var newResults = e.NewResults; List <int> finishedShooters; var updatedRegistrations = m_orionResultUpdater.GetUpdatedRegistrationsAfterResultRegistration( newResults, this.OrionTeamsSetupViewModel.OrionRegistrations, this.OrionResultViewModel.OrionResults, out finishedShooters); if (finishedShooters.Any()) { var finishedPersons = Leon.LeonPersons.Where(l => finishedShooters.Contains(l.ShooterId)); var maxTeamNumber = finishedPersons.Max(f => f.Team); var shouldBeFinished = Leon.LeonPersons.Where(l => l.Team <= maxTeamNumber).Select(l => l.ShooterId); var finishedRegistrations = DatabaseApi.LoadCompetitionFromTable(TableName.FinishedShooter).OfType <FinishedPerson>().Select(f => f.ShooterId); var missingPersons = shouldBeFinished.Except(finishedRegistrations).Except(finishedShooters); finishedShooters.AddRange(missingPersons); } this.OrionCommunicationViewModel.UpdateChangesToOrion(updatedRegistrations); this.OrionResultViewModel.AddNewRegistrations(newResults); if (finishedShooters != null && finishedShooters.Any()) { if (m_minneViewModel != null && m_minneViewModel.MinneRegistrations != null) { LeonWriter.WriteLeonResults( finishedShooters, this.OrionResultViewModel.OrionResults, this.MainOrionViewModel, this.Leon.LeonPersons, this.m_minneViewModel.MinneRegistrations); } else { LeonWriter.WriteLeonResults( finishedShooters, this.OrionResultViewModel.OrionResults, this.MainOrionViewModel, this.Leon.LeonPersons, null); } } }
private List <Registration> GetRegistrations200m(string competition) { DatabaseApi.SelectCompetition200m(competition); var rawResults = DatabaseApi.LoadCompetitionFromTable(TableName.LeonRegistration); var actualRegs = this.AddNewRegistrations(rawResults.OfType <LeonPerson>().ToList()); var results = this.GetResults200m(competition); foreach (var result in results) { var reg = actualRegs.SingleOrDefault(r => r.ShooterId == result.ShooterId); if (reg != null) { reg.Result = result; } } return(actualRegs); }
public void Save_RowAdded() { this.InitTestDatabase("TestStevne", new DateTime(2016, 2, 26)); var leonPerson = new LeonPerson { Class = "4", ClubName = "Bodø Østre", Name = "No Name", Range = 2, ShooterId = 123456, SumIn = 30, Target = 1, Team = 3 }; var result = DatabaseApi.Save(leonPerson); Assert.IsTrue(result); }
private void SaveLeonPersons(int number) { for (int i = 0; i < number; i++) { var leonPerson = new LeonPerson { Class = "4", ClubName = "Bodø Østre", Name = "No Name" + i, Range = 2, ShooterId = 123456 + i, SumIn = 30, Target = i + 1, Team = 3 }; DatabaseApi.Save(leonPerson); } }
private void InitExistingDatabase() { var existing = DatabaseApi.GetAllCompetitions(); if (existing != null && existing.Any()) { var dataBaseViewModels = new List <DataBaseViewModel>(); foreach (var dbPath in existing) { dataBaseViewModels.Add(new DataBaseViewModel { DatabasePath = dbPath }); } SelectedDatabase = dataBaseViewModels.First(); DataBaseNames = new ObservableCollection <DataBaseViewModel>(dataBaseViewModels); } }
public static void Reset() { _databaseApi = null; _accessTokenDao = null; _administratorDao = null; _administratorsInRolesDao = null; _channelDao = null; _channelGroupDao = null; _configDao = null; _contentCheckDao = null; _contentDao = null; _contentGroupDao = null; _databaseDao = null; _dbCacheDao = null; _errorLogDao = null; _keywordDao = null; _libraryGroupDao = null; _libraryImageDao = null; _libraryTextDao = null; _logDao = null; _permissionsInRolesDao = null; _pluginConfigDao = null; _pluginDao = null; _relatedFieldDao = null; _relatedFieldItemDao = null; _roleDao = null; _siteDao = null; _siteLogDao = null; _sitePermissionsDao = null; _specialDao = null; _tableStyleDao = null; _tableStyleItemDao = null; _tagDao = null; _templateDao = null; _templateLogDao = null; _templateMatchDao = null; _userDao = null; _userGroupDao = null; _userLogDao = null; _userMenuDao = null; }
public List <MinneRegistration> GetMinneRegistrations() { var filename = GetFilename(); var updFile = this.GetUPDFilename(); var allLines = m_fileHandler.ReadAllLines(filename); var result = new Dictionary <string, MinneRegistration>(); foreach (var line in allLines) { var lp = this.GetMinneRegistrationFromLine(line); if (result.ContainsKey(lp.Key)) { result.Remove(lp.Key); } result.Add(lp.Key, lp); } var dbroot = DatabaseApi.GetActiveCompetition(); var backupPath = Path.Combine(dbroot, "Backup"); if (!Directory.Exists(backupPath)) { Directory.CreateDirectory(backupPath); } var bkupfilename = Path.Combine(backupPath, string.Format("{0}_Minne_kminew.txt", DateTime.Now.ToString("yyyyMMdd-hhmmss"))); try { File.Move(filename, bkupfilename); File.Delete(updFile); } catch (Exception ex) { Log.Error(ex, "Unable to move to backup: " + filename); } return(result.Values.ToList()); }
public void CreateNewCompetition_NewDbCreated() { Directory.Delete(@"C:\FeltAdmin\TEST\Database"); var expectedPath = Path.Combine(@"C:\FeltAdmin\TEST\Database", "TestStevne_2016.02.26"); var expectedPath1 = Path.Combine(@"C:\FeltAdmin\TEST\Database", "TestStevne_2016.02.26-1"); var expectedPath2 = Path.Combine(@"C:\FeltAdmin\TEST\Database", "TestStevne_2016.02.26-2"); DatabaseApi.CreateNewCompetition("FeltAdmin", "TestStevne", new DateTime(2016, 2, 26)); Thread.Sleep(100); DatabaseApi.CreateNewCompetition("FeltAdmin", "TestStevne", new DateTime(2016, 2, 26)); Thread.Sleep(100); DatabaseApi.CreateNewCompetition("FeltAdmin", "TestStevne", new DateTime(2016, 2, 26)); var directories = DatabaseApi.GetAllCompetitions(); Assert.IsTrue(Directory.Exists(expectedPath)); Assert.IsTrue(Directory.Exists(expectedPath1)); Assert.IsTrue(Directory.Exists(expectedPath2)); Assert.AreEqual(expectedPath2, directories[0]); Assert.AreEqual(expectedPath1, directories[1]); Assert.AreEqual(expectedPath, directories[2]); }
/// <summary> /// Creates a client to work with VK API methods. /// </summary> public CitrinaClient() { AuthHelper = new AuthHelper(); Execute = new ExecuteApi(); Account = new AccountApi(); Ads = new AdsApi(); Apps = new AppsApi(); Auth = new AuthApi(); Board = new BoardApi(); Database = new DatabaseApi(); Docs = new DocsApi(); Fave = new FaveApi(); Friends = new FriendsApi(); Gifts = new GiftsApi(); Groups = new GroupsApi(); Leads = new LeadsApi(); Likes = new LikesApi(); Market = new MarketApi(); Messages = new MessagesApi(); Newsfeed = new NewsfeedApi(); Notes = new NotesApi(); Notifications = new NotificationsApi(); Orders = new OrdersApi(); Pages = new PagesApi(); Photos = new PhotosApi(); Places = new PlacesApi(); Polls = new PollsApi(); Search = new SearchApi(); Secure = new SecureApi(); Stats = new StatsApi(); Status = new StatusApi(); Storage = new StorageApi(); Users = new UsersApi(); Utils = new UtilsApi(); Video = new VideoApi(); Wall = new WallApi(); Widgets = new WidgetsApi(); }
public void UniqueNameTest() { // db1 and db3 will have the same name, we expect the final database names to be // the database name the the GUID. Guid id1 = new Guid("{08205A9C-D879-4EE4-B81C-64D4AB7CA596}"); Guid id2 = new Guid("{3458AAD3-2358-4E02-B28C-36EDEA7C5080}"); Guid id3 = new Guid("{7CFB2864-F606-455A-AC73-9AFA2F57B154}"); Mock <IDatabaseConfig> db1 = new Mock <IDatabaseConfig>(MockBehavior.Strict); db1.Setup(d => d.Name).Returns("My Database"); db1.Setup(d => d.DatabaseId).Returns(id1); Mock <IDatabaseConfig> db2 = new Mock <IDatabaseConfig>(MockBehavior.Strict); db2.Setup(d => d.Name).Returns("My Other Database"); db2.Setup(d => d.DatabaseId).Returns(id2); Mock <IDatabaseConfig> db3 = new Mock <IDatabaseConfig>(MockBehavior.Strict); db3.Setup(d => d.Name).Returns("My Database"); db3.Setup(d => d.DatabaseId).Returns(id3); List <IDatabaseConfig> configs = new List <IDatabaseConfig> { db1.Object, db2.Object, db3.Object }; DatabaseApi api = new DatabaseApi(configs); Assert.AreEqual("My Database " + id1, api.DatabaseNames[id1]); Assert.AreEqual("My Other Database", api.DatabaseNames[id2]); Assert.AreEqual("My Database " + id3, api.DatabaseNames[id3]); }
private static void WriteAllRegistrationsToOrion(string selectedPath, IEnumerable <OrionRegistration> allRegistrationsForThisOrion, int orionId) { var tmpBasePath = DatabaseApi.GetActiveCompetition(); var tmpPath = Path.Combine(tmpBasePath, string.Format("Orion_{0}", orionId)); if (!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } var filenameTmp = Path.Combine(tmpPath, ToOrionDataTmp); var allLinesForThisOrion = new List <string>(); foreach (var orionRegistration in allRegistrationsForThisOrion) { var line = orionRegistration.OrionInput; allLinesForThisOrion.Add(line); } // Feilhåndtering her, når maskin ikke er tilgjengelig.... File.AppendAllLines(filenameTmp, allLinesForThisOrion, Encoding.GetEncoding("ISO-8859-1")); ////var updFile = Path.Combine(selectedPath, ToOrionUPD); ////if (!File.Exists(updFile)) ////{ //// var filename = Path.Combine(selectedPath, ToOrionData); //// File.Move(filenameTmp, filename); //// using (FileStream file = new FileStream(updFile, FileMode.Create, System.IO.FileAccess.Write)) //// { //// file.Write(s_updFileContent, 0, s_updFileContent.Length); //// file.Flush(true); //// file.Close(); //// } ////} }