/// <summary> /// Receive Ticket oid information /// </summary> /// <param name="supportId"></param> /// <param name="informationLogoUsername"></param> /// <param name="informationLogoPassword"></param> /// <returns></returns> #region TicketOidGet private static string TicketOidGet(string supportId, string informationLogoUsername, string informationLogoPassword, string sessionId) { string userAndPassword = System.Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(informationLogoUsername + ":" + informationLogoPassword + ":")); if (sessionId != "" && sessionId != null) { string strResponseValueTicketFirmOid = string.Empty; HttpWebRequest requestTicketFirmOid = (HttpWebRequest)WebRequest.Create("http://localhost/LogoCrmRest//api/v1.0/tickets?SessionId=" + sessionId + "&Filters=TicketId[EQ]=" + supportId + "&isProcessUserAddedItems=false&fields=Oid"); requestTicketFirmOid.Method = "GET"; HttpWebResponse responseTicketFirmOid = (HttpWebResponse)requestTicketFirmOid.GetResponse(); Stream responseStreamTicketFirmOid = responseTicketFirmOid.GetResponseStream(); StreamReader readerTicketFirmOid = new StreamReader(responseStreamTicketFirmOid); strResponseValueTicketFirmOid = readerTicketFirmOid.ReadToEnd().ToString(); dynamic TicketFirmOid = JsonConvert.DeserializeObject <dynamic>(strResponseValueTicketFirmOid); var item2 = TicketFirmOid["Items"] == null ? String.Empty : TicketFirmOid["Items"].ToString(); var itemconvertjsonTicketFirmOid = String.IsNullOrWhiteSpace(item2) ? String.Empty : item2.Substring(1, item2.Length - 1).Substring(0, item2.Length - 2); var Oid = GenericMethods.JsonParseOid(itemconvertjsonTicketFirmOid); return(Oid); } else { return(""); } }
/// <summary> /// Run timer. /// </summary> /// <param name="o"></param> private static void TimerCallback(object e) { try { // Display the date/time when this method got called. Logger.Log("Timer activated"); Console.WriteLine("Mailler okunuyor " + DateTime.Now); List <string> gidenmailler = DatabaseConnection.ListConnection(); string informationEmail = ""; string informationEmailPassword = ""; string informationLogoUsername = ""; string informationLogoPassword = ""; string informationMailType = ""; string informationLogLevel = ""; string informationHostname = ""; int informationPort = 0; int mailTypeInt = 0; int mailI = 0; List <UsernameSession> logoUsernameSessions = new List <UsernameSession>(); while (mailI <= gidenmailler.Count()) { informationEmail = gidenmailler[mailI]; informationEmailPassword = gidenmailler[mailI + 1]; informationLogoUsername = gidenmailler[mailI + 2]; informationLogoPassword = gidenmailler[mailI + 3]; informationMailType = gidenmailler[mailI + 4]; informationLogLevel = gidenmailler[mailI + 5]; informationHostname = gidenmailler[mailI + 6]; // informationPort = gidenmailler[mailI + 7]; Int32.TryParse(gidenmailler[mailI + 7], out informationPort); mailTypeInt = Mailtype(informationMailType); Console.WriteLine("Mailler okunuyor " + informationEmail + " mailI : " + mailI); mailI = mailI + 8; if (string.Compare(informationLogLevel, "True") == 0) { Logger.Log("Email : " + informationEmail + " , EmailPassword : "******", LogoCRMUsername : "******", LogoCRMPassword : "******", MailDomainType : " + informationMailType + " was read information from the database"); } string sessionId = String.Empty; var currentUser = logoUsernameSessions.Where(x => x.logoUsername.Equals(informationLogoUsername)).FirstOrDefault(); if (currentUser == null) { currentUser = new UsernameSession { logoUsername = informationLogoUsername, sessionId = String.Empty, sessionCreateDate = DateTime.Now, isFirstMail = true }; sessionId = GenericMethods.RestLogin(informationLogoUsername, informationLogoPassword, informationLogLevel); if (string.Compare(informationLogLevel, "True") == 0) { if (sessionId == "" && sessionId == null) { Logger.Log("Session Id null"); } } currentUser.sessionId = sessionId; logoUsernameSessions.RemoveAll(x => x.logoUsername.Equals(informationLogoUsername)); logoUsernameSessions.Add(currentUser); } sessionId = currentUser.sessionId; SelectMail(mailTypeInt, informationEmail, informationEmailPassword, informationLogoUsername, informationLogoPassword, informationMailType, sessionId, informationLogLevel, informationHostname, informationPort); } // Force a garbage collection to occur for this demo. GC.Collect(); } catch (Exception ex) { Logger.Log(ex.StackTrace); Logger.Log(ex.Message); } }
/// <summary> /// Create support record /// </summary> /// <param name="receiver"></param> /// <param name="subject"></param> /// <param name="messageBody"></param> /// <param name="informationLogoUsername"></param> /// <param name="informationLogoPassword"></param> /// <returns></returns> public static async Task <string> RestAsync(string receiver, string subject, string messageBody, string informationLogoUsername, string informationLogoPassword, string sessionId, string informationLogLevel) { #region Variables string supportId = ""; Guid responseParseOid = Guid.Empty; Guid responseParseTicketContactOid = Guid.Empty; Guid responseParseTicketContactFirmOid = Guid.Empty; DateTime ticketStartDate = DateTime.Now; string notes = messageBody; string RecordCreateInfoAndRecordLastUpdateInfo = DateTime.Now.ToString("dd-MM-yyyy ") + DateTime.Now.Hour + ":" + DateTime.Now.Minute; #endregion if (sessionId != "" && sessionId != null) { #region TicketFirmOid string strResponseValueTicketFirmOid = string.Empty; HttpWebRequest requestTicketFirmOid = (HttpWebRequest)WebRequest.Create("****************************" + sessionId + "&fields=FiOid,EmailAddress1&Filters=EmailAddress1[EQ]=" + receiver + "&isProcessUserAddedItems=false"); requestTicketFirmOid.Method = "GET"; HttpWebResponse responseTicketFirmOid = (HttpWebResponse)requestTicketFirmOid.GetResponse(); Stream responseStreamTicketFirmOid = responseTicketFirmOid.GetResponseStream(); StreamReader readerTicketFirmOid = new StreamReader(responseStreamTicketFirmOid); strResponseValueTicketFirmOid = readerTicketFirmOid.ReadToEnd().ToString(); dynamic TicketFirmOid = JsonConvert.DeserializeObject <dynamic>(strResponseValueTicketFirmOid); var item2 = string.Empty; if (TicketFirmOid["Items"] != null) { item2 = TicketFirmOid["Items"].ToString(); } var itemconvertjsonTicketFirmOid = String.IsNullOrWhiteSpace(item2) ? String.Empty : item2.Substring(1, item2.Length - 1).Substring(0, item2.Length - 2); if (itemconvertjsonTicketFirmOid == "") { responseParseOid = Guid.Empty; responseParseTicketContactFirmOid = Guid.Empty; } else { string myString = GenericMethods.JsonParseOid(itemconvertjsonTicketFirmOid); Guid Guid2 = new Guid(myString); responseParseTicketContactFirmOid = Guid2; } #endregion #region TicketContactOid string strResponseValueTicketContactOid = string.Empty; HttpWebRequest requestTicketContactOid = (HttpWebRequest)WebRequest.Create("****************************************" + sessionId + "&fields=TicketContact&Filters=EmailAddress1[EQ]=" + receiver + "&isProcessUserAddedItems=false"); requestTicketContactOid.Method = "GET"; HttpWebResponse responseTicketContactOid = (HttpWebResponse)requestTicketContactOid.GetResponse(); Stream responseStreamTicketContactOid = responseTicketContactOid.GetResponseStream(); StreamReader readerTicketContactOid = new StreamReader(responseStreamTicketContactOid); strResponseValueTicketContactOid = readerTicketContactOid.ReadToEnd().ToString(); dynamic TicketContactOid = JsonConvert.DeserializeObject <dynamic>(strResponseValueTicketContactOid); var itemconvertjsonTicketContactOid = String.Empty; if (TicketContactOid["Items"] != null) { var itemTicketContactOid = TicketContactOid["Items"].ToString(); itemconvertjsonTicketContactOid = itemTicketContactOid.Substring(1, itemTicketContactOid.Length - 1).Substring(0, itemTicketContactOid.Length - 2); } //burada responseParseTicketContactOid alanı boş ise firmanın mail adresini varsa atar if (itemconvertjsonTicketContactOid == "") { if (responseParseTicketContactFirmOid != null) { responseParseTicketContactOid = responseParseTicketContactFirmOid; } else { responseParseTicketContactOid = Guid.Empty; } } else { string myString2 = GenericMethods.JsonParseOid(itemconvertjsonTicketContactOid); Guid Guid3 = new Guid(myString2); responseParseTicketContactOid = Guid3; } #endregion #region //TicketIdGet string strResponseValuenewTicket = string.Empty; HttpWebRequest requestnewTicketInformation = (HttpWebRequest)WebRequest.Create("http://localhost/LogoCRMRest/api/v1.0/tickets/new?SessionId=" + sessionId); requestnewTicketInformation.Method = "GET"; HttpWebResponse responsenewTicketInformation = (HttpWebResponse)requestnewTicketInformation.GetResponse(); Stream responseStreamnewTicketInformation = responsenewTicketInformation.GetResponseStream(); StreamReader readerTicketnewFirm = new StreamReader(responseStreamnewTicketInformation); strResponseValuenewTicket = readerTicketnewFirm.ReadToEnd().ToString(); dynamic newTicketId = JsonConvert.DeserializeObject <dynamic>(strResponseValuenewTicket); var itemconvertjsonnewTicketId = String.Empty; var itemnewTicketId = newTicketId["Items"] == null ? String.Empty : newTicketId["Items"].ToString(); itemconvertjsonnewTicketId = String.IsNullOrWhiteSpace(itemnewTicketId) ? String.Empty : itemnewTicketId.Substring(1, itemnewTicketId.Length - 1).Substring(0, itemnewTicketId.Length - 2); string newTicketIdInformation = JsonParsenewTicketId(itemconvertjsonnewTicketId); #endregion #region JsonData JObject payload = new JObject( new JProperty("TicketId", newTicketIdInformation), // Burası rest tarafından otomatik olarak oluşturulacak new JProperty("TicketDescription", subject), // mail konusu new JProperty("Priority", 2), //Bu alan normal olarak açılacaktır new JProperty("TicketStartDate", ticketStartDate), new JProperty("TicketCompletedDate", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")), new JProperty("TicketEstEndDate", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")), new JProperty("IsCompleted", false), new JProperty("TicketState", new JObject( new JProperty("Oid", "371F96FC-44E1-4209-A9AB-4BA067796F52") // açık durumun oidini yolla )), new JProperty("TicketFirm", new JObject( new JProperty("Oid", responseParseTicketContactFirmOid) )), new JProperty("TicketContact", new JObject( new JProperty("Oid", responseParseTicketContactOid) )), new JProperty("Notes", notes), new JProperty("Tags", null), new JProperty("NotifyUsers", null), new JProperty("_CreatedDateTime", ticketStartDate), new JProperty("_LastModifiedDateTime", ticketStartDate), new JProperty("RecordCreateInfo", "System Administrator, " + RecordCreateInfoAndRecordLastUpdateInfo), //ticket tarihi atılacak new JProperty("RecordLastUpdateInfo", "System Administrator, " + RecordCreateInfoAndRecordLastUpdateInfo), //ticketStartDate tarihi new JProperty("IsLoading", false), new JProperty("IsDeleted", false), new JProperty("Loading", false), new JProperty("IsMobile", false), new JProperty("IsControllerSaving", false), new JProperty("MobileSessionUser", "00000000-0000-0000-0000-000000000000"), new JProperty("AvailableSubCategories", ""),// Bu ve alttaki satır değerleri [] idi new JProperty("AvailableTicketTypes", ""), new JProperty("FirmERPId", ""), new JProperty("IsTwitterTicket", false), new JProperty("IsMainCase", true) ); #endregion #region TicketPost HttpClient httpClient = new HttpClient(); var httpContent = new StringContent(payload.ToString(), Encoding.UTF8, "application/json"); HttpResponseMessage responseTicket = await httpClient.PostAsync("***************************************************" + sessionId, httpContent); responseTicket.EnsureSuccessStatusCode(); string responseBody = await responseTicket.Content.ReadAsStringAsync(); var responseParse = JObject.Parse(responseBody); HttpWebRequest requestsupport = (HttpWebRequest)WebRequest.Create("***************************************************" + sessionId); requestsupport.Method = WebRequestMethods.Http.Post; StreamWriter swJSONPayload = new StreamWriter(requestsupport.GetRequestStream()); swJSONPayload.Write(payload); #endregion #region SupportIdReturnMail dynamic jperson = JsonConvert.DeserializeObject <dynamic>(responseBody); var itemconvertjson = String.Empty; if (jperson["Items"] != null) { var item = jperson["Items"].ToString(); itemconvertjson = item.Substring(1, item.Length - 1).Substring(0, item.Length - 2); } supportId = JsonParseSupportId(itemconvertjson); #endregion if (string.Compare(informationLogLevel, "True") == 0) { Logger.Log("#" + supportId + "#" + " id with Support record created"); } } return(supportId); }