How to upload file with BackgroundTransfer for windows phone - windows-phone-7

have check the documentation but there is no sample to show how this is done. This is the code for download :
void Download()
{
btr = new BackgroundTransferRequest(remoteVideoUri, localDownloadUri);
btr.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
BackgroundTransferService.Add(btr);
btr.TransferProgressChanged += new EventHandler<BackgroundTransferEventArgs>(btr_TransferProgressChanged);
btr.TransferStatusChanged += new EventHandler<BackgroundTransferEventArgs>(btr_TransferStatusChanged);
}
For upload, can it be done with this backgroudTransfer ? what and how to do it?

I haven't yet had chance to look at the background transfer stuff in Mango yet, but there is a lab that covers it in the Mango Offline Training Kit: http://msdn.microsoft.com/en-us/WP7MangoTrainingCourse and I do know that it can do uploads as well as downloads.

Related

How to get the battery level from Kontakt.io beacons using AltBeacon API

I need to get the battery level from the kontakt.io beacons. I have set the layout as below and the DataFields are empty when I read the beacons in RangingBeaconsInRegion.
I was expecting I could read the battery level from the last bit as described in the Kontakt.io documentation.
This is my current code:
private BeaconManager InitializeBeaconManager()
{
BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);
var iBeaconParser = new BeaconParser();
iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
bm.BeaconParsers.Add(iBeaconParser);
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);
return bm;
}
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
if (e.Beacons.Count > 0)
{
var beacon = e.Beacons.FirstOrDefault();
var data = beacon.DataFields.FirstOrDefault();
// here DataFields is empty!
}
}
I am using Xamarin Forms and this is the code for the Android Version.
Is this possible? or do I need to use the Kontakt.io API?
UPDATE
I have removed all parsers before apply the new layout and I am able to read the dataFields. However, I am getting a value 8 which I have no idea what this value means.
I am not positive the syntax on Xamarin, but try removing all existing beacon parsers before adding your custom one. I suspect the built in iBeacon parser is still active And it is matching first.
The battery level in Kontakt.io beacons are part of their "scan response packet", not part of the iBeacon structure, you'll have to use CoreBluetooth to read Characteristic 1, Service 5.
A quick breakdown of how this works is also described here, and the recently launched Xamarin component uses the same CoreBluetooth approach.

LoadVars() and method POST for swiffty

He did not know how someone could remake the piece of code to make it Google swiffty received since I wrote that this was not supported. This is a game in flash as1.
on (release) {
sendscore = new LoadVars();
sendscore.gscore = _root.Score;
sendscore.gname = "gamename";
sendscore.send("index.php?act=Arcade&do=newscore","_self","POST");
}
As far as I know, Swiffy only supports AS 2.0 and above

Geolocator and accuracy in Windows Phone 8

I have a few questions about Geolocator and property DesiredAccuracy.
I have the method GetMyPosition:
public async Task<Geoposition> GetMyPosition()
{
Geoposition myGeoposition = null;
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracy = PositionAccuracy.High;
try
{
myGeoposition = await myGeolocator.GetGeopositionAsync();
return myGeoposition;
}
catch (Exception ex)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Can't get the position");
});
return null;
}
}
1) Why
Geolocator.DesiredAccuracy = PositionAccuracy.High;
Geolocator.GetGeopositionAsync();
always return Geoposition.Coordinate.PositionSource = Cellular with accuracy 400 - 1600 m (on device Nokia Lumia 520)?
2) Under what settings I can get a high accuracy (50 - 100 m) and PositionSource = Satellite?
3) If I have the loaded maps on my device and I activated the airplane mode on the device, then code
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracy = PositionAccuracy.High;
try
{
myGeoposition = await myGeolocator.GetGeopositionAsync();
return myGeoposition;
}
will work? Without a celluar, only a satellite?
4) How strong is the precision of coordinates depends on the device?
Thanks in advance!
Taken from MSDN
Although the Location Service uses multiple sources of location information, and any of the sources may not be available at any given time (for example, no GPS satellites or cell phone towers may be accessible), the native code layer handles the work of evaluating the available data and choosing the best set of sources. All your application needs to do is to choose between high accuracy or the default, power-optimized setting. You can set this value when you initialize the main Location Service class, GeoCoordinateWatcher.
C#
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
So it seems like you can't control which source is used but rather the available source will be used based on the specified position accuracy on GeoCoordinateWatcher. Try initializing a GeoCoordinateWatcher with high accuracy and see what happens
var geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
You can use
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracyInMeters = 20;
...
to explicitly state how accurate you want the location to be which would allow the device to manage its power a little better but whether you get close to that accuracy with your result depends on the quality of the location the device can get. If you're inside a building for example you're not going to get something that accurate without connecting to WIFI

Magic in Windows Phone isolated storage performance

I have merged small files into big one. On app first start this file is read and one by one small files are created on file system (Isolated Storage).
When this file contains 44 small files and is ~200kb - algorithm works for 120ms on device.
When this file contains 140 even smaller files and is ~400kb - algorithm works for 3000 ms on device.
If i take from both files only 44 files - first one still works for ~120, second works for ~800ms.
This seems as wonder for me.
Format of data in file is simple
-INT32 - ENTRIES COUNT
--STRING ENTRY NAME |
--INT32 ENTRY DATA LENGTH | REPEATS {ENTRY COUNT} TIMES
--BYTE[] ENTRY DATA |
For me this seems like a magic in Windows Phone IsolatedStorage mechanisms.
There are completely no reasons for second file to work 7-8 times slower when copying equal number of entries.
Repro project - https://www.dropbox.com/s/6bjsve7p8wew3kb/IsoStorageWonder.zip?m
Code:
public static void CopyCache(ILogger logger)
{
using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
var streamInfo = Application.GetResourceStream(new Uri(_dataFilePath, UriKind.RelativeOrAbsolute));
isoStorage.CreateDirectory("HttpCache");
var binaryReader = new BinaryReader(streamInfo.Stream);
{
int itemsCount = binaryReader.ReadInt32();
for (int i = 0; i < ENTRIES_COUNT; i++)
{
string fileName = binaryReader.ReadString();
int length = binaryReader.ReadInt32();
byte[] data = binaryReader.ReadBytes(length);
using (
var fileStream =
new IsolatedStorageFileStream(
Path.Combine(_rootCacheDir, fileName),
FileMode.Create,
FileAccess.Write,
FileShare.None,
isoStorage))
{
fileStream.Write(data, 0, data.Length);
}
}
}
}
}
MAGIC!
I have similar problem with WebClient performance. In emulator request takes 0.3-0.5 seconds, on device 8-22 seconds. I was very confused. But in my case the solution was very simple: DO NOT TEST PERFORMANCE ON DEVISE IN DEBUG MODE. What I do:
Compile project to your device.
Stop Debugging
Close your app on phone (and better reboot device)
All works like a charm))
In your test app IsoStorageWonder:
Emulator 551ms
Emulator 256 mB 564ms
HTC Radar WP7.8 Debug Mode 1835ms
HTC Radar WP7.8 Not Debug Mode 958ms
I hope my reserch help you. Regards
UPD
Test with output2
Emulator 440ms
Emulator 256 mB 447ms
HTC Radar WP7.8 Debug Mode 287ms // very nice
HTC Radar WP7.8 Not Debug Mode 144ms // also nice

mouse double click is not working quite good

I am using the following code to record screen, when recording, when using mouse to double click some item, for example double click a ppt to open it in PowerPoint, it is not very responsive. I have tried and it is much better when using screen recording function of Windows Media Encoder 9. Any ideas what is wrong?
My environment: Windows Vista + Windows Media Encoder 9 + VSTS 2008 + C#. I wrote the following code in the initialization code of a Windows Forms application, and I suspect something wrong with my Windows Forms application?
My code,
IWMEncSourceGroup SrcGrp;
IWMEncSourceGroupCollection SrcGrpColl;
SrcGrpColl = encoder.SourceGroupCollection;
SrcGrp = (IWMEncSourceGroup)SrcGrpColl.Add("SG_1");
IWMEncVideoSource2 SrcVid;
IWMEncSource SrcAud;
SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
SrcVid.SetInput("ScreenCap://ScreenCapture1", "", "");
SrcAud.SetInput("Device://Default_Audio_Device", "", "");
// Specify a file object in which to save encoded content.
IWMEncFile File = encoder.File;
string CurrentFileName = Guid.NewGuid().ToString();
File.LocalFileName = CurrentFileName;
CurrentFileName = File.LocalFileName;
// Choose a profile from the collection.
IWMEncProfileCollection ProColl = encoder.ProfileCollection;
IWMEncProfile Pro;
for (int i = 0; i < ProColl.Count; i++)
{
Pro = ProColl.Item(i);
if (Pro.Name == "Screen Video/Audio High (CBR)")
{
SrcGrp.set_Profile(Pro);
break;
}
}
encoder.Start();
thanks in advance,
George
I faced the same problem. But the problem doesn't reside in your code or mine. When I tried to capture screen from Windows Media Encoder application itself I faced the same problem too in about 50% of the sessions. It's evident that it's a bug in WindowsMediaEncoder itself.
George
Here are a couple options (from http://www.windowsmoviemakers.net/Forums/ShowPost.aspx?PostID=1982):
Enable the MouseKeys Accessibility option, and type + to double-click
Run the encoder and target application on different machines, and capture a remote desktop session

Resources