Example #1
0
        public NonTerminalStack GetPrefixListStackObjectOfGivenTop(string top)
        {
            if (top != Top && Top != Grammar.Epsilon)
            {
                throw new Exception(
                          string.Format("popping {0} from stack graph headed by {1}, should be headed by EPSILON", top, Top));
            }

            var newPrefixList = PrefixList;

            if (Top == Grammar.Epsilon)
            {
                if (PrefixList != null)
                {
                    newPrefixList = PrefixList.Where(x => x.Top == top).ToList();
                }
            }
            if (PrefixList == null)
            {
                return(null);
            }

            if (newPrefixList.Count == 1)
            {
                return(newPrefixList.First());
            }

            var newStack = new NonTerminalStack(Grammar.Epsilon);

            newStack.PrefixList = newPrefixList;


            return(newStack);
        }
Example #2
0
        private PrefixList GetPrefix(long serverId)
        {
            PrefixList prefix = null;

            prefix = _db.PrefixList.Where(p => p.ServerId == serverId).FirstOrDefault();

            return(prefix);
        }
Example #3
0
        public static string GetPrefixNameById(int id)
        {
            if (!PrefixList.ContainsKey(id))
            {
                return(PrefixList[0]);
            }

            return(PrefixList[id]);
        }
Example #4
0
        public static int GetPrefixIdByName(string name)
        {
            if (!PrefixList.ContainsValue(name))
            {
                return(0);
            }

            return(PrefixList.Where(x => x.Value == name).FirstOrDefault().Key);
        }
Example #5
0
        private PrefixList GetPrefix(long serverId)
        {
            PrefixList prefix = null;

            using (var db = new NinjaBotEntities())
            {
                prefix = db.PrefixList.Where(p => p.ServerId == serverId).FirstOrDefault();
            }

            return(prefix);
        }
Example #6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PrefixReadOnlyObservableList{T}"/> class.
        /// </summary>
        /// <param name="source">The source list.</param>
        /// <param name="selector">The condition.</param>
        /// <param name="comparer">The comparer of source items.</param>
        /// <param name="onRemove">The function that is called when removing an item.</param>
        /// <param name="onChange">The function that is called when the result assigned to a pair changes.</param>
        public PrefixReadOnlyObservableList(IReadOnlyList <T> source, Func <T, IObservable <bool> > selector,
                                            IEqualityComparer <T> comparer = null, Action <bool> onRemove = null, Action <bool, bool> onChange = null)
            : base(null, selector, onRemove, onChange)
        {
            _source   = source;
            _comparer = new ContainerEqualityComparer <T, IndexedItemContainer <T, bool> >(comparer);

            _items = new PrefixList(this);
            if (_source is INotifyCollectionChanged notifier)
            {
                CollectionChangedEventManager.AddListener(notifier, this);
            }
        }
Example #7
0
        //if the top symbol is epsilon, then the actual top symbols are contained below it.
        //i.e for instance, Epsilon -> (NP, PP)
        public List <string> GetListOfTopSymbols()
        {
            var l = new List <string>();

            if (Top != Grammar.Epsilon)
            {
                l.Add(Top);
            }
            else
            {
                l = PrefixList.Select(x => x.Top).ToList();
            }
            return(l);
        }
Example #8
0
 //Force one selected item between the two lists
 private void ModList_SelectionChanged(object sender, RoutedEventArgs e)
 {
     if ((sender as ListView).SelectedItem != null)
     {
         if (sender == PrefixList)
         {
             SuffixList.UnselectAll();
         }
         else
         {
             PrefixList.UnselectAll();
         }
     }
 }
Example #9
0
        public static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
        {
            bool flag = false;

            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            if (creator == null)
            {
                throw new ArgumentNullException("creator");
            }
            ExceptionHelper.WebPermissionUnrestricted.Demand();
            lock (InternalSyncObject)
            {
                Uri       uri;
                ArrayList list = (ArrayList)PrefixList.Clone();
                if (Uri.TryCreate(prefix, UriKind.Absolute, out uri))
                {
                    string absoluteUri = uri.AbsoluteUri;
                    if (!prefix.EndsWith("/", StringComparison.Ordinal) && uri.GetComponents(UriComponents.Fragment | UriComponents.PathAndQuery, UriFormat.UriEscaped).Equals("/"))
                    {
                        absoluteUri = absoluteUri.Substring(0, absoluteUri.Length - 1);
                    }
                    prefix = absoluteUri;
                }
                int index = 0;
                while (index < list.Count)
                {
                    WebRequestPrefixElement element = (WebRequestPrefixElement)list[index];
                    if (prefix.Length > element.Prefix.Length)
                    {
                        break;
                    }
                    if ((prefix.Length == element.Prefix.Length) && (string.Compare(element.Prefix, prefix, StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        flag = true;
                        break;
                    }
                    index++;
                }
                if (!flag)
                {
                    list.Insert(index, new WebRequestPrefixElement(prefix, creator));
                    PrefixList = list;
                }
            }
            return(!flag);
        }
Example #10
0
        public char GetServerPrefix()
        {
            char       prefix       = Char.Parse(_config["Prefix"]);
            PrefixList serverPrefix = null;

            if (!(Context.Channel is IDMChannel))
            {
                serverPrefix = GetPrefix((long)Context.Guild.Id);
            }
            if (serverPrefix != null)
            {
                prefix = serverPrefix.Prefix;
            }
            return(prefix);
        }
 private IEnumerable <Prefix> GetActivePrefixs()
 {
     try {
         List <Prefix> PrefixList = null;
         using (DbCommand dbcmdPrefix = _Database.GetStoredProcCommand(PROC_PREFIX_GETALL)) {
             using (IDataReader reader = _Database.ExecuteReader(dbcmdPrefix)) {
                 if (PrefixList == null)
                 {
                     PrefixList = new List <Prefix>();
                 }
                 PrefixList.Add(Mapper(reader));
             }
         }
         return(PrefixList);
     }
     catch (Exception ex) {
         throw ex;
     }
 }
        FilterExpression CreateFilter()
        {
            FilterExpression fExpr = null;

            if (valueExpressionType.SelectedItem == null)
            {
                return(null);
            }
            var tp = ((KeyValuePair <odm.ui.controls.FilterExpression.ftype, string>)valueExpressionType.SelectedItem).Key;

            XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();

            PrefixList.ForEach(p => {
                nspaces.Add(p.Prefix, p.Space);
            });

            switch (tp)
            {
            case FilterExpression.ftype.CONTENT:
                var confiltr = new global::onvif.services.MessageContentFilter();
                confiltr.expression = ExpressionValue;
                if (valueExpressionDialect.SelectedValue != null)
                {
                    confiltr.dialect = ((KeyValuePair <string, string>)valueExpressionDialect.SelectedValue).Key;
                }
                confiltr.namespaces = nspaces;
                fExpr = ContentFilterExpression.CreateFilter(confiltr);
                break;

            default:
                var topfiltr = new global::onvif.services.TopicExpressionFilter();
                topfiltr.expression = ExpressionValue;
                if (valueExpressionDialect.SelectedValue != null)
                {
                    topfiltr.dialect = ((KeyValuePair <string, string>)valueExpressionDialect.SelectedValue).Key;
                }
                topfiltr.namespaces = nspaces;
                fExpr = TopicFilterExpression.CreateFilter(topfiltr);
                break;
            }

            return(fExpr);
        }
Example #13
0
        // this class is where the magic starts, and takes actions upon receiving messages
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // ensures we don't process system/other bot messages
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }

            if (message.Source != MessageSource.User)
            {
                return;
            }

            // sets the argument position away from the prefix we set
            var argPos = 0;

            // get prefix from the configuration file
            char prefix = Char.Parse(_config["Prefix"]);

            var context = new SocketCommandContext(_client, message);

            PrefixList serverPrefix = null;

            if (!(context.Channel is IDMChannel))
            {
                serverPrefix = GetPrefix((long)context.Guild.Id);
            }

            if (serverPrefix != null)
            {
                prefix = serverPrefix.Prefix;
            }

            // determine if the message has a valid prefix, and adjust argPos based on prefix
            if (!(message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasCharPrefix(prefix, ref argPos)))
            {
                return;
            }
            // execute command if one is found that matches
            await _commands.ExecuteAsync(context, argPos, _services);
        }
Example #14
0
        private void ValidateNetmaskTextBox()
        {
            if ((NetMaskText.Text == "") ||
                (!Utilities.ValidNetworkMask(NetMaskText.Text)))
            {
                PrefixList.SelectedIndex = 0;
                NetMaskText.Text         = "";
            }
            else
            {
                UInt32 prefix = 0;
                if (!Utilities.IPStringToInt(NetMaskText.Text, ref prefix))
                {
                    PrefixList.SelectedIndex = 0;
                    NetMaskText.Text         = "";
                }

                var prefixBits = Utilities.CountPrefixBits(prefix);
                PrefixList.SelectedIndex = prefixBits - 1;
                PrefixList.Refresh();
            }
        }
Example #15
0
        public override int ChoosePrefix(Item item, UnifiedRandom rand)
        {
            ItemEdits  modItem    = item.GetGlobalItem <ItemEdits>();
            PrefixList prefixList = new PrefixList();

            if (modItem.chemical == true)
            {
                return(0);
            }
            if (item.accessory == false && item.defense > 0 &&
                !(item.melee && item.ranged && item.magic && item.summon && item.thrown && modItem.chemical))
            {
                int[] result = new int[prefixList.AccessoryPrefixes.Count];
                for (int i = 0; i < prefixList.AccessoryPrefixes.Count; i++)
                {
                    result[i] = prefixList.AccessoryPrefixes[i];
                }
                return(rand.Next(result));
            }
            if (item.ranged && item.mana > 0)
            {
                int[] result = new int[prefixList.ManaGunPrefixes.Count];
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = prefixList.ManaGunPrefixes[i];
                }
                return(rand.Next(result));
            }
            if (item.magic)
            {
                int[] result = new int[prefixList.MagicPrefixes.Count];
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = prefixList.MagicPrefixes[i];
                }
                return(rand.Next(result));
            }
            return(base.ChoosePrefix(item, rand));
        }
        FilterExpression CreateFilter()
        {
            FilterExpression fExpr = null;

            if (valueExpressionType.SelectedItem == null)
            {
                return(null);
            }
            var typeDialect = (TypeDialectPair)valueExpressionType.SelectedItem;


            XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();

            PrefixList.ForEach(p => {
                nspaces.Add(p.Prefix, p.Space);
            });

            switch (typeDialect.tp)
            {
            case FilterExpression.ftype.CONTENT:
                var confiltr = new global::onvif.services.MessageContentFilter();
                confiltr.expression = ExpressionValue;
                confiltr.dialect    = typeDialect.dialect;
                confiltr.namespaces = nspaces;
                fExpr = ContentFilterExpression.CreateFilter(confiltr);
                break;

            default:
                var topfiltr = new global::onvif.services.TopicExpressionFilter();
                topfiltr.expression = ExpressionValue;
                topfiltr.dialect    = typeDialect.dialect;
                topfiltr.namespaces = nspaces;
                fExpr = TopicFilterExpression.CreateFilter(topfiltr);
                break;
            }

            return(fExpr);
        }
        public void SelectFilter(FilterExpression filter)
        {
            if (filter == null)
            {
                return;
            }
            //fill type and dialect
            FillExpressionTypeDialect(filter);

            //fill expression
            ExpressionValue = filter.Value;
            //fill prefix list
            PrefixList.Clear();

            var arr = filter.Namespaces.ToArray();

            arr.ForEach(it => {
                PrefixList.Add(new PrefixSpacePair()
                {
                    Prefix = it.Name, Space = it.Namespace
                });
            });
        }
Example #18
0
        /*++
         *
         *  RegisterPrefix - Register an Uri prefix for creating WebRequests.
         *
         *  This function registers a prefix for creating WebRequests. When an
         *  user wants to create a WebRequest, we scan a table looking for a
         *  longest prefix match for the Uri they're passing. We then invoke
         *  the sub creator for that prefix. This function puts entries in
         *  that table.
         *
         *  We don't allow duplicate entries, so if there is a dup this call
         *  will fail.
         *
         * Input:
         *
         *  Prefix           - Represents Uri prefix being registered.
         *  Creator         - Interface for sub creator.
         *
         * Returns:
         *
         *  True if the registration worked, false otherwise.
         *
         * --*/
        /// <devdoc>
        ///    <para>
        ///       Registers a <see cref='System.Net.WebRequest'/> descendent
        ///       for a specific Uniform Resource Identifier.
        ///    </para>
        /// </devdoc>
        public static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
        {
            bool Error = false;
            int  i;
            WebRequestPrefixElement Current;

            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            if (creator == null)
            {
                throw new ArgumentNullException("creator");
            }

#if FEATURE_MONO_CAS
            ExceptionHelper.WebPermissionUnrestricted.Demand();
#endif

            // Lock this object, then walk down PrefixList looking for a place to
            // to insert this prefix.

            lock (InternalSyncObject) {
                //
                // clone the object and update the clone thus
                // allowing other threads to still read from it
                //

                ArrayList prefixList = (ArrayList)PrefixList.Clone();

                // As AbsoluteUri is used later for Create, account for formating changes
                // like Unicode escaping, default ports, etc.
                Uri tempUri;
                if (Uri.TryCreate(prefix, UriKind.Absolute, out tempUri))
                {
                    String cookedUri = tempUri.AbsoluteUri;

                    // Special case for when a partial host matching is requested, drop the added trailing slash
                    // IE: http://host could match host or host.domain
                    if (!prefix.EndsWith("/", StringComparison.Ordinal) &&
                        tempUri.GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment,
                                              UriFormat.UriEscaped)
                        .Equals("/"))
                    {
                        cookedUri = cookedUri.Substring(0, cookedUri.Length - 1);
                    }

                    prefix = cookedUri;
                }

                i = 0;

                // The prefix list is sorted with longest entries at the front. We
                // walk down the list until we find a prefix shorter than this
                // one, then we insert in front of it. Along the way we check
                // equal length prefixes to make sure this isn't a dupe.

                while (i < prefixList.Count)
                {
                    Current = (WebRequestPrefixElement)prefixList[i];

                    // See if the new one is longer than the one we're looking at.

                    if (prefix.Length > Current.Prefix.Length)
                    {
                        // It is. Break out of the loop here.
                        break;
                    }

                    // If these are of equal length, compare them.

                    if (prefix.Length == Current.Prefix.Length)
                    {
                        // They're the same length.
                        if (String.Compare(Current.Prefix, prefix, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // ...and the strings are identical. This is an error.

                            Error = true;
                            break;
                        }
                    }
                    i++;
                }

                // When we get here either i contains the index to insert at or
                // we've had an error, in which case Error is true.

                if (!Error)
                {
                    // No error, so insert.

                    prefixList.Insert(i,
                                      new WebRequestPrefixElement(prefix, creator)
                                      );

                    //
                    // no error, assign the clone to the static object, other
                    // threads using it will have copied the oriignal object already
                    //
                    PrefixList = prefixList;
                }
            }
            return(!Error);
        }
 public AfreetDxResolver(string prefixFileName)
 {
     prefixList = new PrefixList(prefixFileName);
 }
 public AfreetDxResolver(string prefixFileName, string callFileName)
 {
     prefixList = new PrefixList(prefixFileName);
     loadCallList(callFileName);
 }
        /*++
         *
         *  RegisterPrefix - Register an Uri prefix for creating WebRequests.
         *
         *  This function registers a prefix for creating WebRequests. When an
         *  user wants to create a WebRequest, we scan a table looking for a
         *  longest prefix match for the Uri they're passing. We then invoke
         *  the sub creator for that prefix. This function puts entries in
         *  that table.
         *
         *  We don't allow duplicate entries, so if there is a dup this call
         *  will fail.
         *
         * Input:
         *
         *  Prefix           - Represents Uri prefix being registered.
         *  Creator         - Interface for sub creator.
         *
         * Returns:
         *
         *  True if the registration worked, false otherwise.
         *
         * --*/
        /// <devdoc>
        ///    <para>
        ///       Registers a <see cref='System.Net.WebRequest'/> descendent
        ///       for a specific Uniform Resource Identifier.
        ///    </para>
        /// </devdoc>
        public static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
        {
            bool Error = false;
            int  i;
            WebRequestPrefixElement Current;

            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            if (creator == null)
            {
                throw new ArgumentNullException("creator");
            }

            ExceptionHelper.WebPermissionUnrestricted.Demand();

            // Lock this object, then walk down PrefixList looking for a place to
            // to insert this prefix.

            lock (InternalSyncObject) {
                //
                // clone the object and update the clone thus
                // allowing other threads to still read from it
                //

                ArrayList prefixList = (ArrayList)PrefixList.Clone();

                i = 0;

                // The prefix list is sorted with longest entries at the front. We
                // walk down the list until we find a prefix shorter than this
                // one, then we insert in front of it. Along the way we check
                // equal length prefixes to make sure this isn't a dupe.

                while (i < prefixList.Count)
                {
                    Current = (WebRequestPrefixElement)prefixList[i];

                    // See if the new one is longer than the one we're looking at.

                    if (prefix.Length > Current.Prefix.Length)
                    {
                        // It is. Break out of the loop here.
                        break;
                    }

                    // If these are of equal length, compare them.

                    if (prefix.Length == Current.Prefix.Length)
                    {
                        // They're the same length.
                        if (String.Compare(Current.Prefix, prefix, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // ...and the strings are identical. This is an error.

                            Error = true;
                            break;
                        }
                    }
                    i++;
                }

                // When we get here either i contains the index to insert at or
                // we've had an error, in which case Error is true.

                if (!Error)
                {
                    // No error, so insert.

                    prefixList.Insert(i,
                                      new WebRequestPrefixElement(prefix, creator)
                                      );

                    //
                    // no error, assign the clone to the static object, other
                    // threads using it will have copied the oriignal object already
                    //
                    PrefixList = prefixList;
                }
            }
            return(!Error);
        }
Example #22
0
 static Callsign()
 {
     Prefixes = new PrefixList();
 }
Example #23
0
 static WCCheck()
 {
     Prefixes = new PrefixList();
 }