public static IPastebinProvider GetProviderFromPreferences(object [] args) { Type providerType = Type.GetType(PastebinConfig.SelectedProviderType, true); IPastebinProvider provider = (IPastebinProvider)System.Activator.CreateInstance(providerType, args); return(provider); }
protected virtual void cmbProviderChanged(object sender, System.EventArgs e) { Gtk.ComboBox ProviderBox = (Gtk.ComboBox)sender; Gtk.TreeIter ti; ProviderBox.GetActiveIter(out ti); SelectedProviderType = (string)ProviderBox.Model.GetValue(ti, 1); IPastebinProvider Pastebin = PastebinProviderFactory.GetProviderFromPreferences(); //fill treeview with supported codes FillSyntaxBox(Pastebin); }
public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems) { string text = string.Empty; ITextItem titem = null; foreach (Item item in items) { if (item is IFileItem) { titem = new TextItem(File.ReadAllText((item as IFileItem).Path)); } else { titem = new TextItem((item as ITextItem).Text); } text += titem.Text; } if (string.IsNullOrEmpty(text)) { Services.Notifications.Notify("Pastebin", "No text provided for pasting."); yield break; } IPastebinProvider pastebinProvider = null; if (modifierItems.Any()) { pastebinProvider = PastebinProviderFactory.GetProviderFromPreferences(text, (modifierItems.First() as ITextSyntaxItem).Syntax); } else { pastebinProvider = PastebinProviderFactory.GetProviderFromPreferences(text); } string url = Pastebin.PostUsing(pastebinProvider); if (!string.IsNullOrEmpty(url)) { yield return(new TextItem(url)); } }
private void FillSyntaxBox(IPastebinProvider paster) { //Gtk.ListStore CodeList = new Gtk.ListStore(typeof (Gdk.Pixbuf), typeof (string)); Gtk.ListStore CodeList = new Gtk.ListStore(typeof(string)); int count = 1; //const int scale_height = 25; //Gdk.Pixbuf syntax_icon = null; //Gdk.Pixbuf temp = null; //string[] Icon = null; foreach (TextSyntaxItem syntax in paster.SupportedLanguages) { /* * //first determine if this icon is built in - or - comes from resource * Icon = syntax.Icon.Split (new char[] {'@'}); * if (Icon.Length > 1) * { * temp = Gdk.Pixbuf.LoadFromResource (Icon[0]); * syntax_icon = temp.ScaleSimple ((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear); * } * else * { * //this section is commented because setting * //syntax_icon = null throws a GLIB exception * syntax_icon = null; * } * //CodeList.AppendValues (syntax_icon, syntax.Name); */ CodeList.AppendValues(syntax.Name); count++; } //get rid of our temporary pixbuf //temp.Dispose(); treeCodes.HeadersVisible = false; treeCodes.Model = CodeList; lblCodes.Text = string.Format("{0} syntax highlighting modes supported.", count); }
public static string PostUsing(IPastebinProvider pastebin) { string url = null; try { string postQueryString = CreateQueryString(pastebin.Parameters); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pastebin.BaseUrl); request.Timeout = 15000; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.AllowAutoRedirect = pastebin.ShouldAllowAutoRedirect; request.ServicePoint.Expect100Continue = pastebin.Expect100Continue; if (!string.IsNullOrEmpty(pastebin.UserAgent)) { request.UserAgent = pastebin.UserAgent; } UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(postQueryString); request.ContentLength = data.Length; using (Stream newStream = request.GetRequestStream()) newStream.Write(data, 0, data.Length); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) url = pastebin.GetPasteUrlFromResponse(response); } catch (Exception e) { Log <Pastebin> .Error(e.ToString()); Services.Notifications.Notify("Pastebin", "An error occured while pasting."); url = null; } return(url); }
public override IEnumerable <Item> DynamicModifierItemsForItem(Item item) { IPastebinProvider pastebinProvider = PastebinProviderFactory.GetProviderFromPreferences(); return(pastebinProvider.SupportedLanguages.OfType <Item> ()); }