/// <summary>
        /// Method to be called from the event handler handled in the HandleNavigationInternal
        /// </summary>
        /// <param name="viewName">The view name that is passed to you from HandleNavigationInternal</param>
        public void OnEventFired(string viewName)
        {
            if (_host == null)
            {
                throw new InvalidOperationException("NavigationHost was not specified");
            }

            var export = MEFedContainer.Instance.Resolver.GetValueByContract(viewName, CreationPolicy.NonShared);

            if (export == null)
            {
                throw new InvalidOperationException("View " + viewName + " was not found. Make sure view is exported");
            }

            var view = export.Value as FrameworkElement;

            if (view == null)
            {
                throw new InvalidOperationException("View must be a framework element");
            }
            var navigationInfoSubscriber = view.DataContext as INavigationInfoSubscriber;

            if (navigationInfoSubscriber != null)
            {
                navigationInfoSubscriber.OnNavigationChanged(this, _navigationParameter);
            }

            OnNavigationChanged(new NavigationEventArgs {
                IsCloseRequest = false, NewNavigationView = viewName, NewNavigationInfoSubscriber = navigationInfoSubscriber
            });

            NavigationExtensions.SetNavigationHandler(view, this);

            _host.RenderControl(view);
        }
Esempio n. 2
0
        ///--- Listeneres ---///
        private async void ListView_OnSelectionChanged(object sender, ItemSelectionChangedEventArgs e)
        {
            Data dat = (Data)listView.SelectedItem;

            Globals.SelectedData = dat;
            await NavigationExtensions.PushAsyncSingle(Navigation, new AssignmentsPage(), true);
        }
        /// <summary>
        /// Called when the user chooses an item from the drop down
        /// </summary>
        public int OnItemChosen(int comboBoxId, int index)
        {
            if (_dropDownBar == null)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            var entries = GetEntries(comboBoxId);

            if (entries != null && index < entries.Count)
            {
                SetSelectedIndex(comboBoxId, index);
                _dropDownBar.RefreshCombo(comboBoxId, index);

                var functionEntryInfo = entries[index] as FunctionDefinitionEntryInfo;
                if (functionEntryInfo != null)
                {
                    NavigationExtensions.NavigateToFunctionDefinition(_textView, functionEntryInfo.FunctionDefinition);
                }
                else
                {
                    NavigationExtensions.NavigateToLocation(_textView, entries[index].Start);
                }
            }

            return(VSConstants.S_OK);
        }
Esempio n. 4
0
        private void ValidateFunctionNameSpan(string mockedScript, Span expectedResult)
        {
            var generatedAst       = GenerateAst(mockedScript);
            var functionDefinition = generatedAst.Find(ast => ast is FunctionDefinitionAst, true) as FunctionDefinitionAst;
            var functionNameSpan   = NavigationExtensions.GetFunctionNameSpan(functionDefinition);

            if (functionDefinition == null)
            {
                // If functionDefinition is null, that means the test is running with a version of PowerShell that doesn't support classes, so span should be null
                Assert.IsNull(functionNameSpan);
            }
            else
            {
                Assert.AreEqual(expectedResult, functionNameSpan);
            }
        }
        protected override void IncludeNavigations(
            IncludeSpecification includeSpecification,
            Type resultType,
            LambdaExpression accessorLambda,
            bool querySourceRequiresTracking)
        {
            Check.NotNull(includeSpecification, nameof(includeSpecification));
            Check.NotNull(resultType, nameof(resultType));
            Check.NotNull(accessorLambda, nameof(accessorLambda));

            var primaryKeyParameter        = Expression.Parameter(typeof(EntityKey));
            var relatedKeyFactoryParameter = Expression.Parameter(typeof(Func <ValueBuffer, EntityKey>));
            var navigationPath             = includeSpecification.NavigationPath;

            Expression
                = Expression.Call(
                      _includeMethodInfo.MakeGenericMethod(resultType),
                      QueryContextParameter,
                      Expression,
                      Expression.Constant(navigationPath),
                      accessorLambda,
                      System.Linq.Expressions.Expression.NewArrayInit(
                          typeof(RelatedEntitiesLoader),
                          navigationPath.Select(
                              n =>
            {
                var targetType = NavigationExtensions.GetTargetType((INavigation)n);

                var materializer
                    = _materializerFactory
                      .CreateMaterializer(targetType);

                return(Expression.Lambda <RelatedEntitiesLoader>(
                           Expression.Call(
                               _getRelatedValueBuffersMethodInfo,
                               QueryContextParameter,
                               Expression.Constant(targetType),
                               primaryKeyParameter,
                               relatedKeyFactoryParameter,
                               materializer),
                           primaryKeyParameter,
                           relatedKeyFactoryParameter));
            })),
                      Expression.Constant(querySourceRequiresTracking));
        }
            private static void IncludeCollection <TEntity, TIncludingEntity, TIncludedEntity>(
                QueryContext queryContext,
                IEnumerable <ValueBuffer> innerValueBuffers,
                Func <QueryContext, ValueBuffer, TIncludedEntity> innerShaper,
                TEntity entity,
                INavigation navigation,
                INavigation inverseNavigation,
                Action <TIncludingEntity, TIncludedEntity> fixup,
                bool trackingQuery)
                where TIncludingEntity : class, TEntity
                where TEntity : class
                where TIncludedEntity : class
            {
                if (entity is TIncludingEntity includingEntity)
                {
                    var collectionAccessor = navigation.GetCollectionAccessor();
                    collectionAccessor.GetOrCreate(includingEntity, forMaterialization: true);

                    if (trackingQuery)
                    {
                        queryContext.SetNavigationIsLoaded(entity, navigation);
                    }
                    else
                    {
                        NavigationExtensions.SetIsLoadedWhenNoTracking(navigation, entity);
                    }

                    foreach (var valueBuffer in innerValueBuffers)
                    {
                        var relatedEntity = innerShaper(queryContext, valueBuffer);

                        if (!trackingQuery)
                        {
                            fixup(includingEntity, relatedEntity);
                            if (inverseNavigation != null)
                            {
                                NavigationExtensions.SetIsLoadedWhenNoTracking(inverseNavigation, relatedEntity);
                            }
                        }
                    }
                }
            }
Esempio n. 7
0
        static void Main(string[] args)
        {
            string templateWebUrl = "https://kovag.sharepoint.com/sites/Samenwerkingsgroep_Template";
            string targetWebUrl   = "https://kovag.sharepoint.com/sites/ProvisioningTarget_EN_6";
            string userName       = "******";
            string pwdS           = "Spikes16";

            SecureString pwd = new SecureString();

            foreach (char c in pwdS.ToCharArray())
            {
                pwd.AppendChar(c);
            }

            using (var ctx = new ClientContext(templateWebUrl))
            {
                // ctx.Credentials = new NetworkCredentials(userName, pwd);
                ctx.Credentials    = new SharePointOnlineCredentials(userName, pwd);
                ctx.RequestTimeout = Timeout.Infinite;

                // Just to output the site details
                Web web = ctx.Web;
                ctx.Load(web, w => w.Title);
                ctx.ExecuteQueryRetry();

                var nodes = NavigationExtensions.LoadSearchNavigation(ctx.Web);
            }

            using (var ctx = new ClientContext(targetWebUrl))
            {
                // ctx.Credentials = new NetworkCredentials(userName, pwd);
                ctx.Credentials    = new SharePointOnlineCredentials(userName, pwd);
                ctx.RequestTimeout = Timeout.Infinite;

                // Just to output the site details
                Web web = ctx.Web;
                ctx.Load(web, w => w.Title);
                ctx.ExecuteQueryRetry();

                var nodes = NavigationExtensions.LoadSearchNavigation(ctx.Web);
            }
        }
Esempio n. 8
0
        private static void ValidateDefinitions(IEnumerable <ScriptSectionMock> script)
        {
            var mockedScript     = String.Concat(script.Select(s => s.Code));
            var textSnapshotMock = TextSnapshotMock(mockedScript);

            var includeEnd         = 0;
            var previousCodeLength = 0;

            foreach (var scriptSection in script)
            {
                int start = previousCodeLength + includeEnd;
                includeEnd = scriptSection.ExpectedValues != null ? 1 : 0;

                for (var i = start; i < previousCodeLength + scriptSection.Code.Length + includeEnd; i++)
                {
                    var generatedAst = GenerateAst(mockedScript);
                    var actualVals   = NavigationExtensions.FindFunctionDefinitions(generatedAst, textSnapshotMock, i);

                    if (scriptSection.ExpectedValues == null)
                    {
                        Assert.IsNull(actualVals);
                    }
                    else
                    {
                        Assert.IsNotNull(actualVals);
                        Assert.AreEqual(scriptSection.ExpectedValues.Count(), actualVals.Count());
                        scriptSection.ExpectedValues.Zip(actualVals, (expected, actual) =>
                        {
                            Assert.AreEqual(expected.Name, actual.Name);
                            Assert.AreEqual(expected.StartLineNumber, actual.Extent.StartLineNumber);
                            return(true);
                        });
                    }
                }

                previousCodeLength = previousCodeLength + scriptSection.Code.Length;
            }
        }
 private static void IncludeReference <TEntity, TIncludingEntity, TIncludedEntity>(
     QueryContext queryContext,
     TEntity entity,
     TIncludedEntity relatedEntity,
     INavigation navigation,
     INavigation inverseNavigation,
     Action <TIncludingEntity, TIncludedEntity> fixup,
     bool trackingQuery)
     where TIncludingEntity : class, TEntity
     where TEntity : class
     where TIncludedEntity : class
 {
     if (entity is TIncludingEntity includingEntity)
     {
         if (trackingQuery &&
             navigation.DeclaringEntityType.FindPrimaryKey() != null)
         {
             // For non-null relatedEntity StateManager will set the flag
             if (relatedEntity == null)
             {
                 queryContext.SetNavigationIsLoaded(includingEntity, navigation);
             }
         }
         else
         {
             NavigationExtensions.SetIsLoadedWhenNoTracking(navigation, includingEntity);
             if (relatedEntity != null)
             {
                 fixup(includingEntity, relatedEntity);
                 if (inverseNavigation != null &&
                     !inverseNavigation.IsCollection)
                 {
                     NavigationExtensions.SetIsLoadedWhenNoTracking(inverseNavigation, relatedEntity);
                 }
             }
         }
     }
 }