Windows phone 8 Image not refresh (ListBox with Binding) - binding

On MainPage ListBox
DataTemplate
<StackPanel>
<Image Source="{Binding Image}" Height="160"></Image>
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
Binding
System.Diagnostics.Debug.WriteLine("Refresh()");
ListBox.DataContext = db.Contacts.OrderBy(x => x.Order).ToList();
Image Binding
public ImageSource Image
{
get
{
string path = ApplicationData.Current.LocalFolder.Path + "Image";
if (System.IO.File.Exists(path))
{
System.IO.FileInfo fi = new System.IO.FileInfo(path);
System.Diagnostics.Debug.WriteLine("size: {0} time: {1}", fi.Length, fi.CreationTime);
return new BitmapImage(path);
}
var image = new BitmapImage();
image.SetSource(Application.GetResourceStream(new Uri("Assets/Images/empty.png", UriKind.Relative)).Stream);
return image;
}
From MainPage open SettingPage.
At SettingPage
change DisplayName
add and remove items from db.Contacts
ApplicationData.Current.LocalFolder.Path + "Image" replaced with new image file;
Back to MainPage
DisplayName - refresh
new items - added
removed items - deleted
but image show OLD
If restart app - show new image
In diagnostic
Start MainPage
Refresh()
size: 96005 time: 11.01.2014 20:38:10
Open SettingPage - Change Image - Back to MainPage
Refresh()
size: 132404 time: 11.01.2014 21:05:00
I see image has new size but in list box old image.
Why image not refresh?

Found the solution here
var img = new BitmapImage();
img.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
img.UriSource = new Uri(path);

Related

VSTS Extension - Storing parameters from build task and call a web service from summary tab

I need to display the result of a custom build task in summary tab (“ms.vss-build-web.build-results-section”). In order to do this I need to retain some data from build task and use it to call a web service from summary section. Is it possible to store data in a variable using Extension Data Service and use it in summary page? What should be the best approach for this?
Thanks in advance.
I have attached my build task data using a Logging command
https://github.com/Microsoft/vsts-tasks/blob/986f8f5112017474962affe58c9ebaf394fb9354/docs/authoring/commands.md
//Build Task
class TestClass {
_name: string;
_age: number;
constructor(name: string, age:number) {
this._name = name;
this._age = age;
}
}
var data = new TestClass(TinTin,100);
//Create a folder
tl.mkdirP("c:/myfolder/");
//Write data to a file
tl.writeFile("c:/myfolder/mydata.txt",JSON.stringify(data));
//Executes command to attach the file to build
console.log("##vso[task.addattachment type=myAttachmentType;name=myAttachmentName;]c:/myfolder/mydata.txt");
Retrieve the attachment from summary page.
https://github.com/Microsoft/vsts-extension-samples/blob/master/build-results-enhancer/src/enhancer/tab.ts
//Summary Page
/// <reference path="../definitions/Q.d.ts" />
/// <reference path="../definitions/vss.d.ts" />
/// <reference path="../definitions/tfs.d.ts" />
/// <reference path="../definitions/jquery.d.ts" />
import VSS_Service = require("VSS/Service");
import Controls = require("VSS/Controls");
import TFS_Build_Contracts = require("TFS/Build/Contracts");
import TFS_Build_Extension_Contracts = require("TFS/Build/ExtensionContracts");
import DT_Client = require("TFS/DistributedTask/TaskRestClient");
export class StatusSection extends Controls.BaseControl {
constructor() {
super();
}
public initialize(): void {
super.initialize();
// Get configuration that's shared between extension and the extension host
var sharedConfig: TFS_Build_Extension_Contracts.IBuildResultsViewExtensionConfig = VSS.getConfiguration();
var vsoContext = VSS.getWebContext();
if(sharedConfig) {
// register your extension with host through callback
sharedConfig.onBuildChanged((build: TFS_Build_Contracts.Build) => {
var taskClient = DT_Client.getClient();
taskClient.getPlanAttachments(vsoContext.project.id, "build", build.orchestrationPlan.planId, "myAttachmentType").then((taskAttachments)=> {
if (taskAttachments.length === 1) {
var recId = taskAttachments[0].recordId;
var timelineId = taskAttachments[0].timelineId;
taskClient.getAttachmentContent(vsoContext.project.id, "build", build.orchestrationPlan.planId,timelineId,recId,"myAttachmentType","myAttachmentName").then((attachementContent)=> {
function arrayBufferToString(buffer){
var arr = new Uint8Array(buffer);
var str = String.fromCharCode.apply(String, arr);
if(/[\u0080-\uffff]/.test(str)){
throw new Error("this string seems to contain (still encoded) multibytes");
}
return str;
}
var summaryPageData = arrayBufferToString(attachementContent);
//Deserialize data
var ob = JSON.parse(summaryPageData);
console.log("Name: " + ob._name);
console.log("Age: " + ob._age);
});
}
});
});
}
}
}
StatusSection.enhance(StatusSection, $(".build-status"), {});
// Notify the parent frame that the host has been loaded
VSS.notifyLoadSucceeded();
You can do it but the issue is that the those values are always the values from the latest build, the information in summary page would be incorrect for old builds. So I would recommend to the get the build task result via BuildHttpClient2_2 and then show it in the summary page directly.

Create footer with page number not displayed using Document object of EvoPdf

I have a pdf file that converted from html by EvoPdf HtmlToPdfConverter. I read the file bytes by evopdf Document Class and add footer element to it. after saving the bytes - it's displaying inline webBrowser.
the footer with page number isn't displayed.
This is my code:
Document pdfDoc = new Document("myFilePath.pdf");
//create the footer element
TextElement footerText = new TextElement(0, 30, "Page &p; of &P; ",
new System.Drawing.Font( new System.Drawing.FontFamily("Arial"), 10, System.Drawing.GraphicsUnit.Point));
footerText.EmbedSysFont = true;
footerText.TextAlign = HorizontalTextAlign.Right;
pdfDoc.AddFooterTemplate(50);
pdfDoc.Footer.AddElement(footerText);
byte[] outBuffer = pdfDoc.Save();
pdfDoc.Close();
//...
If I add the footer element to the htmlToPdfConverter it displayed well.
how can I display it?
Thanks.
I have also run into the same situation. Basically, I wanted to add header and footer to existing PDFs without using htmltopdfconverter.
Here is the solution with a few tweaks to your existing code:
//Create a blank document.
Document MergeDocument = new Document();
Document pdfDoc = new Document("myFilePath.pdf");
//Merged n number of existing PDFs to newly created document.
MergedDocument.AppendDocument(pdfDoc, true, true, true);
//create the footer element
TextElement footerText = new TextElement(0, 30, "Page &p; of &P; ",
new System.Drawing.Font( new System.Drawing.FontFamily("Arial"), 10, System.Drawing.GraphicsUnit.Point));
footerText.EmbedSysFont = true;
footerText.TextAlign = HorizontalTextAlign.Right;
//Apply footer to the newly created document after all documents appended.
MergeDocument.AddFooterTemplate(50);
MergeDocument.Footer.AddElement(footerText);
byte[] outBuffer = MergeDocument.Save();
MergeDocument.Close();
In order to apply headers and footer on existing PDF documents you have to create an empty Document object, define the header and footer and then append the external PDF documents using the method Document.AppendDocument(Document doc, bool enableHeaderAndFooter, bool drawHeaderOnFirstPage, bool drawFooterOnFirstPage).
Below you can find a complete example for this. You can also find an online demo at Add Header and Footer in External PDF
public void protected void createPdfButton_Click(object sender, EventArgs e)
{
// Create a PDF document
Document pdfDocument = new Document();
// Add a PDF page to PDF document
PdfPage pdfPage = pdfDocument.AddPage();
try
{
// Add a default document header
AddHeader(pdfDocument, true);
// Add a default document footer
AddFooter(pdfDocument, true, true);
// Create a HTML to PDF element to add to document
HtmlToPdfElement htmlToPdfElement = new HtmlToPdfElement(0, 0, urlTextBox.Text);
// Optionally set a delay before conversion to allow asynchonous scripts to finish
htmlToPdfElement.ConversionDelay = 2;
// Add HTML to PDF element to document
pdfPage.AddElement(htmlToPdfElement);
// Automatically close the external PDF documents after the final document is saved
pdfDocument.AutoCloseAppendedDocs = true;
// Insert an external PDF document in the beginning of the final PDF document
string pdfFileBefore = Server.MapPath("~/DemoAppFiles/Input/PDF_Files/Merge_Before_Conversion.pdf");
Document startExternalDocument = new Document(pdfFileBefore);
pdfDocument.InsertDocument(0, startExternalDocument, addHeaderFooterInInsertedPdfCheckBox.Checked,
showHeaderInFirstPageCheckBox.Checked, showFooterInFirstPageCheckBox.Checked);
// Append an external PDF document at the end of the final PDF document
string pdfFileAfter = Server.MapPath("~/DemoAppFiles/Input/PDF_Files/Merge_After_Conversion.pdf");
Document endExternalDocument = new Document(pdfFileAfter);
pdfDocument.AppendDocument(endExternalDocument, addHeaderFooterInAppendedPdfCheckBox.Checked, true, true);
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = pdfDocument.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Header_Footer_in_External_PDF.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
finally
{
// Close the PDF document
pdfDocument.Close();
}
}
/// <summary>
/// Add a header to document
/// </summary>
/// <param name="pdfDocument">The PDF document object</param>
/// <param name="drawHeaderLine">A flag indicating if a line should be drawn at the bottom of the header</param>
private void AddHeader(Document pdfDocument, bool drawHeaderLine)
{
string headerHtmlUrl = Server.MapPath("~/DemoAppFiles/Input/HTML_Files/Header_HTML.html");
// Create the document footer template
pdfDocument.AddHeaderTemplate(60);
// Create a HTML element to be added in header
HtmlToPdfElement headerHtml = new HtmlToPdfElement(headerHtmlUrl);
// Set the HTML element to fit the container height
headerHtml.FitHeight = true;
// Add HTML element to header
pdfDocument.Header.AddElement(headerHtml);
if (drawHeaderLine)
{
float headerWidth = pdfDocument.Header.Width;
float headerHeight = pdfDocument.Header.Height;
// Create a line element for the bottom of the header
LineElement headerLine = new LineElement(0, headerHeight - 1, headerWidth, headerHeight - 1);
// Set line color
headerLine.ForeColor = Color.Gray;
// Add line element to the bottom of the header
pdfDocument.Header.AddElement(headerLine);
}
}
/// <summary>
/// Add a footer to document
/// </summary>
/// <param name="pdfDocument">The PDF document object</param>
/// <param name="addPageNumbers">A flag indicating if the page numbering is present in footer</param>
/// <param name="drawFooterLine">A flag indicating if a line should be drawn at the top of the footer</param>
private void AddFooter(Document pdfDocument, bool addPageNumbers, bool drawFooterLine)
{
string footerHtmlUrl = Server.MapPath("~/DemoAppFiles/Input/HTML_Files/Footer_HTML.html");
// Create the document footer template
pdfDocument.AddFooterTemplate(60);
// Set footer background color
RectangleElement backColorRectangle = new RectangleElement(0, 0, pdfDocument.Footer.Width, pdfDocument.Footer.Height);
backColorRectangle.BackColor = Color.WhiteSmoke;
pdfDocument.Footer.AddElement(backColorRectangle);
// Create a HTML element to be added in footer
HtmlToPdfElement footerHtml = new HtmlToPdfElement(footerHtmlUrl);
// Set the HTML element to fit the container height
footerHtml.FitHeight = true;
// Add HTML element to footer
pdfDocument.Footer.AddElement(footerHtml);
// Add page numbering
if (addPageNumbers)
{
// Create a text element with page numbering place holders &p; and & P;
TextElement footerText = new TextElement(0, 30, "Page &p; of &P; ",
new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10, System.Drawing.GraphicsUnit.Point));
// Align the text at the right of the footer
footerText.TextAlign = HorizontalTextAlign.Right;
// Set page numbering text color
footerText.ForeColor = Color.Navy;
// Embed the text element font in PDF
footerText.EmbedSysFont = true;
// Add the text element to footer
pdfDocument.Footer.AddElement(footerText);
}
if (drawFooterLine)
{
float footerWidth = pdfDocument.Footer.Width;
// Create a line element for the top of the footer
LineElement footerLine = new LineElement(0, 0, footerWidth, 0);
// Set line color
footerLine.ForeColor = Color.Gray;
// Add line element to the bottom of the footer
pdfDocument.Footer.AddElement(footerLine);
}
}

how to get image file type from ios gallery Titanium Appcelerator

I want get the name of the image type like i selected .png ,.gif ...etc,I need to get the name of the selected from iOS gallery.For that i am using the following code snippet.
Titanium.Media.openPhotoGallery({
success:function(event)
{
var cropRect = event.cropRect;
image = event.media;
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
var newImageName = new Date().getTime() + ".jpg";
//var newImageName = new Date().getTime();
var filename = Titanium.Filesystem.applicationDataDirectory + "/" + newImageName;
Ti.App.Properties.setString("filename", filename);
newImage = Titanium.Filesystem.getFile(filename);
newImage.write(image);
}
through every file is converted to jpg format .I want get the what every file extension in gallery.

MonoTouch.Dialog: When no ImageUrl, default image on StyledStringElement

I am setting the ImageUrl of a StyledStringElement, but do not know if the url exists. I'd like to put in an placeholder image that is used until the image is successfully downloaded:
var item = new StyledStringElement(n.Title);
item.ImageUri = new Uri(n.ImageThumbUrl);
I get this now:
Helpful: http://yusinto.blogspot.ca/2012/05/background-image-downloading-with.html
I copied the StyledStringElement to a new StyledStringElementLoader and edited this code:
if (extraInfo.Uri != null)
{ img = ImageLoader.DefaultRequestImage (extraInfo.Uri, this);
if(img==null)
img=myLoaderImagePassedToConstructor;
}

Is there any way to display image in client browser without uploading it to server?

I am writing a simple "Book" create page in ASP.NET MVC. User can create book by filling title,year etc.. and selecting a cover image. When user press "Create" button Form sends image and data to Controller action called "Create" then I save image to disk and data to database.
But I want to display image when user select image by file dialog.To do this As far as I know I must upload image to server then display in client browser.But if a user cancels the "Create" operation after uploading image, the image will remain in the server's disk.So How can I deal with these temp images or Is there any way to display image in client browser without upload to server?
Due to security reasons, you will not be able to display the images to the users without uploading them to the server. Displaying images from file system is considered a security risk.
EDIT: To remove the unused images, you can create a thread to run a cleanup routine to which will delete them from the upload directory regularly.
Yes, using Silverlight, for example:
In Page.xaml:
<StackPanel x:Name="LayoutRoot" Background="White">
<Button x:Name="btn1" Content="Select image file">
<Image x:Name="img1">
</StackPanel>
and in Page.xaml.cs:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
btn1.Click += new RoutedEventHandler(btn1_Click);
}
void btn1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == true)
{
Stream s = ofd.File.OpenRead();
BitmapImage bi = new BitmapImage();
bi.SetSource(s);
img1.Source = bi;
s.Close();
}
}
}
Read more here.
Yes, you can using javascript
Javascript:
function showThumbnail(files){
for(var i=0;i<files.length;i++){
var file = files[i]
var imageType = /image.*/
if(!file.type.match(imageType)){
console.log("Not an Image");
continue;
}
var image = document.createElement("img");
var thumbnail = document.getElementById("thumbnail");
image.file = file;
thumbnail.appendChild(image)
var reader = new FileReader()
reader.onload = (function(aImg){
return function(e){
aImg.src = e.target.result;
};
}(image))
var ret = reader.readAsDataURL(file);
var canvas = document.createElement("canvas");
ctx = canvas.getContext("2d");
image.onload= function(){
ctx.drawImage(image,100,100)
}
}
}
var fileInput = document.getElementById("upload-image");
fileInput.addEventListener("change",function(e){
var files = this.files
showThumbnail(files)
},false)
HTML:
<input type="file" id="upload-image" multiple="multiple"></input>
<div id="thumbnail"></div>
You just need the input field and The div to display the thumbnail image, and on change for the input field will call showThumbnail function which will append img inside the "thumbnail" div.
You can do it with Simple javascript...
assign the selected image path.. to image tag prefixing the file://, n it works the way you want it to be

Resources