Esempio n. 1
0
        public void Execute(LiteDataContext context)
        {
            //Default existing users to admins
            var usersRepository = context.GetRepository <User>();
            var users           = usersRepository.GetAll().ToList();

            users.ForEach(u => u.AccessLevel = AccessLevel.Administrator);
            usersRepository.Update(users);
        }
Esempio n. 2
0
        public void Execute(LiteDataContext context)
        {
            //set the default sort indexes.
            var machineRepository = context.GetRepository <Machine>();
            var machines          = machineRepository.GetAll();

            for (int i = 0; i < machines.Count; i++)
            {
                machines[i].SortIndex = i;
            }
            machineRepository.Update(machines);
        }
Esempio n. 3
0
        public void Execute(LiteDataContext context)
        {
            var db = context.Database;

            if (!db.CollectionExists(nameof(Machine)))
            {
                return;
            }

            var machines = db.GetCollection(nameof(Machine)).FindAll().ToList();

            foreach (var machine in machines)
            {
                //correct the profile property name to match UI
                if (machine["MachineType"].AsInt32 == (int)MachineType.Octoprint)
                {
                    machine["Profile"] = machine["ProfileName"];
                    machine.Remove("ProfileName");
                }
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Log.Info("Starting Overseer...");
            var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            using (var context = new LiteDataContext())
            {
                var exitSignal = ExitSignal.Create();
                exitSignal.Exit += (sender, eventArgs) =>
                {
                    Log.Info("Received Exit Signal...");
                    waitHandle.Set();
                };

                try
                {
                    var settings = context.GetApplicationSettings();
                    var parser   = new FluentCommandLineParser();
                    parser.Setup <int>("port").Callback(port => settings.LocalPort        = port);
                    parser.Setup <int>("interval").Callback(interval => settings.Interval = interval);
                    parser.Parse(args);

                    context.UpdateApplicationSettings(settings);
                    OverseerStartup.Start(context);
                }
                catch (Exception ex)
                {
                    Log.Error("Application Failure", ex);
                }

                waitHandle.WaitOne();

                Log.Info("Exiting Overseer");
                Environment.Exit(0);
            }
        }
Esempio n. 5
0
        public static bool Update()
        {
            if (!File.Exists(LiteDataContext.DatabasePath))
            {
                return(true);
            }
            var context    = new LiteDataContext();
            var valueStore = context.GetValueStore();

            //this will be the version of the last time the app was run.
            var lastRunVersion = Version.Parse(valueStore.Get <string>("lastRunVersion") ?? "0.0.0.0");
            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

            //only run if the last version was less than the current version
            if (lastRunVersion < currentVersion)
            {
                try
                {
                    //find all update implementations that are greater than the last run version
                    var patches = typeof(IPatch).GetAssignableTypes()
                                  .Select(updateType => (IPatch)Activator.CreateInstance(updateType))
                                  .Where(patch => patch.Version > lastRunVersion)
                                  .OrderBy(patch => patch.Version)
                                  .ToList();

                    if (patches.Any())
                    {
                        Log.Info($"{patches.Count} patches found...");

                        //create a copy of the database before attempting the patching
                        File.Copy(LiteDataContext.DatabasePath, LiteDataContext.DatabaseBackupPath);

                        patches.ForEach(patch =>
                        {
                            Log.Info($"Applying Patch {patch.Version}...");
                            patch.Execute(context);
                        });

                        File.Delete(LiteDataContext.DatabaseBackupPath);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("The update process failed to complete. Please create an issue with the following error details", ex);

                    //dispose of the context to release the database file
                    context.Dispose();
                    //delete the working copy of the database
                    File.Delete(LiteDataContext.DatabasePath);
                    //restore the backup
                    File.Move(LiteDataContext.DatabaseBackupPath, LiteDataContext.DatabasePath);

                    return(false);
                }

                valueStore.Put("lastRunVersion", currentVersion.ToString());
                context.Dispose();
                Log.Info("Update Successful!");
            }

            return(true);
        }
Esempio n. 6
0
        public void Execute(LiteDataContext context)
        {
            var db = context.Database;

            //libsodium-net was dropped in favor of bcrypt.net because bcrypt is implemented with
            //managed code. This was primarily done to simplify the initial installation. However,
            //this means that any passwords that have been generated are no longer compatible.
            if (db.CollectionExists(nameof(User)))
            {
                db.DropCollection(nameof(User));
            }

            //rename the certificate exception collection, the certificate exception was just
            //a wrapper for the certificate detail, it was initially created in case there was additional
            //info that needed to be save that was best not sent to the client. There was not any additional data
            //so it was removed.
            if (db.CollectionExists("CertificateException"))
            {
                db.RenameCollection("CertificateException", nameof(CertificateDetails));
            }

            //The application settings are now stored in the values store
            //There was also some property renames and the RequiresAuthentication property was removed
            //since anonymous access is no longer supported.
            if (db.CollectionExists("ApplicationSettings"))
            {
                var settings = db.GetCollection(nameof(ApplicationSettings)).FindById(1);
                if (settings != null)
                {
                    var newSettings = new ApplicationSettings
                    {
                        HideDisabledMachines = settings["HideDisabledPrinters"].AsBoolean,
                        HideIdleMachines     = settings["HideIdlePrinters"].AsBoolean,
                        Interval             = settings["Interval"].AsInt32 > 0 ?
                                               settings["Interval"].AsInt32 :
                                               ApplicationSettings.DefaultInterval,
                        LocalPort = settings["LocalPort"].AsInt32 > 0 ?
                                    settings["LocalPort"].AsInt32 :
                                    ApplicationSettings.DefaultPort,
                    };

                    context.GetValueStore().Put(newSettings);
                    db.DropCollection(nameof(ApplicationSettings));
                }
            }

            //check if there is a printer collection
            if (db.CollectionExists("Printer"))
            {
                var printerCollection = db.GetCollection("Printer");
                var machineRepository = context.GetRepository <Machine>();
                var printers          = printerCollection.FindAll().ToList();

                foreach (var printer in printers)
                {
                    //this will only pull the data required to load the configuration from the machine
                    var printerType = printer["PrinterType"].AsString;
                    var config      = printer["Config"].AsDocument;

                    switch (printerType)
                    {
                    case "Octoprint":
                        var oMachine = new OctoprintMachine
                        {
                            Id                = printer["Id"].AsInt32,
                            Name              = printer["Name"].AsString,
                            Disabled          = printer["Disabled"].AsBoolean,
                            ApiKey            = config["ApiKey"].AsString,
                            Url               = config["Url"].AsString,
                            WebCamUrl         = config["WebCamUrl"].AsString,
                            SnapshotUrl       = config["SnapshotUrl"].AsString,
                            ClientCertificate = config["ClientCertificate"].AsString
                        };

                        var oProvider = new OctoprintMachineProvider(oMachine);
                        oProvider.LoadConfiguration(oMachine).Wait();
                        machineRepository.Create(oMachine);
                        break;

                    case "RepRap":
                        var rMachine = new RepRapFirmwareMachine
                        {
                            Id                = printer["Id"].AsInt32,
                            Name              = printer["Name"].AsString,
                            Disabled          = printer["Disabled"].AsBoolean,
                            Url               = config["Url"].AsString,
                            WebCamUrl         = config["WebCamUrl"].AsString,
                            SnapshotUrl       = config["SnapshotUrl"].AsString,
                            ClientCertificate = config["ClientCertificate"].AsString
                        };

                        var rProvider = new RepRapFirmwareMachineProvider(rMachine);
                        rProvider.LoadConfiguration(rMachine).Wait();
                        machineRepository.Create(rMachine);
                        break;
                    }
                }

                db.DropCollection("Printer");
            }
        }