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)); } }
private void _backgroundConfigAddCompleted(object sender, RunWorkerCompletedEventArgs e) { _frmMsg.Close(); _frmMsg = null; this.BringToFront(); var req = new AddNewInstall(); req.PlatformId = _installInfo.PlatformId; req.Type = SoftwareUpdateType.Config; req.VersionNumber = _installInfo.VersionNumber; req.Description = _installInfo.Description; req.Date = DateTime.Now; req.SourcePath = Path.GetFileName(textConfigFile.Text); SendRequest(req); }
private void _backgroundVersionAddStart(object sender, DoWorkEventArgs e) { var worker = (BackgroundWorker)sender; worker.ReportProgress(1); var installName = Path.GetFileName(_imagePath); var dstPath = Path.Combine(OscarServerAdmin.InstallsTempPath, installName); Directory.CreateDirectory(dstPath); foreach (var file in Directory.GetFiles(_imagePath, "*.*", SearchOption.TopDirectoryOnly)) { File.Copy(file, Path.Combine(dstPath, Path.GetFileName(file)), true); } worker.ReportProgress(2); _commEvent = new EventWaitHandle(false, EventResetMode.AutoReset); var req = new AddNewInstall(); req.SourcePath = installName; req.PlatformId = BplIdentity.Get(textPlatformID.Text); req.ClientId = BplIdentity.Get(Environment.MachineName); req.Type = SoftwareUpdateType.Image; req.CodeName = textCodeName.Text; OscarServerAdmin.Admin.Services.Invoke(req, _onRequestSuccess, _onRequestFail); _commEvent.WaitOne(); }