public void Load(IBootContext b)
        {
            if (b.WaitService(_data))
            {
                return;
            }

            _service.Register(_get());
        }
Example #2
0
        public void Load(IBootContext bootstrapper)
        {
            if (bootstrapper.WaitService(Data))
            {
                return;
            }

            string oldVersion = "";

            while (true)
            {
                DataVersion version = null;
                try
                {
                    version = Data.FetchOne <DataVersion>(d => d.Module == CurrentModule);
                }
                catch (DataException exception)
                {
                    if (exception.InnerException is PostgresException postgres)
                    {
                        if (postgres.SqlState == "42P01" && postgres.MessageText.Contains("DataVersion"))
                        {
                            CreateDataVersion();
                            version = Data.FetchOne <DataVersion>(d => d.Module == CurrentModule);
                        }
                    }
                }

                if (version == null)
                {
                    version = Data.Add <DataVersion>(v =>
                    {
                        v.Module  = CurrentModule;
                        v.Version = "0.0.0.0";
                    });
                }

                if (version.Version == oldVersion)
                {
                    throw new DataException($"Wrong database version {version.Version} but need {CurrentVersion}", null);
                }

                if (version.Version == CurrentVersion)
                {
#if DEBUG
                    try
                    {
                        Upgrade(version.Version);
                    }
                    catch (Exception ex)
                    {
                    }
                    #endif
                    return;
                }

                oldVersion = version.Version;

                Upgrade(version.Version);
            }
        }