//Upload SQLite database file to the server public static string UploadSQLiteDatabase(HttpPostedFile file, string documentPath, int ClientId, string FileName) { try { var b = new byte[file.ContentLength]; string result = ""; documentPath = documentPath + ClientId; //"\\" + ModuleName MemoryStream ms = new MemoryStream(b); // MemoryStream ms = new MemoryStream(file.ContentLength); bool IsExists = System.IO.Directory.Exists(documentPath); if (IsExists == false) { System.IO.Directory.CreateDirectory(documentPath); } var path = System.IO.Path.Combine(documentPath, FileName); //file.FileName if (File.Exists(path)) { result = "File already Exists"; return(result); } else { file.SaveAs(documentPath + "/" + FileName); //file.FileName ms.Close(); //Change Client IsDatabaseUploaded status ClientDTO ClientDTO = new ClientDTO(); ClientDTO = ClientService.GetById(ClientId); ClientDTO.IsDatabaseUploaded = true; GlobalSettings.LoggedInClientId = ClientDTO.Id; int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId; GlobalSettings.LoggedInPartnerId = PartnerId; ClientService.Edit(ClientDTO); result = "File uploaded successfully"; return(result); } } catch (Exception ex) { return(ex.ToString()); } }
//Upload Sender code document to the server public static string UploadSenderCodeDocument(HttpPostedFile file, string documentPath, int ClientId, string FileName) { try { var b = new byte[file.ContentLength]; string result = ""; documentPath = documentPath + ClientId; //"\\" + ModuleName MemoryStream ms = new MemoryStream(b); // MemoryStream ms = new MemoryStream(file.ContentLength); bool IsExists = System.IO.Directory.Exists(documentPath); if (IsExists == false) { System.IO.Directory.CreateDirectory(documentPath); } var path = System.IO.Path.Combine(documentPath, FileName); //file.FileName if (File.Exists(path)) { result = "File already Exists"; return(result); } else { file.SaveAs(documentPath + "/" + FileName); //file.FileName ms.Close(); ClientDTO ClientDTO = new ClientDTO(); ClientDTO = ClientService.GetById(ClientId); ClientDTO.SenderCodeFilePath = ClientId + "/" + FileName;// file.FileName; ClientService.Edit(ClientDTO); result = "File uploaded successfully"; // Send Mail to Admin PartnerDTO PartnerDTO = new PartnerDTO(); PartnerDTO = PartnerService.GetById(ClientDTO.PartnerId); CommonService.SendEmail("New sendercode application request", "<HTML><BODY><P>Hello " + CommonService.GetFirstname(PartnerDTO.Name) + "</P><P>" + ClientDTO.Company + " has requested for new sender code.</P></BODY></HTML>", PartnerDTO.Email, "", false); return(result); } } catch (Exception ex) { return(ex.ToString()); } }
public static string SendMessage(Byte[] array, Byte[] checksum) { try { //Checking for Data Accuracy Byte[] newchecksum = new MD5CryptoServiceProvider().ComputeHash(array); if (checksum.Length == newchecksum.Length) { int arraylength = 0; while ((arraylength < checksum.Length) && (newchecksum[arraylength] == checksum[arraylength])) { arraylength++; } if (arraylength != newchecksum.Length) { return(ErrorFlag.DataCorrupted.ToString()); } } // Checking User's Validation that is CDKey & MachineID XmlSerializer xs = new XmlSerializer(typeof(MsgInformationDTO)); MemoryStream msgStream = new MemoryStream(array); MsgInformationDTO oMsgInformationDTO = (MsgInformationDTO)xs.Deserialize(msgStream); CampaignDTO CampaignDTO = new CampaignDTO(); CampaignDTO = CampaignService.GetById(oMsgInformationDTO.CampaignId); //CampaignDTO.ClientId = oMsgInformationDTO.ClientId; //CampaignDTO.Id = oMsgInformationDTO.CampaignId; ClientDTO ClientDTO = new ClientDTO(); ClientDTO = ClientService.GetById(CampaignDTO.ClientId); string packet = oMsgInformationDTO.xmlpacket; string fname = null; if (ValidatePacketAgainstSchema(packet)) // Check xml file validation. { if (AllowToProcessClient(CampaignDTO)) { DateTime DateAndTime = System.DateTime.Now; SettingDTO SettingDTO = new SettingDTO(); // Get limit on msg size SettingDTO = SettingService.GetById(1); int requiredCredit = 0; XmlDocument x = new XmlDocument(); x.LoadXml(packet); XmlNodeList messages = x.SelectNodes("/packet/numbers/message/text()"); // Get all messages from xmlpacket XmlNodeList numbers = x.SelectNodes("/packet/numbers/number"); for (int i = 0; i < messages.Count; i++) // Get required credits to send this packet; { requiredCredit += MessageCount(MsgCorrect(messages[i].InnerText.TrimEnd())); } if (messages.Count == 1) // Means one message to all numbers { requiredCredit = requiredCredit * numbers.Count; } if (ClientDTO.SMSCredit >= requiredCredit) { XmlNode root = x.DocumentElement; XmlElement requiredcredits = x.CreateElement("requiredcredits"); requiredcredits.InnerText = requiredCredit.ToString(); root.InsertBefore(requiredcredits, root.LastChild); //_oClsClients.SMSCredits -= requiredCredit; try { fname = DateAndTime.Year.ToString() + DateAndTime.Month + DateAndTime.Day + "-" + DateAndTime.Hour + DateAndTime.Minute + DateAndTime.Second + "-" + oMsgInformationDTO.CampaignId + "-Q.xml"; x.Save(ConfigurationManager.AppSettings["SMSFolderPath"].ToString() + fname); x = null; //dbClients.ReduceSMSCredits(oClient, requiredCredit); CampaignDTO CampaignDTONew = new CampaignDTO(); CampaignDTONew = CampaignDTO; //CampaignDTONew.IsSent = true; CampaignDTONew.Status = "Sent"; CampaignService.Edit(CampaignDTONew); ClientDTO ClientDTOUpdate = new ClientDTO(); ClientDTOUpdate = ClientDTO; ClientDTOUpdate.SMSCredit = ClientDTOUpdate.SMSCredit - requiredCredit; ClientService.Edit(ClientDTOUpdate); } catch (Exception ex) { return(ErrorFlag.FailedToWriteData.ToString()); // Returns "FailedToWriteData" enum name if message file not created } //return ErrorFlag.Success.ToString(); // Return "Success" enum name if Message file created in the SMSQueue folder successfully return(fname); } else { return(ErrorFlag.InsufficientCredits.ToString()); // Returns "InsufficientCredits" enum name if SMSCredits are insufficient for sending message } } else { return(ErrorFlag.InvalidUser.ToString()); // Returns "InvalidUser" enum name if the CDKey or MachineID not matching } } else { return(ErrorFlag.BadXml.ToString()); // Return BAD XmlPacke Error } } catch { throw; // Returns error flag name if there are any web exception } }