I've got the most simple windows store program. It just runs the white-color window till the Quit (as well as the most simple Win32 application would do).
ref class ApplicationViewSource sealed : IFrameworkViewSource {
public:
virtual IFrameworkView^ CreateView() {
return ref new WindowsStoreApp::MainView();
}
};
[MTAThread]
int main(Array<String^>^ args) {
CoreApplication::Run(ref new ApplicationViewSource());
return 0;
}
ref class MainView sealed : IFrameworkView {
public:
virtual void Initialize(CoreApplicationView^ AppView);
virtual void SetWindow(CoreWindow^ Window);
virtual void Load(String^ EntryPoint);
virtual void Run();
virtual void Uninitialize();
void OnActivated(CoreApplicationView^, IActivatedEventArgs^);
};
void MainView::Initialize(CoreApplicationView^ AppView) {
AppView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &MainView::OnActivated);
}
void MainView::SetWindow(CoreWindow^ window) {
window->PointerCursor = ref new CoreCursor(CoreCursorType::Hand, 0);
}
void MainView::Load(String^ EntryPoint) {
}
void MainView::Run() {
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}
void MainView::Uninitialize() {
}
void MainView::OnActivated(CoreApplicationView^, IActivatedEventArgs^) {
CoreWindow::GetForCurrentThread()->Activate();
}
So... What I need to do next ? As for Win32 project I could create some graphical user interface components with CreateWindow(Ex) function as windows of the specific window-classes. With the windows store app API I can't figure out how to add any visuals.
Manual only gives hints about adding ones with code to existing XAML page, allready been connected to the window.
Related
I have created new CustomView.xib file and associated to code-behind class. But when i try to initialise the view, the app getting crashed as below mentioned error.
MonoTouch: Could not install sigaction override, unexpected sigaction implementation.
NSBundle.MainBundle.LoadNib("CustomView", this, null); // App crashes here.
CS class file:
public partial class CustomView : UIView
{
public CustomView(IntPtr handle) : base(handle)
{
}
public override void AwakeFromNib()
{
base.AwakeFromNib();
}
}
Designer class:
[Register("CustomView")]
partial class CustomView
{
[Outlet]
UIKit.UIView contentView { get; set; }
void ReleaseDesignerOutlets ()
{
if (contentView != null) {
contentView.Dispose ();
contentView = null;
}
}
}
Note:
Build Action is set to interfaceDefinition.
File owner of the xib is set the class name "CustomView"
AwakeFromNib override method also implemented.
Thanks in advance.
Edited:
We came across with similar kind of issue after a long time but with different exceptions says "Object Null Reference" on "contentView" in the AwakeFromNib method. App crashes when you try to access the ContentView inside the AwakeFromNib method. This happened only on iOS 9.3.x. The following fix might help someone if they face the same kind of issue.
[Export("initWithFrame:")]
public SampleHeaderView(CGRect frame) : base(frame)
{
Initialize();
}
[Export("initWithCoder:")]
public SampleHeaderView(NSCoder coder) : base(coder)
{
Initialize();
}
public override void AwakeFromNib()
{
base.AwakeFromNib();
}
private void Initialize()
{
if (this.ContentView != null)
{
this.ContentView.BackgroundColor = UIColor.Red();
}
}
In MvvmCross 4.1.4 for Window Universal App (UWP) platform, if we call ShowViewModel too early within ViewModel (like in Constructor, Init, or Start event) then it does not navigate to another model.
public class FirstViewModel : MvxViewModel
{
public FirstViewModel()
{
ShowViewModel<SecondViewModel>();
}
}
Note that it works just fine for iOS and Android platform.
It is a bug of MvvmCross (according to this https://github.com/MvvmCross/MvvmCross/issues/1223).
The work around solution is to trigger the navigation from some events like View_Loaded or View_GotFocus within the View:
public sealed partial class FirstView : MvxWindowsPage
{
public FirstView()
{
this.InitializeComponent();
this.Loaded += FirstView_Loaded;
}
private void FirstView_Loaded(object sender, RoutedEventArgs e)
{
var viewModel = base.ViewModel as FirstViewModel
if (viewModel != null)
{
viewModel.Initialise();
}
}
}
ViewModel updated:
public class FirstViewModel : MvxViewModel
{
public FirstViewModel()
{
}
public void Initialise()
{
//Navigate here
ShowViewModel<SecondViewModel>();
}
}
I have a problem in LinkedIn integration in Monotouch. i have integrated Facebook successfully using Logged In Session like as following :
internal void SaveAuthorization ()
{
var defaults = NSUserDefaults.StandardUserDefaults;
defaults ["FBAccessTokenKey"] = new NSString (facebook.AccessToken);
defaults ["FBExpirationDateKey"] = facebook.ExpirationDate;
defaults.Synchronize ();
}
or using like :
public class SessionDelegate : FBSessionDelegate
{
FacebookLoginViewController container;
public SessionDelegate (FacebookLoginViewController container)
{
this.container = container;
}
public override void DidLogin ()
{
container.ShowLoggedIn ();
container.SaveAuthorization ();
}
public override void DidLogout ()
{
container.ClearAuthorization ();
//container.ShowLoggedOut ();
}
public override void DidNotLogin (bool cancelled)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?
link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void SessionInvalidated ()
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?
link=T%3aMonoTouch.Foundation.ModelAttribute
}
}
Now I want to use same for LinkedIn. how can i complete it.?
thanks in advance
Is it possible to get the value of phobe in-call volume from java me midlet? Changing of the volume is not necessary.
Thanks.
AFAIK,
It is not possible to access the phone volume. But you can set your application volume or get the application.
Sample code for Controlling the volume of your application :
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Ticker;
import javax.microedition.media.*;
public class VolumeControlDemo extends MIDlet implements CommandListener {
private Display display;
private Command exit,incr,decr;
Form frm;
VolumeControl vc;
int vol;
Player player;
public VolumeControlDemo() {
display = Display.getDisplay(this);
}
public void startApp() {
frm=new Form("VolumeControlDemo Demo");
exit= new Command("Exit",Command.EXIT,1);
decr= new Command("Decrease",Command.EXIT,1);
incr= new Command("Increase",Command.EXIT,1);
frm.addCommand(exit);
frm.addCommand(decr);
frm.addCommand(incr);
frm.setCommandListener(this);
display.setCurrent(frm);
try {
// Creating player object
player = Manager.createPlayer("/demo.wav");
// Setting loop count
player.setLoopCount(-1);
// Start sound
player.start();
Control cs[];
// Getting Controls object
cs = player.getControls();
for (int i = 0; i < cs.length; i++) {
if (cs[i] instanceof VolumeControl)
// Getting volume control
vc=(VolumeControl)cs[i];
}
} catch (Exception e) {}
}
public void pauseApp() {
}
public void destroyApp(boolean un) {
}
public void commandAction(Command cmd,Displayable d) {
try {
if(decr) {
if(vol>0) vol--;
vc.setLevel(vol);
} else if() {
if(vol<99) vol--;
vc.setLevel(vol);
}
frm.appent("vol="+vc.getLevel());
}catch(Exception e){}
}
}
I found some sample code posted at
https://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/4d45e9ea5471cba4/4519371a77ed4a74?hl=en&pli=1
for self installing a Windows Service. I am in C# on fx 4.0. Trying
to figure out where I went off the rails...
My questions:
I created a Win Service project. In program.cs / main() I pretty much
copied the code example. It appears most everything is working
except launching a console window if I am in DEBUG mode (passing in -
c of course). For some reason the console window never opens.
The other challenge I had was the call to StartUp() / ShutDown() in
the console portion would not compile. I ended up have to initialize
my service object and then call it.
I am getting the following error when the Console.ReadKey() method is called:
Cannot read keys when either
application does not have a console or
when console input has been redirected
from a file. Try Console.Read.
My code and stuff:
An image of my project structure:
NOTE: I was duplicating the startup sequence in the TestHarness when
in DEBUG mode. If/when I get this working I will be dropping that
from the solution. The Library project is where the majority of my
code lives.
PROGRAM.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ComponentModel;
using System.Configuration.Install;
using System.Collections;
using RivWorks.FeedHandler.Service;
namespace RivWorks.FeedHandler
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static int Main(string[] args)
{
bool install = false, uninstall = false, console = false, rethrow = false;
try
{
foreach (string arg in args)
{
switch (arg)
{
case "-i":
case "-install":
install = true; break;
case "-u":
case "-uninstall":
uninstall = true; break;
case "-c":
case "-console":
console = true; break;
default:
Console.Error.WriteLine("Argument not expected: " + arg);
break;
}
}
if (uninstall)
{
Install(true, args);
}
if (install)
{
Install(false, args);
}
if (console)
{
Console.WriteLine("Starting...");
FeedListener fl = new FeedListener();
fl.StartUp();
Console.WriteLine("System running; press any key to stop");
Console.ReadKey(true);
fl.ShutDown();
Console.WriteLine("System stopped");
}
else if (!(install || uninstall))
{
rethrow = true; // so that windows sees error...
ServiceBase[] services = { new Service.FeedListener() };
ServiceBase.Run(services);
rethrow = false;
}
return 0;
}
catch (Exception ex)
{
if (rethrow) throw;
Console.Error.WriteLine(ex.Message);
return -1;
}
}
static void Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "uninstalling" : "installing");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
}
[RunInstaller(true)]
public sealed class MyServiceInstallerProcess : ServiceProcessInstaller
{
public MyServiceInstallerProcess()
{
this.Account = ServiceAccount.NetworkService;
}
}
[RunInstaller(true)]
public sealed class MyServiceInstaller : ServiceInstaller
{
public MyServiceInstaller()
{
this.Description = "Provides a service to listen for, then import, feed files from various sources.";
this.DisplayName = "RIVWorks Feed Handler (.NET 4.0)";
this.ServiceName = "FeedListener";
this.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
}
}
}
FEEDLISTENER.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using sysIO = System.IO;
using RivWorks.FeedHandler;
using System.Collections;
using RivWorks.FeedHandler.Library;
using System.Threading;
namespace RivWorks.FeedHandler.Service
{
public partial class FeedListener : ServiceBase
{
#region Declarations
static private List<string> _keys = new List<string>();
static private System.Threading.Timer _clock = null;
static private FileSystemWatcher _watcher;
static private RivWorks.FeedHandler.Library.QueueHandler _qHandler = null;
static private bool _isDequeueing = false;
#endregion
#region Constructor
public FeedListener()
{
InitializeComponent();
}
#endregion
#region Internal Methods
internal void StartUp() {...}
internal void ShutDown() {...}
#endregion
#region Start/Stop
protected override void OnStart(string[] args)
{
StartUp();
}
protected override void OnStop()
{
ShutDown();
}
#endregion
#region Event Handlers
static void qHandler_QueuesGrew() {...}
static void qHandler_QueuesShrunk() {...}
static void qHandler_QueuesChanged() {...}
static void fileCreatedOrChanged(object sender, sysIO.FileSystemEventArgs e) {...}
#endregion
#region Private Methods
private static void Tick(object state) {...}
private static void WriteToEventLog(Exception ex, EventLogEntryType eventLogEntryType) {...}
private static void WriteToEventLog(string message, EventLogEntryType eventLogEntryType) {...}
#endregion
}
}
And I found my answer! My project properties were set to Windows App instead of Console App. DOH! (Project Properties > Application Tab > Output type:)
Also.. instead of using -console arg, you can identify its console by using Environment.UserInteractive, which will be false when running as service, but true when running the EXE directly.
You can also have a look at this: http://www.thedavejay.com/2012/04/self-installing-c-windows-service-safe.html
It allows you to debug as a console application, and install the same app as a windows service without having to change the project type.