110 lines
4.4 KiB
C#
110 lines
4.4 KiB
C#
using Sarand.Core.Base;
|
|
using Sarand.Core.Mobile.App;
|
|
using Sarand.LogisticsMgr.Core.App;
|
|
using Sarand.LogisticsMgr.Mobile.Core.CodeTypes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Sarand.LogisticsMgr.Mobile.Core.App
|
|
{
|
|
//=======================================================================
|
|
public abstract class SlmApplication : SaxApplication
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SlmApplication ()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public SlmMobile.Platform MobilePlatform { get; protected set; }
|
|
public Page CurrentPage
|
|
{
|
|
get
|
|
{
|
|
return
|
|
MainPage.Navigation.ModalStack.LastOrDefault()
|
|
?? MainPage.Navigation.NavigationStack.LastOrDefault()
|
|
?? MainPage;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// W e b S e r v i c e
|
|
//-------------------------------------------------------------------
|
|
public abstract Task<bool> IsWebServiceAlive (SlmSiteDefinition siteDefinition);
|
|
|
|
//-------------------------------------------------------------------
|
|
// S i t e D e f i n i t i o n s
|
|
//-------------------------------------------------------------------
|
|
public abstract List<SlmSiteDefinition> GetSiteDefinitions ();
|
|
public SlmSiteDefinition GetSiteDefinition ()
|
|
{
|
|
return SlmGlobals_Mobile.SessionProfile.SiteDefinition;
|
|
}
|
|
public abstract void SetSite (SlmSiteDefinition siteDefinition);
|
|
|
|
//-------------------------------------------------------------------
|
|
// P e r s i s t e n t S e s s i o n P r o p e r t i e s
|
|
//-------------------------------------------------------------------
|
|
public String DefaultEmailAddress { get; set; }
|
|
public SlmSiteDefinition DefaultSiteDefinition { get; set; }
|
|
protected static String PropertyName_Context_Site_Code { get; } = "Context-Site-Code";
|
|
protected static String PropertyName_Context_Site_Url { get; } = "Context-Site-Url";
|
|
protected static String PropertyName_Context_EmailAddress { get; } = "Context-Email";
|
|
public void RestorePersistentSessionProperties ()
|
|
{
|
|
SlmSessionProfile_Mobile sessionProfile = SlmGlobals_Mobile.SessionProfile;
|
|
if (sessionProfile == null) return;
|
|
// Retrieve all session properties first before populating to session.
|
|
Object sessionSiteCode = Properties.GetValue(PropertyName_Context_Site_Code, SlmSystem.GetSiteCode(sessionProfile.Site));
|
|
Object sessionSiteUrl = Properties.GetValue(PropertyName_Context_Site_Url, sessionProfile.SiteDefinition != null ? sessionProfile.SiteDefinition.URL : "");
|
|
Object sessionEmail = Properties.GetValue(PropertyName_Context_EmailAddress, sessionProfile.EmailAddress);
|
|
// Populate default session properties.
|
|
// Site definition.
|
|
if (sessionSiteCode != null && sessionSiteUrl != null)
|
|
{
|
|
Slm.Site site = SlmSystem.GetSiteForCode(sessionSiteCode.ToString());
|
|
string siteUrl = sessionSiteUrl.ToString();
|
|
foreach (SlmSiteDefinition siteDefinition in GetSiteDefinitions())
|
|
{
|
|
if (siteDefinition.Site != site) continue;
|
|
if (!siteDefinition.URL.Equals(siteUrl)) continue;
|
|
DefaultSiteDefinition = siteDefinition;
|
|
}
|
|
}
|
|
// User email.
|
|
if (sessionEmail != null) DefaultEmailAddress = sessionEmail.ToString();
|
|
}
|
|
public void StorePersistentSessionProperties ()
|
|
{
|
|
if (DefaultSiteDefinition != null)
|
|
{
|
|
Properties[PropertyName_Context_Site_Code] = SlmSystem.GetSiteCode(DefaultSiteDefinition.Site);
|
|
Properties[PropertyName_Context_Site_Url] = DefaultSiteDefinition.URL;
|
|
}
|
|
if (!StringUtil.IsEmpty(DefaultEmailAddress))
|
|
Properties[PropertyName_Context_EmailAddress] = DefaultEmailAddress;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n s o l e s
|
|
//-------------------------------------------------------------------
|
|
public abstract SlmCodeTypeConsole_Mobile CodeTypeConsole { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|