Windows phone 8.1 the name 'Thread' does not exist in current context - windows-phone-8.1

I am working on windows phone 8.1.
AM getting an error the name 'Thread' does not exist in current context even adding this->
using System.Threading;
i checked this folder C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhoneApp\v8.1
System.Threading dll is avaliable.
If i select the language in listbox. The whole page has to be changed to that language
SO
private void LocList_SelectedIndexChanged(object sender, SelectionChangedEventArgs e)
{
var selectedCulture = locList.SelectedIndex.ToString();
string cul;
switch (selectedCulture)
{
case "0":
cul = "zh-CN";
break;
case "1":
cul = "da-DK";
break;
case "2":
cul = "fr-FR";
break;
case "3":
cul = "en-US";
break;
case "4":
cul = "en-GB";
break;
default:
cul = "en-US";
break;
}
CultureInfo newCulture = new CultureInfo(cul);
Thread.CurrentThread.CurrentCulture = newCulture;
}
SO am setting culture to Current Thread and planning to reload the page

Add reference System.Thread maybe is missing.

Related

Change date&time format in date picker SSRS

how i can change format in date and time picker for Reporting services. Currently is always in format dd/MM/yyyy, system date&time format is the same. I want to change date to be in format MM/dd/yyyy
In your designer, the date format is determined by the culture of the operating system.
Once deployed, the date format is determined by language of the browser.
Necromancing.
Yes, you can actually do that - sort of.
First, notice that SSRS takes the date format from the language that is specified in your browser.
So you could just change the language of your browser.
Obviously, you don't wanna tell each and every of your users to do that (if they have the rights & skills to do so in the first place).
So you pass an additional parameter into your report:
I called it in_sprache (Sprache means language in German, with possible values "DE, "FR", "IT", "EN").
Now you need to change the localization process, by overriding the virtual method "InitializeCulture" in ReportViewer.aspx.
You can find ReportViewer in
C:\Program Files\Microsoft SQL Server\MSRS<Version>.MSSQLSERVER
C:\Program Files\Microsoft SQL Server\MSRS<Version>.<Instance>
e.g.
C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER
There you add (in the source-code of the /ReportServer/Pages/ReportViewer.aspx):
<script type="text/C#" runat="server">
protected override void InitializeCulture()
{
string sprache = System.Web.HttpContext.Current.Request.QueryString["in_sprache"];
if(string.IsNullOrEmpty(sprache))
sprache = "";
switch(sprache.ToLowerInvariant())
{
case "de":
sprache = "de-CH";
break;
case "fr":
sprache = "fr-CH";
break;
case "it":
sprache = "it-CH";
break;
case "en":
sprache = "en-US";
break;
default:
sprache = "";
break;
}
// System.Web.HttpContext.Current.Response.Write(sprache);
if(!String.IsNullOrEmpty(sprache))
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(sprache);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(sprache);
}
base.InitializeCulture();
}
</script>
This will override how ASP.NET localises, taking the value of the url-parameter in_sprache (in_sprache must be a parameter of your report) instead of the browser-user-language.
Now, unfortunately, you must also override context.Request.UserLanguages for the datepicker to work properly... (otherwise you get an error if culture is en-US and day > 12)
you can do so only by adding a HTTP-Module (libRequestLanguageChanger.dll)
into the web.config of ReportServer
<system.web>
[...]
<httpModules>
[...]
<add name="RequestLanguageChanger" type="libRequestLanguageChanger.RequestLanguageChanger, libRequestLanguageChanger" />
</httpModules>
[...]
</system.web>
.
(Requires changing trust-level from rosetta to "Full", unless you can figure out how to change the rosetta-policy to allow this http-module).
Since we can also override InitializeCulture in the HTTP-Module, you don't really have to add the runat="server" script to ReportViewer.aspx.
namespace libRequestLanguageChanger
{
public class RequestLanguageChanger : System.Web.IHttpModule
{
void System.Web.IHttpModule.Dispose()
{
// throw new NotImplementedException();
}
void System.Web.IHttpModule.Init(System.Web.HttpApplication context)
{
// https://stackoverflow.com/questions/441421/httpmodule-event-execution-order
context.BeginRequest += new System.EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, System.EventArgs e)
{
System.Web.HttpApplication application = sender as System.Web.HttpApplication;
System.Web.HttpContext context = application.Context;
if (context.Request != null)
{
// string language = context.Request.Headers["Accept-Language"];
string language = null;
// string url = context.Request.RawUrl;
// string referrer = null;
if (context.Request.UrlReferrer != null)
{
// referrer = context.Request.UrlReferrer.OriginalString;
string queryString = context.Request.UrlReferrer.Query;
System.Collections.Specialized.NameValueCollection queryStrings = System.Web.HttpUtility.ParseQueryString(queryString);
language = queryStrings["in_sprache"];
}
if(context.Request.QueryString["in_sprache"] != null)
language = context.Request.QueryString["in_sprache"];
if (!string.IsNullOrEmpty(language))
{
language = language.ToLowerInvariant();
switch (language)
{
case "de":
language = "de-CH";
break;
case "fr":
language = "fr-CH";
break;
case "it":
language = "it-CH";
break;
case "en":
language = "en-US";
break;
default:
language = "";
break;
}
} // End if (!string.IsNullOrEmpty(sprache))
// SQL.Log(url, referrer, sprache);
// Simulate Browser-Language = in_sprache
if (!string.IsNullOrEmpty(language))
{
// context.Request.Headers["Accept-Language"] = language;
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(language);
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
if (context.Request.UserLanguages != null)
{
// System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(context.Request.UserLanguages[0]);
for (int i = 0; i < context.Request.UserLanguages.Length; ++i)
{
// context.Request.UserLanguages[i] = "en-US";
context.Request.UserLanguages[i] = language;
} // Next i
} // End if (context.Request.UserLanguages != null)
} // End if (!string.IsNullOrEmpty(language))
} // End if (context.Request != null)
} // End Sub context_BeginRequest
} // End Class
} // End Namespace
And there you are, ReportServer with a "custom"-culture date-format, without having to tell the user to change the browser-language.
You can fetch the links from a SQL-table, where you can replace the text {#language} with the culture-name of your user (in my case DE, FR, IT, EN, since those are the languages spoken in Switzerland).
SELECT
REPLACE(RE_Link, '{#language}', T_Users.USR_Language)
FROM T_Reports
LEFT JOIN T_Users ON USR_ID = #usr
-- http://localhost/Reportserver?/SomeCompany/SomeReport&rs:Command=Render&in_sprache=de
-- http://localhost/Reportserver?/SomeCompany/SomeReport&rs:Command=Render&in_sprache=fr
-- http://localhost/Reportserver?/SomeCompany/SomeReport&rs:Command=Render&in_sprache=it
-- http://localhost/Reportserver?/SomeCompany/SomeReport&rs:Command=Render&in_sprache=en

Get cocos2d-x keyboard info on android

I simply insert following codes in a clean base(at the final of HelloWorld::init()) produced by cocos new:
auto kl = EventListenerKeyboard::create();
kl->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event) {
CCLOG("%s> keyCode=%d",__FUNCTION__,keyCode);
};
auto ed = Director::getInstance()->getEventDispatcher();
ed->addEventListenerWithSceneGraphPriority(kl,this);
On windows, it worked well. But nothing happened on android.
Log with value of keyCode should be left in logcat, I think.
Do I miss anything?
Approach One:
If you just need to handle keyboard as key-event, It's as easy as these below lines of code:
HelloWorld::init()
{
...
auto keyboardListener = EventListenerKeyboard::create();
keyboardListener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event)
{
switch (keyCode)
{
case EventKeyboard::KeyCode::KEY_UP_ARROW: /*Jump maybe*/ break;
case EventKeyboard::KeyCode::KEY_DOWN_ARROW: /*Crouch maybe*/ break;
case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: /*Move Right maybe*/ break;
case EventKeyboard::KeyCode::KEY_LEFT_ARROW: /*Move Left maybe*/ break;
}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyboardListener, this);
...
return true;
}
I think it's clear enough not to need any extra description.
Approach Two: if you need an input box that user/player can enter string with keyboard and you get what is entered, I recommend to use TextField which is available in cocos2d v3 ( and with some difficulty in v2) and has a full functionality. You can create and initial one of them as:
auto textField = cocos2d::ui::TextField::create("hint: enter here","Arial" , 30);
textField->setTextHorizontalAlignment(cocos2d::TextHAlignment::CENTER);
textField->setTextVerticalAlignment(cocos2d::TextVAlignment::CENTER);
textField->setColor(Color3B(100,100,100));
textField->setMaxLength(10);
textField->setMaxLengthEnabled(true);
textField->setTouchAreaEnabled(true);
textField->setTouchSize(Size(200,400));
textField->setPosition(...);
textField->addEventListener(CC_CALLBACK_2(HelloWorld::textFieldEvent, this));
this->addChild(textField, 10);
You can get entered data any time with std::string enteredData= textField->getString();
You can also do something when user entering text with two event as :
void HelloWorld::textFieldEvent(Ref *pSender, cocos2d::ui::TextField::EventType type)
{
switch (type)
{
case cocos2d::ui::TextField::EventType::ATTACH_WITH_IME:
{
textField->setColor(Color3B::BLACK);
// or whatever elese
break;
}
case cocos2d::ui::TextField::EventType::DETACH_WITH_IME:
{
textField->setColor(Color3B(100,100,100));
// or whatever elese
break;
}
}
}
Enjoy !

windows phone 8 download and play audio on background

I'm using background file transfer and background audio player.
in the TransferStatusChanged event i save the file to the isolated storage then play it with the audio player,
It works fine if the application is active and i want to do the same if the application is not active.
In WP8.0 it isn't possible as your TransferStatusChanged is in your App process which is stopped when you navigate away from it:
When the user navigates forward, away from an app, after the Deactivated event is raised, the operating system will attempt to put the app into a dormant state. In this state, all of the application’s threads are stopped and no processing takes place, but the application remains intact in memory.
You can make it work under LockScreen by disabling IdleDetection but it won't work when your App is put into dormant/tombstoned state.
You may consider to start playing when you activate the App or put some logic in BAP where you can check for example upon TrackChange if the file was downloaded and then play it.
edit
thanks to #Romasz suggestion of use empty track to play while the file complete downloading
then in TrackChange i check if the file downloaded and remove it from the download queue -this can be done in the audio background- things work fine now. here is some code
private AudioTrack GetNextTrack(bool isStart = false)
{
AudioTrack track = null;
using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isStart)
{
currentSongIndex = -1;
}
currentSongIndex++;
if (currentSongIndex == _ProgressList.Count())
{
//currentSongIndex = 0;
return track;
}
if (ISF.FileExists("shared/transfers/" + _ProgressList[currentSongIndex].FileName))
{
var request = requests.Where(it => it.Key == _ProgressList[currentSongIndex].FileName).FirstOrDefault().Value;
if (request != null)
{
bool isDone = ProcessTransfer(request, _ProgressList[currentSongIndex].Directory);
if(!isDone )
{
if(request.BytesReceived > LastDownloadedSize)
{
NumberOfTrialsToLoadNextTrack = 0;
LastDownloadedSize = request.BytesReceived;
}
else
{
++NumberOfTrialsToLoadNextTrack;
}
}
}
}
else
{
++NumberOfTrialsToLoadNextTrack;
}
if (ISF.FileExists(_ProgressList[currentSongIndex].Directory+_ProgressList[currentSongIndex].FileName))
{
track = playList[currentSongIndex];
NumberOfTrialsToLoadNextTrack = 0;
LastDownloadedSize = 0;
}
else
{
currentSongIndex--;
if (NumberOfTrialsToLoadNextTrack < 10)
{
track = new AudioTrack(new Uri("halfsec.mp3", UriKind.Relative),
"empty",
"empty",
"empty",
null);
}
}
}
return track;
}
private bool ProcessTransfer(BackgroundTransferRequest transfer, string directory = "")
{
bool isDone = false;
switch (transfer.TransferStatus)
{
case TransferStatus.Completed:
if (transfer.StatusCode == 200 || transfer.StatusCode == 206)
{
RemoveTransferRequest(transfer.RequestId);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
string filename = transfer.Tag;
System.Diagnostics.Debug.WriteLine(directory + filename);
if (isoStore.FileExists(directory + filename))
{
isoStore.DeleteFile(directory + filename);
}
if (isoStore.FileExists(transfer.DownloadLocation.OriginalString))
{
isoStore.MoveFile(transfer.DownloadLocation.OriginalString, directory + filename);
}
}
isDone = true;
}
else
{
RemoveTransferRequest(transfer.RequestId);
if (transfer.TransferError != null)
{
}
}
break;
}
return isDone;
// NotifyComplete();
}
private void RemoveTransferRequest(string transferID)
{
// Use Find to retrieve the transfer request with the specified ID.
BackgroundTransferRequest transferToRemove = BackgroundTransferService.Find(transferID);
// try to remove the transfer from the background transfer service.
try
{
BackgroundTransferService.Remove(transferToRemove);
}
catch (Exception)
{
}
}
protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
{
switch (playState)
{
case PlayState.TrackEnded:
player.Track = GetNextTrack();
break;
case PlayState.TrackReady:
player.Play();
break;
case PlayState.Shutdown:
// TODO: Handle the shutdown state here (e.g. save state)
break;
case PlayState.Unknown:
break;
case PlayState.Stopped:
break;
case PlayState.Paused:
break;
case PlayState.Playing:
break;
case PlayState.BufferingStarted:
break;
case PlayState.BufferingStopped:
break;
case PlayState.Rewinding:
break;
case PlayState.FastForwarding:
break;
}
NotifyComplete();
}
this code in the AudioPlayer class, the files added to the download queue in the xaml.cs normally

ActionScript 3 Undefined property

I have been playing around with Shared Objects trying to understand how they operate. In this basic practical example I am opting for the sharedObject.getRemote instead of using getLocal because I'm using Flash Media Server. I have updated the value of some data in the setProperty method() then if that data exists I try to retrieve it from the data property. When I run the application the output panel should be reading:
paris
250
true
However, it states access of undefined property. Can you please look at the code and tell me what I am doing wrong?
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.SharedObject;
import flash.events.SyncEvent;
var nc:NetConnection = new NetConnection();
nc.connect("rtmfp://localhost/sobjExample");
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
function netHandler(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
trace("Connected Up");
break;
case "NetConnection.Connect.Close":
trace("Closing time");
break;
case "NetConnection.Connect.Failed":
trace("Whoops");
break;
case "NetConnection.Connect.Rejected":
trace("Ouch!!!!!");
break;
}
}
var so:SharedObject = SharedObject.getRemote("city", nc.uri, true);
so.connect(nc);
so.addEventListener(SyncEvent.SYNC, seeSo);
function seeSo(event:SyncEvent):void{
trace(so.changeList[0].code);
switch(so.changeList[0].code){
case "clear":
loadSo();
break;
case "Success":
showSo();
break;
}
}
function loadSo():void{
so.setProperty("city", "Paris");
so.setProperty("bunch", "250");
} so.setProperty("verity", "true");
function showSo():void{
trace(so.data.city);
trace(so.data.bunch);
} trace(so.data.verity);

How to call a setter method with arguments dynamically in flash AS3

This AS3 function works for normal methods and getter methods:
public function MyClassTestAPI(functionName:String, ...rest):* {
var value:*;
try {
switch(rest.length) {
case 0:
value = myObj[functionName];
break;
case 1:
value = myObj[functionName].call(functionName, rest[0]);
break;
case 2:
value = myObj[functionName].call(functionName, rest[0],rest[1]);
break;
default:
throw("Cannot pass more than 2 parameters (passed " + rest.length + ")");
}
}
return value;
}
Sample usage:
this.MyClassTestAPI("Foo", "arg1"); // tests function Foo(arg1:String):String
this.MyClassTestAPI("MyProperty"); // tests function get MyProperty():String
this.MyClassTestAPI("MyProperty", "new value");// tests function set MyProperty(val:String):void
The third call does not work (throws exception).
How can I make it work for setter methods as well?
Thanks!
edit:
This is a version that works, except with getter and setter that have additional parameters.
It is ok for my needs:
public function MyClassTestAPI(functionName:String, ...rest):* {
var value:*;
try {
if (typeof(this.mediaPlayer[functionName]) == 'function') {
switch(rest.length) {
case 0:
value = myObj[functionName].call(functionName);
break;
case 1:
value = myObj[functionName].call(functionName, rest[0]);
break;
case 2:
value = myObj[functionName].call(functionName, rest[0],rest[1]);
break;
default:
throw("Cannot pass more than 2 parameters (passed " + rest.length + ")");
}
} else {
switch(rest.length) {
case 0:
value = myObj[functionName];
break;
case 1:
myObj[functionName] = rest[0];
break;
default:
throw("Cannot pass parameter to getter or more than one parameter to setter (passed " + rest.length + ")");
}
}
}
return value;
}
Setter functions works as variables, so you can't use it in this way:
myProperty.call( "new value" );
Your function for variables is pointless, because you just have to do a value assignment:
myProperty = "new value";
By the way you can include it in your function in two ways:
create a third parameter what tells your function it is a function or variable
create the value assignment in the catch section
You are currently passing only one string with value "new value"
This should do the trick:
this.MyClassTestAPI("MyProperty", "new","value");
For more information on this matter check the Adobe LiveDocs at:
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_19.html
Cheers