Esempio n. 1
0
      internal static SwlResult InstallAddNewConfig(DbConnector dbConn, InstallInfo installInfo, string sourcePath) {
         sourcePath = Path.Combine(LogisticsHelpers.PathTemp, sourcePath);
         if (!File.Exists(sourcePath)) {
            Log.Error("Config file {0} not exists", sourcePath);
            return SwlResult.INVALID_PARAMETER;
         }

         var pi = dbConn.ExecuteBpl(new PlatformGetById(installInfo.PlatformId));
         if (pi == null) {
            Log.Error("Platform with Id {0} not found in database", installInfo.PlatformId);
            return SwlResult.INVALID_PLATFORM;
         }

         var ii = dbConn.ExecuteBpl(new InstallGetByPlatformIdTypeVersionNumber(pi.PlatformId, Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Config, installInfo.VersionNumber));
         if (ii != null) {
            return SwlResult.ALREADY_EXISTS;
         }

         var version = SwlVersion.FromInt32(installInfo.VersionNumber);

         ii = new InstallInfo();

         ii.InstallId = BplIdentity.Get(string.Format("PLID{0}-CID{1:000}{2:000}{3:00000}",
            pi.PlatformId.LocalId.ToString(),
            version.Major, version.Minor, version.Release));
         ii.Type = Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Config;
         ii.PlatformId = installInfo.PlatformId;
         ii.VersionNumber = installInfo.VersionNumber;
         ii.Description = installInfo.Description;
         ii.Date = installInfo.Date;
         ii.Status = InstallStatus.Ready;

         dbConn.ExecuteBpl(new InstallAdd(ii));

         var pki = new PackageInfo();

         pki.PackageId = BplIdentity.Get(string.Format("PLID{0}-T{1:000}{2:000}{3:00000}-FXXX-XXX-XXXXX",
            ii.PlatformId.LocalId.ToString(),
            version.Major, version.Minor, version.Release));

         pki.PackageName = pki.PackageId.LocalId.ToString() + ".pkg";

         var packagePath = Path.Combine(StorageManager.ConfigsPath, pki.PackageName);
         File.Move(sourcePath, packagePath);

         pki.PackageCRC = ComputeCRC(packagePath);
         pki.PackageSize = (int)(new FileInfo(packagePath).Length);
         pki.TargetInstallId = ii.InstallId;
         pki.SourceInstallId = BplIdentity.Empty;

         dbConn.ExecuteBpl(new PackageAdd(pki));

         return SwlResult.OK;
      }
Esempio n. 2
0
      internal static SwlResult InstallCreatePackages(DbConnector dbConn, BplIdentity installId) {
         var installInfo = dbConn.ExecuteBpl(new InstallGetById(installId));
         if (installInfo == null) {
            return SwlResult.NOT_FOUND;
         }

         if (installInfo.Status != InstallStatus.Ready) {
            return SwlResult.NOT_READY;
         }

         installInfo.Status = InstallStatus.Busy;
         dbConn.ExecuteBpl(new InstallSetStatus(installInfo));

         var packages = dbConn.ExecuteBpl(new PackageGetByTargetInstallId { TargetInstallId = installInfo.InstallId });
         foreach (var pkg in packages) {
            PackageDelete(dbConn, pkg, installInfo.Type);
         }

         var platformInstalls = dbConn.ExecuteBpl(new InstallGetByPlatformId(installInfo.PlatformId));
         foreach (var inst in platformInstalls) {
            var currentVersion = SwlVersion.FromInt32(installInfo.VersionNumber);
            var sourceVersion = SwlVersion.FromInt32(inst.VersionNumber);

            if (SwlVersion.Compare(sourceVersion, currentVersion) >= 0) {
               continue;
            }

            var sourceDescriptor = dbConn.ExecuteBpl(new InstallGetRuntimeDescriptor(inst.InstallId));
            if ((sourceDescriptor == null) || (sourceDescriptor.Length == 0)) {
               continue;
            }

            var pkgInfo = new PackageInfo();

            pkgInfo.PackageId = BplIdentity.Get(string.Format("PLID{0}-T{1:000}{2:000}{3:00000}-F{4:000}{5:000}{6:00000}",
               installInfo.PlatformId.LocalId.ToString(),
               currentVersion.Major, currentVersion.Minor, currentVersion.Release,
               sourceVersion.Major, sourceVersion.Minor, sourceVersion.Release));

            pkgInfo.PackageName = pkgInfo.PackageId.LocalId.ToString() + ".pkg";

            var packagePath = Path.Combine(StorageManager.PackagesPath, pkgInfo.PackageName);

            if (!Interop.CreatePackage(_getInstallMasterPackageFileName(installInfo), sourceVersion, sourceDescriptor, packagePath)) {
               continue;
            }

            pkgInfo.PackageCRC = ComputeCRC(packagePath);
            pkgInfo.PackageSize = (int)(new FileInfo(packagePath).Length);
            pkgInfo.TargetInstallId = installInfo.InstallId;
            pkgInfo.SourceInstallId = inst.InstallId;

            dbConn.ExecuteBpl(new PackageAdd(pkgInfo));
         }

         installInfo.Status = InstallStatus.Ready;
         dbConn.ExecuteBpl(new InstallSetStatus(installInfo));

         return SwlResult.OK;
      }
Esempio n. 3
0
      internal static void PackageDelete(DbConnector dbConn, PackageInfo packageInfo, Mpcr.Services.Oscar.Logistics.SoftwareUpdateType type) {
         dbConn.ExecuteBpl(new PackageDeleteById(packageInfo.PackageId));

         var typeDirectory = "";

         switch (type) {
            case Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Image:
               typeDirectory = StorageManager.PackagesPath;
               break;

            case Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Config:
               typeDirectory = StorageManager.ConfigsPath;
               break;

            default:
               return;
         }

         var packagePath = Path.Combine(typeDirectory, packageInfo.PackageName);

         if (File.Exists(packagePath)) {
            File.Delete(packagePath);
         }
      }