private void ProcessFactories(XmlNode node, IList factories)
 {
    foreach ( XmlNode child in node.ChildNodes )
    {
       Type type;
       switch ( child.LocalName )
       {
       case "add":
          type = Type.GetType(child.Attributes["type"].Value);
          if ( !factories.Contains(type) )
             factories.Add(type);
          break;
       case "remove":
          type = Type.GetType(child.Attributes["type"].Value);
          if ( factories.Contains(type) )
             factories.Remove(type);
          break;
       case "clear":
          factories.Clear();
          break;
       default:
          // gives obsolete warning but needed for .NET 1.1 support
          throw new ConfigurationException(string.Format("Unknown element '{0}' in section '{0}'", child.LocalName, node.LocalName));
       }
    }
 }
Example #2
1
        public static void CalculateTime(IList list, int k)
        {
            // Add
            var startAdding = DateTime.Now;
            string test = "Test string";
            for (int i = 0; i < k; i++)
            {
                list.Add(test);
            }
            var finishAdding = DateTime.Now;
            Console.WriteLine("Addition time (" + k + " elements) : " + list.GetType() + "  " + (finishAdding - startAdding));
            // Search
            var startSearch = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                bool a = list.Contains(test);
            }
            var finishSearch = DateTime.Now;
            Console.WriteLine("Search time (" + k + " elements) : " + list.GetType() + "  " + (finishSearch - startSearch));

            // Remove
            k = 1000;
            var startRemoving = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                list.Remove(test);
            }
            var finishRemoving = DateTime.Now;
            Console.WriteLine("Removal time (" + k + " elements) : " + list.GetType() + "  " + (finishRemoving - startRemoving) + "\n");
        }
        /// <summary>
        /// Get framework version for specified SubKey
        /// </summary>
        /// <param name="parentKey"></param>
        /// <param name="subVersionName"></param>
        /// <param name="versions"></param>
        private static void GetDotNetVersion(RegistryKey parentKey, string subVersionName, IList<NetFrameworkVersionInfo> versions)
        {
            if (parentKey != null)
            {
                string installed = Convert.ToString(parentKey.GetValue("Install"));

                if (installed == "1")
                {
                    NetFrameworkVersionInfo versionInfo = new NetFrameworkVersionInfo();

                    versionInfo.VersionString = Convert.ToString(parentKey.GetValue("Version"));

                    var test = versionInfo.BaseVersion;

                    versionInfo.InstallPath = Convert.ToString(parentKey.GetValue("InstallPath"));
                    versionInfo.ServicePackLevel = Convert.ToInt32(parentKey.GetValue("SP"));

                    if (parentKey.Name.Contains("Client"))
                        versionInfo.FrameworkProfile = "Client Profile";
                    else if (parentKey.Name.Contains("Full"))
                        versionInfo.FrameworkProfile = "Full Profile";

                    if (!versions.Contains(versionInfo))
                        versions.Add(versionInfo);
                }
            }
        }
        /// <summary>
        /// FPS command implementation.
        /// </summary>
        private void CommandExecute(IDebugCommandHost host, string command, IList<string> arguments)
        {
            foreach (string arg in arguments) { arg.ToLower(); }

            if (arguments.Contains("list")) { ShowList(); }

            if (arguments.Contains("open"))
            {
                int index = arguments.IndexOf("open");
                string sceneToOpen = arguments[index + 1];

                if (sceneManager.ContainsScene(sceneToOpen))
                {
                    // activate the selected scene
                    sceneManager.ActivateScene(sceneToOpen);
                }
            }

            if (arguments.Contains("close"))
            {
                int index = arguments.IndexOf("close");
                string sceneToClose = arguments[index + 1];

                if (sceneManager.ContainsScene(sceneToClose))
                {
                    sceneManager.ExitScene(sceneToClose);
                }
            }
            // TODO: allow loading and disposing of scenes
        }
Example #5
0
        private static IEnumerable<int> GenerateTermsForSeed(int seed, IList<int> terms)
        {
            if (!terms.Contains(seed))
            {
                terms.Add(seed);
            }

            var current = seed;
            while (current != 1)
            {
                if (current < 0)
                {
                    break;
                }
                // 256 128 64 32 16 8 4 2 1
                if (current % 2 == 0)
                {
                    current = current / 2;
                }
                else
                {
                    current = (3 * current) + 1;
                }
                if (terms.Contains(current)) break;
                terms.Add(current);
            }

            return terms;
        }
        /// <summary>
        /// 验证用户授权:
        /// 验证规则:
        /// (1)没有被记录的url允许任何人访问;
        /// (2)url上的授权为null或者""时,拒绝任何用户访问;
        /// (3)url上的授权角色为问号 (?) ,表示该url可被任何用户访问;
        /// (4)url上的授权角色为问号 (*) ,表示该url可被任何通过授权验证的用户访问;
        /// (5)url上的授权为角色列表时,验证用户是不是同时属于该角色
        /// </summary>
        /// <param name="userRoles"></param>
        /// <param name="menuRoles"></param>
        /// <returns></returns>
        public bool IsMatch(string[] userRoles, IList menuRoles)
        {
            bool result = false;

            // 菜单上没有任何授权
            if (menuRoles == null || menuRoles.Count == 0)
                return false;

            // 菜单授权给匿名用户
            if (menuRoles.Contains("?"))
                return true;

            // 菜单授权给登录的用户
            if (menuRoles.Contains("*") && Context.User.Identity.IsAuthenticated)
                return true;

            // 用户没有任何角色,同时不满足上述条件
            if (userRoles == null)
                return false;
            // 检查用户角色和菜单角色的匹配
            foreach (string role in userRoles)
            {
                if (menuRoles.Contains(role))
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
        private string Summarize(IList items)
        {
            string str = "";
            if (null != items)
            {
                if (items.Contains("Cyan"))
                {
                    str += "C";
                }
                if (items.Contains("Majenta"))
                {
                    str += "M";
                }
                if (items.Contains("Yellow"))
                {
                    str += "Y";
                }
                if (items.Contains("Black"))
                {
                    str += "K";
                }
            }

            return str;
        }
        /// <summary>
        /// ��֤�û���Ȩ��
        /// ��֤����
        /// ��1��û�б���¼��url�����κ��˷��ʣ�
        /// ��2��url�ϵ���ȨΪnull����""ʱ���ܾ��κ��û����ʣ�
        /// ��3��url�ϵ���Ȩ��ɫΪ�ʺ� (?) ����ʾ��url�ɱ��κ��û����ʣ�
        /// ��4��url�ϵ���Ȩ��ɫΪ�ʺ� (*) ����ʾ��url�ɱ��κ�ͨ����Ȩ��֤���û����ʣ�
        /// ��5��url�ϵ���ȨΪ��ɫ�б�ʱ����֤�û��Dz���ͬʱ���ڸý�ɫ
        /// </summary>
        /// <param name="userRoles"></param>
        /// <param name="menuRoles"></param>
        /// <returns></returns>
        public bool IsMatch(string[] userRoles, IList menuRoles)
        {
            bool result = false;

            // �˵���û���κ���Ȩ
            if (menuRoles == null || menuRoles.Count == 0)
                return false;

            // �˵���Ȩ�������û�
            if (menuRoles.Contains("?"))
                return true;

            // �˵���Ȩ����¼���û�
            if (menuRoles.Contains("*") && Context.User.Identity.IsAuthenticated)
                return true;

            // �û�û���κν�ɫ��ͬʱ��������������
            if (userRoles == null)
                return false;
            // ����û���ɫ�Ͳ˵���ɫ��ƥ��
            foreach (string role in userRoles)
            {
                if (menuRoles.Contains(role))
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
		protected void StartCamera() {
			if (_Camera == null) {
				_Camera = Camera.Open();
				_CameraSupportedFlashModes = _CameraSupportedFlashModes ?? _Camera.GetParameters().SupportedFlashModes;
				if (_CameraSupportedFlashModes == null || !_CameraSupportedFlashModes.Contains(FlashlightOnMode) || !_CameraSupportedFlashModes.Contains(FlashlightOffMode)) {
					StopCamera();
				}
			}
		}
Example #10
0
        public static bool IsComposedOfTwoWordsFromList(this string word, IList<string> words)
        {
            for (var i = 1; i < 6; i++)
            {
                if (words.Contains(word.Substring(0, i)) && words.Contains(word.Substring(i)))
                    return true;
            }

            return false;
        }
Example #11
0
        public IEnumerable<BlobEvent> GetBlobEventsByBlob(DateTime fromdate, DateTime todate, IList<int> types, Guid blobId, int pageSize, int currentPage, out int totalPages)
        {
            fromdate = NormalizeFromDate(fromdate);
            todate = NormalizeToDate(todate);

            var count = this.context.BlobEvents.Where(ev => ev.Blob.BlobId == blobId && ev.EventDateTime >= fromdate && ev.EventDateTime < todate && types.Contains(ev.EventType)).Count();
            totalPages = (int)Math.Ceiling((decimal)count / pageSize);

            return this.context.BlobEvents.Where(ev => ev.Blob.BlobId == blobId && ev.EventDateTime >= fromdate && ev.EventDateTime < todate && types.Contains(ev.EventType)).OrderByDescending(ev => ev.EventDateTime).Skip(pageSize * (currentPage - 1)).Take(pageSize).AsEnumerable();
        }
Example #12
0
 public override IList<ReportColumn> GetCrosstabHeaders(IList<ReportColumn> columns)
 {
     if (columns.Count > 0)
     {
         if (columns.Contains(column => IsPrecursorType(column.Table)))
             return new[] { new ReportColumn(typeof(DbPrecursor), "IsotopeLabelType") }; // Not L10N
         if (columns.Contains(column => IsTransitionType(column.Table)))
             return new[] { new ReportColumn(typeof(DbTransition), "Precursor", "IsotopeLabelType") }; // Not L10N
     }
     return new ReportColumn[0];
 }
 public void TestContains()
 {
     list = new List<int>();
     list.Add(1);
     Assert.AreEqual(true, list.Contains(1));
     list.Add(1);
     Assert.AreEqual(true, list.Contains(1));
     list.Remove(1);
     Assert.AreEqual(true, list.Contains(1));
     list.RemoveAt(0);
     Assert.AreEqual(false, list.Contains(0));
 }
Example #14
0
 public void Reload()
 {
     if (MainForm != null)
     {
         mSelectedTjItems = MainForm.SelectedTjItems;
         initTileItem(tileItemSjdy, mSelectedTjItems.Contains(TjItemEnum.数据打印));
         initTileItem(tileItemNbjc, mSelectedTjItems.Contains(TjItemEnum.内部监测));
         initTileItem(tileItemKqys, mSelectedTjItems.Contains(TjItemEnum.库区雨水));
         initTileItem(tileItemGcjs, mSelectedTjItems.Contains(TjItemEnum.工程介绍));
         initTileItem(tileItemZsjs, mSelectedTjItems.Contains(TjItemEnum.知识介绍));
     }
 }
Example #15
0
        public HeaderViewModel(Profile userProfile, IList<string> userRoles)
        {
            if (userProfile == null) { return; }

            this.Email = userProfile.Email;
            this.Username = userProfile.UserName;
            //this.Firstname = userProfile.FirstName;
            //this.Lastname = userProfile.LastName;

            this.Role = (userRoles == null) ? "" 
                : userRoles.Contains(RoleNames.ADMIN) ? RoleNames.ADMIN
                : userRoles.Contains(RoleNames.OWNER) ? RoleNames.OWNER : "";
        }
Example #16
0
 public IList<Category> Get(IList<Guid> ids, bool fullGraph = false)
 {
     if (fullGraph)
     {
         return _context.Category
                 .AsNoTracking()
                 .Include(x => x.Topics.Select(l => l.LastPost.User))
                 .Include(x => x.ParentCategory)
                 .Where(x => ids.Contains(x.Id)).ToList();
     }
     return _context.Category
         .AsNoTracking().Where(x => ids.Contains(x.Id)).ToList();
 }
Example #17
0
 private static void keyboard_OnKeyReleased(IList<Keys> keys)
 {
     if (keys.Contains(Keys.F)) {
         game.ToggleFullScreen();
     }
     if (keys.Contains(Keys.Escape)) {
         game.Exit();
     }
     if (keys.Contains(Keys.R)) {
         HMCameraManager.ActiveCamera.Position = new Vector3(0, 0, 3);
         HMCameraManager.ActiveCamera.Revolve(new Vector3(1, 0, 0), -20 * 0.01f);
         HMCameraManager.ActiveCamera.RevolveGlobal(new Vector3(0, 1, 0), 70 * 0.01f);
     }
 }
 public static bool IsRolesAccessibleToCurrentUser(IList roles)
 {
     // TODO: Your custom logic here
     if (roles.Contains("editor") && !isEditor()) //have to be both signed in and an editor for this to return true
         return false;
     if (roles.Contains("secure") && !isLoggedIn()) //have to be signed in
         return false;
     if (roles.Contains("intra") && !isIntra())
         return false;
     if (roles.Contains("deliveries") && !seeDeliveries())
         return false;
     
     return true;
 }
Example #19
0
        public IList<ClientCard> Select(IList<ClientCard> cards, int min, int max)
        {
            IList<ClientCard> result = new List<ClientCard>();

            switch (_type)
            {
                case SelectType.Card:
                    if (cards.Contains(_card))
                        result.Add(_card);
                    break;
                case SelectType.Cards:
                    foreach (ClientCard card in _cards)
                        if (cards.Contains(card))
                            result.Add(card);
                    break;
                case SelectType.Id:
                    foreach (ClientCard card in cards)
                        if (card.Id == _id)
                            result.Add(card);
                    break;
                case SelectType.Ids:
                    foreach (int id in _ids)
                        foreach (ClientCard card in cards)
                            if (card.Id == id)
                                result.Add(card);
                    break;
                case SelectType.Location:
                    foreach (ClientCard card in cards)
                        if (card.Location == _location)
                            result.Add(card);
                    break;
            }

            if (result.Count < min)
            {
                foreach (ClientCard card in cards)
                {
                    if (!result.Contains(card))
                        result.Add(card);
                    if (result.Count >= min)
                        break;
                }
            }

            while (result.Count > max)
                result.RemoveAt(result.Count - 1);

            return result;
        }
Example #20
0
        private Node GetNodeTree(string name, string projectUrl, IEnumerable<Merge> merges, IList<string> svnBranches)
        {
            var childMerges = merges.Where(m => m.Parent == name);

            return new Node(
                name,
                svnBranches.Contains(name),
                childMerges.Select(m =>
                    new Branch(
                        GetNodeTree(m.Child, projectUrl, merges, svnBranches),
                        m.Enabled,
                        svnBranches.Contains(name) && svnBranches.Contains(m.Child)
                            ? _unmergedRevisionGetter.GetUnmergedRevisions(projectUrl, m.Child, name)
                            : (long?) null)));
        }
Example #21
0
        private List<string> choices; //holds which information had been chose to be displayed

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor for infoSelect form which lets the user choose which information about the process will be displayed
        /// </summary>
        /// <param name="selected"></param>
        /// <param name="allPossibleData"></param>
        public InfoSelect(IList<string> selected, IList<string> allPossibleData)
        {
            InitializeComponent();
            choices = new List<string>();

            checkGroup = new List<CheckBox>();
            checkGroup.AddRange(new CheckBox[] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5,
                checkBox6, checkBox7, checkBox8, checkBox9, checkBox10, checkBox11, checkBox13, checkBox14});

            int i = 0;
            //populate checkboxes with the avilable options
            foreach (CheckBox box in checkGroup)
            {
                if (i < allPossibleData.Count)
                {
                    box.Text = allPossibleData[i];
                    box.Visible = true;
                    i++;
                }
                else
                {
                    break;
                }
            }

            //check the appropriate boxes
            foreach (CheckBox box in checkGroup)
            {
                if (selected.Contains(box.Text))
                {
                    box.Checked = true;
                }
            }
        }
Example #22
0
        public IDictionary<MapNode, double> GetDistance(MapNode source, IList<MapNode> dest)
        {
            distanceTo.Clear();
            foreach (var n in map)
            {
                distanceTo[n] = double.MaxValue;
            }
            distanceTo[source] = 0.0;
            pq.Clear();

            var ret = new Dictionary<MapNode, double>();
            pq.Enqueue(source, 0.0d);
            while (pq.Count != 0)
            {
                var nodeToExam = pq.Dequeue();
                Relax(nodeToExam);
                if (dest.Contains(nodeToExam))
                {
                    ret[nodeToExam] = distanceTo[nodeToExam];
                    if (ret.Count == dest.Count)
                        return ret;
                }
            }

            return ret;
        }
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="value">The value for which to create a <see cref="System.String"/>.</param>
        /// <param name="useLineBreaks"> </param>
        /// <param name="processedObjects">
        /// A collection of objects that 
        /// </param>
        /// <param name="nestedPropertyLevel">
        /// The level of nesting for the supplied value. This is used for indenting the format string for objects that have
        /// no <see cref="object.ToString()"/> override.
        /// </param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public string ToString(object value, bool useLineBreaks, IList<object> processedObjects = null,
            int nestedPropertyLevel = 0)
        {
            if (value.GetType() == typeof (object))
            {
                return string.Format("System.Object (HashCode={0})", value.GetHashCode());
            }

            string prefix = (useLineBreaks ? Environment.NewLine : "");

            if (HasDefaultToStringImplementation(value))
            {
                if (!processedObjects.Contains(value))
                {
                    processedObjects.Add(value);
                    return prefix + GetTypeAndPublicPropertyValues(value, nestedPropertyLevel, processedObjects);
                }
                else
                {
                    return string.Format("{{Cyclic reference to type {0} detected}}", value.GetType());
                }
            }

            return prefix + value;
        }
 public async Task<IList<DeploymentAudit>> GetAllAuditsAsync(IList<Guid> deploymentIds)
 {
     var list = await collection.AsQueryable()
         .Where(d => deploymentIds.Contains(d.DeploymentId))
         .ToListAsync();
     return list;
 }
        private void TestAnnotations(
            string expectedText,
            IList<TextSpan> expectedSpans,
            SyntaxNode fixedRoot,
            string annotationKind,
            bool compareTokens,
            ParseOptions parseOptions = null)
        {
            expectedSpans = expectedSpans ?? new List<TextSpan>();
            var annotatedTokens = fixedRoot.GetAnnotatedNodesAndTokens(annotationKind).Select(n => (SyntaxToken)n).ToList();

            Assert.Equal(expectedSpans.Count, annotatedTokens.Count);

            if (expectedSpans.Count > 0)
            {
                var expectedTokens = TokenUtilities.GetTokens(TokenUtilities.GetSyntaxRoot(expectedText, GetLanguage(), parseOptions));
                var actualTokens = TokenUtilities.GetTokens(fixedRoot);

                for (var i = 0; i < Math.Min(expectedTokens.Count, actualTokens.Count); i++)
                {
                    var expectedToken = expectedTokens[i];
                    var actualToken = actualTokens[i];

                    var actualIsConflict = annotatedTokens.Contains(actualToken);
                    var expectedIsConflict = expectedSpans.Contains(expectedToken.Span);
                    Assert.Equal(expectedIsConflict, actualIsConflict);
                }
            }
        }
        public bool ProccessGues(IList<int> digits, string gues, out int bulls, out int cows)
        {
            bulls = 0;
            cows = 0;
            if (gues.Length != NUMBER_OF_DIGITS)
            {
                return false;
            }

            int[] guestedDigits = new int[NUMBER_OF_DIGITS];
            for (int index = 0; index < NUMBER_OF_DIGITS; index++)
            {
                if (!int.TryParse(gues[index].ToString(), out guestedDigits[index]))
                {
                    return false;
                }

                if (guestedDigits[index] == digits[index])
                {

                    bulls++;
                }
                else if (digits.Contains(guestedDigits[index]))
                {
                    cows++;
                }
            }
            return true;
        }
        public IList<string> GetDayActivity(IList<string> zoo, string killer)
        {
            if (!zoo.Contains(killer))
            {
                return new List<string>();
            }

            var herring = new List<string>(GameResources.Herrings);
            var goodTraits = new List<string>(GameResources.GoodTraits);
            var badTraits = new List<string>(GameResources.BadTraits);
            herring.Shuffle();
            goodTraits.Shuffle();
            badTraits.Shuffle();

            // good and bad traits
            int badIndex = 0;
            int goodIndex = 0;
            var clues = zoo.Select(x =>
                                {
                                    double chance = x == killer ? ChanceBadKillerTrait : ChanceBadFodderTrait;
                                    string trait = Extensions.RandomGenerator.Next(0, 999)/1000.0 < chance
                                        ? badTraits[badIndex++]
                                        : goodTraits[goodIndex++];
                                    return String.Format(trait, x);
                                }).ToList();

            // herrings
            int herringIndex = 0;
            clues.AddRange(zoo.Select(x => String.Format(herring[herringIndex++], x)));

            clues.Shuffle();

            return clues;
        }
Example #28
0
        public Model(
            DisconnectedBufferGraph disconnectedBufferGraph,
            TextSpan textSpan,
            ISignatureHelpProvider provider,
            IList<SignatureHelpItem> items,
            SignatureHelpItem selectedItem,
            int argumentIndex,
            int argumentCount,
            string argumentName,
            int? selectedParameter)
        {
            Contract.ThrowIfNull(selectedItem);
            Contract.ThrowIfFalse(items.Count != 0, "Must have at least one item.");
            Contract.ThrowIfFalse(items.Contains(selectedItem), "Selected item must be in list of items.");

            _disconnectedBufferGraph = disconnectedBufferGraph;
            this.TextSpan = textSpan;
            this.Items = items;
            this.Provider = provider;
            this.SelectedItem = selectedItem;
            this.ArgumentIndex = argumentIndex;
            this.ArgumentCount = argumentCount;
            this.ArgumentName = argumentName;
            this.SelectedParameter = selectedParameter;
        }
Example #29
0
        private Model(
            DisconnectedBufferGraph disconnectedBufferGraph,
            IList<CompletionItem> totalItems,
            IList<CompletionItem> filteredItems,
            CompletionItem selectedItem,
            bool isHardSelection,
            bool isUnique,
            bool useSuggestionCompletionMode,
            CompletionItem builder,
            CompletionItem defaultBuilder,
            CompletionTriggerInfo triggerInfo,
            ITrackingPoint commitSpanEndPoint,
            bool dismissIfEmpty)
        {
            Contract.ThrowIfNull(selectedItem);
            Contract.ThrowIfFalse(totalItems.Count != 0, "Must have at least one item.");
            Contract.ThrowIfFalse(filteredItems.Count != 0, "Must have at least one filtered item.");
            Contract.ThrowIfFalse(filteredItems.Contains(selectedItem) || defaultBuilder == selectedItem, "Selected item must be in filtered items.");

            _disconnectedBufferGraph = disconnectedBufferGraph;
            this.TotalItems = totalItems;
            this.FilteredItems = filteredItems;
            this.SelectedItem = selectedItem;
            this.IsHardSelection = isHardSelection;
            this.IsUnique = isUnique;
            this.UseSuggestionCompletionMode = useSuggestionCompletionMode;
            this.Builder = builder;
            this.DefaultBuilder = defaultBuilder;
            this.TriggerInfo = triggerInfo;
            this.CommitTrackingSpanEndPoint = commitSpanEndPoint;
            this.DismissIfEmpty = dismissIfEmpty;
        }
Example #30
0
 private static void GenerateChains(IList<int> chain, int n)
 {
     var count = chain.Count;
     if (count >= n) return;
     var last = chain.Last();
     var nextElems = _dict[last].Where(k => !chain.Contains(k)).ToList();
     if (nextElems.Any() && count < n)
     {
         foreach (var next in nextElems)
         {
             var deeper = chain.ToList();
             deeper.Add(next);
             GenerateChains(deeper, n);
         }
     }
     else if (IsPrime(last + 1) && count == n - 1)
     {
         _nrOfChains++;
         /*foreach (var elem in chain)
         {
             Console.Write(elem+" ");
         }
         Console.WriteLine(1);*/
     }
 }