public override void Uninstall(DiscoDataContext context, bool uninstallData, ScheduledTaskStatus status) { if (uninstallData) { Internal.Helpers.UninstallData(context, Manifest, status); } }
private static JobDetailsModel LoadJobDetails(DiscoDataContext Database, string Reference, string DeviceSerialNumber) { int onlineWarrantyId = default(int); if (DeviceSerialNumber != null && !string.IsNullOrWhiteSpace(Reference) && int.TryParse(Reference, out onlineWarrantyId)) { JobDetailsModel model; // Try from Cache model = LoadJobDetailsFromCache(onlineWarrantyId, DeviceSerialNumber); if (model == null) { // Load from Web model = LoadJobDetailsFromWeb(onlineWarrantyId, DeviceSerialNumber); // Cache Response CacheJobDetails(model); } return(model); } else { return(EmptyJobDetails(onlineWarrantyId, DeviceSerialNumber)); } }
internal static JobDetailsModel LoadRepairJobDetails(DiscoDataContext Database, Job Job) { string reference = (Job.JobMetaNonWarranty != null) ? Job.JobMetaNonWarranty.RepairerReference : null; string deviceSerialNumber = Job.DeviceSerialNumber; return(LoadJobDetails(Database, reference, deviceSerialNumber)); }
public static bool ValidateEnvironment(DiscoDataContext Database, Controller controller, User TechUser) { // Validate Configuration var config = new ConfigurationStore(Database); if (string.IsNullOrWhiteSpace(config.CustomerEntityId)) { controller.ModelState.AddModelError(string.Empty, "LWT Customer Entity Id is Required (See LWT Plugin Configuration)"); } if (string.IsNullOrWhiteSpace(config.CustomerUsername)) { controller.ModelState.AddModelError(string.Empty, "LWT Customer Username is Required (See LWT Plugin Configuration)"); } // Validate TechUser Email Address if (string.IsNullOrEmpty(TechUser.EmailAddress)) { controller.ModelState.AddModelError(string.Empty, "LWT Requires a Technician Email Address (Update your Email Address in Active Directory)"); } if (string.IsNullOrEmpty(TechUser.PhoneNumber)) { controller.ModelState.AddModelError(string.Empty, "LWT Requires a Technician Phone Number (Update your Telephone Number in Active Directory)"); } return(controller.ModelState.IsValid); }
public override Dictionary <string, string> SubmitJobDiscloseInfo(DiscoDataContext dbContext, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription, Dictionary <string, string> WarrantyProviderProperties) { Dictionary <String, String> info = new Dictionary <string, string>(); // If the device is a part of the NTP then change contact details to them bool ntpDevice = bool.Parse(WarrantyProviderProperties["NTPDevice"]); if (ntpDevice == true) { // Victorian Teacher notebook info.Add("Contact Name", Job.User.DisplayName); info.Add("Contact Email", Job.User.EmailAddress); } else { // School owned devices info.Add("Contact Name", TechUser.DisplayName); info.Add("Contact Email", TechUser.EmailAddress); } info.Add("Contact Company", Address.Name); info.Add("Contact Address", Address.Address); info.Add("Contact Suburb", Address.Suburb); info.Add("Contact State", NNCompatibleContactState(Address.State)); info.Add("Contact Postcode", Address.Postcode); info.Add("Contact Phone", TechUser.PhoneNumber); info.Add("Device Serial Number", Job.DeviceSerialNumber); info.Add("Device Product Description", String.Format("{0} {1}", Job.Device.DeviceModel.Manufacturer, Job.Device.DeviceModel.Model)); info.Add("NTP Device", ntpDevice ? "Yes" : "No"); info.Add("Suspected Issue", NNSuspectedIssues[int.Parse(WarrantyProviderProperties["Issue"])]); return(info); }
public static Dictionary <string, string> DiscloseInformation(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser) { var config = new ConfigurationStore(Database); string serialNumberMessage; if (Job.Device.HasAlternateSerialNumber(out serialNumberMessage)) { serialNumberMessage += " [Acer SNID]"; } else { serialNumberMessage = Job.DeviceSerialNumber; } return(new Dictionary <string, string>() { { "LWT Customer Entity Id", config.CustomerEntityId }, { "LWT Customer Username", config.CustomerUsername }, { "Contact Name", TechUser.DisplayName }, { "Contact Company", Address.Name }, { "Contact Address", Address.Address }, { "Contact Suburb", Address.Suburb }, { "Contact Postcode", Address.Postcode }, { "Contact Phone", TechUser.PhoneNumber }, { "Contact Email", TechUser.EmailAddress }, { "Device Serial Number", serialNumberMessage }, { "Device Product Description", String.Format("{0} {1}", Job.Device.DeviceModel.Manufacturer, Job.Device.DeviceModel.Model) }, { "Device Room Location", String.Format("Customer Job Id: {0}", Job.Id) } }); }
public override PluginConfigurationHandlerGetResponse Get(DiscoDataContext database, Controller controller) { var store = new ConfigurationStore(database); var model = store.DeserializeConfiguration(); return(Response <Views.Configuration>(model)); }
public override void Uninstall(DiscoDataContext Database, bool UninstallData, ScheduledTaskStatus Status) { if (UninstallData) { Internal.Helpers.UninstallData(Database, this.Manifest, Status); } }
public override void Initialize(DiscoDataContext database) { RepositoryMonitor.StreamAfterCommit .Where(e => e.EntityType == typeof(Job) && e.ModifiedProperties.Contains("DeviceReadyForReturn")) .Subscribe(DeviceReadyForReturn); }
internal static void AfterSaveChanges(DiscoDataContext Database, IEnumerable<RepositoryMonitorEvent> changes) { foreach (var change in changes) { UpdateAfterEventFromEntryState(change); streamAfter.OnNext(change); } }
public static void UninstallData(DiscoDataContext database, PluginManifest manifest, ScheduledTaskStatus status) { status.UpdateStatus("Removing Plugin Configuration"); new ConfigurationStore(database) { EmailConfiguration = null }; database.SaveChanges(); }
private static string SubmitJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription) { // Send Job to LWT var config = new ConfigurationStore(Database); // Build Http Post Body var httpBody = new StringBuilder("Automated=1&"); httpBody.Append("EntityID=").Append(HttpUtility.UrlEncode(config.CustomerEntityId)); httpBody.Append("&txtUserName="******"&txtContactName=").Append(HttpUtility.UrlEncode(TechUser.DisplayName)); httpBody.Append("&txtContactCompany=").Append(HttpUtility.UrlEncode(Address.Name)); httpBody.Append("&txtContactAddress=").Append(HttpUtility.UrlEncode(Address.Address)); httpBody.Append("&txtContactSuburb=").Append(HttpUtility.UrlEncode(Address.Suburb)); httpBody.Append("&txtContactPostcode=").Append(HttpUtility.UrlEncode(Address.Postcode)); httpBody.Append("&txtContactPhone=").Append(HttpUtility.UrlEncode(TechUser.PhoneNumber)); httpBody.Append("&txtContactEmail=").Append(HttpUtility.UrlEncode(TechUser.EmailAddress)); httpBody.Append("&txtSerialNumber=").Append(HttpUtility.UrlEncode(Job.Device.ParseSerialNumber())); httpBody.Append("&txtProductDescription=").Append(HttpUtility.UrlEncode(String.Format("{0} {1}", Job.Device.DeviceModel.Manufacturer, Job.Device.DeviceModel.Model))); httpBody.Append("&txtRoomLocation=").Append(HttpUtility.UrlEncode("Customer Job Id: ")).Append(Job.Id); httpBody.Append("&txtFaultDescription=").Append(HttpUtility.UrlEncode(FaultDescription)); HttpWebRequest wreq = (HttpWebRequest)HttpWebRequest.Create("http://www.lwt.com.au/Warranty.asp"); wreq.KeepAlive = false; wreq.Method = WebRequestMethods.Http.Post; wreq.ContentType = "application/x-www-form-urlencoded"; using (StreamWriter sw = new StreamWriter(wreq.GetRequestStream())) sw.Write(httpBody.ToString()); using (HttpWebResponse wres = (HttpWebResponse)wreq.GetResponse()) { string stringResponse; using (Stream s = wres.GetResponseStream()) { using (StreamReader sr = new StreamReader(s)) { stringResponse = sr.ReadToEnd(); } } // If response is an Integer assume Job Reference Number, otherwise error. int jobReference; if (int.TryParse(stringResponse, out jobReference)) { return(jobReference.ToString()); } else { throw new WarrantyProviderSubmitJobException(stringResponse); } } }
public override void AfterUpdate(DiscoDataContext database, PluginManifest previousManifest) { var configStore = new ConfigurationStore(database); var currentConfig = configStore.DeserializeConfiguration(); while (currentConfig.CurrentVersion < CurrentVersion) { switch (currentConfig.CurrentVersion) { } } }
public override dynamic SubmitJobViewModel(DiscoDataContext dbContext, Controller controller, Job Job, OrganisationAddress Address, User TechUser) { SubmitJobValidateEnvironment(dbContext, controller, TechUser, Job, null); var model = new ViewModels.NNOptionsViewModel() { NTPDevice = null, Issue = 0 }; return(model); }
public static void UninstallData(DiscoDataContext Database, PluginManifest Manifest, ScheduledTaskStatus Status) { Status.UpdateStatus("Removing Configuration"); var config = new ConfigurationStore(Database); config.CustomerEntityId = null; config.CustomerUsername = null; Database.SaveChanges(); // Storage Location will be cleared by the framework if requested by the user }
public override bool Post(DiscoDataContext Database, FormCollection form, Controller controller) { var store = new ConfigurationStore(Database); var model = controller.ToConfigurationModel(); if (model == null) { return(false); } model.UpdateStore(store); return(true); }
public override bool Post(DiscoDataContext database, FormCollection form, Controller controller) { var store = new ConfigurationStore(database); var model = controller.ToConfigurationModel(); if (model == null) { return(false); } model.UpdateStore(store); Internal.Email.SendEmailMessage(UserService.CurrentUser); return(true); }
public override Dictionary <string, string> SubmitJobParseProperties(DiscoDataContext dbContext, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription) { ViewModels.NNOptionsViewModel model = new ViewModels.NNOptionsViewModel(); controller.TryUpdateModel(model); SubmitJobValidateEnvironment(dbContext, controller, TechUser, Job, model); return(new Dictionary <string, string>() { { "NTPDevice", model.NTPDevice.ToString() }, { "Issue", model.Issue.ToString() } }); }
public static string SubmitRepairJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription) { if (string.IsNullOrEmpty(RepairDescription)) { RepairDescription = "REPAIR REQUEST"; } else { RepairDescription = "REPAIR REQUEST" + Environment.NewLine + RepairDescription; } return(SubmitJob(Database, Job, Address, TechUser, RepairDescription)); }
private void SubmitJobValidateEnvironment(DiscoDataContext dbContext, Controller controller, User TechUser, Job Job, ViewModels.NNOptionsViewModel OptionsModel) { // Validate TechUser Email Address if (OptionsModel == null || (OptionsModel.NTPDevice.HasValue && !OptionsModel.NTPDevice.Value)) { // Non-NTP Device (or Unknown) // Check for Technicians Details if (string.IsNullOrEmpty(TechUser.EmailAddress)) { controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Email Address (Update your Email Address in Active Directory)"); } if (string.IsNullOrEmpty(TechUser.PhoneNumber)) { controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Phone Number (Update your Telephone Number in Active Directory)"); } } else { if (!NNSuspectedIssues.ContainsKey(OptionsModel.Issue)) { controller.ModelState.AddModelError("Issue", "Unknown Suspected Issue Id"); } if (OptionsModel.NTPDevice.HasValue && OptionsModel.NTPDevice.Value) { // NTP Device (Use Users Details) if (string.IsNullOrEmpty(Job.User.EmailAddress)) { controller.ModelState.AddModelError(string.Empty, "NN NTP Device requires the User's Email Address (Update the Email Address in Active Directory)"); } if (string.IsNullOrEmpty(Job.User.PhoneNumber)) { controller.ModelState.AddModelError(string.Empty, "NN NTP Device requires the User's Phone Number (Update the Phone Number in Active Directory)"); } } else { // Non-NTP Device (or Unknown) // Check for Technicians Details if (string.IsNullOrEmpty(TechUser.EmailAddress)) { controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Email Address (Update your Email Address in Active Directory)"); } if (string.IsNullOrEmpty(TechUser.PhoneNumber)) { controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Phone Number (Update your Telephone Number in Active Directory)"); } } } }
internal static RepositoryMonitorEvent[] BeforeSaveChanges(DiscoDataContext Database) { var contextStateManager = ((IObjectContextAdapter)Database).ObjectContext.ObjectStateManager; Database.ChangeTracker.DetectChanges(); var changes = Database.ChangeTracker.Entries().Where(entry => entry.State == System.Data.EntityState.Added || entry.State == System.Data.EntityState.Deleted || entry.State == System.Data.EntityState.Modified); var events = changes.Select(entryState => { ObjectStateEntry stateEntry = contextStateManager.GetObjectStateEntry(entryState.Entity); var monitorEvent = EventFromEntryState(Database, entryState, stateEntry); // Push to Stream streamBefore.OnNext(monitorEvent); return monitorEvent; }).ToArray(); return events; }
public static void SendEmailMessage(User user, MessageConfig messageConfig = null, Job job = null) { using (var context = new DiscoDataContext()) { var emailConfig = new ConfigurationStore(context).DeserializeConfiguration(); if (messageConfig == null) { // No message config messageConfig = emailConfig.MessageConfig.First(z => z.EmailMessageType == MessageType.PluginTestEmail); } using (var email = new MailMessage()) { using (var smtp = new SmtpClient(emailConfig.SmtpServerAddress)) { if (emailConfig.SmtpServerPort != null) { smtp.Port = emailConfig.SmtpServerPort.Value; } smtp.EnableSsl = emailConfig.EnableSsl; if (emailConfig.AuthenticationRequried) { smtp.Credentials = new NetworkCredential(emailConfig.SmtpUsername, emailConfig.SmtpPassword); } //Message email.To.Add(new MailAddress(user.EmailAddress)); email.From = new MailAddress($"{emailConfig.SmtpSenderAddress}", $"Disco ICT - {context.DiscoConfiguration.OrganisationName}"); email.Subject = messageConfig.EmailSubject; email.Body = messageConfig.EmailBody.Replace("\r\n", "<br />"); email.IsBodyHtml = true; smtp.Send(email); } } } }
public override void Install(DiscoDataContext database, ScheduledTaskStatus status) { var configStore = new ConfigurationStore(database); if (configStore.EmailConfiguration == null) { var defaultConfig = new ConfigurationModel { CurrentVersion = 1, SmtpServerAddress = "", SmtpServerPort = null, EnableSsl = false, SmtpSenderAddress = "", AuthenticationRequried = false, SmtpUsername = "", SmtpPassword = "", MessageConfig = ConfigurationExtensions.CreateDefaultMessages() }; configStore.EmailConfiguration = new JavaScriptSerializer().Serialize(defaultConfig); database.SaveChanges(); status.SetFinishedMessage("Installed initial configuration"); } }
public override void Initialize(DiscoDataContext Database) { Internal.LWTJobDetails.JobDetailsCachePath = System.IO.Path.Combine(this.Manifest.PluginManifest.StorageLocation, "JobDetailCache"); }
public override void Initialize(DiscoDataContext Database) { // Register UI Extension this.Register(); }
public ConfigurationStore(DiscoDataContext context) : base(context) { }
public static string SubmitWarrantyJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription) { return(SubmitJob(Database, Job, Address, TechUser, FaultDescription)); }
public override dynamic SubmitJobViewModel(DiscoDataContext Database, Controller controller, Job Job, OrganisationAddress Address, User TechUser) { Internal.LWTJobs.ValidateEnvironment(Database, controller, TechUser); return(null); }
public override string SubmitJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription, Dictionary <string, string> WarrantyProviderProperties) { return(Internal.LWTJobs.SubmitWarrantyJob(Database, Job, Address, TechUser, FaultDescription)); }
public override Dictionary <string, string> SubmitJobParseProperties(DiscoDataContext Database, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription) { Internal.LWTJobs.ValidateEnvironment(Database, controller, TechUser); return(null); }
public override Tuple <Type, dynamic> JobDetails(DiscoDataContext Database, Controller controller, Job Job) { var model = Internal.LWTJobDetails.LoadRepairJobDetails(Database, Job); return(Tuple.Create(typeof(Views.JobDetails), (object)model)); }
public override dynamic JobDetailsViewModel(DiscoDataContext Database, Controller controller, Job Job) { return(Internal.LWTJobDetails.LoadWarrantyJobDetails(Database, Job)); }
internal static RepositoryMonitorEvent EventFromEntryState(DiscoDataContext Database, DbEntityEntry entityEntry, ObjectStateEntry entryState) { RepositoryMonitorEventType eventType; string[] modifiedProperties = null; Dictionary<string, object> entityKey = null; Type entityType; switch (entryState.State) { case System.Data.EntityState.Added: eventType = RepositoryMonitorEventType.Added; break; case System.Data.EntityState.Deleted: eventType = RepositoryMonitorEventType.Deleted; break; case System.Data.EntityState.Detached: eventType = RepositoryMonitorEventType.Detached; break; case System.Data.EntityState.Modified: eventType = RepositoryMonitorEventType.Modified; break; case System.Data.EntityState.Unchanged: eventType = RepositoryMonitorEventType.Unchanged; break; default: throw new NotSupportedException(string.Format("Database Entry State not supported: {0}", entryState.State.ToString())); } entityType = EntityTypeFromProxy(entryState.Entity.GetType()); // Only pass modified properties on Modified Event if (eventType == RepositoryMonitorEventType.Modified) modifiedProperties = entryState.GetModifiedProperties().ToArray(); else modifiedProperties = new string[] { }; // Empty array for Added/Deleted. // Don't pass entity key when entity newly added if (eventType != RepositoryMonitorEventType.Added) entityKey = DetermineEntityKey(entryState); return new RepositoryMonitorEvent() { EventType = eventType, Entity = entryState.Entity, EntityKey = entityKey, EntityType = entityType, ModifiedProperties = modifiedProperties, Database = Database, dbEntityState = entityEntry, objectEntryState = entryState }; }