示例#1
0
        /// <summary>
        /// would this patch file apply to the current installed version
        /// </summary>
        /// <param name="APatchZipFile"></param>
        /// <param name="AMaxVersion">maximum version to upgrade to, usually this is the version of the exe files</param>
        /// <returns></returns>
        public Boolean PatchApplies(String APatchZipFile, TFileVersionInfo AMaxVersion)
        {
            try
            {
                StringCollection versions = GetVersionsFromDiffZipName(APatchZipFile);
                TFileVersionInfo patchStartVersion = new TFileVersionInfo(versions[0]);
                TFileVersionInfo patchEndVersion = new TFileVersionInfo(versions[1]);

                return patchStartVersion.Compare(this) == 0 && patchEndVersion.Compare(AMaxVersion) <= 0;
            }
            catch (Exception)
            {
                return false;
            }
        }
示例#2
0
        /// <summary>
        /// would this patch file apply to the current installed version
        /// </summary>
        /// <param name="APatchZipFile"></param>
        /// <returns></returns>
        public Boolean PatchApplies(String APatchZipFile)
        {
            StringCollection versions = GetVersionsFromDiffZipName(APatchZipFile);
            TFileVersionInfo patchStartVersion = new TFileVersionInfo(versions[0]);

            return patchStartVersion.Compare(this) == 0;
        }
示例#3
0
        /// <summary>
        /// For standalone installations, we update the SQLite database on the fly.
        /// </summary>
        public void UpdateDatabase(TFileVersionInfo ADBVersion, TFileVersionInfo AExeVersion,
            string AHostOrFile, string ADatabasePort, string ADatabaseName, string AUsername, string APassword)
        {
            // we do not support updating standalone databases at the moment
            if (AExeVersion.FileMajorPart == 0)
            {
                DBAccess.GDBAccessObj.CloseDBConnection();

                throw new EDBUnsupportedDBUpgradeException(String.Format(Catalog.GetString(
                            "Unsupported upgrade: Please rename the file {0} so that we can start with a fresh database!   " +
                            "Please restart the OpenPetra Client after that."),
                        AHostOrFile));
            }

            string dbpatchfilePath = Path.GetDirectoryName(TAppSettingsManager.GetValue("Server.SQLiteBaseFile"));

            ADBVersion.FilePrivatePart = 0;
            AExeVersion.FilePrivatePart = 0;

            using (TDBTransaction transaction = DBAccess.GDBAccessObj.BeginTransaction())
            {
                try
                {
                    // run all available patches. for each release there could be a patch file
                    string[] sqlFiles = Directory.GetFiles(dbpatchfilePath, "*.sql");

                    bool foundUpdate = true;

                    // run through all sql files until we have no matching update files anymore
                    while (foundUpdate)
                    {
                        foundUpdate = false;

                        foreach (string sqlFile in sqlFiles)
                        {
                            if (!sqlFile.EndsWith("pg.sql") && (new TPatchFileVersionInfo(ADBVersion)).PatchApplies(sqlFile, AExeVersion))
                            {
                                foundUpdate = true;
                                StreamReader sr = new StreamReader(sqlFile);

                                while (!sr.EndOfStream)
                                {
                                    string line = sr.ReadLine().Trim();

                                    if (!line.StartsWith("--"))
                                    {
                                        DBAccess.GDBAccessObj.ExecuteNonQuery(line, transaction);
                                    }
                                }

                                sr.Close();
                                ADBVersion = TPatchFileVersionInfo.GetLatestPatchVersionFromDiffZipName(sqlFile);
                            }
                        }
                    }

                    if (ADBVersion.Compare(AExeVersion) == 0)
                    {
                        // if patches have been applied successfully, update the database version
                        string newVersionSql =
                            String.Format("UPDATE s_system_defaults SET s_default_value_c = '{0}' WHERE s_default_code_c = 'CurrentDatabaseVersion';",
                                AExeVersion.ToStringDotsHyphen());

                        DBAccess.GDBAccessObj.ExecuteNonQuery(newVersionSql, transaction);

                        DBAccess.GDBAccessObj.CommitTransaction();
                    }
                    else
                    {
                        DBAccess.GDBAccessObj.RollbackTransaction();

                        throw new Exception(String.Format(Catalog.GetString(
                                    "Cannot connect to old database (version {0}), there are some missing sql patch files"),
                                ADBVersion));
                    }
                }
                catch (Exception)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();

                    throw;
                }
            }
        }
示例#4
0
        private void ImportJob(TFileVersionInfo APetraVersion, TDBTransaction ATransaction)
        {
            Boolean ImportJobAssignment = true;
            PmJobAssignmentRow JobAssignmentRow = FMainDS.PmJobAssignment.NewRowTyped();

            JobAssignmentRow.PartnerKey = FPartnerKey;
            JobAssignmentRow.FromDate = ReadDate();
            JobAssignmentRow.ToDate = ReadNullableDate();
            JobAssignmentRow.PositionName = ReadString();
            JobAssignmentRow.PositionScope = ReadString();
            JobAssignmentRow.AssistantTo = ReadBoolean();

            ReadInt64(); // JobAssignmentRow.JobKey: not to be imported
            ReadInt64(); // JobAssignmentRow.JobAssignmentKey: not to be imported

            JobAssignmentRow.UnitKey = ReadInt64();

            // do not import job record if unit does not exist
            if (!PUnitAccess.Exists(JobAssignmentRow.UnitKey, ATransaction))
            {
                AddVerificationResult(
                    "Error - Job Assignment Unit Key " + JobAssignmentRow.UnitKey.ToString("0000000000") + " for Partner " +
                    FPartnerKey.ToString("0000000000") +
                    " does not exist in database. Job Assignment Record will not be imported.");
                ImportJobAssignment = false;
            }

            JobAssignmentRow.AssignmentTypeCode = CheckJobAssignmentTypeCode(ReadString(), ATransaction);

            if (APetraVersion.Compare(new TFileVersionInfo("3.0.0")) < 0)
            {
                ReadString();       // used to be JobAssignmentRow.LeavingCode
                ReadNullableDate(); // used to be JobAssignmentRow.LeavingCodeUpdatedDate
            }

            if (!FIgnorePartner
                && ImportJobAssignment)
            {
                // find job assignment (ignoring job key and job assignment key)
                PmJobAssignmentRow TmpJobAssignmentRow = FMainDS.PmJobAssignment.NewRowTyped(false);
                TmpJobAssignmentRow.PartnerKey = FPartnerKey;
                TmpJobAssignmentRow.UnitKey = JobAssignmentRow.UnitKey;
                TmpJobAssignmentRow.PositionName = JobAssignmentRow.PositionName;
                TmpJobAssignmentRow.PositionScope = JobAssignmentRow.PositionScope;

                PmJobAssignmentTable ExistingJobAssignmentTable = PmJobAssignmentAccess.LoadUsingTemplate(TmpJobAssignmentRow, null, ATransaction);

                if (ExistingJobAssignmentTable.Count == 0)
                {
                    // if job assignment does not exist: find job
                    UmJobRow TmpJobRow = FMainDS.UmJob.NewRowTyped(false);
                    TmpJobRow.UnitKey = JobAssignmentRow.UnitKey;
                    TmpJobRow.PositionName = JobAssignmentRow.PositionName;
                    TmpJobRow.PositionScope = JobAssignmentRow.PositionScope;

                    UmJobTable ExistingJobTable = UmJobAccess.LoadUsingTemplate(TmpJobRow, null, ATransaction);

                    if (ExistingJobTable.Count == 0)
                    {
                        // if job does not exist: create job with default values
                        UmJobRow JobRow = FMainDS.UmJob.NewRowTyped(true);
                        JobRow.UnitKey = TmpJobRow.UnitKey;
                        JobRow.PositionName = TmpJobRow.PositionName;
                        JobRow.PositionScope = TmpJobRow.PositionScope;
                        JobRow.JobKey = (Int32)MCommon.WebConnectors.TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_job);
                        JobRow.JobType = "Long Term";
                        JobRow.FromDate = JobAssignmentRow.FromDate;
                        JobRow.ToDate = JobAssignmentRow.ToDate;
                        JobRow.CommitmentPeriod = "None";
                        JobRow.TrainingPeriod = "None";
                        JobRow.Present = 1;

                        UmJobAccess.AddOrModifyRecord(JobRow.UnitKey,
                            JobRow.PositionName,
                            JobRow.PositionScope,
                            JobRow.JobKey,
                            FMainDS.UmJob,
                            JobRow,
                            FDoNotOverwrite,
                            ATransaction);

                        JobAssignmentRow.JobKey = JobRow.JobKey;
                    }
                    else
                    {
                        JobAssignmentRow.JobKey = ((UmJobRow)ExistingJobTable.Rows[0]).JobKey;
                    }

                    JobAssignmentRow.JobAssignmentKey = (Int32)MCommon.WebConnectors.TSequenceWebConnector.GetNextSequence(
                        TSequenceNames.seq_job_assignment);
                }
                else
                {
                    // job assignment already exists: update record in database
                    JobAssignmentRow.JobKey = ((PmJobAssignmentRow)ExistingJobAssignmentTable.Rows[0]).JobKey;
                    JobAssignmentRow.JobAssignmentKey = ((PmJobAssignmentRow)ExistingJobAssignmentTable.Rows[0]).JobAssignmentKey;
                }

                // now add or modify job assignment record
                PmJobAssignmentAccess.AddOrModifyRecord(JobAssignmentRow.PartnerKey,
                    JobAssignmentRow.UnitKey,
                    JobAssignmentRow.PositionName,
                    JobAssignmentRow.PositionScope,
                    JobAssignmentRow.JobKey,
                    JobAssignmentRow.JobAssignmentKey,
                    FMainDS.PmJobAssignment,
                    JobAssignmentRow,
                    FDoNotOverwrite,
                    ATransaction);
            }
        }
示例#5
0
        private void ImportPassport(TFileVersionInfo APetraVersion, TDBTransaction ATransaction)
        {
            PmPassportDetailsRow PassportDetailsRow = FMainDS.PmPassportDetails.NewRowTyped();

            PassportDetailsRow.PartnerKey = FPartnerKey;

            PassportDetailsRow.PassportNumber = ReadString();

            if (APetraVersion.Compare(new TFileVersionInfo("2.3.3")) >= 0)
            {
                PassportDetailsRow.MainPassport = ReadBoolean();
            }

            PassportDetailsRow.CountryOfIssue = CheckCountryCode(ReadString(), ATransaction);
            PassportDetailsRow.DateOfExpiration = ReadNullableDate();
            PassportDetailsRow.DateOfIssue = ReadNullableDate();
            PassportDetailsRow.FullPassportName = ReadString();
            PassportDetailsRow.PassportNationalityCode = ReadString();
            PassportDetailsRow.PassportDetailsType = ReadString();
            PassportDetailsRow.PassportDob = ReadNullableDate();
            PassportDetailsRow.PlaceOfBirth = ReadString();
            PassportDetailsRow.PlaceOfIssue = ReadString();

            if (!FIgnorePartner)
            {
                PmPassportDetailsAccess.AddOrModifyRecord(PassportDetailsRow.PartnerKey,
                    PassportDetailsRow.PassportNumber,
                    FMainDS.PmPassportDetails,
                    PassportDetailsRow,
                    FDoNotOverwrite,
                    ATransaction);
            }
        }
示例#6
0
        private void ImportPreviousExperience(TFileVersionInfo APetraVersion, TDBTransaction ATransaction)
        {
            PmPastExperienceRow PastExperienceRow = FMainDS.PmPastExperience.NewRowTyped();

            PastExperienceRow.PartnerKey = FPartnerKey;

            PastExperienceRow.SiteKey = ReadInt64();
            PastExperienceRow.Key = ReadInt64();
            PastExperienceRow.PrevLocation = ReadString();
            PastExperienceRow.StartDate = ReadNullableDate();
            PastExperienceRow.EndDate = ReadNullableDate();
            PastExperienceRow.PrevWorkHere = ReadBoolean();
            PastExperienceRow.PrevWork = ReadBoolean();
            PastExperienceRow.OtherOrganisation = ReadString();
            PastExperienceRow.PrevRole = ReadString();

            if (APetraVersion.Compare(new TFileVersionInfo("2.3.3")) >= 0)
            {
                PastExperienceRow.Category = ReadString();
            }

            PastExperienceRow.PastExpComments = ReadString();

            if (!FIgnorePartner)
            {
                PmPastExperienceAccess.AddOrModifyRecord(PastExperienceRow.SiteKey,
                    PastExperienceRow.Key,
                    FMainDS.PmPastExperience,
                    PastExperienceRow,
                    FDoNotOverwrite,
                    ATransaction);
            }
        }
示例#7
0
        /// <summary>
        /// would this patch file apply to the current installed version
        /// </summary>
        static public Boolean PatchApplies(TFileVersionInfo ACurrentVersion, string APatchZipFile)
        {
            StringCollection versions = GetVersionsFromDiffZipName(APatchZipFile);
            TFileVersionInfo patchStartVersion = new TFileVersionInfo(versions[0]);

            // generic patch
            if (patchStartVersion.FilePrivatePart == 0)
            {
                TFileVersionInfo patchEndVersion = new TFileVersionInfo(versions[1]);
                return patchEndVersion.Compare(ACurrentVersion) > 0;
            }

            return patchStartVersion.Compare(ACurrentVersion) == 0;
        }