Example #1
1
        public void SyncTestItemsIList(ref IList<TestItem> source, ref IList<TestItem> destination)
        {
            foreach (var item in source)
            {
                var dest = destination.SingleOrDefault(d => d.Id == item.Id);
                if (dest == null)
                {
                    destination.Add(item);
                }
                else
                {
                    if (dest.Sync < item.Sync)
                    {
                         destination[destination.IndexOf(dest)] = item.Clone();
                    }
                }
            }

            foreach (var item in destination)
            {
                var sour = source.SingleOrDefault(s => s.Id == item.Id);
                if (sour == null)
                {
                    source.Add(item);
                }
                else
                {
                    if (sour.Sync < item.Sync)
                    {
                        source[source.IndexOf(sour)] = item.Clone();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initialises a new instance of the <see cref="TableInfo"/> class.
        /// </summary>
        /// <param name="columns">The columns that are mapped for the table.</param>
        /// <param name="identifierStrategy">The identifier strategy used by the table.</param>
        /// <param name="name">The name of the table.</param>
        /// <param name="schema">The database schema the table exists within (e.g. 'dbo'); otherwise null.</param>
        /// <exception cref="ArgumentNullException">Thrown if columns or name are null.</exception>
        /// <exception cref="MappingException">Thrown if no there is a problem with the column mappings.</exception>
        public TableInfo(
            IList<ColumnInfo> columns,
            IdentifierStrategy identifierStrategy,
            string name,
            string schema)
        {
            if (columns == null)
            {
                throw new ArgumentNullException("columns");
            }

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

            this.columns = new ReadOnlyCollection<ColumnInfo>(columns);
            this.identifierStrategy = identifierStrategy;
            this.name = name;
            this.schema = schema;

            this.ValidateColumns();

            this.identifierColumn = columns.SingleOrDefault(c => c.IsIdentifier);

            this.insertColumnCount = columns.Count(c => c.AllowInsert);
            this.updateColumnCount = columns.Count(c => c.AllowUpdate);
        }
Example #3
0
        /// <summary>
        /// Generates SriptSharp files
        /// </summary>
        /// <param name="entries">List of jQueryUI entries.</param>
        public void Render(IList<Entry> entries)
        {
            if (entries == null) {
                return;
            }

            DirectoryInfo destination = new DirectoryInfo(DestinationPath);
            if (destination.Exists) {
                destination.Delete(true);
            }

            foreach (Entry entry in entries) {
                Messages.WriteLine("Generating " + Path.Combine(DestinationPath, Utils.PascalCase(entry.Name)));

                Entry baseEntry = null;
                if (!string.IsNullOrEmpty(entry.Type)) {
                    // find the base entry
                    baseEntry = entries.SingleOrDefault(e => e.Name.ToLowerInvariant() == entry.Type.ToLowerInvariant());
                }

                RenderEntry(entry, baseEntry);
            }

            Messages.WriteLine("Generating jQueryUI base files.");
            RenderEventHandler();
            RenderBox();
            RenderSize();
            RenderEffectExtensionMethods(entries.Where(e => e.Category == "effects" && e.Name != "effect"));
            RenderInteractionOrWidgetExtensionMethods("Interaction", entries.Where(e => e.Category == "interactions"));
            RenderInteractionOrWidgetExtensionMethods("Widget", entries.Where(e => e.Category == "widgets" && e.Name != "widget"));
            RenderPositionExtensionMethods(entries.Single(e => e.Name == "position"));
        }
        public void Execute(string[] args, IList<Directory> directoryies)
        {
            if(args.Length != 1)
                throw new ArgumentException();

            string[] fileinfos = args[0].Split('/');

            if(fileinfos.Length != 2)
                throw new ArgumentException();

            var dirname = fileinfos[0];
            var filename = fileinfos[1];

            var targetdir = directoryies.SingleOrDefault(dir =>
            {
                return dir.Name.Equals(dirname);
            });

            if(targetdir == null)
                throw new Exception("Directoryが存在しません");

            if(targetdir.Contains(filename))
                throw new Exception("Fileがすでに存在します");

            targetdir.Add(new File(filename);
        }
        private async Task AddClaim(ApplicationUser user, IList<Claim> claims, string claim)
        {
            var roleType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";

            if (claims.SingleOrDefault(x => x.Type == roleType && x.Value == claim) == null)
                await _userManager.AddClaimAsync(user, new Claim(roleType, claim, null));
        }
        /// <summary>
        /// Generates SriptSharp files
        /// </summary>
        /// <param name="entries">List of jQueryUI entries.</param>
        public void Render(IList<Entry> entries)
        {
            if (entries == null) {
                return;
            }

            DirectoryInfo destination = new DirectoryInfo(DestinationPath);
            if (destination.Exists) {
                destination.Delete(true);
            }

            foreach (Entry entry in entries) {
                Messages.WriteLine("Generating " + Path.Combine(DestinationPath, Utils.PascalCase(entry.Name)));

                Entry baseEntry = null;
                if (!string.IsNullOrEmpty(entry.Type)) {
                    // find the base entry
                    baseEntry = entries.SingleOrDefault(e => e.Name.ToLower() == entry.Type.ToLower());
                }

                RenderEntry(entry, baseEntry);
            }

            RenderEventHandler();
            RenderJQueryUI();
            RenderWidgetType(entries);
        }
        private void RmDir(string dirname, IList<Directory> directoryies)
        {
            var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
            if(dirobj == null)
                new Exception("Directoryが存在しません");

            directoryies.Remove(dirobj);
        }
        private IBinaryInfo BuildBinaryInfo(IAddInfo addInfo, IList<IPackageEntry> fileInfos, IPackageEntry binaryFileInfo)
        {
            var binaryInfo = new BinaryInfo(addInfo);

            binaryInfo.Name = Path.GetFileNameWithoutExtension(binaryFileInfo.FullPath);
            binaryInfo.Type = Path.GetExtension(binaryFileInfo.FullPath).Substring(1);
            binaryInfo.File = binaryFileInfo;

            using (var stream = binaryFileInfo.Stream)
            {
                binaryInfo.Hash = binaryStoreManager.ReadBinaryHash(stream);
                stream.Seek(0, SeekOrigin.Begin);
                binaryInfo.SymbolHash = binaryStoreManager.ReadPdbHash(stream);
            }

            string symbolName = Path.ChangeExtension(binaryFileInfo.FullPath, "pdb");
            var symbolFileInfo = fileInfos.SingleOrDefault(s => s.FullPath == symbolName);
            if (symbolFileInfo != null)
            {
                var symbolInfo = new SymbolInfo(binaryInfo);
                symbolInfo.Type = Path.GetExtension(symbolFileInfo.FullPath).Substring(1);
                symbolInfo.File = symbolFileInfo;

                using (var stream = symbolFileInfo.Stream)
                {
                    symbolInfo.Hash = symbolStoreManager.ReadHash(stream);
                }

                symbolInfo.SourceInfos = sourceDiscover.FindSources(fileInfos, binaryInfo, symbolInfo).OrderBy(s => s.KeyPath).ToArray();
                binaryInfo.SymbolInfo = symbolInfo;
            }

            string documentationName = Path.ChangeExtension(binaryFileInfo.FullPath, "xml");
            var documentationFileInfo = fileInfos.SingleOrDefault(s => s.FullPath == documentationName);
            if (documentationFileInfo != null)
            {
                var documentationInfo = new DocumentationInfo(binaryInfo);
                documentationInfo.Type = Path.GetExtension(documentationFileInfo.FullPath).Substring(1);
                documentationInfo.File = documentationFileInfo;
                binaryInfo.DocumentationInfo = documentationInfo;
            }

            return binaryInfo;
        }
Example #9
0
 internal static void ToApplicationRelativeUrl(IList<AttributeNode> attributes, string name)
 {
     var node = attributes.SingleOrDefault(x => x.Name == name);
     if ((node != null) && (!node.Value.StartsWith("#")))
     {
         var newNode = AddMethodCallingToAttributeValue(node, Constants.TOAPPLICATIONRELATIVEURL);
         attributes.Remove(node);
         attributes.Add(newNode);
     }
 }
        private void RmFile(string dirname, string filename, IList<Directory> directoryies)
        {
            var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
            if(dirobj == null)
                throw new Exception("Fileが存在しません");

            if(!dirobj.Contains(filename))
                throw new Exception("Fileが存在しません");

            dirobj.Remove(filename);
        }
Example #11
0
 internal static void AddApplyPathModifier(IList<AttributeNode> attributes, string name)
 {
     //Response.ApplyAppPathModifier used not only to add cookie, it also resolves urls with ~.
     var node = attributes.SingleOrDefault(x => x.Name == name);
     if ((node != null)&&(!node.Value.StartsWith("#")))
     {
         var newNode = AddMethodCallingToAttributeValue(AddMethodCallingToAttributeValue(node,Constants.TOAPPLICATIONRELATIVEURL), Constants.APPLYAPPPATHMODIFIER);
         attributes.Remove(node);
         attributes.Add(newNode);
     }
 }
Example #12
0
        private ConfigSection GetOrCreateSection( IList<ConfigSection> sections, string sectionName )
        {
            var section = sections.SingleOrDefault( sec => sec.Name == sectionName );
            if ( section == null )
            {
                section = new ConfigSection( sectionName );
                sections.Add( section );
            }

            return section;
        }
        private void MvDir(string dirname, string newdirname, IList<Directory> directoryies)
        {
            bool isExist = directoryies.Any(dir => dir.Name.Equals(newdirname));
            if(isExist)
                throw new Exception("移動先のDirectoryは存在します");

            var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
            if(dirobj == null)
                throw new Exception("移動元のDirectoryは存在します");

            dirobj.Name = newdirname;
        }
Example #14
0
 private void AddOrOverwrite( IList<ConfigSection> sections, ConfigSection section )
 {
     var existingSection = sections.SingleOrDefault( sec => sec.Name == section.Name );
     if ( existingSection != null )
     {
         existingSection.Properties.Clear();
         existingSection.Properties.AddRange( section.Properties );
     }
     else
     {
         sections.Add( section );
     }
 }
        private void MvFile(string dirname, string filename, 
            string newdirname, string newfilename, IList<Directory> directoryies)
        {
            var srcdir = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
            if(srcdir == null)
                throw new Exception("移動元Fileが存在しません");

            if(!srcdir.Contains(filename))
                throw new Exception("移動元Fileが存在しません");

            var dstdir = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
            if(dstdir == null)
                throw new Exception("移動元Fileが存在しません");

            if(!dstdir.Contains(filename))
                throw new Exception("移動元Fileが存在しません");

            var file = srcdir.Get(filename);
            srcdir.Remove(filename);
            file.Name = newfilename;
            dstdir.Add(file);
        }
 /// <summary>
 /// Gets the entry.
 /// </summary>
 /// <param name="workingMemory">The working memory.</param>
 /// <param name="contextObjectType">Type of the context object.</param>
 /// <param name="name">The name of the context object.</param>
 /// <returns>A <see cref="ContextEntry"/> or null if no entry exists.</returns>
 public ContextEntry GetEntry( IList<ContextEntry> workingMemory, Type contextObjectType, string name = null )
 {
     return workingMemory.SingleOrDefault (
         r =>
             {
                 var compareType = r.ContextObject.GetType ();
                 if ( r.ContextObject is INHibernateProxy )
                 {
                     var proxy = r.ContextObject as INHibernateProxy;
                     compareType = proxy.HibernateLazyInitializer.PersistentClass;
                 }
                 return compareType.Equals ( contextObjectType ) && ( name == null || r.Name == name );
             } );
 }
        private static Dictionary<string, string> GetMapForSubproperty(List<PropInfo> viewModelProps, IList<PropInfo> propsToCompare)
        {
            var map = new Dictionary<string, string>();
            foreach (var vmProp in viewModelProps)
            {
                var match = propsToCompare.SingleOrDefault(x => vmProp.Name.StartsWith(x.Name));

                if (match != null)
                {
                    map.Add(vmProp.Name, string.Format("{0}.{1}", match.Name, vmProp.Name.Replace(match.Name, string.Empty)));
                }
            }

            return map;
        }
Example #18
0
 public override void TakeDamage(IList<PlayerDamage> damages)
 {
     //TODO: Rules clarification: Heroic action turns 9 into 10?
     var interceptorDamages = damages.SingleOrDefault(damage => damage.PlayerDamageType == PlayerDamageType.InterceptorsSingle);
     if (interceptorDamages != null)
     {
         var strongerInterceptorDamages = new PlayerDamage(
             9,
             PlayerDamageType.InterceptorsSingle,
             interceptorDamages.Range,
             interceptorDamages.ZoneLocations);
         damages.Remove(interceptorDamages);
         damages.Add(strongerInterceptorDamages);
         sittingDuck.KnockOutPlayers(new [] {StationLocation.Interceptor});
     }
     base.TakeDamage(damages);
 }
        private void loadBookData(EbooksContext db, GutCatDoc doc, IList<GutBook> newBooks, IList<GutAuthor> newAuthors, IList<LanguageName> newLangNames, IList<LanguageCode> newLangCodes) {
            var gutBook = db.GutBooks.SingleOrDefault(b => b.GutBookId == doc.Id);
            if (gutBook == null) {
                gutBook = new GutBook { GutBookId = doc.Id };
                newBooks.Add(gutBook);
            }
            gutBook.Title = doc.Title;
            var gutAuthor = newAuthors.SingleOrDefault(a => a.Name == doc.Author);
            if (gutAuthor == null) gutAuthor = db.GutAuthors.SingleOrDefault(a => a.Name == doc.Author);
            if (gutAuthor == null && doc.Author != null) {
                gutAuthor = new GutAuthor { Name = doc.Author };
                newAuthors.Add(gutAuthor);
            }
            gutBook.GutAuthor = gutAuthor;

            var langCode = newLangCodes.SingleOrDefault(c => c.Code == doc.Language);
            if (langCode == null) langCode = db.LanguageCodes.SingleOrDefault(c => c.Code == doc.Language);
            if (langCode == null) {
                var langName = newLangNames.SingleOrDefault(n => n.Name == doc.Language);
                if (langName == null) newLangNames.Add(langName = new LanguageName { Name = doc.Language });
                langCode = new LanguageCode { Code = doc.Language };
                langCode.LanguageNames = new Collection<LanguageName>();
                langCode.LanguageNames.Add(langName);
                newLangCodes.Add(langCode);
            }
            gutBook.Language = doc.Language;

            var getUrl = new Func<string, string, string>((url, standard) => url != null && url != standard ? url : null);
            gutBook.EpubUrlImages = getUrl(doc.EpubUrlImages, doc.StandardEpubUrlImages);
            gutBook.StandardEpubUrlImages = doc.EpubUrlImages == doc.StandardEpubUrlImages;
            gutBook.EpubUrlNoImages = getUrl(doc.EpubUrlNoImages, doc.StandardEpubUrlNoImages);
            gutBook.StandardEpubUrlNoImages = doc.EpubUrlNoImages == doc.StandardEpubUrlNoImages;
            gutBook.ThumbnailUrl = getUrl(doc.ThumbnailUrl, doc.StandardThumbnailUrl);
            gutBook.StandardThumbnailUrl = doc.ThumbnailUrl == doc.StandardThumbnailUrl;
            gutBook.CoverUrl = getUrl(doc.CoverUrl, doc.StandardCoverUrl);
            gutBook.StandardCoverUrl = doc.CoverUrl == doc.StandardCoverUrl;
        }
Example #20
0
        private CommentView FindCommentInTree(IList<CommentView> comments, int commentId)
        {
            CommentView comment = comments.SingleOrDefault(c => c.Id == commentId);

            if (comment == null)
            {
                foreach (CommentView childComment in comments)
                {
                    comment = FindCommentInTree(childComment.ChildComments, commentId);

                    if (comment != null)
                    {
                        break;
                    }
                }
            }

            return comment;
        }
Example #21
0
 private void UpdateDiskDetails(IList<DiskDetails> diskDetails)
 {
     this.Disks = new List<VirtualHardDisk>();
     foreach (var disk in diskDetails)
     {
         VirtualHardDisk hd = new VirtualHardDisk();
         hd.Id = disk.VhdId;
         hd.Name = disk.VhdName;
         this.Disks.Add(hd);
     }
     DiskDetails OSDisk = diskDetails.SingleOrDefault(d => string.Compare(d.VhdType, "OperatingSystem", StringComparison.OrdinalIgnoreCase) == 0);
     if (OSDisk != null)
     {
         this.OSDiskId = OSDisk.VhdId;
         this.OSDiskName = OSDisk.VhdName;
     }
 }
        // Returns a list of strings describing all of the expected trace records that were not
        // actually traced.
        // If you experience test failures from this list, it means someone stopped tracing or 
        // changed the content of what was traced.  
        // Update the ExpectedTraceRecords property to reflect what is expected.
        private static IList<string> MissingTraces(IList<ExpectedTraceRecord> expectedRecords, IList<TraceRecord> actualRecords)
        {
            List<string> missing = new List<string>();

            foreach (ExpectedTraceRecord expectedRecord in expectedRecords)
            {
                TraceRecord beginTrace = actualRecords.SingleOrDefault(r =>
                    String.Equals(r.Category, expectedRecord.Category, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(r.Operator, expectedRecord.OperatorName, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(r.Operation, expectedRecord.OperationName, StringComparison.OrdinalIgnoreCase) &&
                    r.Kind == TraceKind.Begin
                    );

                if (beginTrace == null)
                {
                    missing.Add(string.Format("Begin category={0}, operator={1}, operation={2}",
                                    expectedRecord.Category, expectedRecord.OperatorName, expectedRecord.OperationName));
                }

                TraceRecord endTrace = actualRecords.SingleOrDefault(r =>
                    String.Equals(r.Category, expectedRecord.Category, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(r.Operator, expectedRecord.OperatorName, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(r.Operation, expectedRecord.OperationName, StringComparison.OrdinalIgnoreCase) &&
                    r.Kind == TraceKind.End
                    );

                if (endTrace == null)
                {
                    missing.Add(string.Format("End category={0}, operator={1}, operation={2}",
                                    expectedRecord.Category, expectedRecord.OperatorName, expectedRecord.OperationName));
                }
            }

            return missing;
        }
Example #23
0
 public static bool checkHuyNiemYeu(string stockCode,IList<string> listHuyNiemYet)
 {
     bool result = false;
     if (listHuyNiemYet.SingleOrDefault(m => m.Contains(stockCode)) != null)
     {
         result = true;
     }
     return result;
 }
Example #24
0
        // Returns true if the tracing records are in the correct order, else returns false.
        private static bool ConfirmTracingOrder(IList<ExpectedTraceRecord> expectedRecords, IList<TraceRecord> actualRecords)
        {
            int traceBeginPos = 0;
            foreach (ExpectedTraceRecord expectedRecord in expectedRecords)
            {
                TraceRecord beginTrace = actualRecords.SingleOrDefault(r =>
                    String.Equals(r.Category, expectedRecord.Category, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(r.Operator, expectedRecord.OperatorName, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(r.Operation, expectedRecord.OperationName, StringComparison.OrdinalIgnoreCase) &&
                    object.Equals(r.Kind, expectedRecord.TraceKind) 
                    );

                if (!object.ReferenceEquals(beginTrace, actualRecords.ElementAt(traceBeginPos)))
                {
                    return false;
                }
                traceBeginPos++;
            }
            return true;
        }
        private void ValidateTable(Table expectedTable, IList<Table> result)
        {
            // Table & Name
            var actualTable = result.SingleOrDefault(t => t.Name.Equals(expectedTable.Name));
            Assert.IsNotNull(actualTable);

            // Columns
            Assert.AreEqual(expectedTable.Columns.Count, actualTable.Columns.Count);
            Assert.IsTrue(expectedTable.Columns.All(c => actualTable.Columns.Contains(c)));
        }
Example #26
0
 private static CampfireState.UserInfo SingleMatch(string target, IList<CampfireState.UserInfo> allUsers, bool smokeSignalCommands)
 {
     // trim off trailing periods so taht references can be at the end of a sentance: "... @Peter."
     string lowered = target.Trim('.').ToLowerInvariant();
     try
     {
         // For reference... if there's only one user who matches... we have a HIT!
         CampfireState.UserInfo referencedUser = allUsers.SingleOrDefault(
             ui => smokeSignalCommands ? ui.PossibleAbbreviations.Any(abbrv => lowered.StartsWith(abbrv)) : ui.PossibleAbbreviations.Contains(lowered));
         if (referencedUser != null)
         {
             return referencedUser;
         }
     }
     catch (InvalidOperationException ex)
     {
         // this means we have multiple people that can match the reference found in the text. Oh well... just skip it
     }
     return null;
 }
        /// <summary>
        /// Gets the value by key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>System.String.</returns>
        public string GetValueByKey(string key)
        {
            _settings = GetValues();
            var singleOrDefault = _settings.SingleOrDefault(s => string.Equals(s.Name, key, StringComparison.CurrentCultureIgnoreCase));

            string val = null;
            if (singleOrDefault != null)
            {
                val = singleOrDefault.Value;
            }

            return val;
        }
Example #28
0
        /// <summary>
        /// Get the value of a property in a Gdto.
        /// </summary>
        public string GetPropertyValue(IList<KeyValuePair<string, string>> properties, string propertyName)
        {
            try
            {
                if (properties == null)
                {
                    return string.Empty;
                }

                var namePropertyValue = properties
                    .SingleOrDefault(p => string.Equals(p.Key, propertyName, StringComparison.CurrentCultureIgnoreCase))
                    .Value;

                return namePropertyValue ?? string.Empty;
            }
            catch (Exception ex)
            {
                this.logger.Error(ex);
                throw;
            }
        }
 /// <summary>
 ///     Mapping new user vote model based on given place votes and voter id
 /// </summary>
 /// <param name="votes">List of place votes</param>
 /// <param name="userId">Id of a voter</param>
 /// <returns>New user vote model</returns>
 public static UsersVoteModel MapToUsersVoteModel(IList<VoteForPlace> votes, string userId)
 {
     return new UsersVoteModel()
     {
         Id = votes.SingleOrDefault(v => v.UserId == userId)?.Id ?? Guid.Empty,
         WillAttend = votes.SingleOrDefault(v => v.UserId == userId)?.WillAttend.ToString() ?? null
     };
 }
        private static BlogPost ReturnBlogPost(int year, int month, int day, string title, IList<BlogPost> blogPostList, bool shouldBlogPostRepositoryAlwayReturnPost)
        {
            if (shouldBlogPostRepositoryAlwayReturnPost)
            {
                var blogPost = new BlogPost("Test", "Test", "Test", new ImageReference(1, "/noimage.jpg"), DateTime.Now, new BlogUser());
                blogPost.SetProperty(p => p.Id, 1);

                return blogPost;
            }

            return blogPostList.SingleOrDefault(p => p.PublishedDate.Year == year && p.PublishedDate.Month == month && p.PublishedDate.Day == day && p.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase));
        }