Exemplo n.º 1
0
        public static bool ConnectToServer(CommonConfigData config)
        {
            var connected = false;

            if (config.FindServerAutomatically)
            {
                connected = ConnectAutomatically(config.HttpTimeout);
            }
            else
            {
                //server specified
                connected = ConnectToServer(config.ServerAddress, config.ServerPort, config.HttpTimeout);
                if (!connected)
                {
                    Logger.ReportWarning("Unable to connect to configured server {0}:{1}. Will try automatic detection", config.ServerAddress, config.ServerPort);
                    connected = ConnectAutomatically(config.HttpTimeout);
                }
            }

            if (connected)
            {
                Logger.ReportInfo("====== Connected to server {0}:{1}", ApiClient.ServerHostName, ApiClient.ServerApiPort);
                AvailableUsers = ApiClient.GetAllUsers().ToList();
                config.LastServerMacAddress = ServerInfo.MacAddress;
                config.ServerPort           = ApiClient.ServerApiPort;
                config.Save();
            }

            return(connected);
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            // set up assembly resolution hooks, so earlier versions of the plugins resolve properly
            AppDomain.CurrentDomain.AssemblyResolve += Kernel.OnAssemblyResolve;

            InitializeComponent();
            //_serviceConfig = ServiceConfigData.FromFile(ApplicationPaths.ServiceConfigFile);
            Async.Queue("Migration", () =>
            {
                var mbphoto = Path.Combine(ApplicationPaths.AppPluginPath, "mbphoto.classic.dll");
                if (File.Exists(mbphoto))
                {
                    try
                    {
                        File.Delete(mbphoto);
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error deleting old MBPhoto plug-in", e);
                    }
                }

                const string chocolate = @"\windows\ehome\chocolate.dll";
                if (File.Exists(chocolate))
                {
                    try
                    {
                        File.Delete(chocolate);
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error deleting old chocolate plug-in", e);
                    }
                }

                if (File.Exists(ApplicationPaths.CommonConfigFile))
                {
                    _config = CommonConfigData.FromFile(ApplicationPaths.CommonConfigFile);
                }

                if (_config == null) // only do this if a fresh install
                {
                    try
                    {
                        _config = CommonConfigData.FromFile(ApplicationPaths.CommonConfigFile); // create a new one
                        Migrate300();
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error during migration", e);
                    }
                }
                if (_config != null)
                {
                    // Set install directory
                    _config.MBInstallDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                    _config.Save();
                }
                Dispatcher.Invoke(DispatcherPriority.Background, (System.Windows.Forms.MethodInvoker)(Close));
            });
        }
Exemplo n.º 3
0
        static Kernel GetDefaultKernel(CommonConfigData config, KernelLoadDirective loadDirective)
        {
            var repository = new MB3ApiRepository();
            var localRepo  = GetLocalRepository();

            var kernel = new Kernel()
            {
                PlaybackControllers = new List <BasePlaybackController>(),
                //MetadataProviderFactories = MetadataProviderHelper.DefaultProviders(),
                CommonConfigData = config,
                //ServiceConfigData = ServiceConfigData.FromFile(ApplicationPaths.ServiceConfigFile),
                StringData           = LocalizedStrings.Instance,
                ImageResolvers       = DefaultImageResolvers(false),
                MB3ApiRepository     = repository,
                LocalRepo            = localRepo,
                MediaLocationFactory = new MediaLocationFactory(),
            };

            //Kernel.UseNewSQLRepo = config.UseNewSQLRepo;

            // kernel.StringData.Save(); //save this in case we made mods (no other routine saves this data)
            if (LoadContext == MBLoadContext.Core)
            {
                kernel.PlaybackControllers.Add(new PlaybackController());
            }

            //kernel.EntityResolver = DefaultResolver(kernel.ConfigData);

            //need a blank root in case plug-ins will add virtual items
            kernel.RootFolder = new AggregateFolder {
                Name = "My Media", Id = new Guid("{F6109BAE-CA26-4746-9EBC-1CD233A7B56F}")
            };

            //create our default config panels with localized names
            kernel.AddConfigPanel(kernel.StringData.GetString("GeneralConfig"), "");
            kernel.AddConfigPanel(kernel.StringData.GetString("ViewOptionsConfig"), "");
            kernel.AddConfigPanel(kernel.StringData.GetString("ThemesConfig"), "");
            kernel.AddConfigPanel(kernel.StringData.GetString("PlaybackConfig"), "");

            //kick off log clean up task if needed
            if (config.LastFileCleanup < DateTime.UtcNow.AddDays(-7))
            {
                Async.Queue(Async.ThreadPoolName.LogfileCleanup, () =>
                {
                    Logger.ReportInfo("Running Logfile clean-up...");
                    var minDateModified = DateTime.UtcNow.AddDays(-(config.LogFileRetentionDays));
                    foreach (var source in new DirectoryInfo(ApplicationPaths.AppLogPath).GetFileSystemInfos("*.log")
                             .Where(f => f.LastWriteTimeUtc < minDateModified))
                    {
                        try
                        {
                            source.Delete();
                        }
                        catch (Exception e)
                        {
                            Logger.ReportException("Error deleting log file {0}", e, source.Name);
                        }
                    }

                    config.LastFileCleanup = DateTime.UtcNow;
                    config.Save();
                });

                Async.Queue(Async.ThreadPoolName.ImageCacheCleanup, () => ImageCache.Instance.Clean(DateTime.UtcNow.AddDays(-(Instance.CommonConfigData.CacheFileRetentionDays))));
            }

            return(kernel);
        }
 private void SaveConfig()
 {
     commonConfig.Save();
 }