public ActionResult Menu(MenuModelView model) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account", null)); } if (ModelState.IsValid) { model.user = User.Identity.Name; model.status = Convert.ToInt16(model.statusb); if (model.menuid != 0) //update { ServiceMenu.UpdateMenu(model); } else //insert { ServiceMenu.InsertMenu(model); } return(Redirect(Domain.Util.config.UrlSite + "Meni/Menu")); } model.menus = ServiceMenu.getMenu(); return(View(model)); }
public ActionResult MenuDelete(Int16 id = 0) { if (id != 0) { //exclui registro ServiceMenu.DeleteMenuId(id); } return(Redirect(Domain.Util.config.UrlSite + "Meni/Menu")); }
/// <summary> /// StartNewTask /// Starts a new thread task for the service request /// </summary> /// <param name="method">the method target (Action delegate)</param> /// <param name="menu">the type of request enum (ServiceMenu)</param> private void StartNewTask(Action method, ServiceMenu menu) { // set the CancelationTokenSource object to a new instance m_TokenSource = new CancellationTokenSource(); // When Tasks complete, TPL provides a mechanism to automatically // continue execution on a WinForm or WPF UI thread.To do this // we need a handle to the UI thread which we’ll use later TaskScheduler ui = TaskScheduler.FromCurrentSynchronizationContext(); // start the Task, passing it the name of the method that // will be the entry point for the Task and the token used for cancellation: Task myServiceCallTask = Task.Run(method, m_TokenSource.Token); // first continuation call will execute only when the Task completes successfully // notifies the user by showing a message box then resetting the buttons to their // default configuration. Notice that the last parameter to ContinueWith is “ui”. // This tells ContinueWith to execute the lambda statements to execute within // the context of the UI thread.No Invoke / BeginInvoke needed here. Task resultOK = myServiceCallTask.ContinueWith(resultTask => { // Update GUI After Task is Complete // Refresh the Remote Files UpdateRemoteFiles(); // Refresh the Local Files UpdateLocalFiles(); // Reset this menu action button UpdateGUIButtons(menu, true); // Refresh the Remote Directory if (menu == ServiceMenu.AddFile) { btnListFiles_Click(this, null); } }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, ui); // second continuation call only executes if the task is cancelled Task resultCancel = myServiceCallTask.ContinueWith(resultTask => { // Update GUI After Cancellation // Refresh the Remote Files UpdateRemoteFiles(); // Refresh the Local Files UpdateLocalFiles(); // Reset this menu action button UpdateGUIButtons(menu, true); }, CancellationToken.None, TaskContinuationOptions.OnlyOnCanceled, ui); } // end of method
public ActionResult Menu(Int16 id = 0) { var model = new MenuModelView(); if (id != 0) { //busca as informações para edição model = ServiceMenu.GetMenuId(id); } model.menus = ServiceMenu.getMenu(); return(View(model)); }
public ActionResult UsuarioMenu(Int16 id = 0) { var model = new UsuarioMenuModelView(); if (id != 0) { //busca as informações para edição model = ServiceUsuarioMenu.GetUsuarioMenuId(id); } model.UsuariosTipos = ServiceUsuarioTipo.getUsuarioTipo(); model.Menus = ServiceMenu.getMenu(); model.UsuariosMenus = ServiceUsuarioMenu.getUsuarioMenu(); return(View(model)); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Зацепин Cтанислав"); Console.ForegroundColor = ConsoleColor.White; int selection; ServiceMenu serviceMenu; ListMenu listMenu = new ListMenu(); listMenu.createList(); listMenu.Printer(); do { Console.WriteLine("Ведите номер дз которое вас интересует. Выход когда видете 0"); try { selection = int.Parse(Console.ReadLine()); serviceMenu = new ServiceMenu(selection); if (selection != 0) { serviceMenu.StartMenu(); } } catch (Exception) { selection = 0; Console.WriteLine("Неверный формат"); Console.ReadKey(); } } while (selection != 0); }
static void Main(string[] args) { ServiceMenu menu = new ServiceMenu(); menu.MainMenu(); }
} // end of method /// <summary> /// UpdateGUIButtons /// </summary> /// <param name="menu">A selection list enum (ServiceMenu)</param> /// <param name="enabled">if the button should be enabled (true or false) </param> private void UpdateGUIButtons(ServiceMenu menu, bool enabled) { switch (menu) { case ServiceMenu.ListFiles: if (enabled) { btnListFiles.Enabled = true; btnListFiles.Focus(); btnCancel.Enabled = false; } else { btnListFiles.Enabled = false; btnCancel.Enabled = true; } break; case ServiceMenu.GetFile: if (enabled) { btnGetFile.Enabled = true; btnGetFile.Focus(); btnCancel.Enabled = false; } else { btnGetFile.Enabled = false; btnCancel.Enabled = true; } break; case ServiceMenu.AddFile: if (enabled) { btnAddFile.Enabled = true; btnAddFile.Focus(); btnCancel.Enabled = false; } else { btnAddFile.Enabled = false; btnCancel.Enabled = true; } break; case ServiceMenu.Load: default: if (enabled) { lblTitle.Focus(); btnListFiles.Enabled = true; btnAddFile.Enabled = true; btnGetFile.Enabled = true; btnCancel.Enabled = false; } else { btnListFiles.Enabled = false; btnAddFile.Enabled = false; btnGetFile.Enabled = false; btnCancel.Enabled = true; } break; } // end of switch } // end of menu
} // end of method /// <summary> /// CallService /// Creates a ChannelFactory proxy to the service /// Listens for Cancellation Event from user clicking cancel /// Called from the Async Task from the UI Thread /// Get resources from the service (when connected) /// </summary> private void CallService(ServiceMenu menuSelection) { try { // Make a ChannelFactory Proxy to the Service using (ChannelFactory <IFileManagerService> cf = new ChannelFactory <IFileManagerService>("NetTcpBinding_IFileManagerService")) { cf.Open(); IFileManagerService proxy = cf.CreateChannel(); if (proxy != null) { // check to see if cancellation was requested // if (m_TokenSource.Token.IsCancellationRequested) throw new OperationCanceledException(); m_TokenSource.Token.ThrowIfCancellationRequested(); try { // Call the Service switch (menuSelection) { case ServiceMenu.ListFiles: remoteFiles = proxy.GetFiles(); break; case ServiceMenu.GetFile: #region GetFile string fileName = selectedRemoteFile.FileName; string outputPath = LocalDirectory; string outputFileName = Path.Combine(outputPath, fileName); using (Stream s = proxy.GetFile(fileName)) { if (s == null) { throw new Exception("Stream is empty."); } int byteCount = 0; int offset = 0; using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) { do { byte[] bytes = new byte[BUFFER]; byteCount = s.Read(bytes, 0, BUFFER); offset += byteCount; fs.Write(bytes, 0, byteCount); }while (byteCount > 0); } // end of using } // end of using #endregion GetFile break; case ServiceMenu.AddFile: #region AddFile string inputPath = LocalDirectory; fileName = selectedLocalFile.FileName; string inputFileName = Path.Combine(inputPath, fileName); if (!File.Exists(inputFileName)) { return; } FileInfo fi = new FileInfo(inputFileName); int chunkSize = proxy.AddFile(fi.Name); int chunks = (int)(fi.Length / chunkSize); int rem = (int)(fi.Length % chunkSize); using (FileStream fs = fi.Open(FileMode.Open, FileAccess.Read)) { byte[] bytes = new byte[chunkSize]; for (int i = 0; i < chunks; i++) { fs.Seek((long)i * (long)chunkSize, SeekOrigin.Begin); fs.Read(bytes, 0, chunkSize); proxy.AddFileChunk(fi.Name, i, bytes); } if (rem > 0) { byte[] remBytes = new byte[rem]; fs.Seek((long)chunks * (long)chunkSize, SeekOrigin.Begin); fs.Read(remBytes, 0, rem); proxy.AddFileChunk(fi.Name, chunks, remBytes); } } // end of using // Signal all file chunks uploaded proxy.CompleteAddFile(fi.Name, chunks + (rem > 0 ? 1 : 0)); break; #endregion AddFile default: break; } // end of switch } // end of try // when the user cancels the Task catch (OperationCanceledException) { throw; } // end of catch catch (Exception) { // Cancel the Task btnCancel_Click(this, null); } // end of catch } // end of if else { // Cannot Connect to Server MessageBox.Show("Cannot Create a Channel to a Proxy. Check Your Configuration Settings.", "Proxy", MessageBoxButtons.OK); return; } // end of else } // end of using } // end of main try // when the user cancels the Task catch (OperationCanceledException) { throw; } // end of catch } // end of method
//Falta inyectar el servicio atraves de un conteiner public MenuController() { _srvMenu = new ServiceMenu(); }
//Falta inyectar el servicio atraves de un conteiner public MenuController() { _service = new ServiceMenu(); }
static void Main(string[] args) { ServiceMenu sm = new ServiceMenu(); sm.MainMenu(); }