Example #1
0
        public static FileContents Load(Project project, ProjectItem projectItem, FileDto translationsFile)
        {
            if (project == null)
                throw new ArgumentNullException("project");
            if (projectItem == null)
                throw new ArgumentNullException("projectItem");

            var nodes = new List<FileNode>();
            var resourceNodes = new Dictionary<string, NodeDto>();

            if (translationsFile != null)
            {
                foreach (var node in translationsFile.Nodes)
                {
                    resourceNodes.Add(node.Name, node);
                }
            }

            string currentDirectory = Environment.CurrentDirectory;

            try
            {
                var directory = project.Directory;
                Environment.CurrentDirectory = directory;

                using (var reader = new ResXResourceReader(Path.Combine(directory, projectItem.FileName)))
                {
                    reader.UseResXDataNodes = true;

                    foreach (DictionaryEntry entry in reader)
                    {
                        var node = (ResXDataNode)entry.Value;

                        if (node.GetValue((ITypeResolutionService)null) is string)
                            AddNode(nodes, resourceNodes, node);
                    }
                }
            }
            finally
            {
                Environment.CurrentDirectory = currentDirectory;
            }

            return new FileContents(nodes);
        }
Example #2
0
        private void LoadSolution()
        {
            var projects = new List<ProjectItem>();

            foreach (string line in File.ReadAllLines(RootNode.FileName))
            {
                var match = ProjectLineRe.Match(line);
                if (match.Success)
                {
                    string guid = match.Groups[1].Value;

                    // Ignore folders.

                    if (guid.ToUpperInvariant().Contains("2150E333-8FDC-42A3-9474-1A3956D46DE8"))
                        continue;

                    var project = new Project(
                        this,
                        Path.Combine(
                            Path.GetDirectoryName(RootNode.FileName),
                            Unquote(match.Groups[3].Value)
                        ),
                        Unquote(match.Groups[2].Value)
                    );

                    projects.Add(project.RootNode);
                }
            }

            projects.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.InvariantCulture));

            RootNode.Children.AddRange(projects);
        }