public Bitmap GetBitmap() { // get dependencies var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { logService.Trace($@"Checking if bitmap for ""{_path}"" has already been cached..."); if (_bitmap != null) { logService.Trace($@"Bitmap for ""{_path}"" has been cached. Returning..."); return(_bitmap); } logService.Trace($@"Loading ""{_path}"" from disk..."); _bitmap = (Bitmap)Image.FromStream(GetFileStream()); logService.Trace($@"Returning a copy of ""{_path}""..."); return(new Bitmap(_bitmap)); } finally { logService.TraceExit(); } }
public FolderWatcher() { // create dependencies _logService = NinjectKernel.Get <ILogService>(); // initialise variables _fileSystemWatchers = new List <FileSystemWatcher>(); _observers = new List <IFolderObserver>(); }
public ListViewItem() { // get dependencies _logService = NinjectKernel.Get <ILogService>(); _taskScheduler = NinjectKernel.Get <TaskScheduler>(); // initialise variables _isMetadataLoaded = false; _isSaved = false; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var form = NinjectKernel.Get <formLogIn>(); //form.FormClosed += MainForm_Closed; //form.Show(); Application.Run(form); }
public ExifData GetExifData() { // create dependencies var logService = NinjectKernel.Get <ILogService>(); // create variables var stopWatch = Stopwatch.StartNew(); logService.TraceEnter(); try { // create the object to return var exifData = new Models.ExifData(); using (var fs = GetFileStream()) { var bitmapSource = BitmapFrame.Create(fs, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None); if (!(bitmapSource.Metadata is BitmapMetadata bitmapMetadata)) { return(exifData); } // try and parse the date exifData.DateTaken = !DateTime.TryParse(bitmapMetadata.DateTaken, out var dateTaken) ? bitmapMetadata.DateTaken : dateTaken.Date.ToString(ShortDateFormat); // is there a latitude on the image exifData.Latitude = GetLatitude(bitmapMetadata); if (exifData.Latitude.HasValue) { exifData.Longitude = GetLongitude(bitmapMetadata); } try { // is there a title on the image? exifData.Title = bitmapMetadata.Title; } catch (NotSupportedException) { // ignore this exception } } return(exifData); } finally { logService.TraceExit(stopWatch); } }
/// <summary> /// Executes 'exit' command /// </summary> /// <param name="commandInfo"></param> /// <returns></returns> public override bool Execute(CommandInfo commandInfo) { Logger.Info($"User {Session.LoggedUser.Email} exited"); var authenService = NinjectKernel.Get <AuthenticationService>(); authenService.LogOut(SessionKey); Exited?.Invoke(this, new EventArgs()); return(true); }
public Bitmap GetPreview() { // get dependencies var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { logService.Trace($@"Checking if preview for ""{_path}"" has already been cached..."); if (_preview != null) { logService.Trace($@"Bitmap for ""{_path}"" has been cached. Returning..."); return(_preview); } logService.Trace($@"Getting bitmap for ""{_path}""..."); var bitmap = GetBitmap(); logService.Trace($"Resizing to fit {PreviewWidth}px x{PreviewHeight}px canvas..."); _preview = new Bitmap(PreviewWidth, PreviewHeight); logService.Trace("Calculating size of resized image..."); var aspectRatio = Math.Min(PreviewWidth / (float)bitmap.Width, PreviewHeight / (float)bitmap.Height); var newPreviewWidth = bitmap.Width * aspectRatio; var newPreviewHeight = bitmap.Height * aspectRatio; var newX = (PreviewWidth - newPreviewWidth) / 2; var newY = (PreviewHeight - newPreviewHeight) / 2; logService.Trace("Drawing resized image..."); using (var graphics = Graphics.FromImage(_preview)) { // initialise the pen graphics.SmoothingMode = SmoothingMode.HighSpeed; graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.Low; // draw the black background graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, PreviewWidth, PreviewHeight); // now draw the image over the top graphics.DrawImage(bitmap, newX, newY, newPreviewWidth, newPreviewHeight); } return(_bitmap); } finally { logService.TraceExit(); } }
private Stream GetFileStream() { // create dependencies var logService = NinjectKernel.Get <ILogService>(); // create variables var stopWatch = Stopwatch.StartNew(); logService.TraceEnter(); try { logService.Trace($@"Checking if file stream for ""{_path}"" has already been cached..."); if (_fileStream != null) { logService.Trace($@"File stream for ""{_path}"" has been cached. Returning..."); _fileStream.Position = 0; return(_fileStream); } var count = 0; while (true) { try { logService.Trace($@"Trying to open ""{_path}"". Count = {count}..."); _fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.Read); return(_fileStream); } catch (IOException ex) { if (count++ == 30) { throw; } Thread.Sleep(1000); } } } finally { logService.TraceExit(stopWatch); } }
public void OnInit(DictionaryAtom initAtom) { try { NinjectKernel = initAtom.GetObject("Ninject.Kernel").CastAs <IKernel>(); initAtom.Set("Logger", Logger); InitBooleanSet = new BooleanSet("OnGameInitialize", Game_OnInitializationComplete); NinjectKernel.Load(_ninjectGameModules.Select( moduleType => (NinjectGameModule)Activator.CreateInstance(moduleType, initAtom, InitBooleanSet))); EventMgr = (EventManager)NinjectKernel.Get <IEventManager>(); LuaMgr = (LuaManager)NinjectKernel.Get <ILuaManager>(); DbMgr = (DatabaseManager)NinjectKernel.Get <IDatabaseManager>(); StaticMgr = (StaticDataManager)NinjectKernel.Get <IStaticDataManager>(); EntityMgr = (EntityManager)NinjectKernel.Get <IEntityManager>(); EntityMgr.EntityInitializer.RegisterEntityTypes(_entityTypes); ChannelMgr = (ChannelManager)NinjectKernel.Get <IChannelManager>(); CmdMgr = (CommandManager)NinjectKernel.Get <ICommandManager>(); PathMgr = (PathManager)NinjectKernel.Get <IPathManager>(); TimeMgr = (TimeManager)NinjectKernel.Get <ITimeManager>(); NetMgr = (NetworkManager)NinjectKernel.Get <INetworkManager>(); // todo DataManager? // todo CombatManager ? LoopProcessor = (GameLoopProcessor)NinjectKernel.Get <ILoopProcessor>(); Contexts = new List <IContext> { new PropertyContext(this) }; // Everything that needs early initialization done before this line // Now, lets begin regular setup (this will include game data) Logger.Debug("Completed initialization of Managers, throwing OnGameInitialize event."); EventMgr.ThrowEvent <OnGameInitialize>(this, new EventTable { { "BooleanSet", InitBooleanSet }, { "InitAtom", initAtom } }); } catch (Exception ex) { ex.Handle <InitializationException>(ExceptionHandlingOptions.RecordAndThrow, Logger); } }
private static float?GetLatitude(BitmapMetadata bitmapMetadata) { // create dependencies var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { logService.Trace("Checking if file has latitude information..."); if (!(bitmapMetadata.GetQuery("System.GPS.Latitude.Proxy") is string latitudeRef)) { logService.Trace("File does not have latitude information. Exiting..."); return(null); } logService.Trace($"Parsing latitude information \"{latitudeRef}\"..."); var latitudeMatch = Regex.Match(latitudeRef, @"^(\d+),([0123456789.]+)([SN])"); if (!latitudeMatch.Success) { logService.Trace($"Unable to parse \"{latitudeRef}\". Exiting..."); return(null); } logService.Trace("Converting to a float..."); var latitudeDecimal = float.Parse(latitudeMatch.Groups[1].Value) + float.Parse(latitudeMatch.Groups[2].Value) / 60; if (latitudeMatch.Groups[3].Value == "S") { latitudeDecimal *= -1; } return(latitudeDecimal); } catch (NotSupportedException) { logService.Trace("Unable to query for latitude. Returning..."); return(null); } finally { logService.TraceExit(); } }
private void FileSystemWatcher_Error(object sender, ErrorEventArgs e) { // create dependencies var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { logService.Trace("Bubbling error up..."); OnError(e.GetException()); } catch (Exception) { // ignored } finally { logService.TraceExit(); } }
public void Watch(string path) { // create dependencies var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { _logService.Trace($@"Watching for changes to ""{path}""..."); _fileSystemWatchers.Add(CreateFileSystemWatcher(path)); } catch (Exception ex) { OnError(ex); } finally { logService.TraceExit(); } }
private void FileSystemWatcher_Created(object sender, FileSystemEventArgs e) { var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { logService.Trace($@"Notifying {_observers.Count} observers of new file {e.FullPath}..."); foreach (var observer in _observers) { observer.OnCreated(e.FullPath); } } catch (Exception ex) { OnError(ex); } finally { logService.TraceExit(); } }
private void FileSystemWatcher_Renamed(object sender, RenamedEventArgs e) { // create dependencies var logService = NinjectKernel.Get <ILogService>(); logService.TraceEnter(); try { logService.Trace($@"Notifying {_observers.Count} observers of rename from ""{e.OldFullPath}"" to ""{e.FullPath}""..."); foreach (var observer in _observers) { observer.OnRenamed(e.OldFullPath, e.FullPath); } } catch (Exception ex) { OnError(ex); } finally { logService.TraceExit(); } }
public LogOutHandler() { authenService = NinjectKernel.Get <AuthenticationService>(); }
public ExportToCvsHandler() { exportMassageService = NinjectKernel.Get <CsvMessageExportService>(); exportUserService = NinjectKernel.Get <CsvUserExportService>(); }
public FindHandler() { userSearchService = NinjectKernel.Get <UserSearcher>(); }
// Due to issue I reported here have to take site as a string: // http://youtrack.jetbrains.com/issue/RSRP-292611 protected HandHistoryParserBaseTests(string site) { Kernel = new NinjectKernel(); SampleHandHistoryRepository = Kernel.Get <ISampleHandHistoryRepository>(); Site = (SiteName)Enum.Parse(typeof(SiteName), site); }
public FriendsHandler() { friendsService = NinjectKernel.Get <FriendsService>(); }
protected CommandHandler() { IoService = NinjectKernel.Get <IInputOutputSevice>(); Session = new SessionInfo(); }
public SignUpHandler() { UserValidator = NinjectKernel.Get <UserValidationService>(); }
public PathSearchHandler() { shortestUserPathService = NinjectKernel.Get <ShortestUserPathService>(); }