internal void DoVisit(ISemanticModel semanticModel, CommonSyntaxNode token, TokenParameter parameter, TokenKind searchTokenKind, Action<int> symbolFoundDelegate)
 {
     this.semanticModel = semanticModel as SemanticModel;
     this.symbolFoundDelegate = symbolFoundDelegate;
     this.parameter = parameter;
     this.searchTokenKind = searchTokenKind;
     Visit(token as SyntaxNode);
 }
        public Task<List<TokenResult>> FindReferences(TokenParameter tokenParameter)
        {
            return Task.Factory.StartNew<List<TokenResult>>(() =>
                {
                    if (this.findProgressListener is IClientCallback)
                    {
                        ((IClientCallback)this.findProgressListener).ProjectConnectionId = ControllerContext.Request.Cookie("ProjectConnectionId");
                    }

                    tokenParameter.Path = tokenParameter.Path.CorrectPathToWindowsStyle();
                    return this.editorService.FindRefernces(tokenParameter, findProgressListener);
                });
        }
        private void TraverseThroughAllTheProjectFiles(TokenParameter parameter, IFindReferenceProgress findReferenceProgressListener, Func< string, string, ISemanticModel, CommonSyntaxNode, bool> visitorAction)
        {
            findReferenceProgressListener.OnFindReferenceStarted();

            var projectCodeDirectory = new DirectoryInfo(this.applicationConfigurationProvider.GetProjectSourceCodePath(parameter.Username, parameter.Project));

            var solutionPath = FindSolutionPath(parameter.Username, parameter.Project);
            if (solutionPath == null)
            {
                findReferenceProgressListener.OnFindReferenceCompleted(0);
                return;
            }

            findReferenceProgressListener.OnFindReferenceInProgress();

            var workspace = Roslyn.Services.Workspace.LoadSolution(solutionPath);
            var currentFilePath = Path.Combine(projectCodeDirectory.FullName, parameter.Path.Replace(@"/", @"\"));
            var solution = workspace.CurrentSolution;

            foreach (var project in solution.Projects)
            {

                try
                {
                    bool processingCompleted = false;

                    if (!project.HasDocuments)
                    {
                        continue;
                    }

                    foreach (var document in project.Documents)
                    {
                        var documentSemanticModel = document.GetSemanticModel();
                        var findReferenceSyntaxtWalker = new FindReferenceSyntaxWalker();
                        CommonSyntaxNode syntaxRoot = null;
                        if (documentSemanticModel.SyntaxTree.TryGetRoot(out syntaxRoot))
                        {
                            var documentRelativePath = new Uri(projectCodeDirectory.FullName + Path.DirectorySeparatorChar).MakeRelativeUri(new Uri(document.FilePath)).ToString();
                            processingCompleted = visitorAction(document.Name, documentRelativePath,documentSemanticModel, syntaxRoot);
                            if (processingCompleted)
                            {
                                break;
                            }
                        }
                    }

                    if (processingCompleted)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    this.logger.Error(ex, "An error has occured while loading the project {0}", project.Name);
                }
            }
        }
        public TokenResult GoToDefinition(TokenParameter parameter, IFindReferenceProgress findReferenceProgressListener)
        {
            try
            {
                return this.sourceCodeQueryService.FindExact(parameter);
            }
            catch (Exception ex)            {

                this.logger.Error(ex, "Error occured while finding definition for {0}", parameter.FullyQualifiedName);
            }

            return null;
        }
        public List<TokenResult> FindRefernces(TokenParameter parameter, IFindReferenceProgress findReferenceProgressListener)
        {
            var result = new List<TokenResult>();
            var findReferenceSyntaxWalker = new FindReferenceSyntaxWalker();
            TraverseThroughAllTheProjectFiles(parameter, findReferenceProgressListener, (documentName, documentRelativePath, semanticModel, syntaxRoot) =>
            {
                findReferenceSyntaxWalker.DoVisit(syntaxRoot, parameter.Text, (foundlocation) =>
                {
                    result.Add(new TokenResult { FileName = documentName, Path = documentRelativePath, Position = foundlocation });
                });

                return false;
            });

            findReferenceProgressListener.OnFindReferenceCompleted(result.Count);
            return result;
        }