public void SendPaste(PasteData pasteData, IEnumerable <string> recipientIds) { try { var paste = new Paste() { Data = pasteData, Sender = UserProfileStore.Instance.GetProfile(Context.User.Identity.Name), Received = DateTime.Now }; foreach (var recipientId in recipientIds) { Clients.User(recipientId).receivePaste(paste); } } catch (Exception ex) { Trace.TraceError(TraceHelper.FormatErrorMessage("Exception raised in SendPaste", ex, new Dictionary <string, object>() { { "pasteData", pasteData }, { "Context.User.Identity", Context.User.Identity }, { "Context.ConnectionId", Context.ConnectionId } })); throw; } }
public override void ExecuteAction() { #if UNITY_EDITOR Unsupported.CopyGameObjectsToPasteboard(); #endif Paste.SetBufferDistance(Selection.transforms); }
/// <summary> /// Changes the values of the record from the DB with the same ID as the give. It sets the properties of the given to the one in the database. /// </summary> /// <param name="paste">The updated paste</param> /// <param name="authorID">The userID of the current user</param> /// <exception cref="InvalidOperationException">Thrown when the current user is not the author</exception> /// <exception cref="KeyNotFoundException">Thrown when the given paste does not exist in the database.</exception> public void Update(Paste paste, string authorID) { bool didIthrow = false; try { // Find the record by id var item = context.Pastes.Where(x => x.Id == paste.Id).First(); // Check if the user can edit the record if (item.AuthorID != authorID || authorID == null || authorID == "") { didIthrow = true; throw new InvalidOperationException("The user is not permited to do this!"); } // Update the record paste.AuthorID = item.AuthorID; context.Entry(item).CurrentValues.SetValues(paste); context.SaveChanges(); } catch (InvalidOperationException e) { if (didIthrow) { throw e; } // There is no such a record throw new KeyNotFoundException("Record doesn't exist"); } }
// GET: Home public ActionResult Index() { List <Language> lang = new List <Language> { new Language { LanguageId = 1, Name = "C#", PrismName = "language-csharp" }, new Language { LanguageId = 2, Name = "JavaScript", PrismName = "language-javascript" }, new Language { LanguageId = 3, Name = "Markdown", PrismName = "language-markdown" } }; Paste paste = new Paste(); paste.PasteId = 1; paste.Expiry = DateTime.Now.AddDays(5); paste.Title = "Title"; paste.Languages = lang; ViewBag.LanguageId = new SelectList(lang, "LanguageId", "Name"); return(View(paste)); }
public ActionResult Create(PasteVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var uri = GenerateUri.RandomString(); while (_context.Pastes.Any(_ => _.URI == uri)) { uri = GenerateUri.RandomString(); } var paste = new Paste() { Title = viewModel.Title, URI = uri, Content = viewModel.Content, LanguageId = viewModel.LanguageId }; _context.Pastes.Add(paste); _context.SaveChanges(); return(RedirectToAction("Detail", new { url = uri })); }
private Task Add(Command command) { switch (command) { case Command.ToggleWindow: return(ToggleWindow.Add()); case Command.NextTab: return(NextTab.Add()); case Command.PreviousTab: return(PreviousTab.Add()); case Command.NewTab: return(NewTab.Add()); case Command.CloseTab: return(CloseTab.Add()); case Command.NewWindow: return(NewWindow.Add()); case Command.ShowSettings: return(ShowSettings.Add()); case Command.Copy: return(Copy.Add()); case Command.Paste: return(Paste.Add()); } return(Task.CompletedTask); }
public ActionResult Create() { var createPastes = new Paste(); createPastes.SyntaxHighlights = _repo.GetSyntax(); return(View(createPastes)); }
public async Task <ActionResult> Create(Paste newPaste) { try { var client = PastehubHttpClient.GetClient(); newPaste.UserId = User.Identity.GetUserId(); newPaste.CreatedDateTime = DateTime.Now; var serializedItem = JsonConvert.SerializeObject(newPaste); var response = await client.PostAsync("/api/pastes", new StringContent(serializedItem, Encoding.Unicode, "application/json")); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Home")); } else { return(Content("Error")); } } catch (Exception exception) { return(Content(exception.Message)); } }
public async Task <ActionResult> Post() { if (Request.ContentType != "application/x-www-form-urlencoded") { return(StatusCode(400, "Incorrect Content-Type. Expected 'application/x-www-form-urlencoded'.")); } var paste = new Paste(); var result = PasteBodyData.TryValidate(Request.Form, (item, data) => { if (item.Name == "title") { paste.Title = data; } else if (item.Name == "content") { paste.Content = data; } return(null); }); if (result != null) { return(StatusCode(400, result)); } paste.SetNewEditCode(); await Program.Database.Pastes.InsertSingleAsync(paste); return(Created(Url.Content("~/paste/" + paste.ID), paste)); }
private void SRE_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result.Text == "read") { Read.PerformClick(); } else if (e.Result.Text == "pause") { Pause.PerformClick(); } else if (e.Result.Text == "resume") { Pause.PerformClick(); } else if (e.Result.Text == "stop") { Stop.PerformClick(); } else if (e.Result.Text == "paste") { Paste.PerformClick(); } else if (e.Result.Text == "clear") { Clear.PerformClick(); } // throw new NotImplementedException(); }
public Paste ActualizarPaste(Paste pasteActualizado) { var pasteAEditar = db.Paste.Attach(pasteActualizado); pasteAEditar.State = EntityState.Modified; return(pasteActualizado); }
public override void Paste() { Paste paste = new Paste(); paste.Execute(textedit.ActiveTextAreaControl.TextArea); paste = null; }
public async Task <Paste> SavePasteAsync(Paste paste) { paste = context.Paste.Add(paste).Entity; context.SaveChanges(); return(paste); }
public Paste GetPasteWithId(int id) { Paste paste = _context.Pastes.FirstOrDefault(p => p.Id == id); paste.Hits++; _context.SaveChanges(); return(paste); }
public void PasteTwoStrings() { var fn = new Paste(); var result = fn.Apply(null, new object[] { "foo", "bar" }, null); Assert.IsNotNull(result); Assert.AreEqual("foo bar", result); }
public async Task <string> OnPaste(string html) { var args = new HtmlEditorPasteEventArgs { Html = html }; await Paste.InvokeAsync(args); return(args.Html); }
public ActionResult Create([Bind(Include = "Id,Title,Content,Description,IsHidden,Expieres")] Paste paste) { if (ModelState.IsValid) { paste.AuthorID = User.Identity.Name; dbPastes.Add(paste); return(RedirectToAction("Index")); } return(View(paste)); }
public void AnonymousSingedInUpdate() { Paste p = new Paste { AuthorID = "", Content = "content", Description = "description", Expieres = DateTime.MaxValue, IsHidden = false, Title = "title", Id = 0 }; getDbContext(new List <Paste> { p }); db.Delete(0, ""); }
public void ToString_ReturnsValueOfNameProperty() { const string title = "PASTE_TITLE"; var p = new Paste() { Title = title, }; Assert.Equal(title, p.Title); }
static async Task PastebinExample() { //before using any class in the api you must enter your api dev key Pastebin.DevKey = "your dev key goes here"; //you can see yours here: https://pastebin.com/api#1 try { // login and get user object User me = await Pastebin.LoginAsync("user", "pass"); // user contains information like e-mail, location etc... Console.WriteLine("{0}({1}) lives in {2}", me, me.Email, me.Location); // lists all pastes for this user foreach (Paste paste in await me.ListPastesAsync(3)) // we limmit the results to 3 { Console.WriteLine(paste.Title); } string code = "<your fancy &code#() goes here>"; //creates a new paste and get paste object Paste newPaste = await me.CreatePasteAsync(code, "MyPasteTitle", Language.HTML5, Visibility.Public, Expiration.TenMinutes); //newPaste now contains the link returned from the server Console.WriteLine("URL: {0}", newPaste.Url); Console.WriteLine("Paste key: {0}", newPaste.Key); Console.WriteLine("Content: {0}", newPaste.Text); //deletes the paste we just created await me.DeletePasteAsync(newPaste); //lists all currently trending pastes(similar to me.ListPastes()) foreach (Paste paste in await Pastebin.ListTrendingPastesAsync()) { Console.WriteLine("{0} - {1}", paste.Title, paste.Url); } //you can create pastes directly from Pastebin static class but they are created as guests and you have a limited number of guest uploads Paste anotherPaste = await Paste.CreateAsync("another paste", "MyPasteTitle2", Language.CSharp, Visibility.Unlisted, Expiration.OneHour); Console.WriteLine(anotherPaste.Title); } catch (PastebinException ex) //api throws PastebinException { //in the Parameter property you can see what invalid parameter was sent //here we check if the exeption is thrown because of invalid login details if (ex.Parameter == PastebinException.ParameterType.Login) { Console.Error.WriteLine("Invalid username/password"); } else { throw; //all other types are rethrown and not swalowed! } } Console.ReadKey(); }
public void OtherUserDelete() { Paste p = new Paste { AuthorID = "pesho", Content = "content", Description = "description", Expieres = DateTime.MaxValue, IsHidden = false, Title = "title", Id = 0 }; getDbContext(new List <Paste> { p }); db.Delete(0, "gosho"); }
public ActionResult Crear(Paste pasteNuevo) { if (!ModelState.IsValid) { //ViewBag.TipoSabor = new SelectList(tipoSaborRepositorio.ObtenerListaTipoSabor(), "Id", "Nombre"); return(View()); } pastesRepositorio.CrearPaste(pasteNuevo); pastesRepositorio.Commit(); return(RedirectToAction("Index")); }
private static void DuplicateNodes() { var text = Clipboard.Text; try { Copy.CopyToClipboard(); Paste.Perform(); } finally { Clipboard.Text = text; } }
public void PasteTwoStringsUsingEmptySeparator() { var fn = new Paste(); var result = fn.Apply(null, new object[] { "foo", "bar" }, new Dictionary <string, object>() { { "sep", string.Empty } }); Assert.IsNotNull(result); Assert.AreEqual("foobar", result); }
public void AnonymousSignedInUpdate() { Paste p = new Paste { AuthorID = null, Content = "content", Description = "description", Expieres = DateTime.MaxValue, IsHidden = false, Title = "title", Id = 0 }; getDbContext(new List <Paste> { p }); p.Content = "updatedContent"; db.Update(p, "pesho"); }
public Response DispatchCommand() { var cmdName = Parameters["cmd"]; if (string.IsNullOrEmpty(cmdName)) { return new ErrorResponse("Command not set"); } ICommand cmd = null; switch (cmdName) { case "open": if (!string.IsNullOrEmpty(Parameters["init"]) && Parameters["init"] == "true") cmd = new Init(); else { cmd = new Open(Parameters["target"]); } break; case "mkdir": cmd = new MkDir(Parameters["current"], Parameters["name"]); break; case "rm": cmd = new Rm(Parameters["current"], Parameters["targets[]"]); break; case "rename": cmd = new Rename(Parameters["current"], Parameters["target"], Parameters["name"]); break; case "upload": cmd = new Upload(Parameters["current"], Files); break; case "ping": cmd = new Ping(); break; case "duplicate": cmd = new Duplicate(Parameters["current"], Parameters["target"]); break; case "paste": cmd = new Paste(Parameters["src"], Parameters["dst"], Parameters["targets[]"], Parameters["cut"]); break; } if (cmd == null) { return new ErrorResponse("Unknown command"); } return cmd.Execute(); return new ErrorResponse("Unknown error"); }
/// <summary> /// Adds Paste object to DB /// </summary> /// <param name="paste">Should be paste object to insert to DB</param> public void AddPaste(Paste paste) { using (var db = new PasteDBContext()) { //if paste not exists if (!db.Pastes.Any(p => p.Identifier == paste.Identifier)) { db.Pastes.Add(paste); db.SaveChanges(); } } }
public ActionResult Eliminar(int?idPaste) { if (idPaste.HasValue) { Paste = pastesRepositorio.ObtenerPastePorId(idPaste.Value); } else { Paste = new Paste(); } return(View(Paste)); }
public void AddPaste(Paste newPaste) { try { _context.Pastes.Add(newPaste); _context.SaveChanges(); } catch (Exception) { throw; } }
/// <summary> /// Fills content of a paste object from file store if necessary. /// </summary> public static void FillPaste(Paste paste) { if (paste != null && paste.IsInFileStore) { MemoryStream stream = new MemoryStream(); Internal.FileStorage.Download($"/paste/raw/{paste.ID}.txt", stream); paste.Raw = Encoding.UTF8.GetString(stream.ToArray()); stream = new MemoryStream(); Internal.FileStorage.Download($"/paste/formatted/{paste.ID}.txt", stream); paste.Formatted = Encoding.UTF8.GetString(stream.ToArray()); } }
private static void DuplicateNodes() { Document.Current.History.BeginTransaction(); var text = Clipboard.Text; try { Copy.CopyToClipboard(); Paste.Perform(); } finally { Clipboard.Text = text; } Document.Current.History.EndTransaction(); }
protected void Page_Load(object sender, EventArgs e) { string pasteId = Request.QueryString["id"]; if (pasteId != null) { var requestedPastes = this.PasteService .GetPasteDetails(new Guid(pasteId)) .ToList(); if (requestedPastes != null) { this.requestedPaste = requestedPastes[0]; this.PasteDetailsFormView.DataSource = requestedPastes; this.PasteDetailsFormView.DataBind(); } } }