public static List <SDM_Contact> Find_Contact(int SID, string UserID = "", string Last_Name = "", string First_Name = "", string Email = "", string Access_Type = "", bool Only_Active = true) { SDMWS.USD_WebServiceSoapClient ws_client = WebServiceSoapClient(); int inactiveFlag = new int(); if (Only_Active) { inactiveFlag = 0; } else { inactiveFlag = -999; } XDocument ReturnedXml = XDocument.Parse(ws_client.findContacts(SID, UserID, Last_Name, First_Name, Email, Access_Type, inactiveFlag)); List <SDM_Contact> results = new List <SDM_Contact>(); foreach (var contact in ReturnedXml.Descendants("UDSObject")) { SDM_Contact nextContact = new SDM_Contact(); results.Add(Find_Contact_By_Handle(SID, contact.Element("Handle").Value)); } return(results); }
public static string Get_Site(int SID, string UserId) { SDMWS.USD_WebServiceSoapClient ws_client = WebServiceSoapClient(); List <SDM_Contact> contactList = Find_Contact(SID, UserId); SDM_Contact contact = new SDM_Contact(); if (contactList.Count() != 1) { throw new Exception(); } else { contact = contactList[0]; } var rawXml = ws_client.getContact(SID, contact.Id.ToString()); XDocument ReturnedXml = XDocument.Parse(rawXml); string loc = String.Empty; foreach (var attribute in ReturnedXml.Descendants("Attribute")) { if (attribute.Element("AttrName").Value == "location") { loc = attribute.Element("AttrValue").Value; } } rawXml = ws_client.doSelect(SID, "loc", "id=U'" + loc + "'", -1, new string[] { "site" }); ReturnedXml = XDocument.Parse(rawXml); string siteNum = String.Empty; foreach (var attribute in ReturnedXml.Descendants("Attribute")) { if (attribute.Element("AttrName").Value == "site") { siteNum = attribute.Element("AttrValue").Value; } } rawXml = ws_client.doSelect(SID, "site", "id=" + siteNum, -1, new string[] { "name" }); ReturnedXml = XDocument.Parse(rawXml); string siteName = String.Empty; foreach (var attribute in ReturnedXml.Descendants("Attribute")) { if (attribute.Element("AttrName").Value == "name") { siteName = attribute.Element("AttrValue").Value; } } return(siteName); }
public static List <SDM_Contact> Get_VIPContacts(int SID) { SDMWS.USD_WebServiceSoapClient ws_client = WebServiceSoapClient(); var rawXml = ws_client.doSelect(SID, "special_handling", @"description LIKE '%VIP'", -1, new string[] { "persistent_id" }); XDocument ReturnedXml = XDocument.Parse(rawXml); string persistentId = ""; foreach (var attribute in ReturnedXml.Descendants("Attribute")) { if (attribute.Element("AttrName").Value == "persistent_id") { persistentId = attribute.Element("AttrValue").Value; } } SDMWS.ListResult getList = ws_client.getRelatedList(SID, persistentId, "cnthandling_list"); int listHandle = getList.listHandle; rawXml = ws_client.getListValues(SID, listHandle, 1, -1, new string[] { "contact" }); ReturnedXml = XDocument.Parse(rawXml); List <SDM_Contact> vipList = new List <SDM_Contact>(); foreach (var attributeSet in ReturnedXml.Descendants("Attributes")) { SDM_Contact nextVip = new SDM_Contact(); foreach (var attribute in attributeSet.Descendants("Attribute")) { if (attribute.Element("AttrName").Value == "contact") { string contactHandle = attribute.Element("AttrValue").Value.Trim(); nextVip = Find_Contact_By_Handle(SID, contactHandle); } } vipList.Add(nextVip); } return(vipList); }
private static SDM_Contact Find_Contact_By_Handle(int SID, string Handle) { SDMWS.USD_WebServiceSoapClient ws_client = WebServiceSoapClient(); SDM_Contact contact = new SDM_Contact(); contact.Handle = Handle.Replace("cnt:", ""); var rawXml = ws_client.getContact(SID, contact.Handle); XDocument ReturnedXml = XDocument.Parse(rawXml); foreach (var attributes in ReturnedXml.Descendants("UDSObject")) { foreach (var attribute in attributes.Descendants("Attribute")) { if (attribute.Element("AttrName").Value == "first_name") { contact.First_Name = attribute.Element("AttrValue").Value; } if (attribute.Element("AttrName").Value == "last_name") { contact.Last_Name = attribute.Element("AttrValue").Value; } if (attribute.Element("AttrName").Value == "email_address") { contact.Email = attribute.Element("AttrValue").Value; } if (attribute.Element("AttrName").Value == "userid") { contact.UserId = attribute.Element("AttrValue").Value; } if (attribute.Element("AttrName").Value == "access_type") { contact.AccessType = Int32.Parse(attribute.Element("AttrValue").Value); } if (attribute.Element("AttrName").Value == "id") { contact.Id = attribute.Element("AttrValue").Value; } } } return(contact); }
public static int Create_Ticket(int SID, string CreatorUserId, string AffectedUserId, string TicketType, string RequestArea, string Group, string Status = "OP", string RequesterUserID = "", string AssigneeUserID = "", int Priority = 0, int Severity = 0, int Urgency = 2, int Impact = 1, string Summary = "", string Description = "") { SDMWS.USD_WebServiceSoapClient ws_client = WebServiceSoapClient(); Dictionary <string, string> attrValues = new Dictionary <string, string>(); //Check that user comes back with one contact SDM_Contact creatorUser = new SDM_Contact(); if (!String.IsNullOrEmpty(CreatorUserId)) { List <SDM_Contact> tempUserCheck = Find_Contact(SID, CreatorUserId); if (tempUserCheck.Count() != 1) { throw new ArgumentException("UserId returns " + tempUserCheck.Count() + " users (Must be 1)"); } creatorUser = tempUserCheck[0]; } else { throw new ArgumentException("Invalid creator user ID given"); } //Check that Affected User comes back with only one contact if (!String.IsNullOrEmpty(AffectedUserId)) { List <SDM_Contact> tempUserCheck = Find_Contact(SID, AffectedUserId); if (tempUserCheck.Count() != 1) { throw new ArgumentException("AffectedUserId returns " + tempUserCheck.Count() + " users (Must be 1)"); } attrValues.Add("customer", tempUserCheck[0].Handle); } else { throw new ArgumentException("No valid affected user given"); } //Verify Requester comes back with one contact if (!String.IsNullOrEmpty(RequesterUserID)) { List <SDM_Contact> tempUserCheck = Find_Contact(SID, RequesterUserID); if (tempUserCheck.Count() != 1) { throw new ArgumentException("RequesterUserId returns " + tempUserCheck.Count() + " users (Must be 1)"); } attrValues.Add("requested_by", tempUserCheck[0].Handle); } //Verify ticket type is valid and create name-value string if (TicketType.ToUpper() != "R" && TicketType.ToUpper() != "I") { throw new ArgumentException("Ticket Type must be either 'I' for Incident or 'R' for Request"); } else { attrValues.Add("type", TicketType.ToUpper()); } //Verify Request Area and create name-value string var rawXml = ws_client.doSelect(SID, "pcat", "sym = '" + RequestArea + "'", 250, new string[] { "sym" }); XDocument ReturnedXml = XDocument.Parse(rawXml); if (ReturnedXml.Descendants("UDSObjectList").Elements().Count() == 0) { throw new ArgumentException("Invalid Request Area"); } else { foreach (var attribute in ReturnedXml.Descendants("UDSObject")) { attrValues.Add("category", attribute.Element("Handle").Value); } } //Verify group rawXml = ws_client.doSelect(SID, "cnt", "last_name = '" + Group + "' AND type = 2308", 250, new string[] { "persistent_id" }); ReturnedXml = XDocument.Parse(rawXml); if (ReturnedXml.Descendants("UDSObjectList").Elements().Count() == 0) { throw new ArgumentException("Invalid Group"); } else { foreach (var attribute in ReturnedXml.Descendants("UDSObject")) { attrValues.Add("group", attribute.Element("Handle").Value); } } //Verify Status if (Status.ToUpper() != "OP" && Status.ToUpper() != "CL") { throw new ArgumentException("Ticket status must be 'OP' or 'CL'"); } else { attrValues.Add("status", Status.ToUpper()); } //Verify proper priority if (Priority < 0 || Priority > 5) { throw new ArgumentException("Priority must be between 0 and 5"); } else { attrValues.Add("priority", Priority.ToString()); } //Verify proper severity if (Severity < 0 || Severity > 5) { throw new ArgumentException("Severity must be between 1 and 5 (or 0 for blank)"); } else if (Severity == 0) { attrValues.Add("severity", ""); } else { attrValues.Add("severity", Severity.ToString()); } //Verify proper urgency if (Urgency < 0 || Urgency > 4) { throw new ArgumentException("Urgency must be between 0 and 4"); } else { attrValues.Add("urgency", Urgency.ToString()); } //Verify proper impact if (Impact < 0 || Impact > 5) { throw new ArgumentException("Severity must be between 0 and 5"); } else { attrValues.Add("impact", Impact.ToString()); } // ------------------Create ticket portion -------------------- String csv = String.Join( ",", attrValues.Select(d => d.Key + "," + d.Value)); string requestHandle = ""; string requestNumber = ""; rawXml = ws_client.createRequest(SID, creatorUser.Handle, csv, new string[0], "", new string[] { "persistent_id" }, ref requestHandle, ref requestNumber); ReturnedXml = XDocument.Parse(rawXml); return(Int32.Parse(requestNumber)); }