public static List<SelectListItem> ToSelectListItems(this IEnumerable<OrganisationAddress> organisationAddressess, OrganisationAddress SelectedItem) { int? selectedId = default(int?); if (SelectedItem != null) selectedId = SelectedItem.Id; return organisationAddressess.ToSelectListItems(selectedId); }
public OrganisationAddress SetAddress(OrganisationAddress Address) { if (!Address.Id.HasValue) { Address.Id = NextOrganisationAddressId; } Set(Address, Address.Id.ToString()); return Address; }
/// <summary> /// Called when the plugin should submit the job to the external party. /// </summary> /// <returns>A reference number/identifier from the external party which is stored in <see cref="Disco.Models.Repository.RepairerReference"/></returns> public abstract string SubmitJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription, Dictionary<string, string> ProviderProperties);
/// <summary> /// Called when a user selects this plugin to repair and allows a plugin to inject a View to collect additional information. /// </summary> /// <returns>A Tuple consisting of the Razor View type and a View Model</returns> public virtual Tuple<Type, dynamic> SubmitJobBegin(DiscoDataContext Database, Controller controller, Job Job, OrganisationAddress Address, User TechUser) { return null; }
/// <summary> /// Called after the RepairDescription is completed and allows the plugin to parse any data collected from SubmitJobBegin. /// </summary> /// <returns>A Dictionary of key/value items which are persisted throughout the submission and passed into the final SubmitJob method.</returns> public virtual Dictionary<string, string> SubmitJobParseProperties(DiscoDataContext Database, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription) { return null; }
public static void OnLogRepair(this Job j, DiscoDataContext Database, string RepairDescription, List<JobAttachment> SendAttachments, PluginFeatureManifest RepairProviderDefinition, OrganisationAddress Address, User TechUser, Dictionary<string, string> RepairProviderProperties) { if (!j.CanLogRepair()) throw new InvalidOperationException("Log Repair was Denied"); PublishJobResult publishJobResult = null; using (RepairProviderFeature RepairProvider = RepairProviderDefinition.CreateInstance<RepairProviderFeature>()) { if (SendAttachments != null && SendAttachments.Count > 0) { publishJobResult = DiscoServicesJobs.Publish( Database, j, TechUser, RepairProvider.ProviderId, null, RepairDescription, SendAttachments, AttachmentDataStoreExtensions.RepositoryFilename); if (!publishJobResult.Success) throw new Exception(string.Format("Disco ICT Online Services failed with the following message: ", publishJobResult.ErrorMessage)); if (string.IsNullOrWhiteSpace(RepairDescription)) RepairDescription = publishJobResult.PublishMessage; else RepairDescription = string.Concat(RepairDescription, Environment.NewLine, "___", Environment.NewLine, publishJobResult.PublishMessage); } string submitDescription; if (string.IsNullOrWhiteSpace(RepairDescription)) submitDescription = j.GenerateFaultDescriptionFooter(Database, RepairProviderDefinition); else submitDescription = string.Concat(RepairDescription, Environment.NewLine, Environment.NewLine, j.GenerateFaultDescriptionFooter(Database, RepairProviderDefinition)); string providerRef = RepairProvider.SubmitJob(Database, j, Address, TechUser, submitDescription, RepairProviderProperties); j.JobMetaNonWarranty.RepairerLoggedDate = DateTime.Now; j.JobMetaNonWarranty.RepairerName = RepairProvider.ProviderId; if (providerRef != null && providerRef.Length > 100) j.JobMetaNonWarranty.RepairerReference = providerRef.Substring(0, 100); else j.JobMetaNonWarranty.RepairerReference = providerRef; // Write Log JobLog jobLog = new JobLog() { JobId = j.Id, TechUserId = TechUser.UserId, Timestamp = DateTime.Now, Comments = string.Format("# Repair Request Submitted\r\nProvider: **{0}**\r\nAddress: **{1}**\r\nReference: **{2}**\r\n___\r\n```{3}```", RepairProvider.Manifest.Name, Address.Name, providerRef, RepairDescription) }; Database.JobLogs.Add(jobLog); if (publishJobResult != null) { try { DiscoServicesJobs.UpdateRecipientReference(Database, j, publishJobResult.Id, publishJobResult.Secret, j.JobMetaNonWarranty.RepairerReference); } catch (Exception ex) { ex.ToExceptionless().Submit(); } // Ignore Errors as this is not completely necessary } } }
public static void OnLogRepair(this Job j, DiscoDataContext Database, string FaultDescription, string ManualProviderName, string ManualProviderReference, OrganisationAddress Address, User TechUser) { if (!j.CanLogRepair()) throw new InvalidOperationException("Log Repair was Denied"); j.JobMetaNonWarranty.RepairerLoggedDate = DateTime.Now; j.JobMetaNonWarranty.RepairerName = ManualProviderName; if (ManualProviderReference != null && ManualProviderReference.Length > 100) j.JobMetaNonWarranty.RepairerReference = ManualProviderReference.Substring(0, 100); else j.JobMetaNonWarranty.RepairerReference = ManualProviderReference; // Write Log JobLog jobLog = new JobLog() { JobId = j.Id, TechUserId = TechUser.UserId, Timestamp = DateTime.Now, Comments = string.Format("# Manual Repair Request Submitted\r\nProvider: **{0}**\r\nAddress: **{1}**\r\nReference: **{2}**\r\n___\r\n```{3}```", ManualProviderName, Address.Name, ManualProviderReference ?? "<none>", FaultDescription) }; Database.JobLogs.Add(jobLog); }
public abstract Dictionary<string, string> SubmitJobParseProperties(DiscoDataContext Database, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription);
public abstract Dictionary<string, string> SubmitJobDiscloseInfo(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription, Dictionary<string, string> WarrantyProviderProperties);
public abstract dynamic SubmitJobViewModel(DiscoDataContext Database, Controller controller, Job Job, OrganisationAddress Address, User TechUser);
public override string SubmitJob(DiscoDataContext dbContext, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription, Dictionary<string, string> WarrantyProviderProperties) { // Send Job to NN var httpBody = new StringBuilder("Automated=1"); bool ntpDevice = bool.Parse(WarrantyProviderProperties["NTPDevice"]); // Determine if DEECD NTP job is to be processed or not. if (ntpDevice == true) { httpBody.Append("&txtContact="); httpBody.Append(HttpUtility.UrlEncode(Job.User.DisplayName)); httpBody.Append("&txtemail="); httpBody.Append(HttpUtility.UrlEncode(Job.User.EmailAddress)); } else { httpBody.Append("&txtContact="); httpBody.Append(HttpUtility.UrlEncode(TechUser.DisplayName)); httpBody.Append("&txtemail="); httpBody.Append(HttpUtility.UrlEncode(TechUser.EmailAddress)); } httpBody.Append("&txtorg="); httpBody.Append(HttpUtility.UrlEncode(Address.Name)); httpBody.Append("&txtorgaddress="); httpBody.Append(HttpUtility.UrlEncode(Address.Address)); httpBody.Append("&txtorgsub="); httpBody.Append(HttpUtility.UrlEncode(Address.Suburb)); httpBody.Append("&txtorgpost="); httpBody.Append(HttpUtility.UrlEncode(Address.Postcode)); httpBody.Append("&txtorgstate="); httpBody.Append(NNCompatibleContactState(Address.State)); httpBody.Append("&txtphone="); httpBody.Append(HttpUtility.UrlEncode(TechUser.PhoneNumber)); httpBody.Append("&txtSerial="); httpBody.Append(HttpUtility.UrlEncode(Job.DeviceSerialNumber)); httpBody.Append("&txtModel="); httpBody.Append(HttpUtility.UrlEncode(Job.Device.DeviceModel.Model)); httpBody.Append("&txtProblemDesc="); httpBody.Append(HttpUtility.UrlEncode(FaultDescription)); httpBody.Append("&nttpUnit="); httpBody.Append(ntpDevice ? "1" : "0"); httpBody.Append("&sltSuspectedIssue="); httpBody.Append(WarrantyProviderProperties["Issue"]); string stringResponse = null; try { HttpWebRequest wreq = HttpWebRequest.Create("http://portal.nn.net.au/ajax/warranty/ajaxWarrantyCreateJob.php") as HttpWebRequest; 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()) { using (StreamReader sr = new StreamReader(wres.GetResponseStream())) { stringResponse = sr.ReadToEnd(); } } // TODO: Parse the JSON Correctly - http://en.wikipedia.org/wiki/Json // JSON.net is used in Disco, eg: // dynamic response = JsonConvert.DeserializeObject(stringResponse); // string jobReference = response.SomeChildObject.SomeOtherObject.PropertyWhichHoldsJobReference; // return jobReference; // END TODO // NN Get last 6 Chars to gather jobID stringResponse = stringResponse.Substring(stringResponse.Length - 6); // remove end bracket to make it a proper number char[] remove = { '}' }; stringResponse = stringResponse.TrimEnd(remove); int jobReference = default(int); if (int.TryParse(stringResponse, out jobReference)) { return jobReference.ToString(); } else { // Throw error if unable to get Job task ID throw new WarrantyProviderSubmitJobException(stringResponse); } } catch (Exception ex) { string errorMessage = string.Format("Unable to successfully log warranty:{0}{1}{0}{2}{0}Server Responded: {3}", Environment.NewLine, ex.GetType().Name, ex.Message, stringResponse ?? "Unknown/None"); throw new WarrantyProviderSubmitJobException(errorMessage); } }
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 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 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; }