private async void SignIn()
        {
            ShowProgressRing(true);

            // First of all, try to get OAuth URL by using specified ServerUrl
            try
            {
                await CRMHelper.DiscoveryAuthority();
            }
            catch (Exception ex)
            {
                // If failed, then simply go back to page without doing anything more.
                ShowProgressRing(false);
                return;
            }

            // Assing ServerUrl, ResourceName to CRMHelper._proxy
            CRMHelper._proxy.ServiceUrl = CRMHelper.ResourceName = txtServerUrl.Text;

            // Cache ServerUrl
            await Util.SaveToLocal(txtServerUrl.Text, "serverUrl.dat");

            // Register background task.
            await Util.RegisterBackgroundTask("CRMtoGoBackgroundTasks.UpdateSystemUserTimeZone",
                                              "UpdateSystemUserTimeZone",
                                              new SystemTrigger(SystemTriggerType.TimeZoneChange, false),
                                              new SystemCondition(SystemConditionType.InternetAvailable));

            // Initialize CRMHelper
            await CRMHelper.Initialize();

            Frame.Navigate(typeof(Home));
            // To prevent user from back to this page by pressing back button, remove this page history from Navigation history
            Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1);
        }
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            // Check if there is any temporaryData
            object[] parameters = CRMHelper.temporaryData as object[];
            if (parameters.Count() != 3)
            {
                throw new Exception("SetRegardingPage takes 3 parameters, SourceRecord, RelatedData and EntityMetadataEx");
            }

            this.record           = parameters[0] as Entity;
            this.relatedData      = parameters[1] as RelatedData;
            this.entityMetadataEx = parameters[2] as EntityMetadataEx;

            // Then initialize page
            Initialize();

            progressRing.IsActive = false;
        }
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            // Check if there is any temporaryData. if restored, then temporary data does not exist
            object[] parameters = CRMHelper.temporaryData as object[];
            if (parameters != null)
            {
                // if this if first navigation, then no formFieldData, otherwise its restored or back from new record
                if (formFieldData == null)
                {
                    this.formFieldData = parameters[0] as FormFieldData;
                }
                else // assume back after created new record or back just by clicking cancel button.
                {
                    Entity record = parameters[0] as Entity;
                    // If record is created, then filter result down to the created record.
                    if (record != null)
                    {
                        searchCriteria = record[lookForEntities.
                                                Where(x => x.EntityMetadata.LogicalName == record.LogicalName).First().EntityMetadata.PrimaryNameAttribute].ToString();
                    }
                }
            }

            //if restored, then temporary data does not exist
            if (lookForEntities == null || lookForEntities.Count() == 0)
            {
                List <EntityMetadataEx> targetList = new List <EntityMetadataEx>();
                targetList.AddRange(CRMHelper.EntityMetadataExCollection.Where(x => (parameters[1] as string[]).Contains(x.EntityMetadata.LogicalName)));
                foreach (var target in targetList)
                {
                    lookForEntities.Add(target);
                }
            }

            Initialize();

            progressRing.IsActive = false;
        }
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            LoadData();

            progressRing.IsActive = false;
        }
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            // Retrieve EntityMetadataEx by using passed parameter (ObjectTypeCode)
            this.entityMetadataEx = CRMHelper.EntityMetadataExCollection.Where(x => x.EntityMetadata.ObjectTypeCode == (int)e.Parameter).First();
            Initialize();

            progressRing.IsActive = false;
        }
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            Initialize();

            // If there is a parameter, then this is called from BackGround Task
            if (e.Parameter != null)
            {
                // check if equivalent timezone info is available for CRM
                TimeZoneDefinition timeZoneDefinition = CRMHelper.TimeZones.
                                                        Where(x => x.UserInterfaceName == e.Parameter.ToString()).FirstOrDefault();
                if (timeZoneDefinition == null)
                {
                    return;
                }
                //Show message to confirm if user want to update TimeZone
                string        message = loader.GetString("ConfirmTimeZone");
                MessageDialog dialog  = new MessageDialog(message);
                dialog.Commands.Add(new UICommand(loader.GetString("Yes")));
                dialog.Commands.Add(new UICommand(loader.GetString("No")));
                dialog.DefaultCommandIndex = 1;
                dialog.CancelCommandIndex  = 1;
                var result = await dialog.ShowAsync();

                // If user wants to update TimeZone data, then do it.
                if (result.Label == loader.GetString("Yes"))
                {
                    CRMHelper.UserSettings.TimeZoneCode = timeZoneDefinition.TimeZoneCode;
                    cbTimeZones.SelectedItem            = timeZoneDefinition;
                    await SaveSettings();
                }
            }

            progressRing.IsActive = false;
        }
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            if (fields == null) // If fields are not yet has value, means just navigated to this page
            {
                // Check if there is any temporaryData
                object[] parameters = CRMHelper.temporaryData as object[];
                if (parameters.Count() != 3)
                {
                    new Exception("RecordModifyPage needs 3 parameters. Record, Fields, EntityMetadataEx");
                }
                this.record           = parameters[0] as Entity;               // record for update/related new
                this.fields           = parameters[1] as List <FormFieldData>; // form fields
                this.entityMetadataEx = parameters[2] as EntityMetadataEx;     // target entity
            }
            else // It has been restored of page back from lookup page
            {
                // Assign lookup value when retruning from lookup page.
                if (CRMHelper.temporaryData != null &&
                    CRMHelper.temporaryData.GetType().Equals(typeof(FormFieldData)))
                {
                    FormFieldData formfieldData = CRMHelper.temporaryData as FormFieldData;
                    fields.Where(x => x.FieldMetadata.LogicalName == formfieldData.FieldMetadata.LogicalName).First().FieldData = formfieldData.FieldData;
                }
            }

            // Then initialize page
            Initialize();

            progressRing.IsActive = false;
        }
Example #8
0
        /// <summary>
        /// This method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            if (id == Guid.Empty) // If id does not have value, this is new page.
            {
                // Check if there is any temporaryData
                object[] parameters = CRMHelper.temporaryData as object[];
                this.id = Guid.Parse(parameters[0].ToString());
                this.entityMetadataEx = parameters[1] as EntityMetadataEx;
            }
            // if id has value, then this page is navigate back from another page.
            else
            {
                // Check parameter
                object[] parameters = CRMHelper.temporaryData as object[];
                // If first parameter is Entity, then this is back from Modify Page.
                // In this case, as record may have newer value, clear the cache.
                if (parameters != null && parameters.Count() == 1 && parameters[0].GetType().Equals(typeof(Entity)))
                {
                    fields = null;
                    record = null;
                }
            }

            // Initalize the page.
            Initialize();

            progressRing.IsActive = false;
        }