internal void SetComponentLinks(IEnumerable<AbstractEndpoint.IAbstractComponentLink> componentLinks)
        {
            var links = new List<ComponentsOrderingViewModel>();

            var setOrder = new Action(() =>
                {
                    var worker = new BackgroundWorker();
                    worker.DoWork += (e, s) =>
                    {
                        foreach (var cl in links.AsEnumerable().Reverse())
                        {
                            cl.Link.Order = links.IndexOf(cl) + 1;
                        }
                    };
                    worker.RunWorkerAsync();
                });
            foreach (var cl in componentLinks.OrderBy(x => x.Order))
            {
                var vm = new ComponentsOrderingViewModel { Link = cl };
                links.Add(vm);
                vm.UpCommand = new RelayCommand(
                    () =>
                    {
                        var prevIndex = links.IndexOf(vm);
                        links.Remove(vm);
                        links.Insert(prevIndex - 1, vm);
                        this.ComponentList.ItemsSource = null;
                        this.ComponentList.ItemsSource = links;
                        this.ComponentList.SelectedItem = vm;
                        setOrder();
                    }, () => links.IndexOf(vm) > 0);
                vm.DownCommand = new RelayCommand(
                    () =>
                    {
                        var prevIndex = links.IndexOf(vm);
                        links.Remove(vm);
                        links.Insert(prevIndex + 1, vm);
                        this.ComponentList.ItemsSource = null;
                        this.ComponentList.ItemsSource = links;
                        this.ComponentList.SelectedItem = vm;
                        setOrder();
                    }, () => links.IndexOf(vm) < links.Count - 1);
            }
            this.ComponentList.ItemsSource = links;
        }
        private async void CreateRepo_Click(object sender, RoutedEventArgs e)
        {
            CreateRepo.IsEnabled = false;
            RepoProgress.Visibility = Visibility.Visible;

            var asd = new List<string>();
            foreach (CheckBox item in ListOfFolders.Items)
            {
                if (item.IsChecked.HasValue)
                {
                    if ((bool)item.IsChecked) asd.Add((string)item.Content);
                }
            }

            if (asd.Count > 0)
            {
                await Task.Run(() =>
                {
                    var newRepo = new RepositoryData();
                    newRepo.DownloadRoot = Repository.DefaultUrlBase;

                    newRepo.Files = r.CreateRepositoryData(asd.AsEnumerable());
                    string output = JsonConvert.SerializeObject(newRepo);

                    try
                    {
                        using (var wr = new StreamWriter("updater.json", false))
                        {
                            wr.Write(output);
                            wr.Flush();
                        }
                        MessageBox.Show("Metadata created successfully.");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to write metadata file.");
                    }
                });
            }

            CreateRepo.IsEnabled = true;
            RepoProgress.Visibility = Visibility.Hidden;
        }
        /*
         * Get the member access in the document, returning a tuple of member access node and the RefactoringType it is accessing.
         */
        public IEnumerable<Tuple<SyntaxNode, ITypeSymbol>> GetMemberAccessAndAccessedTypes()
        {
            // For all the classes whose memeber is accessed and their types.
            var typedAccesses = new List<Tuple<SyntaxNode, ITypeSymbol>>();

            // Get all nodes whose RefactoringType is member access.
            var accesses = root.DescendantNodes().Where(n => n.Kind == SyntaxKind.MemberAccessExpression);

            // For all the access in the list.
            foreach (SyntaxNode access in accesses)
            {
                // Get left and right side of the access.
                var analyzer = AnalyzerFactory.GetMemberAccessAnalyzer();
                analyzer.SetMemberAccess(access);
                var left = analyzer.GetLeftPart();

                // Query about the RefactoringType of the left side of the access, if it is not null, add to the results.
                // ATTENTION: mode.GetTypeInfo() cannot get primitive RefactoringType such as int.
                var infor = model.GetTypeInfo(left);
                if(infor.Type != null)
                    typedAccesses.Add(Tuple.Create(access, infor.Type));
            }
            return typedAccesses.AsEnumerable();
        }
        /* Map all the nodes to another document. */
        public IEnumerable<SyntaxNode> MapToAnotherDocument(IDocument document)
        {
            var analyzer = AnalyzerFactory.GetSyntaxNodeAnalyzer();
            var list = new List<SyntaxNode>();

            foreach (SyntaxNode node in nodes)
            {
                analyzer.SetSyntaxNode(node);
                list.Add(analyzer.MapToAnotherDocument(document));
            }
            return list.AsEnumerable();
        }
        /*
         * Get groups of nodes. In each group, nodes are sequentially ordered and no code in
         * between of each two nearby nodes.
         */
        public IEnumerable<IEnumerable<SyntaxNode>> GetNeighborredNodesGroups()
        {
            // Remove all the nodes contained by other node in the list, also sort the list by starting position
            var sortedNodes = RemoveSubNodes().OrderBy(n => n.Span.Start);
            var breakIndexes = new List<int>();
            var analyzer = AnalyzerFactory.GetSyntaxNodeAnalyzer();
            logger.Debug("Sourted node count: " + sortedNodes.Count());

            // Iterate all the nodes, if one is not neighborred with its previous one, add to the break indexes.
            for (int i = 1; i < sortedNodes.Count(); i++)
            {
                analyzer.SetSyntaxNode(nodes.ElementAt(i));
                if (!analyzer.IsNeighborredWith(sortedNodes.ElementAt(i - 1)))
                {
                    breakIndexes.Add(i);
                }
            }

            // The number of elements shall be the last break index.
            breakIndexes.Add(nodes.Count());

            var lists = new List<IEnumerable<SyntaxNode>>();
            int start = 0;

            // Iterate each break index, from 'last break index' to 'current break index -1'
            // is a group of neiborred syntax node.
            foreach (var end in breakIndexes)
            {
                lists.Add(sortedNodes.Skip(start).Take(end - start));
                start = end;
            }
            return lists.AsEnumerable();
        }
 /* Get a subset of all the containing statements, start and end index are inclusive. */
 public IEnumerable<SyntaxNode> GetStatementsByIndexRange(int start, int end)
 {
     var statements = GetStatements();
     var subList = new List<SyntaxNode>();
     for(int i = start; i <= end; i++)
     {
         subList.Add(statements.ElementAt(i));
     }
     return subList.AsEnumerable();
 }
        public IEnumerable<SyntaxNode> GetStatementsBefore(int position)
        {
            // Get all the statements first.
            IEnumerable<SyntaxNode> statements = GetStatements();

            // Initiate an empty statement list.
            IList<SyntaxNode> result = new List<SyntaxNode>();

            // Iterate all the statement.
            foreach(var statement in statements)
            {
                // For statement whose end point is before the position, add it to the result
                if (statement.Span.End < position)
                {
                    result.Add(statement);
                }
            }
            return result.AsEnumerable();
        }
        public IEnumerable<IEnumerable<SyntaxNode>> GetParameterUsages()
        {
            // Containing the results.
            var list = new List<IEnumerable<SyntaxNode>>();

            // All the parameters taken.
            var parameters = GetParameters();

            // Block of the method declaration.
            var block = ASTUtil.GetBlockOfMethod(method);

            // For each parameter.
            // ATTENTION: foreach will throw null exception if it has nothing in it.
            foreach (ParameterSyntax para in parameters)
            {
                // Need a new subList to copy out nodes, IEnumerable is a read only interface that will not copy out as new
                // elements. To copy out as new elements, a list is needed.
                // ATTENTION: cannot list.add(block.DecendantNodes()...), because if have multiple paras the previous added IEnumerable
                // will be rewrite.
                var sublist = new List<SyntaxNode>();

                // Only able to retrieve the parameter usages if the method block exists.
                if (block != null)
                {
                    // If an identifier name equals the paraemeter's name, it is one usage of the
                    // parameter.
                    sublist.AddRange(block.DescendantNodes().Where(n => n.Kind == SyntaxKind.IdentifierName
                        && n.GetText().Equals(para.Identifier.ValueText)));
                }
                logger.Info("Parameter " + para.Identifier + " usage:" +
                               StringUtil.ConcatenateAll(",", sublist.Select(n => n.Span.ToString())));
                list.Add(sublist.AsEnumerable());
            }
            return list.AsEnumerable();
        }
Beispiel #9
0
        private void XMLParser_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                CheckingLabel.Content = "Picking the right edition for you";
            }
            ));
            //OSParams Tree: [0] = LanguageCode, [1] = Edition, [2] = Architecture, [3] ProductName
            CurrentOSParams = new List<string>();
            CurrentOSParams.Add((CultureInfo.InstalledUICulture).Name.ToLower());
            CurrentOSParams.Add((string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "EditionId", null));
            if (Environment.Is64BitOperatingSystem)
                CurrentOSParams.Add("x64");
            else
                CurrentOSParams.Add("x86");
            CurrentOSParams.Add((string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", null));
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                MainWindowHandle.SendGXNReport("Launched on Build " + (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber", null) + ": LanguageCode=" + CurrentOSParams[0] + ", Edition=" + CurrentOSParams[1] + ", Architecture=" + CurrentOSParams[2] + ", ProductName=" + CurrentOSParams[3]);
            }
            ));
            ESDList = new List<EsdFile>();
            HttpWebRequest wreq = HttpWebRequest.Create("http://msft.gq/pub/xml/mct/10240.16384_prd.xml") as HttpWebRequest;

            using (HttpWebResponse wres = wreq.GetResponse() as HttpWebResponse)
            using (Stream wresStr = wres.GetResponseStream())
            {
                XDocument xdoc = XDocument.Load(wresStr);

                var files = from f in xdoc.Descendants("File")
                            select new EsdFile()
                            {
                                FileName = f.Element("FileName").Value,
                                LanguageCode = f.Element("LanguageCode").Value,
                                Language = f.Element("Language").Value,
                                Edition = f.Element("Edition").Value,
                                Architecture = f.Element("Architecture").Value,
                                Size = long.Parse(f.Element("Size").Value),
                                Sha1 = f.Element("Sha1").Value,
                                FilePath = f.Element("FilePath").Value,
                                Key = f.Element("Key").Value,
                                Architecture_Loc = f.Element("Architecture_Loc").Value,
                                Edition_Loc = f.Element("Edition_Loc").Value,
                                IsRetailOnly = Convert.ToBoolean(f.Element("IsRetailOnly").Value)
                            };

                ESDList.AddRange(files);
            }
            IEnumerable<EsdFile> ESDListEnum = from XMLEntry in ESDList.AsEnumerable()
                                                where XMLEntry.LanguageCode.Equals(CurrentOSParams[0]) &&
                                                      XMLEntry.Edition.Equals(CurrentOSParams[1]) &&
                                                      XMLEntry.Architecture.Equals(CurrentOSParams[2])
                                                select XMLEntry;
            ESDParams = new List<string>();
            UpcomingOSParams = new List<string>();
            foreach (var ESD in ESDListEnum)
            {
                if (UpcomingOSParams.Count < 4)
                {
                    UpcomingOSParams.Add(ESD.LanguageCode);
                    UpcomingOSParams.Add(ESD.Edition);
                    UpcomingOSParams.Add(ESD.Architecture);
                    if (ESD.Edition_Loc.Equals("%EDU_N%"))
                        UpcomingOSParams.Add("Windows 10 Education N");
                    else if (ESD.Edition_Loc.Equals("%BASE_K%"))
                        UpcomingOSParams.Add("Windows 10 Home K");
                    else if (ESD.Edition_Loc.Equals("%BASE%"))
                        UpcomingOSParams.Add("Windows 10 Home");
                    else if (ESD.Edition_Loc.Equals("%BASE_CHINA%"))
                        UpcomingOSParams.Add("Windows 10 Home China");
                    else if (ESD.Edition_Loc.Equals("%EDU_K%"))
                        UpcomingOSParams.Add("Windows 10 Education K");
                    else if (ESD.Edition_Loc.Equals("%BASE_N%"))
                        UpcomingOSParams.Add("Windows 10 Home N");
                    else if (ESD.Edition_Loc.Equals("%PRO_K%"))
                        UpcomingOSParams.Add("Windows 10 Pro K");
                    else if (ESD.Edition_Loc.Equals("%EDU%"))
                        UpcomingOSParams.Add("Windows 10 Education");
                    else if (ESD.Edition_Loc.Equals("%SINGLE_LANGUAGE%"))
                        UpcomingOSParams.Add("Windows 10 Home Single Language");
                    else if (ESD.Edition_Loc.Equals("%EDU_KN%"))
                        UpcomingOSParams.Add("Windows 10 Education KN");
                    else if (ESD.Edition_Loc.Equals("%PRO_N%"))
                        UpcomingOSParams.Add("Windows 10 Pro N");
                    else if (ESD.Edition_Loc.Equals("%PRO%"))
                        UpcomingOSParams.Add("Windows 10 Pro");
                    else if (ESD.Edition_Loc.Equals("%PRO_KN%"))
                        UpcomingOSParams.Add("Windows 10 Pro KN");
                    else if (ESD.Edition_Loc.Equals("%BASE_KN%"))
                        UpcomingOSParams.Add("Windows 10 Home KN");
                }
                //ESDParams Tree: [0] Url, [1] FileName, [2] Sha1, [3] Key
                if (ESDParams.Count < 4)
                {
                    ESDParams.Add(ESD.FilePath);
                    ESDParams.Add(ESD.FileName);
                    ESDParams.Add(ESD.Sha1);
                    ESDParams.Add(ESD.Key);
                }
            }
            if (ESDParams.Count < 4)
            {
                HasFailed = true;
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                {
                    MainWindowHandle.JumpToErrorPage("There is no edition of Windows 10 we could upgrade you to.");
                    return;
                }
                ));
            }
            else
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                {
                    MainWindowHandle.SendGXNReport("ESD to download: " + ESDParams[1]);
                }
                ));
            }
        }
        /*
         * Get tuples of node and RefactoringType. Nodes shall be identifier names.
         * ATTENTION: the declarations cannot get RefactoringType info, only identifiers(references) can.
         */
        public IEnumerable<Tuple<SyntaxNode, ITypeSymbol>> GetTypableIdentifierTypeTuples()
        {
            var typedIdentifiers = new List<Tuple<SyntaxNode, ITypeSymbol>>();

            // Get all identifiers.
            var identifiers = root.DescendantNodes().Where(n => n.Kind == SyntaxKind.IdentifierName);
            foreach (SyntaxNode id in identifiers)
            {
                // Query RefactoringType information of an identifier.
                var info = model.GetTypeInfo(id);

                // If RefactoringType is retrieved, add to the result.
                if (info.Type != null)
                    typedIdentifiers.Add(Tuple.Create(id, info.Type));
            }
            return typedIdentifiers.AsEnumerable();
        }