当前位置: 首页>>代码示例>>C#>>正文


C# CsvFileReader.CheckValidRow方法代码示例

本文整理汇总了C#中CsvFileReader.CheckValidRow方法的典型用法代码示例。如果您正苦于以下问题:C# CsvFileReader.CheckValidRow方法的具体用法?C# CsvFileReader.CheckValidRow怎么用?C# CsvFileReader.CheckValidRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvFileReader的用法示例。


在下文中一共展示了CsvFileReader.CheckValidRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportReferral

        public List<string> ImportReferral(string serverPath, Stream stream, string destinationPath, string filename,
            int campaignId,
            int userId, string ip_address, out ImportReferralHistory history)
        {
            try
            {
                history = new ImportReferralHistory();
                List<Tuple<string, string>> listUsers = new List<Tuple<string, string>>();
                string savedFile = destinationPath + filename;
                List<string> builderErrors = new List<string>(); ;
                List<Tuple<int, string>> listValidUsername = new List<Tuple<int, string>>();
                List<string> listInValidUsername = new List<string>();

                using (CsvFileReader reader = new CsvFileReader(stream))
                {
                    CsvRow row = new CsvRow();
                    int rowNumber = 1;
                    List<string> username = new List<string>();

                    using (CsvFileWriter writer = new CsvFileWriter(savedFile))
                    {
                        while (!reader.EndOfStream)
                        {
                            var errorMsg = reader.CheckValidRow(row, rowNumber == 1, ref username);
                            if (!string.IsNullOrEmpty(errorMsg))
                                builderErrors.Add(string.Format("Line {0}: {1}", rowNumber, errorMsg));
                            else if (username != null && username.Any())
                            {
                                foreach (var item in username)
                                {
                                    if (!listValidUsername.Select(t => t.Item2).Contains(item) && !listInValidUsername.Contains(item))
                                    {
                                        var id = GetIdByUsername(item);
                                        if (id > 0)
                                            listValidUsername.Add(new Tuple<int, string>(id, item));
                                        else
                                        {
                                            listInValidUsername.Add(item);
                                            builderErrors.Add(string.Format("Line {0}: {1} is invalid username", rowNumber, item));
                                        }
                                    }
                                }
                                listUsers.Add(new Tuple<string, string>(username[0], username[1]));
                            }
                            else if (rowNumber != 1 && !username.Any())
                            {
                                builderErrors.Add(string.Format("Line {0}: This row is empty", rowNumber));
                            }
                            rowNumber++;

                            reader.ReadRow(row);
                            writer.WriteRow(row);
                        }
                    }
                }

                if (builderErrors != null && builderErrors.Any())
                    return builderErrors;

                string filePath = savedFile.Replace(serverPath, "\\");
                if (string.IsNullOrEmpty(filePath))
                {
                    builderErrors.Add(ErrorCodes.SAVE_FILE_ERROR.ToErrorMessage());
                    return builderErrors;
                }

                #region Save data to DB
                var repo = Repo.Instance;
                using (var db = repo.OpenConnectionFromPool())
                {
                    ReferralCampaign referralCampaign = repo.GetReferralCampaign(db
                        , new List<int>() { (int)ReferralCampaignStatus.Running, (int)ReferralCampaignStatus.Finished }
                        , campaignId);
                    if (referralCampaign == null)
                    {
                        builderErrors.Add(ErrorCodes.INVALID_REFERRAL_CAMPAIGN.ToErrorMessage());
                        return builderErrors;
                    }

                    //if (repo.CountRecordDownloadHistory(db, referralCampaign.id) + listUsers.Count() > referralCampaign.quantity)
                    //{
                    //    builderErrors.Add(ErrorCodes.REFERRAL_CAMPAIGN_QUANTITY_IS_OVER.ToErrorMessage());
                    //    return builderErrors;
                    //}

                    List<Tuple<string, string, string>> listFail = new List<Tuple<string, string, string>>();

                    foreach (var row in listUsers)
                    {
                        var uid = listValidUsername.FirstOrDefault(u => string.Compare(u.Item2, row.Item1, true) == 0).Item1;
                        string error = ImportUserRerralCampaigns(repo, db, uid, referralCampaign.game_id, row.Item1, row.Item2, ip_address, referralCampaign);
                        if (!string.IsNullOrEmpty(error))
                        {
                            listFail.Add(new Tuple<string, string, string>(row.Item1, row.Item2, error));
                        }
                    }

                    string failData = string.Empty;
                    if (listFail.Any())
                    {
//.........这里部分代码省略.........
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:101,代码来源:Api-Common.cs


注:本文中的CsvFileReader.CheckValidRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。