/// <summary>
        /// Change the text in the source file
        /// </summary>
        public override void ApplyTranslation()
        {
            if (!Applied)
            {
                ResXResourceWriter writer = null;
                MemoryStream       stream = null;
                try {
                    stream          = new MemoryStream();
                    writer          = new ResXResourceWriter(stream);
                    writer.BasePath = Path.GetDirectoryName(Filename);

                    // change resource values in all BufferTranslateInfoItems
                    BufferTranslateInfoItem i = this;
                    while (true)
                    {
                        if (i == null || i.Applied)
                        {
                            break;
                        }
                        writer.AddResource(i.ResourceKey, i.Value);

                        i.Applied = true;
                        i         = i.Prev;
                    }
                    foreach (ResXDataNode node in GlobalTranslateItem.NonStringData)
                    {
                        writer.AddResource(node);
                    }

                    writer.Generate();
                    writer.Close();

                    VLDocumentViewsManager.SaveStreamToBuffer(stream, IVsTextLines, false);
                } finally {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
            }
        }
        /// <summary>
        /// Add string data from given ResX file to the list of data for translation
        /// </summary>
        private void AddDataForTranslation(GlobalTranslateProjectItem item, List <AbstractTranslateInfoItem> data)
        {
            string path = item.ProjectItem.GetFullPath();

            if (RDTManager.IsFileOpen(path))                              // file is open
            {
                object docData = VLDocumentViewsManager.GetDocData(path); // get document buffer
                if (docData is ResXEditor)                                // document is opened in ResX editor -> use custom method to get string data
                {
                    ResXEditor editor = (ResXEditor)docData;
                    editor.UIControl.AddForTranslation(data);
                }
                else     // document is opened in original VS editor
                {
                    IVsTextLines lines = VLDocumentViewsManager.GetTextLinesForFile(path, false);
                    string       text  = VLDocumentViewsManager.GetTextFrom(lines); // get plain text of ResX file

                    ResXResourceReader reader = null;

                    BufferTranslateInfoItem prev  = null;
                    BufferTranslateInfoItem first = null;

                    try {
                        reader = ResXResourceReader.FromFileContents(text);
                        reader.UseResXDataNodes = true;

                        // add all string resources to the list
                        // items are linked like a linked-list, allowing ApplyTranslation to work
                        foreach (DictionaryEntry entry in reader)
                        {
                            ResXDataNode node = (entry.Value as ResXDataNode);
                            if (node.HasValue <string>())
                            {
                                BufferTranslateInfoItem translateItem = new BufferTranslateInfoItem();
                                translateItem.ResourceKey         = entry.Key.ToString();
                                translateItem.Value               = node.GetValue <string>();
                                translateItem.Filename            = path;
                                translateItem.Applied             = false;
                                translateItem.GlobalTranslateItem = item;
                                translateItem.Prev         = prev;
                                translateItem.IVsTextLines = lines;

                                data.Add(translateItem);
                                prev = translateItem;
                                if (first == null)
                                {
                                    first = translateItem;
                                }
                            }
                            else
                            {
                                item.NonStringData.Add(node);
                            }
                        }
                        if (first != null)
                        {
                            first.Prev = prev;
                        }
                    } finally {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
            }
            else     // file is closed
            {
                ResXProjectItem resxItem = ResXProjectItem.ConvertToResXItem(item.ProjectItem, item.ProjectItem.ContainingProject);
                resxItem.Load();
                loadedResxItems.Add(resxItem);

                // add string data from ResX file
                resxItem.AddAllStringReferencesUnique(data);
            }
        }