applicationWillBecomeActive in MonoTouch - xamarin.ios

I'm trying to use the applicationDidBecomeActive method (and similar ones) - I can find plenty of examples in ObjC but none in Monotouch.
Have tried an override in AppDelegate and in UIViewController but the compiler finds no suitable method to override. So, how do I use this?
I want to use it (in conjunction with a timer and IdleTimerDisabled) to stop the device from going to sleep for longer than usual (it's a stopwatch-type app). Maybe I'm on the wrong track.

In your app delegate that inherits from UIApplicationDelegate, you can override these:
/// <summary>
/// Gets called by iOS if the app is started from scratch and is not resumed from background.
/// We have 17 seconds to leave this methos before iOS will kill the app.
/// </summary>
public override bool FinishedLaunching ( UIApplication application, NSDictionary launchOptions )
/// <summary>
/// Called if the app comes back from background or gets started. Triggered after FinishedLaunching().
/// </summary>
public override void OnActivated ( UIApplication application )
/// <summary>
/// Called if the application gets pushed to the background because the user hits the home button.
/// </summary>
public override void DidEnterBackground ( UIApplication application )
/// <summary>
/// Gets called if the app is resumed from background but NOT if the app starts first time.
/// </summary>
public override void WillEnterForeground ( UIApplication application )

Related

Where does Kestrel look for what ports to listen to?

I have a couple of .NET Core apps, which when I run dotnet run decide to listen to different ports (one to 5000, one to both 5000 and 5001).
I've been looking around for some comprehensive documentation on exactly how these decisions are made, but can't find what I'm looking for.
What is an exhaustive list of places Kestrel looks for this setting, in order of precedence?
For simplicity, let's assume I'm using the default WebHostBuilder:
public class Program
{
public static void Main(string[] args)
{
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build()
.Run();
}
}
According to documentation under Endpoint configuration
By default, ASP.NET Core binds to:
http://localhost:5000
https://localhost:5001 (when a local development certificate is present)
...
The source code also supports this
/// <summary>
/// The endpoint Kestrel will bind to if nothing else is specified.
/// </summary>
public static readonly string DefaultServerAddress = "http://localhost:5000";
/// <summary>
/// The endpoint Kestrel will bind to if nothing else is specified and a default certificate is available.
/// </summary>
public static readonly string DefaultServerHttpsAddress = "https://localhost:5001";
Which is used by the internal AddressBinder to set the host and port to use by default when none is provided.

Why route table filling happens in first request of MVC application

For a MVC 5 application, when I debug the solution, then only on first request, break point hits the RouteConfig class, next request on wards, it's not filling the route table again.
Question, where the routing table stored, how it will match on second request?
Thanks,
The RouteTable is implemented as a singleton. In ASP.NET (or MVC), a singleton's lifetime lasts until the application pool is recycled.
namespace System.Web.Routing
{
using System;
using System.Runtime.CompilerServices;
[TypeForwardedFrom("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
public class RouteTable
{
private static RouteCollection _instance = new RouteCollection();
public static RouteCollection Routes
{
get
{
return _instance;
}
}
}
}
So all web requests will use the same instance of the RouteTable, first, second, or otherwise.
The RouteTable is automatically repopulated when the application pool recycles because it is initialized within the Application.Start event (usually in Global.asax). This event only fires 1 time when the application first starts (or when the application pool recycles).

sharepoint event receiver never fire

I tried to follow a few examples on how to create sharepoint event receiver. Most examples are fairly straightforward in instructions. So I was able to create a sharepoint event receiver project (for example: item adding or site deleting) in visual studio 2010 and deployed to server and site. I checked the feature and it is activated. I ran some test like deleting a test site or even uploading a file. But the test error messages i put in the code never run. I cannot figure out why the events are never fired.
The following is an example of my code:
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace DeletingSite.EventReceiver1
{
/// <summary>
/// Web Events
/// </summary>
public class EventReceiver1 : SPWebEventReceiver
{
/// <summary>
/// A site is being deleted.
/// </summary>
public override void WebDeleting(SPWebEventProperties properties)
{
base.WebDeleting(properties);
properties.Cancel = true;
properties.ErrorMessage = "You cannot ";
}
}
}
Under Event Receiver item, there would be element.xml file. This file defines how and where your event receiver is attached. Please check if everything is correct within that file.

Why is my static constructor called twice in an Azure Web Role?

I'm trying to initialise my dependency registration for a WCF service running in an Azure Web Role, but I'm seeing a very unusual behaviour whereby the static constructor of my class is being invoked twice.
This is the Dependencies class I'm using as a registry point for the dependencies of the application.
public static class Dependencies
{
private static IUnityContainer container;
static Dependencies()
{
Dependencies.container = new UnityContainer();
}
public static IUnityContainer Container
{
get
{
...
}
set
{
...
}
}
public static void ConfigureContainer()
{
var container = new UnityContainer();
// Configure container.
Dependencies.container = container;
}
}
In my overload of RoleEntryPoint.OnStart(), I make a call to a static ConfigureContainer method to set up the container with my dependencies registered:
public override bool OnStart()
{
// Configure container for dependency resolution.
Dependencies.ConfigureContainer();
return base.OnStart();
}
My expectation is that the static members of the Dependencies class should be initialised by this code and will be available to the components of the application.
What I'm seeing (using a breakpoint and the VS2012 debugger) is that the static constructor of Dependencies is being called twice: once during the original initialisation of the application and again during first request to the service. Subsequent requests don't invoke the static constructor (as expected).
I'd love to hear an explanation of why the runtime is behaving this way and what I should be doing instead to produce my static registry of dependencies.
It's likely because when you host a webrole in full IIS, the RoleEntryPoint code and the rest of the web application run in different AppDomains.
http://blogs.msdn.com/b/windowsazure/archive/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core.aspx
By default you use "full IIS" mode in a web role and you get two processes - IIS worker process for handling HTTP requests and role worker process for running RoleEntryPoint descendant code. Depending on how your code is designed you may end up using that static constructor in both processes and then it'll be invoked twice.

msiexec: Silent deploy website to IIS

Our team at work has written a wrapper application/interface to install a series of msi's silently using msiexec.
My issue relates to installing the msi's directed at IIS.
I keep getting the following error
Error 1314. The specified path 'Default Web Site/ROOT/someVirtual' is
unavailable. The Internet Information Server might not be running or
the path exists and is redirected to another machine. Please check the
status of this virtual directory in the Internet Services Manager.
The msi gets executed with the following parameters set as follows
msiexec.exe /i "D:\SOME.msi" UseShellExecute="false" TARGETSITE="Default Web Site" TARGETVDIR="someVirtual" TARGETAPPPOOL="DefaultAppPool" /qn /l* D:\SOME_log.txt
I realize this issue is stricly IIS related as I'm probably missing some setting/option that i need to setup.
As far as I can see my virtual is in this location "NT4334RB\Sites\Default Web Site\someVirtual", so my best guess would be that "Default Web Site/ROOT/someVirtual" - ROOT is the issue and needs to be set, but to what? and how?
I just came across this line in the logfile - I think this might be of use?
Getting AppRoot From Url key 'TARGETURL'
Seemed like my issue was related to me not specifying the metabase path correctly.
I ended up adding a helper in my code to the likes of this.
Found various solutions on SO (this got me thinking in the right direction), & I also installed something called IIS Metabase Explorer which was quite useful
//Added for reference purposes
//HasRequiredOption("site|s=", "The site location", c =>
//AddOrUpdateAdditionalMsiProperty("TARGETSITE", BuildMetabasePath(c)));
//apppool => TARGETAPPPOOL
//virtualdir => TARGETVDIR
/// <summary>
/// Builds the meta-base path.
/// </summary>
/// <param name="websiteName">Name of the website.</param>
/// <returns>The fully constructed meta-base path</returns>
private string BuildMetabasePath(string websiteName)
{
return "/LM/W3SVC/" + this.GetWebSiteId(websiteName);
}
/// <summary>
/// Gets the web site id.
/// </summary>
/// <param name="websiteName">Name of the website.</param>
/// <param name="serverName">Name of the server. Defaults to: localhost if none specified</param>
/// <returns>The website id</returns>
private string GetWebSiteId(string websiteName, string serverName = "localhost")
{
using (var entries = new DirectoryEntry(string.Format("IIS://{0}/w3svc", serverName)))
{
var children = entries.Children.Cast<DirectoryEntry>();
var sites =
(from de in children
where
de.SchemaClassName == "IIsWebServer" &&
de.Properties["ServerComment"].Value.ToString() == websiteName
select de).ToList();
if (sites.Any())
{
return sites.First().Name;
}
}
return "-1";
}

Resources