Esempio n. 1
0
        /// <summary>
        /// Saves the service app, updating the existing record, if found, or creating a new record.
        /// </summary>
        /// <param name="app">The service app.</param>
        /// <returns>The entropy value for the service app.</returns>
        public string SaveServiceApp(Models.ServiceApp app)
        {
            ServiceApplication appEntity = this.GetServiceApplication(app);

            bool created = false;

            if (appEntity == null)
            {
                appEntity = new ServiceApplication();
                appEntity.CreatedByUserId = Environment.UserName;
                appEntity.CreatedDate     = DateTime.Now;
                this.Insert(appEntity);
                created = true;
            }

            // history is created before update
            this.CreateHistory(appEntity);

            appEntity.Name                    = app.Name;
            appEntity.Active                  = true;
            appEntity.CronSchedule            = app.Schedule;
            appEntity.Description             = app.Description;
            appEntity.Environment             = app.Environment;
            appEntity.ModifiedByUserId        = Environment.UserName;
            appEntity.ModifiedDate            = DateTime.Now;
            appEntity.AppFilePath             = app.AppFilePath;
            appEntity.SendSuccessNotification = app.SendSuccessNotification;
            appEntity.EntropyValue2           = app.EntropyValue2 ?? appEntity.EntropyValue2; // update entropy value only if it exists on the model

            AuditType appAuditType = created ? AuditType.Create : AuditType.Update;

            appEntity.ServiceApplicationAudits.Add(new ServiceApplicationAudit
            {
                AuditType       = appAuditType,
                CreatedByUserId = Environment.UserName,
                CreatedDate     = DateTime.Now,
                Message         = app.LastMessage
            });

            SubmitChanges();

            // update the model with the last run date. TODO: should this be here?
            var lastRun = GetLastRunDate(app.Name);

            app.LastRun = lastRun.Item1;

            return(appEntity.EntropyValue2);
        }
Esempio n. 2
0
 /// <summary>
 /// Gets the service application.
 /// </summary>
 /// <param name="app">The service app model.</param>
 /// <returns></returns>
 private ServiceApplication GetServiceApplication(Models.ServiceApp app)
 {
     return(this.GetServiceApplication(app.Name));
 }