private Guid OpenInternal(string address, string dataBase, string userID, SecureString password) { this.address = AddressUtility.GetDisplayAddress(address); this.log = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath); this.log.Verbose = this.verbose; this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password); var user = this.userContext.Users[userID]; user.SetUserState(UserState.Online); this.userID = userID; this.authority = user.Authority; this.dataBases = new DataBaseCollection(this, this.ipAddress, dataBase, serviceInfos[nameof(DataBaseCollectionService)]); this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]); this.isConnected = true; this.configs = new CremaConfiguration(this.ConfigPath); this.plugins = this.container.GetService(typeof(IEnumerable <IPlugin>)) as IEnumerable <IPlugin>; foreach (var item in this.plugins) { var authentication = new Authentication(new AuthenticationProvider(user), item.ID); this.authentications.Add(authentication); item.Initialize(authentication); } this.OnOpened(EventArgs.Empty); this.token = Guid.NewGuid(); CremaLog.Info($"Crema opened : {address} {userID}"); return(token); }
private void Close(CloseInfo closeInfo) { this.OnClosing(EventArgs.Empty); foreach (var item in this.services.Reverse <ICremaService>()) { item.Close(closeInfo); } this.services.Clear(); this.domainContext = null; this.dataBases = null; this.userContext = null; foreach (var item in this.plugins) { item.Release(); } foreach (var item in this.authentications) { item.InvokeExpiredEvent(Authentication.SystemID); } this.dispatcher.InvokeAsync(() => { this.log?.Dispose(); this.log = null; }); this.address = null; this.userID = null; this.isConnected = false; this.OnClosed(new ClosedEventArgs(closeInfo.Reason, closeInfo.Message)); CremaLog.Info("Crema closed."); }
private static void LoadFromDb() { _pool = new Dictionary<long, FactorStatistic>(); var collection = new DataBaseCollection<FactorStatistic>(); collection.Load(@"select BIT_MASK, FACTOR_NAME, NUMBER_OF_STARTERS, NUMBER_OF_WINNERS, ROI, IV from FACTOR_NAME"); collection.ForEach(fs => _pool.Add(fs.BitMask, fs)); }
public Guid Open(string address, string userID, SecureString password) { if (this.isConnected == true) { throw new InvalidOperationException(Resources.Exception_AlreadyConnected); } this.ipAddress = AddressUtility.GetIPAddress(address); this.serviceInfos = GetServiceInfo(address).ToDictionary(item => item.Name); this.OnOpening(EventArgs.Empty); return(this.dispatcher.Invoke(() => { try { this.address = AddressUtility.GetDisplayAddress(address); this.log = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath); this.log.Verbose = this.verbose; this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password); var user = this.userContext.Users[userID]; user.SetUserState(UserState.Online); this.userID = userID; this.authority = user.Authority; this.dataBases = new DataBaseCollection(this, this.ipAddress, serviceInfos[nameof(DataBaseCollectionService)]); this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]); this.isConnected = true; this.configs = new CremaConfiguration(this.ConfigPath); this.plugins = this.container.GetService(typeof(IEnumerable <IPlugin>)) as IEnumerable <IPlugin>; foreach (var item in this.plugins) { var authentication = new Authentication(new AuthenticationProvider(user), item.ID); this.authentications.Add(authentication); item.Initialize(authentication); } this.OnOpened(EventArgs.Empty); this.token = Guid.NewGuid(); CremaLog.Info($"Crema opened : {address} {userID}"); return token; } catch { this.userContext?.Close(CloseInfo.Empty); this.userContext = null; this.log?.Dispose(); this.log = null; this.address = null; throw; } })); }
public void Open() { this.OnOpening(EventArgs.Empty); this.dispatcher.Invoke(() => { this.Info(Resources.Message_ProgramInfo, AppUtility.ProductName, AppUtility.ProductVersion); this.repository = this.repositoryProvider.CreateInstance(this.repositoryPath, this.workingPath); this.Info("Repository module : {0}", this.settings.RepositoryModule); this.Info("Repository path : " + this.repositoryPath); foreach (var logger in this.GetService <IEnumerable <ILogService> >()) { this.Info($"{logger.Name} log path : {logger.FileName}"); } this.Info(Resources.Message_ServiceStart); this.configs = new CremaConfiguration(Path.Combine(this.basePath, "configs.xml"), this.propertiesProvider); this.userContext = new UserContext(this); this.userContext.Dispatcher.Invoke(() => this.userContext.Initialize()); this.dataBases = new DataBaseCollection(this); this.domainContext = new DomainContext(this, this.userContext); if (this.settings.NoCache == false) { foreach (var item in this.dataBases) { this.domainContext.Restore(Authentication.System, item); } } this.plugins = this.container.GetService(typeof(IEnumerable <IPlugin>)) as IEnumerable <IPlugin>; this.plugins = this.plugins.TopologicalSort(); foreach (var item in this.plugins) { var authentication = new Authentication(new AuthenticationProvider(item), item.ID); item.Initialize(authentication); this.Info("Plugin : {0}", item.Name); } this.dispatcher.InvokeAsync(() => this.dataBases.RestoreState(this.settings)); GC.Collect(); this.Info("Crema module has been started."); this.OnOpened(EventArgs.Empty); }); }
public void Close(CloseReason reason, string message) { this.OnClosing(EventArgs.Empty); this.dispatcher.Invoke(() => { this.userContext.Dispatcher.Invoke(() => this.userContext.Clear()); this.UserContext.Dispose(); this.userContext = null; this.domainContext.Dispose(); this.domainContext = null; this.dataBases.Dispose(); this.dataBases = null; foreach (var item in this.plugins.Reverse()) { item.Release(); } this.Info("Crema module has been stopped."); this.OnClosed(new ClosedEventArgs(reason, message)); }); }
public static void CreateGoldenFigureFile(string filename) { var collection = new DataBaseCollection<StarterInfo>(); collection.Load(_sqlLoad); int counter = 0; using (var tw = new StreamWriter(filename)) { string currentHorse = ""; string line = ""; foreach (var si in collection) { ++counter; if (0 == counter % 100) { Console.WriteLine(counter); } if(si.GoldenFigure == -999 || si.WinnersGoldenFigure == -999) continue; string horse = si.HorseName; if (currentHorse.Length > 0 && currentHorse != horse) { if (line.Length > 0) { tw.Write(currentHorse); tw.Write(","); tw.WriteLine(line); } line = ""; } currentHorse = horse; if (si.FinishPosition > 0) { if (line.Length > 0) { line += ","; } line += si.GetAsParsableString(); } } if (line.Length > 0) { tw.Write(currentHorse); tw.Write(","); tw.WriteLine(line); } tw.Close(); } }
private void LoadAllRacesForTheDistance() { if (_skipLoading) return; try { Cursor = Cursors.WaitCursor; if (null == _currentRaceInfo) return; _gridShowAllRacesForTheDistance.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; DateTime fd = _periodSelector.FromDate; DateTime td = _periodSelector.ToDate; string fromDate = string.Format("{0}{1:00}{2:00}", fd.Year, fd.Month, fd.Day); string toDate = string.Format("{0}{1:00}{2:00}", td.Year, td.Month, td.Day); string surf = _currentRaceInfo.Surface; string trackCode = _currentRaceInfo.TrackCode; string aboutFlag = _currentRaceInfo.AboutFlag.Trim(); _tbDistance.Text = Utilities.ConvertYardsToMilesOrFurlongs((int) _currentRaceInfo.Distance); if (aboutFlag.Contains("A")) { _tbDistance.Text = new string('*', 1) + _tbDistance.Text; } _tbSurface.Text = surf; var collection = new DataBaseCollection<RaceResults>(); string sqlLoader = string.Format(_sqlLoadRacesForDistanceAndTrack, trackCode, _currentRaceInfo.Distance, surf, aboutFlag, fromDate, toDate); collection.Load(sqlLoader); RaceResults.InitializeGrid(_gridShowAllRacesForTheDistance, collection.Count); WinnerInfo thisRaceInfo = null; int rowIndex = 0; collection.ForEach(rr => rr.AddToGrid(_gridShowAllRacesForTheDistance, _currentRaceInfo.RaceId, rowIndex++)); _gridShowAllRacesForTheDistance.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; _tbNumberOfRaces.Text = collection.Count.ToString(); } finally { Cursor = Cursors.Default; } }