コード例 #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);
        }
コード例 #2
0
        public void Save(ProjectItem projectItem, List<NodeDto> nodes)
        {
            if (projectItem == null)
                throw new ArgumentNullException("projectItem");
            if (nodes == null)
                throw new ArgumentNullException("nodes");

            nodes.RemoveAll(p => String.IsNullOrEmpty(p.Text));

            var file = new FileDto
            {
                Name = GetFileName(projectItem),
                Nodes = nodes
            };

            int index = _translations.Files.FindIndex(p => p.Name == file.Name);
            if (index == -1)
            {
                if (file.Nodes.Count > 0)
                    _translations.Files.Add(file);
            }
            else
            {
                if (file.Nodes.Count == 0)
                    _translations.Files.RemoveAt(index);
                else
                    _translations.Files[index] = file;
            }

            Sort();

            using (var stream = File.Create(FileName))
            using (var writer = new StreamWriter(stream, Encoding))
            {
                Serializer.Serialize(writer, _translations);
            }

            Project.FindProject(projectItem).UpdateProjectItemState(projectItem, this);
        }
コード例 #3
0
 public static FileContents Load(ProjectItem projectItem, FileDto translationsFile)
 {
     return Load(Project.FindProject(projectItem), projectItem, translationsFile);
 }