Esempio n. 1
0
      private void _listImagesOnSelectedIndexChanged(object sender, EventArgs e) {
         if (listImages.SelectedItems.Count == 0) {
            return;
         }

         var installItem = (InstallListItem)listImages.SelectedItems[0];
         _selectedInstall = installItem.Install;
      }
Esempio n. 2
0
         public InstallListItem(InstallInfo install) {
            _install = install;

            var v = SwlVersion.FromInt32(_install.VersionNumber);
            Text = string.Format("{0:000}.{1:000}.{2:00000}", v.Major, v.Minor, v.Release);

            SubItems.Add(string.Format("{0:0000}-{1:00}-{2:00} {3:00}:{4:00}", _install.Date.Year, _install.Date.Month, _install.Date.Day, _install.Date.Hour, _install.Date.Minute));
            SubItems.Add(_install.Description);
         }
Esempio n. 3
0
 private static string _getInstallMasterPackageFileName(InstallInfo installInfo) {
    return Path.Combine(InstallGetStoragePath(installInfo), InstallMasterPackageFileName);
 }
Esempio n. 4
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. 5
0
      internal static SwlResult InstallAddNewImage(DbConnector dbConn, BplIdentity requestPlatformId, string requestCodeName, string sourcePath) {
         sourcePath = Path.Combine(LogisticsHelpers.PathTemp, sourcePath);

         var tempImageFile = Path.Combine(sourcePath, InstallImageFileName);
         var tempMasterPackageFile = Path.Combine(sourcePath, InstallMasterPackageFileName);

         var imageHdr = Interop.GetImageHeader(tempImageFile);
         if (imageHdr == null) {
            Log.Error("Bad image file {0}", tempImageFile);
            return SwlResult.INVALID_DATA;
         }

         var platformId = BplIdentity.Get(string.Format("{0:X08}", imageHdr.Value.PlatformId));
         if (platformId != requestPlatformId) {
            Log.Error("Platform id ({0}) in request is not equal image file platform id ({1})", requestPlatformId, platformId);
            return SwlResult.INVALID_PLATFORM;
         }

         var pi = dbConn.ExecuteBpl(new PlatformGetById(platformId));
         if (pi == null) {
            pi = new PlatformInfo();
            pi.PlatformId = platformId;
            pi.PlatformUId = (int)imageHdr.Value.PlatformId;
            pi.PlatformName = imageHdr.Value.PlatformName;
            pi.PlatformVersion = imageHdr.Value.PlatformVersion.ToInt32();

            dbConn.ExecuteBpl(new PlatformAdd(pi));

            dbConn.ExecuteBpl(new PlatformSetLock(platformId, PlatformLockType.ByClient, BplIdentity.Empty));
         }

         var ii = dbConn.ExecuteBpl(new InstallGetByPlatformIdTypeVersionNumber(pi.PlatformId, Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Image, imageHdr.Value.Version.ToInt32()));
         if (ii != null) {
            return SwlResult.ALREADY_EXISTS;
         }

         ii = new InstallInfo();

         ii.InstallId = BplIdentity.Get(string.Format("PLID{0:X08}-IID{1:000}{2:000}{3:00000}",
            imageHdr.Value.PlatformId,
            imageHdr.Value.Version.Major, imageHdr.Value.Version.Minor, imageHdr.Value.Version.Release));
         ii.Type = Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Image;
         ii.PlatformId = platformId;
         ii.VersionNumber = imageHdr.Value.Version.ToInt32(); ;
         ii.Description = imageHdr.Value.Desc;
         ii.Date = imageHdr.Value.Date.ToDateTime();
         ii.Status = InstallStatus.Ready;
         ii.CodeName = requestCodeName;

         var installStoragePath = LogisticsHelpers.InstallGetStoragePath(ii);

         Directory.CreateDirectory(installStoragePath);
         File.Move(tempImageFile, Path.Combine(installStoragePath, LogisticsHelpers.InstallImageFileName));
         File.Move(tempMasterPackageFile, Path.Combine(installStoragePath, LogisticsHelpers.InstallMasterPackageFileName));
         Directory.Delete(sourcePath, true);

         dbConn.ExecuteBpl(new InstallAdd(ii));

         var swlr = LogisticsHelpers.InstallCreatePackages(dbConn, ii.InstallId);
         if (swlr != SwlResult.OK) {
            return swlr;
         }

         return SwlResult.OK;
      }
Esempio n. 6
0
 internal static string InstallGetStoragePath(InstallInfo installInfo) {
    return Path.Combine(PathInstalls, installInfo.InstallId.LocalId.ToString());
 }
Esempio n. 7
0
      internal void Handle(AddNewInstall request) {
         var resp = new SwlResponse();
         resp.swlr = SwlResult.GENERAL_FAIL;

         using (var dbConn = DatabaseManager.DbConn()) {
            var pi = dbConn.ExecuteBpl(new PlatformGetById(request.PlatformId));
            if (pi != null) {
               if (pi.Lock != PlatformLockType.NoLock) {
                  Log.Error("Platform with Id {0} locked {1}.", pi.PlatformId.LocalId.ToString(), pi.Lock.ToString());
                  resp.swlr = SwlResult.BUSY;
                  Reply(resp);
                  return;
               }

               dbConn.ExecuteBpl(new PlatformSetLock(request.PlatformId, PlatformLockType.ByClient, request.ClientId));

               Log.Trace("Platform with Id {0} successfully locked to add installation.", pi.PlatformId.LocalId.ToString());
            }

            switch (request.Type) {
               case SoftwareUpdateType.Image: {
                     resp.swlr = SwlResult.OK;
                     Reply(resp);
                     LogisticsHelpers.InstallAddNewImage(dbConn, request.PlatformId, request.CodeName, request.SourcePath);

                     break;
                  }

               case SoftwareUpdateType.Config: {
                     if (pi == null) {
                        Log.Error("Platform with Id {0} not found in database", request.PlatformId);
                        resp.swlr = SwlResult.INVALID_PLATFORM;
                        Reply(resp);
                        return;
                     }

                     resp.swlr = SwlResult.OK;
                     Reply(resp);

                     var ii = new InstallInfo();

                     ii.PlatformId = pi.PlatformId;
                     ii.Type = request.Type;
                     ii.VersionNumber = request.VersionNumber;
                     ii.Description = request.Description;
                     ii.Date = request.Date;

                     LogisticsHelpers.InstallAddNewConfig(dbConn, ii, request.SourcePath);

                     break;
                  }

               default: {
                     Log.Error("Unsupported update type {0}", request.Type);
                     resp.swlr = SwlResult.INVALID_PARAMETER;
                     Reply(resp);

                     break;
                  }
            }
           
            dbConn.ExecuteBpl(new PlatformSetLock(request.PlatformId, PlatformLockType.NoLock, BplIdentity.Empty));
         }
      }
Esempio n. 8
0
      private void _listVersionsOnSelectedIndexChanged(object sender, EventArgs e) {
         if (listVersions.SelectedItems.Count == 0) {
            return;
         }

         var installItem = (InstallListItem)listVersions.SelectedItems[0];
         _selectedInstall = installItem.Install;

         textSelectedVersion.Text = string.Format("{0}", _selectedInstall.InstallId.LocalId.ToString());
      }
Esempio n. 9
0
      private void _listInstallsRefresh(IEnumerable<InstallInfo> installs) {
         textSelectedVersion.Text = "";
         _selectedInstall = null;
         listVersions.Items.Clear();

         foreach (var inst in installs) {
            var li = new InstallListItem(inst);
            listVersions.Items.Add(li);
         }

         if (listVersions.Items.Count > 0) {
            listVersions.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
         }
      }