Example #1
0
      private void _onRequestSuccess(SwlResponse resp) {
         _swlr = resp.swlr;

         if (_commEvent != null) {
            _commEvent.Set();
         }
      }
      internal void Handle(RebuildInstallPackages request) {
         var resp = new SwlResponse();
         resp.swlr = SwlResult.GENERAL_FAIL;

         using (var dbConn = DatabaseManager.DbConn()) {
            var ii = dbConn.ExecuteBpl(new InstallGetById(request.InstallId));
            if (ii == null) {
               resp.swlr = SwlResult.NOT_FOUND;
               Reply(resp);
               return;
            }

            if (ii.Status != InstallStatus.Ready) {
               resp.swlr = SwlResult.NOT_READY;
               Reply(resp);
               return;
            }

            var pi = dbConn.ExecuteBpl(new PlatformGetById(ii.PlatformId));
            if (pi == null) {
               resp.swlr = SwlResult.INVALID_PLATFORM;
               Reply(resp);
               return;
            }

            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(pi.PlatformId, PlatformLockType.ByClient, request.ClientId));

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

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

            Log.Trace("Install Id: {0} ==> Build packages started", ii.InstallId);
            var swlr = LogisticsHelpers.InstallCreatePackages(dbConn, ii.InstallId);
            if (swlr == SwlResult.OK) {
               Log.Trace("Install Id: {0} ==> Build packages finished successfully", ii.InstallId);
            } else {
               Log.Error("Install Id: {0} ==> Build packages finished with error {1}", ii.InstallId, swlr);
            }

            dbConn.ExecuteBpl(new PlatformSetLock(pi.PlatformId, PlatformLockType.NoLock, BplIdentity.Empty));
         }
      }
      internal void Handle(SetInstallRuntimeDescriptor request) {
         var resp = new SwlResponse();
         resp.swlr = SwlResult.GENERAL_FAIL;

         using (var dbConn = DatabaseManager.DbConn()) {
            var ii = dbConn.ExecuteBpl(new InstallGetByPlatformIdTypeVersionNumber(request.PlatformId, SoftwareUpdateType.Image, request.VersionNumber));
            if (ii == null) {
               Log.Error("Install with Id {0} not found in the database", request.PlatformId);
               resp.swlr = SwlResult.NOT_FOUND;
               Reply(resp);
               return;
            }

            var descriptor = Encoding.ASCII.GetString(request.Descriptor);
            dbConn.ExecuteBpl(new InstallSetRuntimeDescriptor(ii.InstallId, descriptor));
         }

         resp.swlr = SwlResult.OK;
         Reply(resp);
      }
Example #4
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));
         }
      }