/// <summary>
 /// Evaluates given result item
 /// </summary>
 /// <returns>
 /// Null if the criterion is not relevant for the result item (testing element prefix for C# string literal...), true if it is relevant and the result item satisfies the condition, false otherwise
 /// </returns>
 public override bool?Eval(CodeStringResultItem resultItem)
 {
     if (resultItem == null)
     {
         throw new ArgumentNullException("resultItem");
     }
     return(Predicate(resultItem));
 }
Пример #2
0
        /// <summary>
        /// Marks given result item with no-localization comment
        /// </summary>
        /// <returns>Length of no-localization comment (language specific)</returns>
        private int MarkAsNoLoc(IVsTextLines textLines, CodeStringResultItem resultItem)
        {
            int hr = textLines.ReplaceLines(resultItem.ReplaceSpan.iStartLine, resultItem.ReplaceSpan.iStartIndex, resultItem.ReplaceSpan.iStartLine, resultItem.ReplaceSpan.iStartIndex,
                                            Marshal.StringToBSTR(resultItem.NoLocalizationComment), resultItem.NoLocalizationComment.Length, new TextSpan[1]);

            Marshal.ThrowExceptionForHR(hr);

            return(resultItem.NoLocalizationComment.Length);
        }
Пример #3
0
        /// <summary>
        /// Perform actual replacement of the string literal
        /// </summary>
        /// <returns>Length of the reference</returns>
        private int MoveToResource(IVsTextLines textLines, CodeStringResultItem resultItem, ReferenceString referenceText)
        {
            string newText = resultItem.GetReferenceText(referenceText);
            int    hr      = textLines.ReplaceLines(resultItem.ReplaceSpan.iStartLine, resultItem.ReplaceSpan.iStartIndex, resultItem.ReplaceSpan.iEndLine, resultItem.ReplaceSpan.iEndIndex,
                                                    Marshal.StringToBSTR(newText), newText.Length, new TextSpan[] { resultItem.ReplaceSpan });

            Marshal.ThrowExceptionForHR(hr);

            return(newText.Length);
        }
Пример #4
0
        /// <summary>
        /// Returns list of namespaces that affect given result item (using blocks and namespaces declarations)
        /// </summary>
        private NamespacesList GetUsedNamespacesFor(CodeStringResultItem resultItem)
        {
            if (resultItem is NetStringResultItem)
            {
                CodeNamespace namespaceElement = (resultItem as NetStringResultItem).NamespaceElement;

                if (namespaceElement == null)   // no parent namespace - use source item as a key
                {
                    if (!usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                    {
                        usedNamespacesCache.Add(resultItem.SourceItem, namespaceElement.GetUsedNamespaces(resultItem.SourceItem));
                    }
                    return(usedNamespacesCache[resultItem.SourceItem]);
                }
                else     // has parent namespace - used namespaces can differ, use the parent namespace as a key
                {
                    if (!usedNamespacesCache.ContainsKey(namespaceElement))
                    {
                        usedNamespacesCache.Add(namespaceElement, namespaceElement.GetUsedNamespaces(resultItem.SourceItem));
                        if (usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                        {
                            usedNamespacesCache[namespaceElement].AddRange(usedNamespacesCache[resultItem.SourceItem]);
                        }
                    }

                    return(usedNamespacesCache[namespaceElement]);
                }
            }
            else if (resultItem is AspNetStringResultItem)
            {
                // in case of ASP .NET result items, always use source item as a key
                if (!usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                {
                    usedNamespacesCache.Add(resultItem.SourceItem, (resultItem as AspNetStringResultItem).DeclaredNamespaces);
                }
                return(usedNamespacesCache[resultItem.SourceItem]);
            }
            else
            {
                throw new Exception("Unkown result item type.");
            }
        }
Пример #5
0
 /// <summary>
 /// Checks that given result item has key, value and destination item defined and that no errors occured in toolwindow's grid
 /// </summary>
 private void Validate(CodeStringResultItem resultItem)
 {
     if (string.IsNullOrEmpty(resultItem.Key) || resultItem.Value == null)
     {
         throw new InvalidOperationException("Item key and value cannot be null");
     }
     if (resultItem.DestinationItem == null)
     {
         throw new InvalidOperationException("Item destination cannot be null");
     }
     if (resultItem.DestinationItem.InternalProjectItem == null)
     {
         throw new InvalidOperationException("Item destination cannot be null");
     }
     if (!File.Exists(resultItem.DestinationItem.InternalProjectItem.GetFullPath()))
     {
         throw new InvalidOperationException("File does not exist");
     }
     if (!string.IsNullOrEmpty(resultItem.ErrorText))
     {
         throw new InvalidOperationException(string.Format("on key \"{0}\": \"{1}\"", resultItem.Key, resultItem.ErrorText));
     }
 }
Пример #6
0
        public void Move(List <CodeStringResultItem> dataList, ref int errorRows)
        {
            // sort according to position
            dataList.Sort(new ResultItemsPositionCompararer <CodeStringResultItem>());

            for (int i = dataList.Count - 1; i >= 0; i--)
            {
                try {
                    // initialization of data
                    CodeStringResultItem resultItem   = dataList[i];
                    string              path          = resultItem.SourceItem.GetFullPath();
                    ReferenceString     referenceText = null;
                    bool                addUsingBlock = false;
                    CONTAINS_KEY_RESULT keyConflict   = CONTAINS_KEY_RESULT.DOESNT_EXIST;

                    if (resultItem.MoveThisItem) // row was checked in the toolwindow
                    {
                        Validate(resultItem);    // check that key, value and destination item was specifed and that row has no errors
                        if (!resultItem.DestinationItem.IsLoaded)
                        {
                            resultItem.DestinationItem.Load();
                        }
                        if (!loadedResxItems.Contains(resultItem.DestinationItem))
                        {
                            loadedResxItems.Add(resultItem.DestinationItem);
                        }

                        // check if such item already exists in destination file
                        keyConflict = resultItem.DestinationItem.GetKeyConflictType(resultItem.Key, resultItem.Value, true);
                        if (keyConflict == CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE)
                        {
                            throw new InvalidOperationException(string.Format("Key \"{0}\" already exists with different value.", resultItem.Key));
                        }
                        resultItem.Key = resultItem.DestinationItem.GetRealKey(resultItem.Key); // if key already exists, return its name (solves case-sensitivity problems)

                        NamespacesList usedNamespaces = GetUsedNamespacesFor(resultItem);

                        if (UseFullName || resultItem.MustUseFullName || (resultItem.Language == LANGUAGE.VB && resultItem.DestinationItem.IsProjectDefault(resultItem.SourceItem.ContainingProject)))   // reference will contain namespace
                        {
                            referenceText = new ReferenceString(resultItem.DestinationItem.Namespace, resultItem.DestinationItem.Class, resultItem.Key);
                            addUsingBlock = false; // no using block will be added
                        }
                        else
                        {
                            // use resolver whether it is ok to add using block
                            addUsingBlock = usedNamespaces.ResolveNewElement(resultItem.DestinationItem.Namespace, resultItem.DestinationItem.Class, resultItem.Key,
                                                                             resultItem.SourceItem.ContainingProject, out referenceText);
                        }
                        if (addUsingBlock)   // new using block will be added
                        {
                            if (!usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                            {
                                usedNamespacesCache.Add(resultItem.SourceItem, new NamespacesList());
                            }
                            foreach (var pair in usedNamespacesCache)
                            {
                                if (!pair.Value.ContainsNamespace(resultItem.DestinationItem.Namespace))
                                {
                                    pair.Value.Add(resultItem.DestinationItem.Namespace, null, true);
                                }
                            }
                        }
                    }

                    if (RDTManager.IsFileOpen(path) && RDTManager.IsFileVisible(path))                                                    // file is open
                    {
                        if (resultItem.MoveThisItem || (MarkUncheckedStringsWithComment && !resultItem.IsMarkedWithUnlocalizableComment)) // string literal in text will be modified (referenced or marked with comment)
                        {
                            if (!buffersCache.ContainsKey(path))
                            {
                                // load file's buffer
                                IVsTextLines textLines = DocumentViewsManager.GetTextLinesForFile(path, false);
                                buffersCache.Add(path, textLines);

                                IOleUndoManager m;
                                // get file's undo manager
                                int hr = textLines.GetUndoManager(out m);
                                Marshal.ThrowExceptionForHR(hr);
                                undoManagersCache.Add(path, m);
                            }
                        }

                        if (resultItem.MoveThisItem)
                        {
                            // perform the text replacement
                            MoveToResource(buffersCache[path], resultItem, referenceText);

                            if (resultItem.IsConst && resultItem.CodeModelSource is CodeVariable2)
                            {
                                CodeVariable2 codeVar = (CodeVariable2)resultItem.CodeModelSource;
                                codeVar.ConstKind = vsCMConstKind.vsCMConstKindNone;
                            }

                            if (addUsingBlock)
                            {
                                // add using block to the source file
                                int beforeLines, afterLines;
                                buffersCache[path].GetLineCount(out beforeLines);
                                resultItem.AddUsingBlock(buffersCache[path]);
                                buffersCache[path].GetLineCount(out afterLines);
                                int diff = afterLines - beforeLines;

                                // because of the previous step, it is necessary to adjust position of all not-yet referenced result items
                                for (int j = i; j >= 0; j--)
                                {
                                    var item = dataList[j];
                                    if (item.SourceItem == resultItem.SourceItem)
                                    {
                                        TextSpan ts = new TextSpan();
                                        ts.iEndIndex     = item.ReplaceSpan.iEndIndex;
                                        ts.iEndLine      = item.ReplaceSpan.iEndLine + diff;
                                        ts.iStartIndex   = item.ReplaceSpan.iStartIndex;
                                        ts.iStartLine    = item.ReplaceSpan.iStartLine + diff;
                                        item.ReplaceSpan = ts;
                                    }
                                }
                            }

                            // previous step (replace and possibly new using block) caused undo unit to be added - remove it
                            int unitsToRemoveCount    = (resultItem.IsConst && addUsingBlock ? 3 : (resultItem.IsConst || addUsingBlock ? 2 : 1));
                            List <IOleUndoUnit> units = undoManagersCache[path].RemoveTopFromUndoStack(unitsToRemoveCount);

                            // and add custom undo unit
                            AbstractUndoUnit newUnit = null;
                            if (keyConflict == CONTAINS_KEY_RESULT.DOESNT_EXIST)
                            {
                                newUnit = new MoveToResourcesUndoUnit(resultItem.Key, resultItem.Value, resultItem.DestinationItem);
                            }
                            else if (keyConflict == CONTAINS_KEY_RESULT.EXISTS_WITH_SAME_VALUE)
                            {
                                newUnit = new MoveToResourcesReferenceUndoUnit(resultItem.Key);
                            }

                            newUnit.AppendUnits.AddRange(units);
                            undoManagersCache[path].Add(newUnit);
                        }
                        else if (MarkUncheckedStringsWithComment && !resultItem.IsMarkedWithUnlocalizableComment)     // string literal should be marked with comment
                        {
                            AspNetStringResultItem aitem = resultItem as AspNetStringResultItem;

                            // this operation is only possible if string literal comes from C# code
                            if (resultItem is CSharpStringResultItem || (aitem != null && aitem.ComesFromCodeBlock && aitem.Language == LANGUAGE.CSHARP))
                            {
                                // add the comment
                                int c = MarkAsNoLoc(buffersCache[path], resultItem);

                                // add undo unit
                                List <IOleUndoUnit> units = undoManagersCache[path].RemoveTopFromUndoStack(1);
                                MarkAsNotLocalizedStringUndoUnit newUnit = new MarkAsNotLocalizedStringUndoUnit(resultItem.Value);
                                newUnit.AppendUnits.AddRange(units);
                                undoManagersCache[path].Add(newUnit);
                            }
                        }
                    }
                    else     // file is closed
                    // same as with open file, only operating with text, not buffers

                    {
                        if (resultItem.MoveThisItem || (MarkUncheckedStringsWithComment && !resultItem.IsMarkedWithUnlocalizableComment))   // string literal will be modified
                        // load file's text into the cache
                        {
                            if (!filesCache.ContainsKey(path))
                            {
                                filesCache.Add(path, new StringBuilder(File.ReadAllText(path)));
                            }
                        }

                        if (resultItem.IsConst && resultItem.CodeModelSource is CodeVariable2)
                        {
                            CodeVariable2 codeVar = (CodeVariable2)resultItem.CodeModelSource;
                            fieldsToRemoveConst.Add(codeVar);
                        }

                        if (resultItem.MoveThisItem)
                        {
                            StringBuilder b = filesCache[path];

                            // perform the replacement
                            string insertText = resultItem.GetReferenceText(referenceText);
                            b.Remove(resultItem.AbsoluteCharOffset, resultItem.AbsoluteCharLength);
                            b.Insert(resultItem.AbsoluteCharOffset, insertText);

                            if (addUsingBlock)
                            {
                                // add using block
                                if (!newUsingsPlan.ContainsKey(path))
                                {
                                    newUsingsPlan.Add(path, new List <string>());
                                }
                                newUsingsPlan[path].Add(resultItem.DestinationItem.Namespace);
                            }
                        }
                        else if (MarkUncheckedStringsWithComment && !resultItem.IsMarkedWithUnlocalizableComment)
                        {
                            AspNetStringResultItem aitem = resultItem as AspNetStringResultItem;

                            if (resultItem is CSharpStringResultItem || (aitem != null && aitem.ComesFromCodeBlock && aitem.Language == LANGUAGE.CSHARP))
                            {
                                StringBuilder b = filesCache[path];
                                b.Insert(resultItem.AbsoluteCharOffset, resultItem.NoLocalizationComment);
                            }
                        }
                    }

                    if (resultItem.MoveThisItem && keyConflict == CONTAINS_KEY_RESULT.DOESNT_EXIST)
                    {
                        if (!resultItem.DestinationItem.IsInBatchMode)
                        {
                            resultItem.DestinationItem.BeginBatch();
                        }
                        // add the key to the ResX file
                        resultItem.DestinationItem.AddString(resultItem.Key, resultItem.Value);
                    }
                } catch (Exception ex) {
                    errorRows++;
                    VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                }
            }

            // add using blocks to closed files texts
            foreach (var pair in newUsingsPlan)
            {
                foreach (string nmspc in pair.Value)
                {
                    AddUsingBlockTo(pair.Key, nmspc);
                }
            }

            // flush closed files texts
            foreach (var pair in filesCache)
            {
                if (RDTManager.IsFileOpen(pair.Key))
                {
                    RDTManager.SetIgnoreFileChanges(pair.Key, true);
                    File.WriteAllText(pair.Key, pair.Value.ToString());
                    RDTManager.SetIgnoreFileChanges(pair.Key, false);
                    RDTManager.SilentlyReloadFile(pair.Key);
                }
                else
                {
                    File.WriteAllText(pair.Key, pair.Value.ToString());
                }
            }

            // remove 'const' modifier from fields in closed files
            HashSet <ProjectItem> itemsToSave = new HashSet <ProjectItem>();

            foreach (CodeVariable2 codeVar in fieldsToRemoveConst)
            {
                codeVar.ConstKind = vsCMConstKind.vsCMConstKindNone;
                itemsToSave.Add(codeVar.ProjectItem);
            }
            foreach (ProjectItem item in itemsToSave)
            {
                item.Save(null);
            }

            foreach (ResXProjectItem item in loadedResxItems)
            {
                if (item.IsInBatchMode)
                {
                    item.EndBatch();
                }
                item.Unload();
            }
            if (errorRows > 0)
            {
                throw new Exception("Error occured while processing some rows - see Output window for details.");
            }
        }
        /// <summary>
        /// Returns target property's value
        /// </summary>
        /// <param name="resultItem">Result item from which the value is taken</param>
        /// <param name="relevant">OUT - true if the target is relevant for the result item</param>
        private string GetTarget(CodeStringResultItem resultItem, out bool relevant)
        {
            string testString = null;
            NetStringResultItem    cResItem = resultItem as NetStringResultItem;
            AspNetStringResultItem aResItem = resultItem as AspNetStringResultItem;

            relevant = false;

            switch (Target)
            {
            case LocalizationCriterionTarget.VALUE:
                relevant   = true;
                testString = resultItem.Value;
                break;

            case LocalizationCriterionTarget.NAMESPACE_NAME:
                if (cResItem == null)
                {
                    return(null);                      // ASP .NET result items don't have namespaces
                }
                try {
                    CodeNamespace nmspc = cResItem.NamespaceElement;
                    if (nmspc != null)
                    {
                        testString = nmspc.FullName;
                    }
                    relevant = true;
                } catch (COMException) { }
                break;

            case LocalizationCriterionTarget.METHOD_NAME:
                if (cResItem == null)
                {
                    return(null);                      // ASP .NET result items don't have methods
                }
                relevant   = true;
                testString = cResItem.MethodElementName;
                break;

            case LocalizationCriterionTarget.CLASS_NAME:
                if (cResItem == null)
                {
                    return(null);                      // ASP .NET result items don't have classes
                }
                relevant   = true;
                testString = cResItem.ClassOrStructElementName;
                break;

            case LocalizationCriterionTarget.ELEMENT_NAME:
                if (aResItem == null)
                {
                    return(null);                       // C# or VB result items don't have element names
                }
                if (aResItem.ComesFromDirective || aResItem.ComesFromElement || aResItem.ComesFromPlainText)
                {
                    relevant   = true;
                    testString = aResItem.ElementName;
                }
                else
                {
                    return(null);
                }
                break;

            case LocalizationCriterionTarget.ELEMENT_PREFIX:
                if (aResItem == null)
                {
                    return(null);                       // C# or VB result items don't have element prefixes
                }
                if (aResItem.ComesFromDirective || aResItem.ComesFromElement || aResItem.ComesFromPlainText)
                {
                    relevant   = true;
                    testString = aResItem.ElementPrefix;
                }
                else
                {
                    return(null);
                }
                break;

            case LocalizationCriterionTarget.VARIABLE_NAME:
                if (cResItem == null)
                {
                    return(null);
                }
                ;                                        // ASP .NET result items don't initialize variables
                relevant   = true;
                testString = cResItem.VariableElementName;
                break;

            case LocalizationCriterionTarget.ATTRIBUTE_NAME:
                if (aResItem == null)
                {
                    return(null);                       // C# or VB result items don't originate from elements
                }
                if (aResItem.ComesFromDirective || aResItem.ComesFromElement)
                {
                    relevant   = true;
                    testString = aResItem.AttributeName;
                }
                else
                {
                    return(null);
                }
                break;

            case LocalizationCriterionTarget.LINE:
                if (resultItem.Context == null)
                {
                    return(null);
                }
                string[] lines = resultItem.Context.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                if (resultItem.ContextRelativeLine >= 0 && resultItem.ContextRelativeLine < lines.Length)
                {
                    relevant   = true;
                    testString = lines[resultItem.ContextRelativeLine];
                }
                else
                {
                    return(null);
                }
                break;
            }
            return(testString);
        }
        /// <summary>
        /// Evaluates given result item
        /// </summary>
        /// <returns>
        /// Null if the criterion is not relevant for the result item (testing element prefix for C# string literal...), true if it is relevant and the result item satisfies the condition, false otherwise
        /// </returns>
        public override bool?Eval(CodeStringResultItem resultItem)
        {
            if (resultItem == null)
            {
                throw new ArgumentNullException("resultItem");
            }

            bool   relevant;
            string testString = GetTarget(resultItem, out relevant);

            if (!relevant)
            {
                return(null);
            }

            switch (Predicate)
            {
            case LocalizationCriterionPredicate.MATCHES:
                if (testString == null)
                {
                    return(false);
                }
                return(System.Text.RegularExpressions.Regex.IsMatch(testString, Regex));

            case LocalizationCriterionPredicate.DOESNT_MATCH:
                if (testString == null)
                {
                    return(false);
                }
                return(!System.Text.RegularExpressions.Regex.IsMatch(testString, Regex));

            case LocalizationCriterionPredicate.IS_NULL:
                return(testString == null);

            case LocalizationCriterionPredicate.NO_LETTERS:
                if (testString == null)
                {
                    return(true);
                }
                bool containsLetter = false;
                foreach (char c in testString)
                {
                    if (char.IsLetter(c))
                    {
                        containsLetter = true; break;
                    }
                }
                return(!containsLetter);

            case LocalizationCriterionPredicate.ONLY_CAPS:
                if (testString == null)
                {
                    return(true);
                }
                bool ok = true;
                foreach (char c in testString)
                {
                    if (!char.IsUpper(c) && !char.IsSymbol(c) && !char.IsPunctuation(c) && !char.IsDigit(c))
                    {
                        ok = false; break;
                    }
                }
                return(ok);

            case LocalizationCriterionPredicate.NO_WHITESPACE:
                if (testString == null)
                {
                    return(true);
                }
                bool containsWhitespace = false;
                foreach (char c in testString)
                {
                    if (char.IsWhiteSpace(c))
                    {
                        containsWhitespace = true; break;
                    }
                }
                return(!containsWhitespace);
            }

            return(null);
        }
 /// <summary>
 /// Evaluates given result item
 /// </summary>
 /// <returns>Null if the criterion is not relevant for the result item (testing element prefix for C# string literal...), true if it is relevant and the result item satisfies the condition, false otherwise</returns>
 public abstract bool?Eval(CodeStringResultItem resultItem);
Пример #10
0
        /// <summary>
        /// Compares expected and actual result item
        /// </summary>
        internal static void ValidateItems(AbstractResultItem a, AbstractResultItem b)
        {
            if (b is NetStringResultItem)
            {
                NetStringResultItem an = a as NetStringResultItem;
                NetStringResultItem bn = b as NetStringResultItem;
                Assert.AreEqual(an.VariableElementName, bn.VariableElementName, "Variable names are not equal, " + a.Value);
                Assert.AreEqual(an.MethodElementName, bn.MethodElementName, "Method names are not equal, " + a.Value);
            }
            if (b is CSharpStringResultItem)
            {
                TestCSharpStringResultItem an = a as TestCSharpStringResultItem;
                CSharpStringResultItem     bn = b as CSharpStringResultItem;
                if (an.NamespaceElementName == null)
                {
                    Assert.IsNull(bn.NamespaceElement, "Namespace null, " + a.Value);
                }
                else
                {
                    Assert.AreEqual(an.NamespaceElementName, bn.NamespaceElement.FullName, "Namespace names are not equal, " + a.Value);
                }
            }
            if (b is VBStringResultItem)
            {
                TestVBStringResultItem an = a as TestVBStringResultItem;
                VBStringResultItem     bn = b as VBStringResultItem;
                if (an.NamespaceElementName == null)
                {
                    Assert.IsNull(bn.NamespaceElement, "Namespace null, " + a.Value);
                }
                else
                {
                    Assert.AreEqual(an.NamespaceElementName, bn.NamespaceElement.FullName, "Namespace names are not equal, " + a.Value);
                }
            }
            if (b is AspNetStringResultItem)
            {
                TestAspNetStringResultItem an = a as TestAspNetStringResultItem;
                AspNetStringResultItem     bn = b as AspNetStringResultItem;

                Assert.AreEqual(an.ComesFromClientComment, bn.ComesFromClientComment, "ComesFromClientComment are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ComesFromCodeBlock, bn.ComesFromCodeBlock, "ComesFromCodeBlock are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ComesFromDirective, bn.ComesFromDirective, "ComesFromDirective are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ComesFromElement, bn.ComesFromElement, "ComesFromElement are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ComesFromInlineExpression, bn.ComesFromInlineExpression, "ComesFromInlineExpression are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ComesFromPlainText, bn.ComesFromPlainText, "ComesFromPlainText are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ElementName, bn.ElementName, "ElementName are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ElementPrefix, bn.ElementPrefix, "ElementPrefix are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.LocalizabilityProved, bn.LocalizabilityProved, "LocalizabilityProved are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.Language, bn.Language, "Language are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            }
            if (b is CodeStringResultItem)
            {
                CodeStringResultItem an = a as CodeStringResultItem;
                CodeStringResultItem bn = b as CodeStringResultItem;
                Assert.AreEqual(an.WasVerbatim, bn.WasVerbatim, "Verbatim options are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ClassOrStructElementName, bn.ClassOrStructElementName, "Class names are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            }


            if (b is CodeReferenceResultItem)
            {
                CodeReferenceResultItem an = a as CodeReferenceResultItem;
                CodeReferenceResultItem bn = b as CodeReferenceResultItem;

                Assert.AreEqual(an.FullReferenceText, bn.FullReferenceText, "FullReferenceText are not equal" + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.OriginalReferenceText, bn.OriginalReferenceText, "OriginalReferenceText are not equal" + " on line " + a.ReplaceSpan.iStartLine);
            }
            if (b is AspNetCodeReferenceResultItem)
            {
                AspNetCodeReferenceResultItem an = a as AspNetCodeReferenceResultItem;
                AspNetCodeReferenceResultItem bn = b as AspNetCodeReferenceResultItem;

                Assert.AreEqual(an.ComesFromInlineExpression, bn.ComesFromInlineExpression, "ComesFromInlineExpression are not equal" + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.ComesFromWebSiteResourceReference, bn.ComesFromWebSiteResourceReference, "ComesFromWebSiteResourceReference are not equal" + " on line " + a.ReplaceSpan.iStartLine);
                Assert.AreEqual(an.Language, bn.Language, "Language are not equal" + " on line " + a.ReplaceSpan.iStartLine);

                if (an.ComesFromInlineExpression)
                {
                    Assert.IsNotNull(an.InlineReplaceSpan);
                    Assert.IsNotNull(bn.InlineReplaceSpan);
                    Assert.AreEqual(an.InlineReplaceSpan.StartLine, bn.InlineReplaceSpan.StartLine, "StartLine are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                    Assert.AreEqual(an.InlineReplaceSpan.StartIndex, bn.InlineReplaceSpan.StartIndex, "StartIndex are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                    Assert.AreEqual(an.InlineReplaceSpan.EndLine, bn.InlineReplaceSpan.EndLine, "EndLine are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                    Assert.AreEqual(an.InlineReplaceSpan.EndIndex, bn.InlineReplaceSpan.EndIndex, "EndIndex are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);

                    Assert.AreEqual(an.InlineReplaceSpan.AbsoluteCharOffset, bn.InlineReplaceSpan.AbsoluteCharOffset, "Offsets are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                    Assert.AreEqual(an.InlineReplaceSpan.AbsoluteCharLength, bn.InlineReplaceSpan.AbsoluteCharLength, "AbsoluteLengths are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
                }
                else
                {
                    Assert.IsNull(an.InlineReplaceSpan);
                    Assert.IsNull(bn.InlineReplaceSpan);
                }
            }

            Assert.AreEqual(a.Value, b.Value, "Values are not equal on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.SourceItem, b.SourceItem, "Source items are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.IsWithinLocalizableFalse, b.IsWithinLocalizableFalse, "[Localizable(false)] options are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.IsMarkedWithUnlocalizableComment, b.IsMarkedWithUnlocalizableComment, "/*VL_NO_LOC*/ options are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.ComesFromDesignerFile, b.ComesFromDesignerFile, "Designer file options are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);

            Assert.IsNotNull(a.ReplaceSpan);
            Assert.IsNotNull(b.ReplaceSpan);
            Assert.AreEqual(a.ReplaceSpan.iStartLine, b.ReplaceSpan.iStartLine, "iStartLine are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.ReplaceSpan.iStartIndex, b.ReplaceSpan.iStartIndex, "iStartIndex are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.ReplaceSpan.iEndLine, b.ReplaceSpan.iEndLine, "iEndLine are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.ReplaceSpan.iEndIndex, b.ReplaceSpan.iEndIndex, "iEndIndex are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);

            Assert.AreEqual(a.AbsoluteCharOffset, b.AbsoluteCharOffset, "Offsets are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);
            Assert.AreEqual(a.AbsoluteCharLength, b.AbsoluteCharLength, "AbsoluteLengths are not equal, " + a.Value + " on line " + a.ReplaceSpan.iStartLine);

            Assert.AreEqual(a.IsConst, b.IsConst, "IsConst are not equal on line " + a.ReplaceSpan.iStartLine);
        }
Пример #11
0
        public SelectResourceFileForm(ProjectItem sourceItem, CodeStringResultItem resultItem)
        {
            if (sourceItem == null)
            {
                throw new ArgumentNullException("sourceItem");
            }
            if (resultItem == null)
            {
                throw new ArgumentNullException("resultItem");
            }

            InitializeComponent();

            this.Icon          = VSPackage._400;
            this.resultItem    = resultItem;
            this.referenceText = new ReferenceString();

            // add suggestions of key names to suggestions list
            foreach (string s in resultItem.GetKeyNameSuggestions())
            {
                keyBox.Items.Add(s);
            }

            if (SettingsObject.Instance.SelectedKeyIndex >= 0 && SettingsObject.Instance.SelectedKeyIndex < keyBox.Items.Count)
            {
                keyBox.SelectedIndex = SettingsObject.Instance.SelectedKeyIndex;
            }
            else
            {
                keyBox.SelectedIndex = 0;
            }

            valueBox.Text = resultItem.Value;
            // add possible destination files

            int selectedPathIndex = -1;
            int i = 0;

            foreach (var item in sourceItem.ContainingProject.GetResXItemsAround(true, false))
            {
                comboBox.Items.Add(item);
                if (string.Compare(item.InternalProjectItem.GetFullPath(), SettingsObject.Instance.SelectedResourceFilePath, true) == 0)
                {
                    selectedPathIndex = i;
                }
                i++;
            }

            if (selectedPathIndex >= 0 && selectedPathIndex < comboBox.Items.Count)
            {
                comboBox.SelectedIndex = selectedPathIndex;
            }
            else
            {
                if (comboBox.Items.Count > 0)
                {
                    comboBox.SelectedIndex = 0;
                }
            }

            usingBox.Checked = !SettingsObject.Instance.SelectedUseFullName;
            fullBox.Checked  = SettingsObject.Instance.SelectedUseFullName;

            overwriteButton.Visible  = false;
            inlineButton.Visible     = false;
            existingLabel.Visible    = false;
            existingValueBox.Visible = false;

            errorLabel.Text = "";
        }