Exemple #1
0
        internal AdsSymbolLoader(IAdsConnection connection, SymbolLoaderSettings settings, IAccessorRawValue accessor, ISession session, SymbolUploadInfo symbolsInfo)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }
            if (symbolsInfo == null)
            {
                throw new ArgumentNullException("symbolsInfo");
            }
            ISymbolFactory symbolFactory = null;

            this._connection       = connection;
            this._symbolUploadInfo = symbolsInfo;
            symbolFactory          = (settings.SymbolsLoadMode != SymbolsLoadMode.DynamicTree) ? ((ISymbolFactory) new TwinCAT.Ads.TypeSystem.SymbolFactory(settings.NonCachedArrayElements)) : ((ISymbolFactory) new DynamicSymbolFactory(new TwinCAT.Ads.TypeSystem.SymbolFactory(settings.NonCachedArrayElements), settings.NonCachedArrayElements));
            this._settings         = settings;
            AdsBinder binder = new AdsBinder(this._connection.Address, this, symbolFactory, this.UseVirtualInstances);

            this._symbolFactorServices = new SymbolFactoryServices(binder, symbolFactory, accessor, session);
            symbolFactory.Initialize(this._symbolFactorServices);
            this._rootNamespace = this._connection.Address.ToString();
            this._namespaces    = new NamespaceCollection();
        }
Exemple #2
0
        void AddNamespaces(Dictionary <string, bool> imports)
        {
            if (BuildManager.HaveResources)
            {
                imports.Add("System.Resources", true);
            }

            PagesSection pages = PagesConfig;

            if (pages == null)
            {
                return;
            }

            NamespaceCollection namespaces = pages.Namespaces;

            if (namespaces == null || namespaces.Count == 0)
            {
                return;
            }

            foreach (NamespaceInfo nsi in namespaces)
            {
                string ns = nsi.Namespace;
                if (imports.ContainsKey(ns))
                {
                    continue;
                }

                imports.Add(ns, true);
            }
        }
Exemple #3
0
        public override IEnumerable <Completion> GetEntries(char quote, SnapshotPoint caret)
        {
            if (apiDef == null)
            {
                apiDef = deserialize(API_SCHEMA);
            }
            Namespace output;

            if (_namespaces.TryGetValue(currentText, out output))
            {
                return(GetCompletions(currentText, _namespaces[currentText]));
            }

            if (currentText[currentText.Length - 1] == '.')
            {
                currentText = currentText.Remove(currentText.LastIndexOf("."), 1);
            }
            foreach (var autoCompletedTerm in apiDef.Items
                     .Select(nameSpace => Find(nameSpace, currentText))
                     .Where(autoCompletedTerm => autoCompletedTerm != null))
            {
                _namespaces[currentText] = autoCompletedTerm;
                return(GetCompletions(currentText, autoCompletedTerm));
            }
            return(null);
        }
        public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            var namespaceName = node.Name;

            NamespaceCollection.Add(namespaceName.ToString());

            base.VisitNamespaceDeclaration(node);
        }
        public void MachinetagsGetNamespacesBasicTest()
        {
            NamespaceCollection col = Instance.MachineTagsGetNamespaces();

            Assert.IsTrue(col.Count > 10, "Should be greater than 10 namespaces.");

            foreach (var n in col)
            {
                Assert.IsNotNull(n.NamespaceName, "NamespaceName should not be null.");
                Assert.AreNotEqual(0, n.Predicates, "Predicates should not be zero.");
                Assert.AreNotEqual(0, n.Usage, "Usage should not be zero.");
            }
        }
Exemple #6
0
        protected override void InitializeDefault()
        {
            ExpressionBuilderElementCollection exprBuilders = this.Compilation.ExpressionBuilders;

            exprBuilders.Add(
                new ExpressionBuilderElement(RequestExpressionBuilder.Namespace, typeof(RequestExpressionBuilder))
            {
                LockItem = true
            }
                );

            exprBuilders.Add(
                new ExpressionBuilderElement(SessionExpressionBuilder.Namespace, typeof(SessionExpressionBuilder))
            {
                LockItem = true
            }
                );

            exprBuilders.Add(
                new ExpressionBuilderElement(CodeExpressionBuilder.Namespace, typeof(CodeExpressionBuilder))
            {
                LockItem = true
            }
                );

            NamespaceCollection pagesNamespaces = this.Pages.Namespaces;

            pagesNamespaces.Add(new NamespaceInfo("System"));
            pagesNamespaces.Add(new NamespaceInfo("System.Collections.Generic"));
            pagesNamespaces.Add(new NamespaceInfo("System.IO"));
            pagesNamespaces.Add(new NamespaceInfo("System.Linq"));
            pagesNamespaces.Add(new NamespaceInfo("System.Net"));
            pagesNamespaces.Add(new NamespaceInfo("System.Web"));
            pagesNamespaces.Add(new NamespaceInfo("System.Web.Security"));
            pagesNamespaces.Add(new NamespaceInfo("System.Web.UI"));

            base.InitializeDefault();
        }
Exemple #7
0
        /// <summary>
        /// Answer a collection of namespaces in which the topic actually exists
        /// </summary>
        /// <param name="topic">The topic you want to search for in this namespace.</param>
        /// <returns>A list of namespaces (as strings); empty if none</returns>
        public NamespaceCollection TopicNamespaces(string topic)
        {
            NamespaceCollection answer = new NamespaceCollection();

            if (TopicExists(topic, ImportPolicy.DoNotIncludeImports))
            {
                answer.Add(Namespace); 
            }

            foreach (NamespaceManager manager in ImportedNamespaceManagers)
            {
                if (manager.TopicExists(topic, ImportPolicy.DoNotIncludeImports))
                {
                    answer.Add(manager.Namespace);
                }
            }
            return answer;
        }
Exemple #8
0
        /// <summary>
        /// Parse a matched wiki link syntax.
        /// </summary>
        /// <param name="link">Regular expression match.</param>
        /// <param name="goal">Discord server ID.</param>
        /// <returns>A parsed URL from the match.</returns>
        static public string AddLink(Match link, string goal)
        {
            string          linkFormat = Config.GetWiki(goal);
            GroupCollection groups     = link.Groups;
            string          type       = (groups[1].Value.Length == 0 ? groups[3].Value : groups[1].Value).Trim();
            string          str        = (groups[2].Value.Length == 0 ? groups[4].Value : groups[2].Value).Trim();

            // Default site info
            WikiSite defaultSiteInfo = WikiSiteInfo[Config.GetWiki(goal)];

            // Temporary site info storage for other wikis
            WikiSite tempSiteInfo = null;

            // Remove escaping symbols before Markdown syntax in Discord
            // (it converts \ to / anyway)
            str = str.Replace(@"\", "");

            // Check for invalid page titles
            if (IsInvalid(str))
            {
                return("");
            }

            // Storages for prefix and namespace data
            string iw = "%%%%%";
            string ns = "";

            if (str.Length > 0)
            {
                // Add template namespace for template links and remove substitution
                if (type == "{{")
                {
                    if (!str.StartsWith(':'))
                    {
                        ns  = defaultSiteInfo.Namespaces["template"].CustomName;
                        str = Regex.Replace(str, "^:?(?:subst|подст):", "");

                        // MediaWiki page transclusion
                        if (str.StartsWith("int:"))
                        {
                            ns  = defaultSiteInfo.Namespaces["mediawiki"].CustomName;
                            str = Regex.Replace(str, "^int:", "");
                        }
                    }
                }

                WikiSite latestSiteInfo = defaultSiteInfo;

                // Check if link contains interwikis
                Match iwMatch = Regex.Match(str, "^:?([A-Za-z-]+):");
                while (type == "[[" && iwMatch.Length > 0)
                {
                    string prefix = iwMatch.Groups[1].Value.ToLower();
                    latestSiteInfo = tempSiteInfo ?? defaultSiteInfo;
                    InterwikiMap        latestIWList = latestSiteInfo.InterwikiMap;
                    NamespaceCollection latestNSList = latestSiteInfo.Namespaces;
                    if (latestIWList.Contains(prefix) && !latestNSList.Contains(prefix))
                    {
                        string oldLinkFormat = linkFormat;
                        linkFormat = latestIWList[prefix].Url;

                        // Fetch temporary site information if necessary and store new prefix
                        if (iw != "" || oldLinkFormat.Replace(iw, prefix) != linkFormat)
                        {
                            WikiSite data = FetchSiteInfo(linkFormat).Result;
                            tempSiteInfo   = data;
                            latestSiteInfo = tempSiteInfo;
                        }
                        iw = prefix;

                        Regex only = new Regex($":?{prefix}:", RegexOptions.IgnoreCase);
                        str = only.Replace(str, "", 1).Trim();

                        iwMatch = Regex.Match(str, "^:?([A-Za-z-]+):");
                    }
                    else
                    {
                        // Return the regex that can’t be matched
                        iwMatch = Regex.Match(str, "^\b$");
                    }
                }

                // Check if link contains namespace
                Match nsMatch = Regex.Match(str, "^:?([^:]+):");
                if (nsMatch.Length > 0)
                {
                    string prefix = nsMatch.Groups[1].Value.ToUpper();
                    NamespaceCollection latestNSList = latestSiteInfo.Namespaces;
                    if (latestNSList.Contains(prefix))
                    {
                        var namespaceInfo = latestNSList[prefix];
                        if ((namespaceInfo.Id == 2 || namespaceInfo.Id == 3) && namespaceInfo.Aliases.Count > 0)
                        {
                            // Get title according to gender for User namespaces
                            str = GetNormalisedTitle(str, linkFormat).Result;
                        }
                        else
                        {
                            ns = namespaceInfo.CustomName;
                            Regex only = new Regex($":?{prefix}:", RegexOptions.IgnoreCase);
                            str = only.Replace(str, "", 1).Trim();
                        }
                    }
                }

                // If there is only namespace, return nothing
                if (ns != "" && str.Length == 0)
                {
                    return("");
                }

                // Check if it’s a parser function
                if (type == "{{" && str.StartsWith("#"))
                {
                    return("");
                }

                // Check for invalid page title length
                if (IsInvalid(str, true))
                {
                    return("");
                }

                // Rewrite other text
                if (str.Length > 0)
                {
                    // Trim : from the start (nuisance)
                    str = str.TrimStart(':');

                    // Capitalise first letter if wiki does not allow lowercase titles
                    if (latestSiteInfo?.SiteInfo?.IsTitleCaseSensitive == false)
                    {
                        str = str[0].ToString().ToUpper() + str.Substring(1);
                    }

                    // Add namespace before any transformations
                    if (ns != "")
                    {
                        str = string.Join(":", new[] { ns, str });
                    }
                }
                return(string.Format("<{0}>", GetLink(str, linkFormat)));
            }

            return("");
        }
Exemple #9
0
        static public string AddLink(Match link, string goal)
        {
            string          linkFormat = Config.GetWiki(goal);
            GroupCollection groups     = link.Groups;
            string          type       = (groups[1].Value.Length == 0 ? groups[3].Value : groups[1].Value).Trim();
            string          str        = (groups[2].Value.Length == 0 ? groups[4].Value : groups[2].Value).Trim();

            // Default site info
            InterwikiMap        defaultIWList = GetList(goal, "iw");
            NamespaceCollection defaultNSList = GetList(goal, "ns");

            // Temporary site info for other wikis
            InterwikiMap        tempIWList = null;
            NamespaceCollection tempNSList = null;
            bool tempIsCaseSensitive       = true;

            // Remove escaping symbols before Markdown syntax in Discord
            // (it converts \ to / anyway)
            str = str.Replace("\\", "");

            // Check for invalid page titles
            if (IsInvalid(str))
            {
                return("");
            }

            // Storages for prefix and namespace data
            string iw = "%%%%%";
            string ns = "";

            if (str.Length > 0)
            {
                // Add template namespace for template links and remove substitution
                if (type == "{{")
                {
                    ns  = defaultNSList["template"].CustomName;
                    str = Regex.Replace(str, "^(?:subst|подст):", "");
                }

                // Check if link contains interwikis
                Match iwMatch = Regex.Match(str, "^:?([A-Za-z-]+):");
                while (type == "[[" && iwMatch.Length > 0)
                {
                    string              prefix       = iwMatch.Groups[1].Value.ToLower();
                    InterwikiMap        latestIWList = (tempIWList != null ? tempIWList : defaultIWList);
                    NamespaceCollection latestNSList = (tempNSList != null ? tempNSList : defaultNSList);
                    if (latestIWList.Contains(prefix) && !latestNSList.Contains(prefix))
                    {
                        string oldLinkFormat = linkFormat;
                        linkFormat = latestIWList[prefix].Url;

                        // Fetch temporary site information if necessary and store new prefix
                        if (iw != "" || oldLinkFormat.Replace(iw, prefix) != linkFormat)
                        {
                            SiteInfo data = FetchSiteInfo(linkFormat).Result;
                            tempIWList          = data.iw;
                            tempNSList          = data.ns;
                            tempIsCaseSensitive = data.isCaseSensitive;
                        }
                        iw = prefix;

                        Regex only = new Regex($":?{prefix}:", RegexOptions.IgnoreCase);
                        str = only.Replace(str, "", 1).Trim();

                        iwMatch = Regex.Match(str, "^:?([A-Za-z-]+):");
                    }
                    else
                    {
                        // Return the regex that can’t be matched
                        iwMatch = Regex.Match(str, "^\b$");
                    }
                }

                // Check if link contains namespace
                Match nsMatch = Regex.Match(str, "^:?([^:]+):");
                if (nsMatch.Length > 0)
                {
                    string prefix = nsMatch.Groups[1].Value.ToUpper();
                    NamespaceCollection latestNSList = defaultNSList;
                    if (linkFormat != Config.GetWiki(goal) && tempNSList != null)
                    {
                        latestNSList = tempNSList;
                    }

                    if (latestNSList.Contains(prefix))
                    {
                        ns = latestNSList[prefix].CustomName;
                        Regex only = new Regex($":?{prefix}:", RegexOptions.IgnoreCase);
                        str = only.Replace(str, "", 1).Trim();
                    }
                }

                // If there is only namespace, return nothing
                if (ns != "" && str.Length == 0)
                {
                    return("");
                }

                // Check if it’s a parser function
                if (type == "{{" && str.StartsWith("#"))
                {
                    return("");
                }

                // Rewrite other text
                if (str.Length > 0)
                {
                    // Capitalise first letter if wiki does not allow lowercase titles
                    if ((linkFormat == Config.GetWiki(goal) && !GetList(goal)) || (linkFormat != Config.GetWiki(goal) && !tempIsCaseSensitive))
                    {
                        str = str[0].ToString().ToUpper() + str.Substring(1);
                    }

                    // Clear temporary site info
                    tempIWList          = null;
                    tempNSList          = null;
                    tempIsCaseSensitive = false;

                    // Add namespace before any transformations
                    if (ns != "")
                    {
                        str = string.Join(":", new[] { ns, str });
                    }
                }
                return(string.Format("<{0}>", GetLink(str, linkFormat)));
            }

            return("");
        }
Exemple #10
0
        internal static long GetRecompilationHash(PagesSection ps)
        {
            HashCodeCombiner combiner = new HashCodeCombiner();

            combiner.AddObject(ps.Buffer);
            combiner.AddObject(ps.EnableViewState);
            combiner.AddObject(ps.EnableViewStateMac);
            combiner.AddObject(ps.EnableEventValidation);
            combiner.AddObject(ps.SmartNavigation);
            combiner.AddObject(ps.ValidateRequest);
            combiner.AddObject(ps.AutoEventWireup);
            if (ps.PageBaseTypeInternal != null)
            {
                combiner.AddObject(ps.PageBaseTypeInternal.FullName);
            }
            if (ps.UserControlBaseTypeInternal != null)
            {
                combiner.AddObject(ps.UserControlBaseTypeInternal.FullName);
            }
            if (ps.PageParserFilterTypeInternal != null)
            {
                combiner.AddObject(ps.PageParserFilterTypeInternal.FullName);
            }
            combiner.AddObject(ps.MasterPageFile);
            combiner.AddObject(ps.Theme);
            combiner.AddObject(ps.StyleSheetTheme);
            combiner.AddObject(ps.EnableSessionState);
            combiner.AddObject(ps.CompilationMode);
            combiner.AddObject(ps.MaxPageStateFieldLength);
            combiner.AddObject(ps.ViewStateEncryptionMode);
            combiner.AddObject(ps.MaintainScrollPositionOnPostBack);
            NamespaceCollection namespaces = ps.Namespaces;

            combiner.AddObject(namespaces.AutoImportVBNamespace);
            if (namespaces.Count == 0)
            {
                combiner.AddObject("__clearnamespaces");
            }
            else
            {
                foreach (NamespaceInfo info in namespaces)
                {
                    combiner.AddObject(info.Namespace);
                }
            }
            TagPrefixCollection controls = ps.Controls;

            if (controls.Count == 0)
            {
                combiner.AddObject("__clearcontrols");
            }
            else
            {
                foreach (TagPrefixInfo info2 in controls)
                {
                    combiner.AddObject(info2.TagPrefix);
                    if ((info2.TagName != null) && (info2.TagName.Length != 0))
                    {
                        combiner.AddObject(info2.TagName);
                        combiner.AddObject(info2.Source);
                    }
                    else
                    {
                        combiner.AddObject(info2.Namespace);
                        combiner.AddObject(info2.Assembly);
                    }
                }
            }
            TagMapCollection tagMapping = ps.TagMapping;

            if (tagMapping.Count == 0)
            {
                combiner.AddObject("__cleartagmapping");
            }
            else
            {
                foreach (TagMapInfo info3 in tagMapping)
                {
                    combiner.AddObject(info3.TagType);
                    combiner.AddObject(info3.MappedTagType);
                }
            }
            return(combiner.CombinedHash);
        }
        private static ImportElement[] CreateImportsElements(NamespaceCollection namespaces)
        {
            if (namespaces.Count > 0)
            {
                var elements = new ImportElement[namespaces.Count];

                for (int i = 0; i < namespaces.Count; i++)
                    elements[i] = new ImportElement() { Namespace = namespaces[i] };

                return elements;
            }

            return null;
        }