Beispiel #1
0
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            var           unityContainer = new IocUnityContainer();

            ServicesToRun = new ServiceBase[]
            {
                new Service(unityContainer.Resolve <ILogManager>(), unityContainer.Resolve <IEmailMessageService>())
            };

            ServiceBase.Run(ServicesToRun);
        }
Beispiel #2
0
        public MainWindow()
        {
            _container = new IocUnityContainer();

            _playerStatus = new PlayerStatus();

            InitializeComponent();

            CheckConfigurationKey("HostId");

            CheckConfigurationKey("UndeadMusicRelayUrl");

            CheckConfigurationKey("UndeadMusicPath");

            var hostId = Convert.ToInt32(ConfigurationManager.AppSettings["HostId"]);

            UndeadMusicRelayUrl = ConfigurationManager.AppSettings["UndeadMusicRelayUrl"];
            UndeadMusicPath     = ConfigurationManager.AppSettings["UndeadMusicPath"];

            _host = _container.Resolve <IHostService>().GetHost(hostId);
            Title = string.Format("Undead Music Player - {0}", _host.Name);
            ConsoleLog("Hostname: " + _host.Name);

            Player.LoadedBehavior = MediaState.Manual;
            Player.MediaEnded    += PlayerOnMediaEnded;

            InitializeSignalR(UndeadMusicRelayUrl);
        }
Beispiel #3
0
        protected void Application_Error()
        {
            var unityContainer = new IocUnityContainer();
            var logManager     = unityContainer.Resolve <ILogManager>();

            logManager.DefaultLogger.Error.Write("An unhandled Error has occurred", Server.GetLastError());
        }
Beispiel #4
0
        protected void Session_Start()
        {
            var unityContainer = new IocUnityContainer();
            var logManager     = unityContainer.Resolve <ILogManager>();

            try
            {
                var userName = HttpContext.Current.User.Identity.Name;
                logManager.DefaultLogger.Information.Write(string.Format("User {0} logged", userName));
                var userService = unityContainer.Resolve <IUserService>();
                var user        = userService.CreateUser(userName, UserHelper.GetDefaultAvatarUrl(HttpContext.Current.Request));

                UserHelper.SetUserInfo(user);
            }
            catch (Exception ex)
            {
                logManager.DefaultLogger.Error.Write("Session_Start", ex);
            }
        }
Beispiel #5
0
 private void CheckConfigurationKey(string configurationKey)
 {
     if (ConfigurationManager.AppSettings[configurationKey] == null)
     {
         string message = string.Format("Missing {0} configuration key", configurationKey);
         _container.Resolve <ILogService>().Fatal(message);
         MessageBox.Show(message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
         Close();
     }
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            var container = new IocUnityContainer();

            _logService = container.Resolve <ILogService>();

            if (ConfigurationManager.AppSettings["MusicFolderPath"] == null)
            {
                ConsoleLog("Error:: The required MusicFolderPath configuration key is missing");
                return;
            }

            var songService = container.Resolve <ISongService>();

            var folderPath = ConfigurationManager.AppSettings["MusicFolderPath"];

            int totalFiles = 0;
            int errorCount = 0;

            ConsoleLog(string.Format("Scan started: {0}", DateTime.Now.ToString("hh\\:mm\\:ss")));
            DateTime scanTime = DateTime.Now;

            if (Directory.Exists(folderPath))
            {
                ConsoleLog("Computing hash of files...");
                StringDictionary filesHash = ComputeFolderHash(folderPath);
                ConsoleLog("Processing files...");
                var filePaths = Directory.GetFiles(folderPath, "*.mp3");
                foreach (var filePath in filePaths)
                {
                    try
                    {
                        var fileName = Path.GetFileName(filePath).ToLower(CultureInfo.InvariantCulture);
                        var fileHash = filesHash[fileName];
                        if (!songService.SongExistsByHash(fileHash))
                        {
                            var musicTrack = Id3Reader.Instance.GetMusicTrackFromId3(filePath);
                            if (musicTrack == null)
                            {
                                continue;
                            }

                            var song = SongFromMusicTrack(musicTrack, fileHash, fileName);

                            songService.AddSong(song);
                            ConsoleLog(string.Format("{0} : added to the database", fileName));
                        }
                        else
                        {
                            ConsoleLog(string.Format("{0} : already exists in database", fileName));
                        }
                    }
                    catch (Exception ex)
                    {
                        var innerException = ex.InnerException != null ? "InnerException::" + ex.InnerException.Message : "";
                        ConsoleLog(string.Format("ERROR:: {0} : {1}", filePath, ex.Message + "StackTrace::" + ex.StackTrace + innerException));
                        errorCount += 1;
                    }

                    totalFiles += 1;
                }
            }

            ConsoleLog(string.Format("Scan finished. Total time: {0}. Total {1} files scanned. Total Errors {2} (see application file log for more details)", DateTime.Now.Subtract(scanTime).ToString("hh\\:mm\\:ss"), totalFiles, errorCount));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            try
            {
                var container    = new IocUnityContainer();
                var movieService = container.Resolve <IMovieService>();
                _logService = container.Resolve <ILogService>();
                DateTime scanTime = DateTime.Now;

                var rootFolder            = ConfigurationManager.AppSettings["RootFolder"];
                var mediaFileExtensions   = ConfigurationManager.AppSettings["MediaFileExtensions"];
                var pictureFileExtensions = ConfigurationManager.AppSettings["PictureFileExtensions"];

                ConsoleLog($"starting scan on {rootFolder}");
                var folderPaths = Directory.GetDirectories(rootFolder);
                ConsoleLog($"{folderPaths.Length} folders found");
                int movieCount = 0;

                foreach (var path in folderPaths)
                {
                    var folderName        = Path.GetFileName(path);
                    var match             = Regex.Match(folderName, "(\\d+)-([\\w\\s]+)", RegexOptions.IgnoreCase);
                    var year              = match.Groups[1].Value;
                    var name              = match.Groups[2].Value;
                    var movieFileName     = Directory.GetFiles(path, mediaFileExtensions).Select(Path.GetFileName).ToList();
                    var thumbnailFileName =
                        Path.GetFileName(Directory.GetFiles(path, pictureFileExtensions).FirstOrDefault());
                    string sinopsis     = string.Empty;
                    var    sinopsisPath = Path.Combine(path, "sinopsis.txt");
                    if (File.Exists(sinopsisPath))
                    {
                        sinopsis = File.ReadAllText(sinopsisPath, Encoding.Default);
                    }

                    if (movieFileName.Any())
                    {
                        var movie = new Movie
                        {
                            Year        = Convert.ToInt32(year),
                            Name        = name,
                            MovieFolder = folderName,
                            MovieFiles  = movieFileName.Select(m => new MovieFile
                            {
                                FileName = m
                            }).ToList(),
                            ThumbnailFileName = thumbnailFileName,
                            Sinopsis          = sinopsis
                        };
                        movieCount += 1;
                        var existingMovie = movieService.GetByName(name);
                        if (existingMovie == null)
                        {
                            movieService.CreateMovie(movie);
                            ConsoleLog($"scanning folder: {name} [create]");
                        }
                        else
                        {
                            movieService.UpdateMovie(movie);
                            ConsoleLog($"scanning folder: {name} [update]");
                        }
                    }
                    else
                    {
                        ConsoleLog($"no movie files found for folder: {name}");
                    }
                }

                ConsoleLog("scan finished");
                ConsoleLog($"{movieCount} movies found");
                ConsoleLog($"total time: {DateTime.Now.Subtract(scanTime).ToString("hh\\:mm\\:ss")}");
                _logService.Info($"{Environment.NewLine}=========================================================================================");
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }
Beispiel #8
0
        private void lnkOptions_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (MessageBox.Show(
                    "This process will override all the information stored in the DB. Are you sure to continue?", Text,
                    MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                cmbSearchText.Text = string.Empty;
                WindowState        = FormWindowState.Minimized;
                Hide();
                notifyIcon.BalloonTipTitle = Text;
                notifyIcon.BalloonTipText  = "Full Scan started";
                notifyIcon.ShowBalloonTip(3000);
                var fileCount = 0;

                var networkService = _container.Resolve <INetworkService>();
                var mp3FileService = _container.Resolve <IMp3FileService>();
                var myIp           = networkService.GetMyIp();
                if (myIp != null)
                {
                    var myNetworkIp = $"{myIp[0]}.{myIp[1]}.{myIp[2]}";
                    for (int i = 0; i < 255; i++)
                    {
                        if (i == myIp[3])
                        {
                            var serverIp  = $"{myNetworkIp}.{i}";
                            var shareList = networkService.GetNetworkShareFoldersList(serverIp);

                            foreach (var share in shareList)
                            {
                                var directories = new List <string> {
                                    $"\\\\{serverIp}\\{share}"
                                };
                                for (int j = 0; j < directories.Count; j++)
                                {
                                    var directoryPath = directories[j];
                                    directories.AddRange(Directory.GetDirectories(directoryPath));

                                    Console.WriteLine($"scanning directory:{directoryPath}");
                                    foreach (var filePath in Directory.GetFiles(directoryPath))
                                    {
                                        Console.WriteLine($"        file:{filePath}");
                                        var fileExtension = Path.GetExtension(filePath);

                                        if (fileExtension.ToLower(CultureInfo.InvariantCulture) == ".mp3")
                                        {
                                            var mp3File = mp3FileService.GetMp3File(filePath);
                                            if (mp3File != null)
                                            {
                                                if (mp3FileService.Mp3FileExists(mp3File))
                                                {
                                                    mp3FileService.UpdateMp3File(mp3File);
                                                }
                                                else
                                                {
                                                    mp3FileService.SaveMp3File(mp3File);
                                                }

                                                fileCount += 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                notifyIcon.BalloonTipTitle = Text;
                notifyIcon.BalloonTipText  = $"Full Scan finished, total files added: {fileCount}";
                notifyIcon.ShowBalloonTip(3000);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            var container = new IocUnityContainer();

            _logService = container.Resolve <ILogService>();
            DateTime scanTime = DateTime.Now;

            ConsoleLog("scan started");

            try
            {
                // Startup check
                var mediaConfigurationManager = new MediaConfigurationManager(args, new FolderValidator());
                ConsoleLog("startup checking...");
                if (!mediaConfigurationManager.StartupCheck())
                {
                    ConsoleLog("startup check failed, please see log for more details");
                    ConsoleLog("usage: UPictures.Discover.exe [MediaFolderPath]");
                    _logService.Error(mediaConfigurationManager.Errors);
                    return;
                }
                ConsoleLog("all ok!");

                var mediaProcessorFactory = new MediaProcessorFactory(mediaConfigurationManager.IrfanViewBinPath, mediaConfigurationManager.ThumbnailFolderPath, mediaConfigurationManager.SearchFolderPath, mediaConfigurationManager.MasterFolderPath, mediaConfigurationManager.ViewFolderPath);
                var fileProcessor         = new FileProcessor(mediaConfigurationManager.PictureFileExtensions);
                var totalFiles            = 0;
                var errorCount            = 0;
                var folderPaths           = Directory.GetDirectories(mediaConfigurationManager.RootFolder);
                var folderIndex           = 0;
                var folderCount           = folderPaths.Length;
                ConsoleLog($"{folderCount} subfolders discovered at {mediaConfigurationManager.RootFolder}");
                foreach (var folderPath in folderPaths)
                {
                    folderIndex += 1;
                    var folderName = Path.GetFileName(folderPath);
                    ConsoleLog($"start processing of '{folderName}' [{folderIndex} of {folderCount}]");
                    var titleResult = TitleProcessor.Process(folderName);
                    if (titleResult != null)
                    {
                        var albumService  = container.Resolve <IAlbumService>();
                        var existingAlbum = albumService.GetByName(titleResult.Title);
                        if (existingAlbum != null)
                        {
                            ConsoleLog($"album '{titleResult.Title}' already exists, skipping folder");
                            continue;
                        }

                        ConsoleLog($"creating album '{titleResult.Title}'");
                        var album     = new Album(titleResult.Title);
                        var files     = Directory.GetFiles(folderPath);
                        var fileIndex = 0;
                        var fileCount = files.Count();

                        foreach (var filePath in files)
                        {
                            fileIndex += 1;
                            var fileProcess = fileProcessor.Process(filePath);

                            if (fileProcess == null)
                            {
                                ConsoleLog($"ERROR: Unknown file type for: {filePath}");
                                errorCount += 1;
                                continue;
                            }

                            ConsoleLog($"[{folderIndex}/{folderCount}]:[{fileIndex}/{fileCount:00}] processing '{fileProcess.Name}{fileProcess.Extension}' of type '{fileProcess.Extension}'");
                            var mediaProcessor = mediaProcessorFactory.GetFileProcessor();

                            ConsoleLog($"[{folderIndex}/{folderCount}]:[{fileIndex}/{fileCount}] creating thumbnails for '{fileProcess.Name}{fileProcess.Extension}'");
                            mediaProcessor.CreateThumbnail(fileProcess);

                            ConsoleLog($"[{folderIndex}/{folderCount}]:[{fileIndex}/{fileCount}] creating search for '{fileProcess.Name}{fileProcess.Extension}'");
                            mediaProcessor.CreateSearch(fileProcess);

                            ConsoleLog($"[{folderIndex}/{folderCount}]:[{fileIndex}/{fileCount}] creating view for '{fileProcess.Name}{fileProcess.Extension}'");
                            mediaProcessor.CreateView(fileProcess);

                            ConsoleLog($"[{folderIndex}/{folderCount}]:[{fileIndex}/{fileCount}] creating master for '{fileProcess.Name}{fileProcess.Extension}'");
                            mediaProcessor.CreateMaster(fileProcess);

                            var mediaFile = new Picture(fileProcess.Name, fileProcess.FileSize, fileProcess.Width, fileProcess.Height, album.Name)
                            {
                                DateTaken   = fileProcess.DateTaken,
                                CameraModel = fileProcess.CameraModel,
                                CameraMaker = fileProcess.CameraMaker
                            };

                            album.AddPicture(mediaFile);
                            totalFiles += 1;
                        }

                        ConsoleLog($"saving album '{album.Name}'");
                        albumService.SaveAlbum(album);
                    }
                    else
                    {
                        ConsoleLog($"ERROR: failed to process folder title for: {folderPath}");
                        errorCount += 1;
                    }
                }

                ConsoleLog("scan finished");
                ConsoleLog($"total time: {DateTime.Now.Subtract(scanTime).ToString("hh\\:mm\\:ss")}");
                ConsoleLog($"total folders scanned: {folderCount}");
                ConsoleLog($"total files scanned: {totalFiles}");
                ConsoleLog($"total errors: {errorCount} (see application file log for more details)");
            }
            catch (Exception ex)
            {
                ConsoleLog("ERROR: an unhandled error has occurred. Please see log for more details.");

                var errorMessage = new StringBuilder();
                errorMessage.AppendLine(ex.Message);
                errorMessage.AppendLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    errorMessage.AppendLine(ex.InnerException.Message);
                    errorMessage.AppendLine(ex.InnerException.StackTrace);
                }

                _logService.Error(errorMessage.ToString());
            }
        }