High level Mesh Client interface.
        /// <summary>
        /// Start the Mesh as a direct service
        /// </summary>
        void StartService() {
            // Create test Mesh
            File.Delete(LogMesh);
            File.Delete(LogPortal);


            Portal = new MeshPortalTraced(NameService, LogMesh, LogPortal);
            MeshPortal.Default = Portal;

            MeshClient = new MeshClient(NameService);
            }
        /// <summary>
        /// Bind to the Mesh client for the specified portal account
        /// </summary>
        /// <param name="PortalID"></param>
        /// <returns></returns>
        public MeshClient GetMeshClient(string PortalID) {
            this.PortalID = PortalID;

            Utils.Assert(PortalID != null, "No Portal account specified");
            Account.SplitAccountID(PortalID, out AccountID, out Portal);
            Utils.Assert(AccountID != null | Portal != null, "[{0}] is not a valid portal address");

            MeshClient = new MeshClient(Portal);
            Utils.Assert(MeshClient != null, "Could not connect to portal {0}", Portal);

            return MeshClient;
            }
        /// <summary>
        /// Attempt to create an account at the specified portal.
        /// </summary>
        /// <param name="Portal"></param>
        /// <param name="Account"></param>
        /// <returns>true if succeeded, false otherwise.</returns>
        public bool TryNewPortalAccount(string Portal, string Account) {
            Portal = (Portal == null) || (Portal == "") ? "mesh.prismproof.org" : Portal;


            this.Portal = Portal;
            this.AccountName = Account;

            MeshClient = new MeshClient(Portal);


            var ValidateResponse = MeshClient.Validate(AccountID);

            if (!ValidateResponse.Valid) {
                InvalidInput = ValidateResponse.Reason;
                }

            return ValidateResponse.Valid;
            }
        /// <summary>
        /// One time initialization of the page.
        /// </summary>
        public override void Initialize() {

            // Get the device profile or create a new one if necessary.
            ThisDevice = SignedDeviceProfile.GetLocal(Device1, Device1Description);



            if (DoLocal) {
                MeshPortal.Default = new MeshPortalDirect();

                // Get the default profile if possible
                MeshClient = new MeshClient(); // default account
                MeshClient.AccountID = AccountID;

                if (MeshClient.Connected) {
                    AccountName = MeshClient.AccountName;
                    Portal = MeshClient.Portal;
                    SignedCurrentProfile = SignedPersonalProfile.GetLocal(MeshClient.UDF);
                    Navigate(Data_SetupComplete);
                    }
                }


            else {

                JPCProvider.LocalLoopback = false;
                var Portal = new MeshPortalRemote();
                MeshPortal.Default = Portal;


                }


            }
        /// <summary>
        /// Attempt to complete the connection
        /// </summary>
        /// <returns></returns>
        public bool CompleteConnect () {
            var Connected = MeshClient.ConnectStatus(DevProfile.UDF);

            // Success?

            // Pull the new profile from the mesh.
            MeshClient = new MeshClient(Portal, AccountID);
            SignedPersonalProfile = MeshClient.GetPersonalProfile();


            // extract the personal profile

            var PersonalProfile = SignedPersonalProfile.Signed;
            PersonalProfile.SignedDeviceProfile = DevProfile;

            // extract the mail profile(s)

            foreach (var AppProfile in PersonalProfile.Applications) {
                if (AppProfile.Type == "MailProfile") {
                    InstallMail(PersonalProfile, AppProfile.Identifier);
                    }

                }

            // Create WLM accounts.


            return true;
            }
        /// <summary>
        /// Create a MeshClient for the specified portal and request the specified 
        /// account.
        /// </summary>
        /// <param name="Portal">Mesh Portal.</param>
        /// <param name="Account">Mesh Account.</param>
        /// <returns>UDF of the personal profile.</returns>
        public string GetAccount (string Portal, string Account) {

            // Attempt to connect to portal and connect to account.

            this.Portal = Portal;
            this.AccountName = Account;

            MeshClient = new MeshClient(Portal, AccountID);
            SignedPersonalProfile = MeshClient.GetPersonalProfile();
            if (SignedPersonalProfile == null) return null;
            return SignedPersonalProfile.UDF;
            }
        public void MeshStoreAPI() {

            if (DoLocal) {
                File.Delete(Store);
                File.Delete(Portal);
                MeshPortal.Default = new MeshPortalDirect(Store, Portal);
                }
            else {
                JPCProvider.LocalLoopback = false;
                var Portal = new MeshPortalRemote();
                MeshPortal.Default = Portal;
                }


            MeshClient1 = new MeshClient(Service);
            var valid = MeshClient1.Validate(AccountID);
            if (!valid.Status.StatusSuccess()) {
                Console.WriteLine("Validate failed");
                }

            var DevProfile = new SignedDeviceProfile(Device1, Device1Description);
            var UserProfile = new PersonalProfile(DevProfile);
            var SignedProfile = UserProfile.Signed;

            MeshClient1.CreatePersonalProfile(AccountID, SignedProfile);

            // Create a password profile
            //var PasswordProfile = new PasswordProfile(UserProfile);
            //var SignedPasswordProfile = PasswordProfile.Signed;
            //SignedProfile = UserProfile.Signed;

            //MeshClient1.Publish(SignedPasswordProfile);
            //MeshClient1.Publish(SignedProfile);


            MeshClient2 = new MeshClient(Service, AccountID);
            MeshClient2.SignedDeviceProfile = DevProfile;
            MeshClient2.GetPersonalProfile();

            // Read back the password profile and add entry 
            var AccountPasswordProfile = MeshClient2.GetPasswordProfile();
            AccountPasswordProfile.Add(PWDSite, PWDUser, PWDPassword);
            var AccountSignedPassword = AccountPasswordProfile.Signed;



            // Publish updates to both profiles.
            MeshClient2.Publish(AccountSignedPassword);

            // Create a new device profile.
            var DevProfile2 = new SignedDeviceProfile(Device2, Device2Description);

            MeshClient3 = new MeshClient(Service, AccountID);

            MeshClient3.ConnectRequest(DevProfile2);
            MeshClient2.ConnectStatus(DevProfile2.UniqueID);

            var PendingResponse = MeshClient1.ConnectPending();

            foreach (var Request in PendingResponse.Pending) {
                MeshClient1.ConnectClose(Request, ConnectionStatus.Accepted);
                }

            MeshClient3.ConnectStatus(DevProfile2.UniqueID);

            MeshClient3.GetPasswordProfile();

            }