public static async Task <bool> UpdateSaveFromFTP(SavesClass SV, ProgressBar PB, Label LBL) { SavesContainer SVC = new SavesContainer(); try { SV.IsUpdate = "1"; string SV_obj = ""; SV_obj = SV_obj + JsonConvert.SerializeObject(SV, Formatting.Indented); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(Constants.URL + "/api.savecentral.com/v1/files_data/" + WebUtility.UrlEncode(SV.FileName))); request.Accept = "application/json"; request.ContentType = "application/json"; request.Headers.Add("authorization", Constants.ApiKey); request.Method = "POST"; request.KeepAlive = true; byte[] byteArray = Encoding.UTF8.GetBytes(SV_obj); request.ContentLength = byteArray.Length; using (Stream DataStream = await request.GetRequestStreamAsync()) { DataStream.Write(byteArray, 0, byteArray.Length); DataStream.Close(); using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) { using (Stream ResponseStream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(ResponseStream)) { string ServerResponse = await sr.ReadToEndAsync(); SVC = JsonConvert.DeserializeObject <SavesContainer>(ServerResponse); if (SVC.status.Equals("1")) { //Success MessageBox.Show(SVC.message); UpdateMessages.UpdateMsg(103, PB, LBL); return(true); } else { //Fail await Delete.DeleteSelSave(SV, PB, LBL); MessageBox.Show(SVC.message); return(false); } } } } } } catch (Exception e) { await Delete.DeleteSelSave(SV, PB, LBL); MessageBox.Show("The save info could no be updated due to the following error: " + e.Message + System.Environment.NewLine + "Please try again later."); return(false); } }
public static async Task <bool> DownloadFilesAsync(string FileName, string PathToDownload, string DeviceIP, ProgressBar PB, Label LBL) { bool b = false; try { char separator = Path.DirectorySeparatorChar; string DirToDownload = PathToDownload + "TempDL"; Directory.CreateDirectory(DirToDownload); //MessageBox.Show(lbitemsToDownload[lbFilesToDownload.SelectedIndex].FileName + " " + lbitemsToDownload[lbFilesToDownload.SelectedIndex].NomUser); string DLink = await Download.GetDLinkFromWeb(FileName); if (DLink.Equals("")) { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(101, PB, LBL); })); MessageBox.Show("Could not get download link. Please try again. If the problem persists report it."); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(103, PB, LBL); })); return(b); } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(0, PB, LBL); })); SavesClass SV = new SavesClass(); SV.FileName = FileName; SV.DLCount = "1"; await Update.UpdateDLCount(SV); MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); Progress <double> ze = new Progress <double>(p => PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg((int)p, PB, LBL); }))); await client.DownloadFileAsync(new Uri(DLink), DirToDownload + separator + FileName, ze); ZipFile.ExtractToDirectory(DirToDownload + separator + FileName, DirToDownload); File.Delete(DirToDownload + separator + FileName); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(104, PB, LBL); })); b = await FTP.CopyFilesFromLocalToFTP(DeviceIP, DirToDownload); GC.Collect(); // TENGO QUE LLAMAR ESTO O NO DEJA BORRAR EL ARCHIVO ZIP PORQUE DICE QUE AUN ESTA EN USO. client.Logout(); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(105, PB, LBL); })); Misc.Dir.DeleteDir(Constants.TempFolder + System.IO.Path.DirectorySeparatorChar + "TempDL"); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(103, PB, LBL); })); //Misc.Utils.TryToDeleteFile(DirToDownload + "/" + FileName); return(b); } } catch (Exception e) { UpdateMessages.DownloadMsg(102, PB, LBL); MessageBox.Show("Save could not be downloaded due to the following error: " + e.Message); UpdateMessages.DownloadMsg(103, PB, LBL); return(b); } }
public static async Task <SavesClass> UploadFilesAsync(string PathFileToUpload, string Username, ProgressBar PB, Label LBL) { string Filename = Path.GetFileName(PathFileToUpload); string DLink, FileSize; try { using (MALogin MAL = new MALogin()) { MegaApiClient client = MAL.Login(); INode Folder = await Task.Run(() => ChkIfFolderAndFileExist(client, Username, Filename)); if (Folder != null) { Progress <double> ze = new Progress <double>(p => PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg((int)p, PB, LBL); }))); using (FileStream stream = File.Open(@PathFileToUpload, FileMode.Open)) { INode FileUploaded = await client.UploadAsync(stream, Filename, Folder, ze); //Uploading File from PC to Mega //INode FileUploaded = await client.UploadFileAsync(PathFileToUpload, Folder, ze); //Uploading File from PC to Mega if (FileUploaded != null) { DLink = (await client.GetDownloadLinkAsync(FileUploaded)).ToString(); FileSize = (((int)(FileUploaded.Size / 1024))).ToString(); //Size in Kb client.Logout(); GC.Collect(); // TENGO QUE LLAMAR ESTO O NO DEJA BORRAR EL ARCHIVO ZIP PORQUE DICE QUE AUN ESTA EN USO. if (!DLink.Equals("")) { SavesClass SC = new SavesClass(); SC.DLink = DLink; SC.Size = FileSize; return(SC); } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } } catch { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(102, PB, LBL); })); return(null); } }
public void UpdateMessages(UpdateMessages model) { using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["DemoDBConnection"].ConnectionString)) { //open connection to talk to the database server con.Open(); var cmd = con.CreateCommand(); cmd.CommandText = "UpdateMessages"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", model.Id); cmd.Parameters.AddWithValue("@Title", model.Title); cmd.Parameters.AddWithValue("@Message", model.Message); cmd.ExecuteNonQuery(); } }
private async void lbGameSavesToDownload_DoubleClick(object sender, MouseButtonEventArgs e) { isOtherProcRunning = true; int index = lbGameSavesToDownload.SelectedIndex; gridUpload.IsEnabled = false; TabSaves.IsEnabled = false; if (index >= 0) { if (await Mega.DownloadFilesAsync(listGameSavesToDownload[index].FileName, Constants.TempFolder, txtDeviceIPAddress.Text, PBNotifyProgress, lblNotifyProgress)) { UpdateMessages.DownloadMsg(106, PBNotifyProgress, lblNotifyProgress); listGameSavesToDownload[index].DLCount = txtDLCount.Text = await Download.GetDLCountFromWeb(listGameSavesToDownload[index].FileName, txtDLCount.Text); UpdateMessages.DownloadMsg(103, PBNotifyProgress, lblNotifyProgress); MessageBox.Show("Save downloaded and transferred successfully to Device."); } } gridUpload.IsEnabled = true; TabSaves.IsEnabled = true; isOtherProcRunning = false; }
public static async Task <bool> DownloadFilesToLocal(string DeviceIP, string SavesFTPPath, string SaveTitle, string SaveDescription, string SaveRegion, string SaveType, TextBox txtHasExtData, ProgressBar PB, Label LBL) { try { string FilesIncluded = ""; UpdateMessages.UploadMsg(-1, PB, LBL); int HasExtData = 0; char separator = Path.DirectorySeparatorChar; string TempFolderPath = Constants.TempFolder + separator + "TempSaves"; string SavesPath = SavesFTPPath.Substring(1); //MessageBox.Show(SavesPath); string ExtDataPath = Utils.ReplaceFirstOccurrence(SavesPath, "Saves", "ExtData"); string fullPath = Path.GetFullPath(SavesFTPPath).TrimEnd(separator); string GameName = Path.GetFileName(Path.GetDirectoryName(fullPath)); fullPath = Utils.ReplaceLastOccurrence(fullPath, separator.ToString(), "_"); string ZipName = Path.GetFileName(fullPath) + "_" + Constants.User + ".zip"; List <String> SavesList = new List <string>(); List <String> ExtDataList = new List <string>(); // create an FTP client using (FtpClient client = new FtpClient(DeviceIP)) { client.Port = 5000; // if you don't specify login credentials, we use the "anonymous" user account client.Credentials = new System.Net.NetworkCredential("anonymous", "anonymous"); // begin connecting to the server client.Connect(); // retry up to 4 times when uploading a file (in case of file corruption) client.RetryAttempts = 4; // get a list of files and directories foreach (FtpListItem item in await client.GetListingAsync(SavesFTPPath)) { // if it is a file if (item.Type == FtpFileSystemObjectType.File) { SavesPath = System.IO.Path.GetDirectoryName(item.FullName).Substring(1); Dir.CreateDir(TempFolderPath, SavesPath, null); // download the file await client.DownloadFileAsync(@item.FullName.Substring(1), item.FullName, true, FtpVerify.Retry); SavesList.Add(item.FullName); FilesIncluded += item.Name + "|"; } // if it is a folder then go deeper to fin more files if (item.Type == FtpFileSystemObjectType.Directory) { foreach (FtpListItem itemLevel2 in await client.GetListingAsync(item.FullName)) { SavesPath = System.IO.Path.GetDirectoryName(itemLevel2.FullName).Substring(1); Dir.CreateDir(TempFolderPath, SavesPath, null); await client.DownloadFileAsync(@itemLevel2.FullName.Substring(1), itemLevel2.FullName, true, FtpVerify.Retry); SavesList.Add(itemLevel2.FullName); FilesIncluded += itemLevel2.Name + "|"; } } } string ExtDataFTP = Utils.ReplaceFirstOccurrence(SavesFTPPath, "Saves", "ExtData"); if (client.DirectoryExists(ExtDataFTP)) { foreach (FtpListItem item in await client.GetListingAsync(ExtDataFTP)) { // if it is a file if (item.Type == FtpFileSystemObjectType.File) { ExtDataPath = System.IO.Path.GetDirectoryName(item.FullName).Substring(1); Dir.CreateDir(TempFolderPath, null, ExtDataPath); // download the file await client.DownloadFileAsync(@item.FullName.Substring(1), item.FullName, true, FtpVerify.Retry); ExtDataList.Add(item.FullName); FilesIncluded += "(ExtData) " + item.Name + "|"; } // if it is a folder then go deeper to find more files if (item.Type == FtpFileSystemObjectType.Directory) { foreach (FtpListItem itemLevel2 in await client.GetListingAsync(item.FullName)) { ExtDataPath = System.IO.Path.GetDirectoryName(itemLevel2.FullName).Substring(1); Dir.CreateDir(TempFolderPath, null, ExtDataPath); await client.DownloadFileAsync(@itemLevel2.FullName.Substring(1), itemLevel2.FullName, true, FtpVerify.Retry); ExtDataList.Add(itemLevel2.FullName); FilesIncluded += "(ExtData) " + itemLevel2.Name + "|"; } } } } if (FilesIncluded.Length > 0) { FilesIncluded = FilesIncluded.Substring(0, FilesIncluded.Length - 1); } //Check if the saves also hast ExtData if (ExtDataList.Count > 0) { HasExtData = 1; txtHasExtData.Text = "Yes"; } else { txtHasExtData.Text = "No"; } System.IO.Compression.ZipFile.CreateFromDirectory(@"JKSV" + separator, @TempFolderPath + separator + ZipName, System.IO.Compression.CompressionLevel.Optimal, true); client.Disconnect(); //Uploading to mega SavesClass SV = new SavesClass(); SV = await Mega.UploadFilesAsync(@TempFolderPath + separator + ZipName, Constants.User, PB, LBL); //Here I get DLink and FileSize if (SV != null) { //If true then Insert/update record in DB SV.IdUser = Constants.IdUser; SV.FileName = ZipName; SV.GameName = GameName; SV.SaveType = SaveType; SV.Region = SaveRegion; SV.Title = SaveTitle; SV.Description = SaveDescription; SV.FilesIncluded = FilesIncluded; SV.HasExtData = HasExtData.ToString(); if (SaveType != null) { if (await Insert.InsertNewSave(SV, PB, LBL)) { return(true); } } else { if (await Update.UpdateSaveFromFTP(SV, PB, LBL)) { return(true); } } } } return(false); } catch (Exception e) { MessageBox.Show("Could not complete the operation due to the following error: " + e.Message); return(false); // null; } }
public static async Task <bool> InsertNewSave(SavesClass SV, ProgressBar PB, Label LBL) { SavesContainer SVC = new SavesContainer(); try { string SV_obj = ""; SV_obj = SV_obj + JsonConvert.SerializeObject(SV, Formatting.Indented); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(Constants.URL + "/api.savecentral.com/v1/files_data")); request.Accept = "application/json"; request.ContentType = "application/json"; request.Headers.Add("authorization", Constants.ApiKey); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(SV_obj); request.ContentLength = byteArray.Length; using (Stream DataStream = await request.GetRequestStreamAsync()) { DataStream.Write(byteArray, 0, byteArray.Length); DataStream.Close(); using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) { using (Stream ResponseStream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(ResponseStream)) { string ServerResponse = await sr.ReadToEndAsync(); SVC = JsonConvert.DeserializeObject <SavesContainer>(ServerResponse); if (SVC.status.Equals("1")) { //Success MessageBox.Show(SVC.message); UpdateMessages.UploadMsg(103, PB, LBL); return(true); } else { //Fail await Delete.DeleteSelSave(SV, PB, LBL); MessageBox.Show("An error ocurred when trying to register the upload in the DB, please try again."); UpdateMessages.UploadMsg(103, PB, LBL); return(false); } } } } } } catch (WebException e) { await Delete.DeleteSelSave(SV, PB, LBL); if (e.Response != null) { using (var errorResponse = (HttpWebResponse)e.Response) { using (var reader = new StreamReader(errorResponse.GetResponseStream())) { string error = reader.ReadToEnd(); SVC = JsonConvert.DeserializeObject <SavesContainer>(error); MessageBox.Show("The save could no be uploaded due to the following error: " + SVC.message); } } } UpdateMessages.UploadMsg(103, PB, LBL); return(false); } }
public ActionResult GetUpdates(UpdatesRequestViewModel model) { // Errors // 400: Invalid parameters // 401: Not logged in // 409: Chat does not exist // 417: User not in chat if (!Request.IsAuthenticated) { Response.StatusCode = (int)HttpStatusCode.Unauthorized; // Set http error 401 return(new EmptyResult()); } if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; // Set http error 400 return(new EmptyResult()); } ApplicationDbContext context = new ApplicationDbContext(); UpdatesViewModel returnModel = new UpdatesViewModel(); // Get chat updates if (model.ChatIds != null) { foreach (int chatid in model.ChatIds) { // Get chat for given id Chat target = (from f in context.Chats where f.Id == chatid select f).FirstOrDefault(); // Check if chat exists if (target == null) { returnModel.Errors.Add(new UpdateError("Message", chatid, 404)); continue; } List <string> pending = null; // Check if user is in chat if (target.Receiver == User.Identity.Name) { if (target.ReceiverPending == null) { continue; // Check if pending string is null } pending = JsonConvert.DeserializeObject <List <string> >(target.ReceiverPending); // Deserialize pending string List <string> newList = new List <string>(); target.ReceiverPending = JsonConvert.SerializeObject(newList); // Rewrite pending messages with empty list target.LastCheckTime = DateTime.Now; // Set last check time for message context.SaveChanges(); // Update db } else if (target.Sender == User.Identity.Name) { if (target.SenderPending == null) { continue; } pending = JsonConvert.DeserializeObject <List <string> >(target.SenderPending); List <string> newList = new List <string>(); target.SenderPending = JsonConvert.SerializeObject(newList); target.LastCheckTime = DateTime.Now; context.SaveChanges(); } else // User not in chat { returnModel.Errors.Add(new UpdateError("Message", chatid, 401)); continue; } if (!pending.Any()) { continue; // no new messages } UpdateMessages newMessages = new UpdateMessages(chatid, pending); returnModel.Messages.Add(newMessages); } } // Get all requests user is a party to List <ChatRequest> requests = (from r in context.ChatRequests where (r.Receiver == User.Identity.Name | r.Sender == User.Identity.Name) select r).ToList(); foreach (ChatRequest request in requests) { if (request.Sender == User.Identity.Name) // User sent request { // Check if request has been answered if (request.Status == 0) { continue; } UpdateRequestResponse newRequestResponse = new UpdateRequestResponse(request.Id, request.Status, request.ReceiverKey, request.ChatId); context.ChatRequests.Remove(request); context.SaveChanges(); returnModel.RequestResponses.Add(newRequestResponse); } if (request.Receiver == User.Identity.Name) // User received request { if (request.Status != 0) { continue; // Check if user has already responded to request } if (request.SenderKey == null) { returnModel.Errors.Add(new UpdateError("Request", request.Id, 404)); // Indicate that request has been deleted continue; } if (request.Seen == true) { continue; // Check if user has seen request } request.Seen = true; context.SaveChanges(); UpdateNewRequest newRequest = new UpdateNewRequest { RequestId = request.Id, Username = request.Sender, Key = request.SenderKey }; returnModel.NewRequests.Add(newRequest); } } return(Json(returnModel, JsonRequestBehavior.AllowGet)); }
public static async Task <string> DownloadFilesAsyncForUpdate(string FileName, string PathToDownload, ProgressBar PB, Label LBL) { string filepath = null; try { char separator = Path.DirectorySeparatorChar; string DirToDownload = PathToDownload + "TempDL"; Directory.CreateDirectory(DirToDownload); //MessageBox.Show(lbitemsToDownload[lbFilesToDownload.SelectedIndex].FileName + " " + lbitemsToDownload[lbFilesToDownload.SelectedIndex].NomUser); string DLink = await Download.GetDLinkFromWeb(FileName); if (DLink.Equals("")) { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(101, PB, LBL); })); MessageBox.Show("Could not get download link. Please try again. If the problem persists report it."); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(103, PB, LBL); })); return(filepath); } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(0, PB, LBL); })); MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); Progress <double> ze = new Progress <double>(p => PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg((int)p, PB, LBL); }))); await client.DownloadFileAsync(new Uri(DLink), DirToDownload + separator + FileName, ze); ZipFile.ExtractToDirectory(DirToDownload + separator + FileName, DirToDownload); File.Delete(DirToDownload + separator + FileName); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(104, PB, LBL); })); GC.Collect(); // TENGO QUE LLAMAR ESTO O NO DEJA BORRAR EL ARCHIVO ZIP PORQUE DICE QUE AUN ESTA EN USO. client.Logout(); string[] subdirectoryEntries = Directory.GetDirectories(DirToDownload + separator + "JKSV"); //With this I get Saves and ExtData (if it exists) int count = 0; foreach (string st in subdirectoryEntries) { string[] subdirectoryEntrieslv2 = Directory.GetDirectories(st); //Here I get game name foreach (string st2 in subdirectoryEntrieslv2) { string[] subdirectoryEntrieslv3 = Directory.GetDirectories(st2); //Here I get gslot name foreach (string st3 in subdirectoryEntrieslv3) { if (st3.Contains("Saves") && !st3.Contains("ExtData")) { filepath = st3.Substring(st3.IndexOf("JKSV") - 1); } } } count++; //If this is 2 then it means the save hast ExtData folder } Misc.Dir.DeleteDir(Constants.TempFolder + System.IO.Path.DirectorySeparatorChar + "TempDL"); PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.DownloadMsg(103, PB, LBL); })); return(filepath); } } catch (Exception e) { UpdateMessages.DownloadMsg(102, PB, LBL); MessageBox.Show("Save could not be downloaded due to the following error: " + e.Message); UpdateMessages.DownloadMsg(103, PB, LBL); return(null); } }
public static async Task <bool> DeleteSelSave(SavesClass SV, ProgressBar PB, Label LBL) { UpdateMessages.DeleteMsg(10, PB, LBL); SavesContainer SVC = new SavesContainer(); try { SV.IsDelete = "1"; string SV_obj = ""; SV_obj = SV_obj + JsonConvert.SerializeObject(SV, Formatting.Indented); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(Constants.URL + "/api.savecentral.com/v1/files_data/" + WebUtility.UrlEncode(SV.FileName))); request.Accept = "application/json"; request.ContentType = "application/json"; request.Headers.Add("authorization", Constants.ApiKey); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(SV_obj); request.ContentLength = byteArray.Length; using (Stream DataStream = await request.GetRequestStreamAsync()) { DataStream.Write(byteArray, 0, byteArray.Length); DataStream.Close(); UpdateMessages.DeleteMsg(50, PB, LBL); using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) { using (Stream ResponseStream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(ResponseStream)) { string ServerResponse = await sr.ReadToEndAsync(); SVC = JsonConvert.DeserializeObject <SavesContainer>(ServerResponse); if (SVC.status.Equals("1")) { //Success using (MALogin MAL = new MALogin()) { MegaApiClient client = MAL.Login(); //DELETE FILE FROM MEGA var nodes = client.GetNodes(); var SelNodes = nodes.First(n => n.Name == SV.FileName && n.Type == NodeType.File); await client.DeleteAsync(SelNodes, false); client.Logout(); } UpdateMessages.DeleteMsg(100, PB, LBL); MessageBox.Show(SVC.message); UpdateMessages.DeleteMsg(103, PB, LBL); return(true); } else { //Fail UpdateMessages.DeleteMsg(101, PB, LBL); MessageBox.Show(SVC.message); UpdateMessages.DeleteMsg(103, PB, LBL); return(false); } } } } } } catch (WebException e) { UpdateMessages.DeleteMsg(102, PB, LBL); //MessageBox.Show("Save could not be deleted due to the following error:" + e.Message); if (e.Response != null) { using (var errorResponse = (HttpWebResponse)e.Response) { using (var reader = new StreamReader(errorResponse.GetResponseStream())) { string error = reader.ReadToEnd(); SVC = JsonConvert.DeserializeObject <SavesContainer>(error); MessageBox.Show(SVC.message); return(false); } } } UpdateMessages.DeleteMsg(103, PB, LBL); return(false); } }
public void UpdateMessages(UpdateMessages model) { new DemoDataService().UpdateMessages(model); }
protected void sendUpdateDialPlanRequest(UpdateMessages message, TransferedUser transferedUser, string newCurrentAsterisk) { updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG, true); switch (message) { case UpdateMessages.addToTrunkContextInOriginal: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})"); break; case UpdateMessages.addToOriginalContext: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, transferedUser.original_context, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; case UpdateMessages.addToOthersAsteriskDialPlans: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; case UpdateMessages.deleteInOriginalContext: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, transferedUser.original_context, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; case UpdateMessages.deleteFromSourceAsteriskDialPlan: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})"); break; case UpdateMessages.deleteFromRestAsteriskDialPlan: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; case UpdateMessages.updateDialPlanInDestinationAsterisk: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; case UpdateMessages.updateInCurrentAsteriskDialPlan: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})"); break; case UpdateMessages.updateInOriginalAsteriskDialPlan: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_context, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + newCurrentAsterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; case UpdateMessages.updateInRestAsteriskDialPlan: updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + newCurrentAsterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")"); break; default: break; } managerResponse = managerConnection.SendAction(updateExtensionsConfig); if (!managerResponse.IsSuccess() && !rollbackState) { throw new ManagerException(managerResponse.Message); } }