Fill Windows Share Charm with Clipboard Data - windows-8.1

I want to share data in the Clipboard (for example Images) through the share charm. Is it possible to use the windows clipboard content in the Windows 8.1 Share Charm? Unfortunately the DataTransferManager isn't available in desktop apps, so how am I able to share the clipboard with the charms-bar?

You can’t copy to the clipboard via the share charm, but you can certainly build the functionality into your app. To copy an image to the clipboard you could do something like this:
void OnCopyAppBarButtonClick(object sender, RoutedEventArgs args)
{
Windows.ApplicationModel.DataTransfer.DataPackage dataPackage = new DataPackage
{
RequestedOperation = DataPackageOperation.Move
};
dataPackage.SetBitmap(bitmapStream);
Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
}
Note that you'll need to convert your image to a RandomAccessStreamReference.
The DataPackage class also contains other methods to copy other data types - checkout the documentation here: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.datapackage.aspx

Related

How to convert a emf image file into PNG format in Azure web app

I want to convert a emf image file into PNG format.It works in local machine. But while running it in azure does not give a correct output. It gives only blank image frame.What should I do?
According to your description and your profile, I suggest you could use System.Drawing.Image class to convert the emd to png.
I also created a test demo and publish it to the azure, it works well.
More details, you could refer to this codes:
protected void Button2_Click(object sender, EventArgs e)
{
System.Drawing.Image image1 = System.Drawing.Image.FromFile(Server.MapPath(#"/image/test.Emf"));
image1.Save(Server.MapPath(#"/image/test2.png"), System.Drawing.Imaging.ImageFormat.Png);
}
If you use another way and still face this issue, I suggest you could post more relevant codes for us to repro your issue.

Azure functions structure from a Git repository

I have a C# class that does an address lookup. I want to expose this as an Azure function. I've been going through the documentation but can't see how I can/if it's possible to do the following:
I have a Git repository in Team Services that contains a class library of my AddressLookup. Can my Function reference this project?
If I look at the folder structure of the site I can see it has copied over all the source files from the Git repository, can I get it to build the solution or does it literally just pull all the files?
Where in the solution do I put the function? Do I create a solution folder of the name of the function and place the relevant files in there?
My AddressLookup class returns an object that is defined in the class library. Will the function be able to use and return this?
Thanks
Alex
Follow-up to Q1: Are you trying to setup CI? For continuous integration with Azure Functions, you may reference the following:
https://azure.microsoft.com/en-us/documentation/articles/functions-continuous-deployment/#setting-up-continuous-deployment
http://flgmwt.github.io/azure/azure-functions/c-sharp/2016/04/04/azure-fns-with-ci.html
--Update 10/17--
Specific to Team Services, here are the steps:
Make sure that your VSTS account is linked to your Azure Subscription. Follow the instructions in this article.
Navigate to the Functions Portal for your Function App and click on Function app Settings -> Configure continuous integration.
In the Deployements blade, click on Setup and configure your Deployment source information (see sample snapshot below). Click on the OK button. Wait for the sync to succeed. Close the Deployments blade.
Give it a minute and refresh your Functions Portal session. You should now see the function added to your Function site. The snapshot below is my AddressLookup function that was synced from my Team Services project named MyFirstProject.
Note the disclaimer message above the Code editor. If you hook up CI for your Function, you will not be able to edit it in the Functions Portal. Since this particular example requires a request body, you will need to test it using Postman.
--End of update 10/17--
Answer to Q2:
Here's a good documentation describing the folder structure of Azure Functions:
https://azure.microsoft.com/en-us/documentation/articles/functions-reference/
I also recommend the follow-up documentation specific to C# development for Azure Functions:
https://azure.microsoft.com/en-us/documentation/articles/functions-reference-csharp/
Answer to Q3 & Q4: I will attempt to answer these by providing a sample implementation. I don't have any context on the implementation of your AddressLookup library, however, in the interest of providing an example, I am going to take a wild leap and assume that it is a library that will perform some Geocoding operations. Assuming again that you want to use this library in an HTTP-triggered Function, you may begin by first generating the AddressLookup.dll and then uploading it to the bin folder inside your Function. You may then reference that DLL from your Function script.
For instance, using this article as a reference, I generated a AddressLookup.dll library in Visual Studio that has the following implementation. This DLL will serve as a proxy for your AddressLookup library so that I can demonstrate how we can use it in a Function.
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Xml.Linq;
namespace AddressLookup
{
public class GeoLocation
{
public double Longitude { get; set; }
public double Latitude { get; set; }
}
public class GeoCoder
{
private const string geoCodeLookupUrlPattern =
"https://maps.googleapis.com/maps/api/geocode/xml?address={0}&key={1}";
private const string addressLookupUrlPattern =
"https://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&key={2}";
private string _apiKey = null;
public GeoCoder(string apiKey)
{
if (string.IsNullOrEmpty(apiKey))
{
throw new ArgumentNullException("apiKey");
}
_apiKey = apiKey;
}
public GeoLocation GetGeoLocation(string address)
{
GeoLocation loc = null;
string encodedAddress = HttpUtility.UrlEncode(address);
string url = string.Format(geoCodeLookupUrlPattern, encodedAddress, _apiKey);
WebRequest request = WebRequest.Create(url);
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
if (stream != null)
{
XDocument document = XDocument.Load(new StreamReader(stream));
XElement longitudeElement = document.Descendants("lng").FirstOrDefault();
XElement latitudeElement = document.Descendants("lat").FirstOrDefault();
if (longitudeElement != null && latitudeElement != null)
{
loc = new GeoLocation
{
Longitude = Double.Parse(longitudeElement.Value, CultureInfo.InvariantCulture),
Latitude = Double.Parse(latitudeElement.Value, CultureInfo.InvariantCulture)
};
}
}
}
}
return loc;
}
public string GetAddress(GeoLocation loc)
{
string address = null;
string url = string.Format(addressLookupUrlPattern, loc.Latitude, loc.Longitude, _apiKey);
WebRequest request = WebRequest.Create(url);
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
if (stream != null)
{
XDocument document = XDocument.Load(new StreamReader(stream));
XElement element = document.Descendants("formatted_address").FirstOrDefault();
if (element != null)
{
address = element.Value;
}
}
}
}
return address;
}
}
}
Now, let's create an HTTP-Triggered Function by performing the following steps:
Go to the Functions Portal. Create a Function using the HTTP
Trigger - C# template.
Fill in the name (e.g., AddressLookup) and authorization level (e.g., Anonymous). You should now see a Function named AddressLookup created with some pre-populated code.
On the left pane, click on the Function app settings button.
Optional: Click on Configure app Settings. Under the "App settings" section, add a value for the key GoogleMapsAPIKey with your api key, then click on the Save button. Note: If you skip this step, then you will need to hard-code the key in your function code later.
Next, use the Kudu console to upload your DLL. Click on the Go to Kudu button. This will launch a new browser window
with a cmd console. Type the following to navigate to your
Function directory,
cd site\wwwroot\AddressLookup
Create a bin folder by typing mkdir bin at the command prompt as follows,
Double-click on the bin folder and upload (see "Add files") the AddressLookup.dll into the folder. When you are done, you should a similar snapshot below,
Go back to the Functions Portal. In your Function's editor, at the bottom of the Code section, click on View Files. You should now see the newly created bin folder as follows,
Replace the contents of the pre-populated Function script with the following code
#r "AddressLookup.dll"
using System;
using AddressLookup;
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
// Reading environment variable from App Settings, replace with hardcoded value if not using App settings
string apiKey = System.Environment.GetEnvironmentVariable("GoogleMapsAPIKey", EnvironmentVariableTarget.Process);
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
string address = data?.address;
string name = data?.name;
GeoCoder geoCoder = new GeoCoder(apiKey);
GeoLocation loc = geoCoder.GetGeoLocation(address);
string formattedAddress = geoCoder.GetAddress(loc);
HttpResponseMessage message = null;
if (name == null)
{
message = req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name in the request body");
}
else
{
var msg = $"Hello {name}. Lon: '{loc.Longitude}', Lat: '{loc.Latitude}', Formatted address: '{formattedAddress}'";
message = req.CreateResponse(HttpStatusCode.OK, msg);
}
return message;
}
Click on the Save button.
In the "Run" section, supply the following request body,
{
"name": "Azure",
"address": "One Microsoft Way Redmond WA 98052"
}
Click on the Run button.
You should see some log entries similar to the following,
2016-10-15T03:54:31.538 C# HTTP trigger function processed a request. RequestUri=https://myfunction.azurewebsites.net/api/addresslookup
2016-10-15T03:54:31.773 Function completed (Success, Id=e4308c0f-a615-4d43-8b16-3a6afc017f73)
and the following HTTP response message,
"Hello Azure. Lon: '-122.1283833', Lat: '47.6393225', Formatted address: '1 Microsoft Way, Redmond, WA 98052, USA'"
Since this is a HTTP-triggered Function, you may also test your Function using Postman. See snapshot below,
If you upload your own DLL in step 5 and edit the Function code to call your library, the Function should work just as well.
Is the assembly you want to reference frozen, or do you want to see updates? If you don't want to see updates, see the answer by Ling Toh.
But if you want to see updates when the assembly updates:
Link your function to a some form of continuous delivery. The official documentation explains how to do this. At the moment, you seem to need a separate git repository, VSTS project (or whatever) to do this easily. (It is possible to edit the deployment process in Kudu, but I would avoid that if you possibly can).
The functions project should contain only the functions code themselves. So it should contain something like the followling:
global.json
host.json
packages.config
Web.config
function1/
function1/run.csx
function1/project.json
function1/function.json
Where you should replace function1 by the name of your function.
Once you've configured this to push to your functions host, you're most of the way to where you want to be. Next, add a function1/run subdirectory where you place yourAssembly.dll. This should be automatically copied here on a successful build of the assembly project. I don't have experience of VSTS to know exactly the best way to do this, so you might need to ask another question.
You've now placed the assembly in the right place. You now refer to it by adding the assembly reference line to the top of your run.csx:
#r "yourAssembly.dll"
Note that all of the references have to be before everything else at the top of the run.csx. So you can put it after other references, but it has to be before anythign else, including load specifications.
Note that for custom assemblies you include the .dll and quote the file, whereas for framework assemblies that aren't referenced by default, you don't
In an ideal world, this will be enough.
But functions doesn't trigger a rebuild if the assembly is updated at the moment, only if project.json, run.csx or function.json is updated. So as part of this process, I then look at the end of the file and add or remove a blank line. It needs to be meaningless (so that you're not changing something important), but enough for your version control tool to think that the file has changed. Clearly, this step is not necessary if you've also made other changes to the file.
If you're using git, you'd now commit and push the changes up. Functions will see that function has changed, and recompile. You should see this in the log pane in the function itself.
Note that if you have two functions using the same dependent assembly, you need to copy it into both function folders; this can't be shared.

Get cellular carrier's name from windows phone 10

I am currently developing UWP application that I need to get the celullar carrier's name. I saw posts about it for windows phone 8 and 8.1. They use:
DeviceNetworkInformation.CellularMobileOperator;
But it is depricated now.
Here is what I want for better clarification:
Does anyone knows how to make it work for windows phone 10?
All the help would be greatly appreciated. Thanks in advance.
We can use PhoneLine.NetworkName to get the name of the current network that is being used by the phone line.
To use the Windows.ApplicationModel.Calls namespace, we need add the reference like the following image:
The telephony options and information classes use the CallsPhoneContract. In order to use these classes, you will need to declare the phoneCall capability in your manifest like the following image.
For example:
private async void Button_Click(object sender, RoutedEventArgs e)
{
PhoneCallStore phoneCallStore = await PhoneCallManager.RequestStoreAsync();
Guid lineId = await phoneCallStore.GetDefaultLineAsync();
PhoneLine line = await PhoneLine.FromIdAsync(lineId);
var currentOperatorName = line.NetworkName;
}
An example that demonstrates how to use much of the functionality of the Windows.ApplicationModel.Calls API can be found here.
The UWP does not provide built-in api's for things like Mobile Network and Carrier related information, so MNC, MCC, carrier name etc are not possible to get afaik.
From the documentation thing might help you. I'm not sure, but it stands to reason that some of that information might be hidden there.
Microsoft documentation
Javascript:
var networkInformation = Windows.Networking.Connectivity.NetworkInformation;
C#
public static class NetworkInformation
C++
public ref class NetworkInformation abstract sealed
And you might need to go into one of the submethods provided by this class. Maybe getConnectionProfiles will do what you want

How do i get current Branch path from Source control explorer using VS package

I have created VS extension that creates a menu command on Source control explorer by right click on that it open custom form,Now i want to display current TFS path(from where user right click) in that custom form.Same as TFS "Branching and Merging => Branch" Source Path.
Any help Appreciate.
You can use the VersionControlExplorerExt object with its properties SelectedItems, CurrentFolderItem, etc. From a package it would be something like:
private void MenuItemCallback(object sender, EventArgs e)
{
Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt versionControlExt;
Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt versionControlExplorerExt;
EnvDTE.DTE dte;
try
{
dte = base.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
versionControlExt = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt")
as Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt;
versionControlExplorerExt = versionControlExt.Explorer;
MessageBox.Show(versionControlExplorerExt.CurrentFolderItem.LocalPath);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
The extensibility for Source Control Explorer should be exposed through the VersionControlExt.Explorer class. The VersionControlExt.Explorer.SelectedItems property should contain the server paths for the selected items. Here is an old blog post that might also have some useful information for writing extensions.

Read/Write Excel Files Directly To/From Memory

Several people have asked, in a roundabout way, but I have yet to see a workable solution. Is there any way to open an excel file directly from memory (like a byte[]) ? Likewise is there a way to write a file directly to memory? I am looking for solutions that will not involve the hard disk or juggling temporary files. Thanks in advance for any suggestions.
Excel does not support saving to memory, at least not that I have been able to find - and I have looked because I could use it.
SpreadsheetGear for .NET can save to and load from a byte array. Here is a simple example:
using System;
using SpreadsheetGear;
namespace Program
{
class Program
{
static void Main(string[] args)
{
// Create a simple Hello World workbook.
IWorkbook workbook = Factory.GetWorkbook();
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].Value = "Hello World";
// Save to memory.
byte[] data = workbook.SaveToMemory(FileFormat.OpenXMLWorkbook);
// Load from memory and output the contents of A1.
workbook = Factory.GetWorkbookSet().Workbooks.OpenFromMemory(data);
worksheet = workbook.Worksheets[0];
Console.WriteLine("A1={0}", worksheet.Cells["A1"].Value);
}
}
}
You can see live SpreadsheetGear samples here and download the free trial here if you want to try it yourself.
Disclaimer: I own SpreadsheetGear LLC

Resources