Eclipse Plugin Creating a IJavaLineBreakpoint programmatically does not show method info in Breakpoints view - eclipse

I'm creating a Eclipse plugin and I'm trying to create JavaLineBreakpoint using JDIDebugModel.
However, when a line breakpoint is created from the Java editor, it displays the Class name, the line number and the method name as the following image:
When the line breakpoint is created in the plugin the method name is replaced by the class name as follows:
The following is the code used to create the breakpoint.
Thank you.
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
if (breakpoints.length == 0) {
return null;
}
IJavaLineBreakpoint oldBreakpoint = null;
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (breakpoint instanceof IJavaLineBreakpoint) {
oldBreakpoint = (IJavaLineBreakpoint)breakpoint;
break;
}
}
if (oldBreakpoint != null) {
Map newAttrMap = null;
IResource resource = null;
try {
IMarker marker = oldBreakpoint.getMarker();
if (marker != null && marker.exists()) {
newAttrMap = marker.getAttributes();
resource = marker.getResource();
}
} catch (CoreException ce) {
Activator.logError("SinfoniaCloudBreakpointItem - Contructor - Marker attributes not found", ce);
}
int lineNumber = -1;
try {
lineNumber = (Integer)newAttrMap.get(IMarker.LINE_NUMBER);
} catch (ClassCastException cce) {
} catch (NullPointerException ne) {
}
try {
JDIDebugModel.createLineBreakpoint(
resource,
oldBreakpoint.getTypeName(),
lineNumber, -1, -1, 0, true, newAttrMap);
oldBreakpoint.delete();
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Related

Whether to use Flowable.create or Flowable.generate to make a file observable?

From https://github.com/ReactiveX/RxJava/wiki/Backpressure-(2.0)
the following snippet is provide to indicate correct usage for RXified file reading.
Flowable<Integer> o = Flowable.generate(
() -> new FileInputStream("data.bin"),
(inputstream, output) -> {
try {
int byte = inputstream.read();
if (byte < 0) {
output.onComplete();
} else {
output.onNext(byte);
}
} catch (IOException ex) {
output.onError(ex);
}
return inputstream;
},
inputstream -> {
try {
inputstream.close();
} catch (IOException ex) {
RxJavaHooks.onError(ex);
}
}
);
I am doing the following
public Flowable<byte[]> createFlowable(File file) {
return Flowable.create(source -> {
try (FileInputStream fin = new FileInputStream(file);
BufferedInputStream in = new BufferedInputStream(fin)) {
while (in.available() > 0) {
byte[] data = getMessageRawData(in);
source.onNext(data);
}
source.onComplete();
}
catch (Exception ex) {
source.onError(ex);
}
}, BackpressureStrategy.BUFFER);
}
Does my code (uses try with resource) suffer from resource leakage if dispose is called mid way or what other side effects can be expected or is it just a different way of doing things?

How to invoke unit test a Print Event handler in c#

I have below method which will get invoked when I call Print() method. I need to unit test the same. Is there any suggestions on how to do this?
internal PrintRemovalController(IApplicationContextHelper applicationContextHelper)
{
_applicationContextHelper = applicationContextHelper;
using (PrintDocument)
_printDocument.PrintPage += PrintDocument_PrintPage;
}
public void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Font printFont = null;
try
{
PrintDetails pd;
do
{
pd = _printLines[_printPosition];
printFont = new Font("Courier New", 11, pd.Style);
if (pd.Text != "PAGE~~END")
e.Graphics.DrawString(pd.Text, printFont, Brushes.Black, pd.XPos, d.YPos);
_printPosition++;
}
while (pd.Text != "PAGE~~END");
e.HasMorePages = _printPosition < _printLines.Count;
}
finally
{
if (printFont != null)
printFont.Dispose();
}
}

SharePoint Backup Tool for Custom Lists

I have a SharePoint 2013 document library with three custom lists.
Once a day I would like to backup the custom lists as excel documents.
Is there an inbuilt functionality in SharePoint 2013 which can be configured as a recurring task?
Or should one use PowerShell or CSOM to write script or an application which is then run by a Windows Task?
you dont have any OOB features to do this, i had the same req and i wrote an Utility - PFB the code - this will give you an o/p in .csv file
class Program
{
private static DataTable dataTable;
private static SPList list;
static void Main(string[] args)
{
try
{
Console.WriteLine("Site Url: ");
string _siteUrl = Console.ReadLine();
if (!string.IsNullOrEmpty(_siteUrl))
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(_siteUrl))
{
if (site != null)
{
SPWeb web = site.RootWeb;
if (web != null)
{
// Export List code segment
Console.WriteLine("List Name:");
string _listName = Console.ReadLine();
if (!string.IsNullOrEmpty(_listName))
{
list = web.Lists[_listName];
if (list != null)
{
dataTable = new DataTable();
//Adds Columns to SpreadSheet
InitializeExcel(list, dataTable);
string _schemaXML = list.DefaultView.ViewFields.SchemaXml;
if (list.Items != null && list.ItemCount > 0)
{
foreach (SPListItem _item in list.Items)
{
DataRow dr = dataTable.NewRow();
foreach (DataColumn _column in dataTable.Columns)
{
if (dataTable.Columns[_column.ColumnName] != null && _item[_column.ColumnName] != null)
{
dr[_column.ColumnName] = _item[_column.ColumnName].ToString();
}
}
dataTable.Rows.Add(dr);
}
}
}
}
System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
grid.HeaderStyle.Font.Bold = true;
grid.DataSource = dataTable;
grid.DataBind();
using (StreamWriter streamWriter = new StreamWriter("C:\\" + list.Title + ".xls", false, Encoding.UTF8))
{
using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(streamWriter))
{
grid.RenderControl(htmlTextWriter);
}
}
Console.WriteLine("File Created");
#endregion
}
}
}
});
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
Console.ReadLine();
}
// Create excel funution
public static void InitializeExcel(SPList list, DataTable _datatable)
{
if (list != null)
{
string _schemaXML = list.DefaultView.ViewFields.SchemaXml;
if (list.Items != null && list.ItemCount > 0)
{
foreach (SPListItem _item in list.Items)
{
foreach (SPField _itemField in _item.Fields)
{
if (_schemaXML.Contains(_itemField.InternalName))
{
if (_item[_itemField.InternalName] != null)
{
if (!_datatable.Columns.Contains(_itemField.InternalName))
{
_datatable.Columns.Add(new DataColumn(_itemField.StaticName, Type.GetType("System.String")));
}
}
}
}
}
}
}
}
}

Markes dump displays nulls for IMarker.LINE_NUMBER and IMarker.CHAR_START Plugin development markers

I have following generic code that dumps all the markers with all the attibutes in the system. If I set some breakpoints the value for both LINE_NUMBER and IMarker.CHAR_START is always displaed as null despite them having a clear value.
Can Anybody help understand that?
private void printAllMarkers() {
IMarker[] markers = null;
IWorkspace root = ResourcesPlugin.getWorkspace();
IProject projects[] = root.getRoot().getProjects();
for (IProject p : projects) {
try {
markers = p.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
System.out.println("\nAll Markers Are: ");
for (IMarker m : markers) {
System.out.println("-----------Marker of Type: " + m.getType());
dumpMarker(m);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
}
public static void dumpMarker(IMarker m) {
try {
for (String attrName : m.getAttributes().keySet()) {
System.out.println("Attribute:" + attrName + "=" + m.getAttribute(attrName, null));
}
} catch (CoreException e) {
e.printStackTrace();
}
}
I found the problem. It's an Eclipse bug that displays the value as null if it comes from a 'supertype"
so getAttribute(attrName, null) will return null for lineStart even if the attribute exists.

How can i attach multiple images with email in Blackberry?

I want to attach multiple images with email in BB. How can I do this? Does any body have an idea? please help me.Below is my code which works fine when i send only one image with email. so what modification should I make in my code for attaching multiple images.
public static void SendMailAttachment(Bitmap screenshot)
{
String htmlContent = "String" ;
try
{
Multipart mp = new Multipart();
Message msg = new Message();
Address[] addresses = {new Address("","")};
for (int i = 0; i<2 ; i++)
{
PNGEncodedImage img = PNGEncodedImage.encode(screenshot);
SupportedAttachmentPart pt = new SupportedAttachmentPart(mp, img.getMIMEType(),
"Weed.png", img.getData());
mp.addBodyPart(pt);
}
msg.setContent(mp);
msg.setContent(htmlContent);
msg.addRecipients(RecipientType.TO, addresses);
msg.setSubject("Subject");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(msg));
}
catch (AddressException ex)
{
System.out.println("Exception -->"+ex.getMessage());
}
catch (MessagingException ex)
{
System.out.println("Exception -->"+ex.getMessage());
}
}
Thanx in advance.
following code can be used to attach multiple images or files.
public void upload()
{
Multipart mp = new Multipart();
String fileName = null;
for (int i = 0; i<2 ; i++)
{
// Dialog.alert(image.);
byte[] stream = readStream("file:///SDCard/IMG00001-20110404-1119.JPEG");
SupportedAttachmentPart sap = new SupportedAttachmentPart(mp, MIMETypeAssociations.getMIMEType("IMG00001-20110404-1119.JPEG"),"IMG00001-20110404-1119.JPEG", stream);
mp.addBodyPart(sap);
}
TextBodyPart tbp = new TextBodyPart(mp,"test bodyString");
mp.addBodyPart(tbp);
Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);
Message message = new Message(folders[0]);
Address[] toAdds = new Address[1];
try {
toAdds[0] = new Address("testmailid", null);
message.addRecipients(Message.RecipientType.TO,toAdds);
// message.setFrom(new InternetAddress(_from));
// message.addRecipients(Message.RecipientType.FROM,toAdds);
message.setContent(mp);
message.setSubject("test subject");
Transport.send(message);
Dialog.alert("message send successfully.");
} catch (AddressException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
Dialog.alert(e.getMessage());
} catch (MessagingException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
Dialog.alert(e.getMessage());
}
}
private byte[] readStream(String path)
{
InputStream in = null;
FileConnection fc = null;
byte[] bytes = null;
try
{
fc = (FileConnection) Connector.open(path);
if (fc !=null && fc.exists())
{
in = fc.openInputStream();
if (in !=null)
{
bytes = IOUtilities.streamToBytes(in);
}
}
}
catch(IOException e)
{
}
finally
{
try
{
if (in != null)
{
in.close();
}
}
catch(IOException e)
{
}
try
{
if (fc !=null)
{
fc.close();
}
}
catch(IOException e)
{
}
}
return bytes;
}
i have used this code. it works fine.
Just create a new SupportedAttachmentPart for each image and add them to the message with the addBodyPart method.
Once the multipart is populated with the body part and the attachment parts, call msg.setContent(mp).