Example #1
0
 public override void Uninstall(DiscoDataContext context, bool uninstallData, ScheduledTaskStatus status)
 {
     if (uninstallData)
     {
         Internal.Helpers.UninstallData(context, Manifest, status);
     }
 }
Example #2
0
        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));
            }
        }
Example #3
0
        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));
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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));
        }
Example #8
0
 public override void Uninstall(DiscoDataContext Database, bool UninstallData, ScheduledTaskStatus Status)
 {
     if (UninstallData)
     {
         Internal.Helpers.UninstallData(Database, this.Manifest, Status);
     }
 }
Example #9
0
 public override void Initialize(DiscoDataContext database)
 {
     RepositoryMonitor.StreamAfterCommit
     .Where(e =>
            e.EntityType == typeof(Job) &&
            e.ModifiedProperties.Contains("DeviceReadyForReturn"))
     .Subscribe(DeviceReadyForReturn);
 }
Example #10
0
 internal static void AfterSaveChanges(DiscoDataContext Database, IEnumerable<RepositoryMonitorEvent> changes)
 {
     foreach (var change in changes)
     {
         UpdateAfterEventFromEntryState(change);
         streamAfter.OnNext(change);
     }
 }
Example #11
0
 public static void UninstallData(DiscoDataContext database, PluginManifest manifest, ScheduledTaskStatus status)
 {
     status.UpdateStatus("Removing Plugin Configuration");
     new ConfigurationStore(database)
     {
         EmailConfiguration = null
     };
     database.SaveChanges();
 }
Example #12
0
        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);
                }
            }
        }
Example #13
0
        public override void AfterUpdate(DiscoDataContext database, PluginManifest previousManifest)
        {
            var configStore   = new ConfigurationStore(database);
            var currentConfig = configStore.DeserializeConfiguration();

            while (currentConfig.CurrentVersion < CurrentVersion)
            {
                switch (currentConfig.CurrentVersion)
                {
                }
            }
        }
Example #14
0
        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);
        }
Example #15
0
        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
        }
Example #16
0
        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);
        }
Example #18
0
        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() }
            });
        }
Example #19
0
        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));
        }
Example #20
0
        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)");
                    }
                }
            }
        }
Example #21
0
        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;
        }
Example #22
0
        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);
                    }
                }
            }
        }
Example #23
0
        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");
            }
        }
Example #24
0
 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();
 }
Example #26
0
 public ConfigurationStore(DiscoDataContext context) : base(context)
 {
 }
Example #27
0
 public static string SubmitWarrantyJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription)
 {
     return(SubmitJob(Database, Job, Address, TechUser, FaultDescription));
 }
Example #28
0
        public override dynamic SubmitJobViewModel(DiscoDataContext Database, Controller controller, Job Job, OrganisationAddress Address, User TechUser)
        {
            Internal.LWTJobs.ValidateEnvironment(Database, controller, TechUser);

            return(null);
        }
Example #29
0
 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));
 }
Example #30
0
        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));
        }
Example #32
0
 public override dynamic JobDetailsViewModel(DiscoDataContext Database, Controller controller, Job Job)
 {
     return(Internal.LWTJobDetails.LoadWarrantyJobDetails(Database, Job));
 }
Example #33
0
        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
            };
        }