private async Task LoadObjectsAsync(DesignTimeAuthentication authentication)
        {
            try
            {
                IEnumerable<SObjectDescription> objects = await MetadataLoader.LoadObjectsAsync(authentication);
                IEnumerable<ObjectPickerObject> children = objects
                    .Select(o => new ObjectPickerObject(this.allObjectsCategory, o.Name) { State = o })
                    .ToArray();

                if (this.Wizard.Context.IsUpdating)
                {
                    await this.InitializeObjectSelectionState(children);
                }

                // Make any previously selected items appear at the top then sort by name.
                this.allObjectsCategory.Children = children
                    .OrderByDescending(o => o.IsChecked)
                    .ThenBy(o => o.Name)
                    .ToArray();
                this.allObjectsCategory.IsSelected = true;
            }
            catch (Exception ex)
            {
                if (GeneralUtilities.IsCriticalException(ex))
                {
                    throw;
                }

                this.ErrorMessage = Resources.ObjectSelectionViewModel_LoadingError.FormatCurrentCulture(ex);
            }
        }
예제 #2
0
        private async Task LoadObjectsAsync(DesignTimeAuthentication authentication)
        {
            try
            {
                IEnumerable <SObjectDescription> objects = await MetadataLoader.LoadObjectsAsync(authentication);

                IEnumerable <ObjectPickerObject> children = objects
                                                            .Select(o => new ObjectPickerObject(this.allObjectsCategory, o.Name)
                {
                    State = o
                })
                                                            .ToArray();

                if (this.Wizard.Context.IsUpdating)
                {
                    await this.InitializeObjectSelectionState(children);
                }

                // Make any previously selected items appear at the top then sort by name.
                this.allObjectsCategory.Children = children
                                                   .OrderByDescending(o => o.IsChecked)
                                                   .ThenBy(o => o.Name)
                                                   .ToArray();
                this.allObjectsCategory.IsSelected = true;
            }
            catch (Exception ex)
            {
                if (GeneralUtilities.IsCriticalException(ex))
                {
                    throw;
                }

                this.ErrorMessage = Resources.ObjectSelectionViewModel_LoadingError.FormatCurrentCulture(ex);
            }
        }
예제 #3
0
        public static async Task <IEnumerable <SObjectDescription> > LoadObjectDetailsAsync(
            IEnumerable <SObjectDescription> sObjects, DesignTimeAuthentication authentication)
        {
            // Note:  There is no batch support with the REST endpoint therefore individual requests must be made.
            IEnumerable <Task <SObjectDescription> > detailTasks = sObjects
                                                                   .Select(o => MetadataLoader.GetSalesforceAsync <SObjectDescription>(
                                                                               "sobjects/" + o.Name + "/describe/", authentication));

            return(await Task.WhenAll <SObjectDescription>(detailTasks));
        }
        /// <summary>
        /// Refreshes the objects displayed in the picker asynchronously.  The objects are only refreshed if the specified
        /// authentication is different than the last time the objects were retrieved.
        /// </summary>
        public void BeginRefreshObjects(DesignTimeAuthentication authentication)
        {
            // In the future, consider preserving any previously selected objects.  This is not currently done because
            // there is no mechanism to indicate to the user when previously selected objects are no longer available.

            if (this.lastDesignTimeAuthentication == null ||
                !this.lastDesignTimeAuthentication.Equals(authentication))
            {
                this.allObjectsCategory.Children = null;
                this.ErrorMessage = null;
                this.lastDesignTimeAuthentication = authentication;
                this.loadObjectsTask = this.LoadObjectsAsync(authentication);
            }
        }
예제 #5
0
        /// <summary>
        /// Refreshes the objects displayed in the picker asynchronously.  The objects are only refreshed if the specified
        /// authentication is different than the last time the objects were retrieved.
        /// </summary>
        public void BeginRefreshObjects(DesignTimeAuthentication authentication)
        {
            // In the future, consider preserving any previously selected objects.  This is not currently done because
            // there is no mechanism to indicate to the user when previously selected objects are no longer available.

            if (this.lastDesignTimeAuthentication == null ||
                !this.lastDesignTimeAuthentication.Equals(authentication))
            {
                this.allObjectsCategory.Children = null;
                this.ErrorMessage = null;
                this.lastDesignTimeAuthentication = authentication;
                this.loadObjectsTask = this.LoadObjectsAsync(authentication);
            }
        }
예제 #6
0
        public static async Task RefreshAccessTokenAsync(DesignTimeAuthentication designTimeAuthentication)
        {
            AuthenticationClient client = new AuthenticationClient();

            client.AccessToken  = designTimeAuthentication.AccessToken;
            client.RefreshToken = designTimeAuthentication.RefreshToken;
            client.InstanceUrl  = designTimeAuthentication.InstanceUrl;

            await client.TokenRefreshAsync(
                Constants.VisualStudioConnectedAppClientId,
                client.RefreshToken,
                string.Empty,
                new Uri(designTimeAuthentication.Domain, "/services/oauth2/token").ToString());

            designTimeAuthentication.AccessToken = client.AccessToken;
            designTimeAuthentication.InstanceUrl = client.InstanceUrl;
        }
예제 #7
0
        private static async Task <T> GetSalesforceAsync <T>(string urlSuffix, DesignTimeAuthentication authentication)
        {
            T result = default(T);
            await AuthenticationHelper.ExecuteSalesforceRequestAsync <ForceException>(
                authentication,
                async() =>
            {
                ServiceHttpClient client = new ServiceHttpClient(
                    authentication.InstanceUrl,
                    Constants.SalesforceApiVersionWithPrefix,
                    authentication.AccessToken,
                    new HttpClient());
                result = await client.HttpGetAsync <T>(urlSuffix);
            },
                (e) => e.Error == Error.InvalidGrant);

            return(result);
        }
예제 #8
0
        public static async Task <IEnumerable <GeneratedObject> > BuildObjectModelAsync(
            IEnumerable <SObjectDescription> sObjects,
            DesignTimeAuthentication authentication,
            GeneratedService generatedService,
            ConnectedServiceLogger logger)
        {
            IEnumerable <SObjectDescription> sObjectsWithDetails = await MetadataLoader.LoadObjectDetailsAsync(sObjects, authentication);

            IEnumerable <GeneratedObject> generatedObjects = sObjectsWithDetails
                                                             .Select(o => new GeneratedObject()
            {
                Model             = o,
                Service           = generatedService,
                StorageProperties = CodeModelBuilder.BuildStorageProperties(o, logger)
            })
                                                             .ToArray();

            return(generatedObjects);
        }
        public static async Task<IEnumerable<GeneratedObject>> BuildObjectModelAsync(
            IEnumerable<SObjectDescription> sObjects,
            DesignTimeAuthentication authentication,
            GeneratedService generatedService,
            ConnectedServiceLogger logger)
        {
            IEnumerable<SObjectDescription> sObjectsWithDetails = await MetadataLoader.LoadObjectDetailsAsync(sObjects, authentication);

            IEnumerable<GeneratedObject> generatedObjects = sObjectsWithDetails
                .Select(o => new GeneratedObject()
                {
                    Model = o,
                    Service = generatedService,
                    StorageProperties = CodeModelBuilder.BuildStorageProperties(o, logger)
                })
                .ToArray();

            return generatedObjects;
        }
예제 #10
0
        public static async Task ExecuteSalesforceRequestAsync <TException>(
            DesignTimeAuthentication designTimeAuthentication,
            Func <Task> executeRequest,
            Func <TException, bool> getIsAccessTokenExpired,
            Action onRefreshToken = null)
            where TException : Exception
        {
            bool isAccessTokenExpired = false;

            try
            {
                await executeRequest();
            }
            catch (TException e)
            {
                if (getIsAccessTokenExpired(e))
                {
                    isAccessTokenExpired = true;
                }
                else
                {
                    throw;
                }
            }

            if (isAccessTokenExpired)
            {
                await AuthenticationHelper.RefreshAccessTokenAsync(designTimeAuthentication);

                if (onRefreshToken != null)
                {
                    onRefreshToken();
                }

                await executeRequest();
            }
        }
예제 #11
0
        public static async Task <IEnumerable <SObjectDescription> > LoadObjectsAsync(DesignTimeAuthentication authentication)
        {
            GlobalDescribeResponse describeResponse = await MetadataLoader.GetSalesforceAsync <GlobalDescribeResponse>(
                "sobjects", authentication);

            return(describeResponse.SObjects);
        }