Beispiel #1
0
        public IHttpActionResult Export()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var formInfo = FormManager.GetFormInfoByPost(request);
                if (formInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.MenuFormsPermission))
                {
                    return(Unauthorized());
                }

                var fieldInfoList = FieldManager.GetFieldInfoList(formInfo.Id);
                var logs          = LogManager.Repository.GetAllLogInfoList(formInfo);

                var head = new List <string> {
                    "编号"
                };
                foreach (var fieldInfo in fieldInfoList)
                {
                    head.Add(fieldInfo.Title);
                }
                head.Add("添加时间");

                var rows = new List <List <string> >();

                foreach (var log in logs)
                {
                    var row = new List <string>
                    {
                        log.Guid
                    };
                    foreach (var fieldInfo in fieldInfoList)
                    {
                        row.Add(LogManager.GetValue(fieldInfo, log));
                    }

                    if (log.AddDate.HasValue)
                    {
                        row.Add(log.AddDate.Value.ToString("yyyy-MM-dd HH:mm"));
                    }

                    rows.Add(row);
                }

                var fileName = $"{formInfo.Title}.csv";
                CsvUtils.Export(Context.PluginApi.GetPluginPath(FormUtils.PluginId, fileName), head, rows);
                var downloadUrl = Context.PluginApi.GetPluginUrl(FormUtils.PluginId, fileName);

                return(Ok(new
                {
                    Value = downloadUrl
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
 private void loadPetCharacterCsv(string csvFilePath)
 {
     string[,] strArray = CsvUtils.Deserialize(ResourceUtil.LoadSafe <TextAsset>(csvFilePath, false).text);
     for (int i = 0; i < strArray.GetLength(1); i++)
     {
         if (strArray[0, i] == null)
         {
             continue;
         }
         Character e    = new Character();
         int       num2 = 0;
         e.Id   = strArray[num2++, i];
         e.Name = _.L(strArray[num2++, i], null, false);
         num2++;
         e.FlavorText      = _.L(strArray[num2++, i], null, false);
         e.Type            = GameLogic.CharacterType.Pet;
         e.Prefab          = base.parseEnumType <CharacterPrefab>(strArray[num2++, i]);
         e.Rarity          = base.parseInt(strArray[num2++, i]);
         e.AvatarSpriteId  = strArray[num2++, i];
         e.CoreAiBehaviour = base.parseEnumType <AiBehaviourType>(strArray[num2++, i]);
         KeyValuePair <string, float>   pair      = base.parseStringFloatPair(strArray[num2++, i]);
         KeyValuePair <string, float>   pair2     = base.parseStringFloatPair(strArray[num2++, i]);
         KeyValuePair <string, float>   pair3     = base.parseStringFloatPair(strArray[num2++, i]);
         KeyValuePair <string, float>   pair4     = base.parseStringFloatPair(strArray[num2++, i]);
         KeyValuePair <string, float>[] pairArray = new KeyValuePair <string, float>[] { pair, pair2, pair3, pair4 };
         e.FixedPerks = new GatedPerkContainer();
         for (int j = 0; j < pairArray.Length; j++)
         {
             if (string.IsNullOrEmpty(pairArray[j].Key) || (j >= ConfigGameplay.PET_PERK_MILESTONE_LEVELS.Count))
             {
                 break;
             }
             int      num4               = ConfigGameplay.PET_PERK_MILESTONE_LEVELS[j];
             PerkType perkType           = base.parseEnumType <PerkType>(pairArray[j].Key);
             ConfigPerks.SharedData data = ConfigPerks.SHARED_DATA[perkType];
             float bestModifier          = (data.LinkedToRunestone == null) ? pairArray[j].Value : ConfigRunestones.GetRunestoneData(data.LinkedToRunestone).PerkInstance.Modifier;
             if (bestModifier == 0f)
             {
                 bestModifier = ConfigPerks.GetBestModifier(perkType);
             }
             GatedPerkContainer.Entry item = new GatedPerkContainer.Entry();
             item.RankReq = num4;
             PerkInstance instance = new PerkInstance();
             instance.Type     = perkType;
             instance.Modifier = bestModifier;
             item.PerkInstance = instance;
             e.FixedPerks.Entries.Add(item);
         }
         e.RangedProjectileType        = base.parseEnumType <ProjectileType>(strArray[num2++, i]);
         e.MainHeroDamagePerHitPct     = base.parseFloat(strArray[num2++, i]);
         e.AttackContactTimeNormalized = base.parseFloat(strArray[num2++, i]);
         e.BaseStats = new Dictionary <string, double>();
         e.BaseStats.Add(BaseStatProperty.AttacksPerSecond.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.AttackRange.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.CriticalHitChancePct.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.CriticalHitMultiplier.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.CleaveDamagePct.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.CleaveRange.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.MovementSpeed.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.Threat.ToString(), base.parseDouble(strArray[num2++, i]));
         e.BaseStats.Add(BaseStatProperty.Life.ToString(), 999.0);
         e.BaseStats.Add(BaseStatProperty.DamagePerHit.ToString(), 0.0);
         e.BaseStats.Add(BaseStatProperty.UniversalArmorBonus.ToString(), 0.0);
         e.BaseStats.Add(BaseStatProperty.SkillDamage.ToString(), 0.0);
         e.BaseStats.Add(BaseStatProperty.UniversalXpBonus.ToString(), 0.0);
         this.postProcess(e);
     }
 }
Beispiel #3
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var isChanged = false;

            try
            {
                if (_flg == 0)
                {
                    var totalNum = TranslateUtils.ToInt(TbTotalNum.Text);
                    if (totalNum > 1000)
                    {
                        FailMessage("新增失败,一次最多只能新增1000张优惠劵");
                    }
                    else
                    {
                        DataProviderWx.CouponSnDao.Insert(PublishmentSystemId, _couponId, totalNum);

                        Body.AddSiteLog(PublishmentSystemId, "新增优惠劵数量", $"数量:{totalNum}");
                        isChanged = true;
                    }
                }
                if (_flg == 1)
                {
                    //string filehou = this.hifUpload.PostedFile.FileName.Split('.')[1].ToString();

                    //if (filehou != "xls" || filehou != "xlsx")
                    //{
                    //    base.FailMessage("请检查上传文件的类型.必须为EXCEL文件.");
                    //}

                    var filePath = PathUtils.GetTemporaryFilesPath("coupon_sn_upload.csv");
                    FileUtils.DeleteFileIfExists(filePath);

                    HifUpload.PostedFile.SaveAs(filePath);

                    try
                    {
                        List <List <string> > snList;
                        List <string>         head;
                        CsvUtils.Import(filePath, out head, out snList);

                        if (snList.Count > 0)
                        {
                            //DataProviderWx.CouponSnDao.Insert(PublishmentSystemId, _couponId, snList);
                            Body.AddSiteLog(PublishmentSystemId, "新增优惠劵数量", $"数量:{snList.Count}");
                            isChanged = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, "失败:" + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                FailMessage(ex, "失败:" + ex.Message);
            }

            if (isChanged)
            {
                PageUtils.CloseModalPage(Page);
            }
        }
Beispiel #4
0
        public static List <ContentInfo> GetContentsByCsvFile(string filePath, SiteInfo siteInfo,
                                                              ChannelInfo nodeInfo)
        {
            var contentInfoList = new List <ContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count <= 0)
            {
                return(contentInfoList);
            }

            var relatedidentityes =
                RelatedIdentities.GetChannelRelatedIdentities(
                    siteInfo.Id, nodeInfo.Id);
            var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo);
            // ArrayList tableStyleInfoArrayList = TableStyleManager.GetTableStyleInfoArrayList(ETableStyle.BackgroundContent, siteInfo.AuxiliaryTableForContent, relatedidentityes);

            var styleInfoList       = ContentUtility.GetAllTableStyleInfoList(TableStyleManager.GetTableStyleInfoList(tableName, relatedidentityes));
            var nameValueCollection = new NameValueCollection();

            foreach (var styleInfo in styleInfoList)
            {
                nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
            }

            var attributeNames = new List <string>();

            foreach (var columnName in head)
            {
                attributeNames.Add(!string.IsNullOrEmpty(nameValueCollection[columnName])
                    ? nameValueCollection[columnName]
                    : columnName);
            }

            foreach (var row in rows)
            {
                var contentInfo = new ContentInfo();
                if (row.Count != attributeNames.Count)
                {
                    continue;
                }

                for (var i = 0; i < attributeNames.Count; i++)
                {
                    var attributeName = attributeNames[i];
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        var value = row[i];
                        contentInfo.Set(attributeName, value);
                    }
                }

                if (!string.IsNullOrEmpty(contentInfo.Title))
                {
                    contentInfo.SiteId       = siteInfo.Id;
                    contentInfo.ChannelId    = nodeInfo.Id;
                    contentInfo.LastEditDate = DateTime.Now;

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
 public void GetReportAsCsv()
 {
     CsvUtils.ConvertToCSV(_columnHeaders, _reportData.ToList(), _columnsToHide.ToList());
 }
Beispiel #6
0
        public void BtnExport_Click(object sender, EventArgs e)
        {
            var head = new List <string> {
                "标题", "序号", "选项", "票数", "占比"
            };

            var rows = new List <List <string> >();

            var index = 1;

            foreach (var fieldInfo in _fieldInfoList)
            {
                if (fieldInfo.Items == null || fieldInfo.Items.Count == 0)
                {
                    continue;
                }

                if (Utils.IsSelectFieldType(fieldInfo.FieldType))
                {
                    continue;
                }

                rows.Add(new List <string>
                {
                    fieldInfo.Title,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty
                });

                var logTotalCount = GetLogTotalCount(fieldInfo, _logInfoList);

                var isMultiple = fieldInfo.FieldType == InputType.CheckBox.Value ||
                                 fieldInfo.FieldType == InputType.SelectMultiple.Value;

                foreach (var itemInfo in fieldInfo.Items)
                {
                    var itemCount = 0;
                    foreach (var logInfo in _logInfoList)
                    {
                        var value = logInfo.GetString(fieldInfo.Title);
                        if (isMultiple)
                        {
                            List <string> values = null;
                            try
                            {
                                values = JsonConvert.DeserializeObject <List <string> >(value);
                            }
                            catch
                            {
                                // ignored
                            }
                            if (values != null)
                            {
                                if (values.Contains(itemInfo.Value))
                                {
                                    itemCount++;
                                }
                            }
                        }
                        else
                        {
                            if (value == itemInfo.Value)
                            {
                                itemCount++;
                            }
                        }
                    }

                    double percent;
                    if (logTotalCount == 0)
                    {
                        percent = 0;
                    }
                    else
                    {
                        var d = Convert.ToDouble(itemCount) / Convert.ToDouble(logTotalCount) * 100;
                        percent = Math.Round(d, 2);
                    }

                    rows.Add(new List <string>
                    {
                        string.Empty,
                        index++.ToString(),
                        itemInfo.Value,
                        itemCount.ToString(),
                        percent + "%"
                    });
                }
            }

            var relatedPath = "数据统计.csv";

            CsvUtils.Export(Main.Instance.PluginApi.GetPluginPath(relatedPath), head, rows);

            HttpContext.Current.Response.Redirect(Main.Instance.PluginApi.GetPluginUrl(relatedPath));
        }
Beispiel #7
0
        public static List <BackgroundContentInfo> GetContentsByCsvFile(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                                        NodeInfo nodeInfo)
        {
            var contentInfoList = new List <BackgroundContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count > 0)
            {
                var relatedidentityes =
                    RelatedIdentities.GetChannelRelatedIdentities(
                        publishmentSystemInfo.PublishmentSystemId, nodeInfo.NodeId);
                var modelInfo = ContentModelManager.GetContentModelInfo(publishmentSystemInfo,
                                                                        nodeInfo.ContentModelId);
                var tableStyle = EAuxiliaryTableTypeUtils.GetTableStyle(modelInfo.TableType);
                // ArrayList tableStyleInfoArrayList = TableStyleManager.GetTableStyleInfoArrayList(ETableStyle.BackgroundContent, publishmentSystemInfo.AuxiliaryTableForContent, relatedidentityes);

                var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(tableStyle,
                                                                                 modelInfo.TableName, relatedidentityes);
                tableStyleInfoList = ContentUtility.GetAllTableStyleInfoList(publishmentSystemInfo,
                                                                             tableStyle, tableStyleInfoList);
                var nameValueCollection = new NameValueCollection();

                foreach (var styleInfo in tableStyleInfoList)
                {
                    nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
                }

                var attributeNames = new List <string>();
                foreach (var columnName in head)
                {
                    if (!string.IsNullOrEmpty(nameValueCollection[columnName]))
                    {
                        attributeNames.Add(nameValueCollection[columnName]);
                    }
                    else
                    {
                        attributeNames.Add(columnName);
                    }
                }

                foreach (var row in rows)
                {
                    var contentInfo = new BackgroundContentInfo();
                    if (row.Count != attributeNames.Count)
                    {
                        continue;
                    }

                    for (var i = 0; i < attributeNames.Count; i++)
                    {
                        var attributeName = attributeNames[i];
                        if (!string.IsNullOrEmpty(attributeName))
                        {
                            var value = row[i];
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    if (!string.IsNullOrEmpty(contentInfo.Title))
                    {
                        contentInfo.PublishmentSystemId = publishmentSystemInfo.PublishmentSystemId;
                        contentInfo.NodeId       = nodeInfo.NodeId;
                        contentInfo.LastEditDate = DateTime.Now;

                        contentInfoList.Add(contentInfo);
                    }
                }
            }

            return(contentInfoList);
        }
Beispiel #8
0
        private void MakeSpectrumFile()
        {
            Ground.I.Logger.Info("MakeSpectrumFile.1");
            WaveData wavDat = new WaveData(this.MasterWavFile);

            Ground.I.Logger.Info("MakeSpectrumFile.2");

#if true
            using (WorkingDir wd = new WorkingDir())
                using (MultiThreadEx mtx = new MultiThreadEx())
                {
                    Ground.I.Logger.Info("MakeSpectrumFile.3");

                    int frameEnd;

                    {
                        int frame;

                        for (frame = 1; MPF_GetWavPartPos(frame, wavDat) < wavDat.Length; frame++)
                        {
                        }

                        frameEnd = frame;
                    }

                    int THREAD_NUM = this.ThreadCount;

                    Ground.I.Logger.Info("THREAD_NUM:" + THREAD_NUM);

                    if (THREAD_NUM < 1)
                    {
                        throw null;
                    }

                    const string SP_CSV_LOCAL_FILE_BASE = "SP_Csv_";

                    for (int c = 0; c < THREAD_NUM; c++)
                    {
                        string thc_wFile            = wd.GetPath(SP_CSV_LOCAL_FILE_BASE + c);
                        int    thc_frameSt          = (frameEnd * (c + 0)) / THREAD_NUM;
                        int    thc_frameEd          = (frameEnd * (c + 1)) / THREAD_NUM;
                        WaveData.WavPartInfo thc_wp = new WaveData.WavPartInfo();

                        mtx.Add(() =>
                        {
                            using (CsvFileWriter writer = new CsvFileWriter(thc_wFile))
                            {
                                for (int frame = thc_frameSt; frame < thc_frameEd; frame++)
                                {
                                    int wavPartPos = MPF_GetWavPartPos(frame, wavDat);
                                    wavDat.LoadWavPart(thc_wp, wavPartPos);
                                    SpectrumGraph graph = new SpectrumGraph(hz => wavDat.GetSpectrum(thc_wp, hz));
                                    CsvUtils.WriteRow(writer, graph);
                                }
                            }
                        });
                    }

                    Ground.I.Logger.Info("MakeSpectrumFile.4");
                    mtx.RelayThrow();
                    Ground.I.Logger.Info("MakeSpectrumFile.5");

                    using (CsvFileWriter writer = new CsvFileWriter(this.SpectrumFile))
                    {
                        for (int c = 0; c < THREAD_NUM; c++)
                        {
                            string rFile = wd.GetPath(SP_CSV_LOCAL_FILE_BASE + c);

                            using (CsvFileReader reader = new CsvFileReader(rFile))
                            {
                                for (; ;)
                                {
                                    string[] row = reader.ReadRow();

                                    if (row == null)
                                    {
                                        break;
                                    }

                                    writer.WriteRow(row);
                                }
                            }
                        }
                    }

                    Ground.I.Logger.Info("MakeSpectrumFile.6");
                }
#else // old
            using (CsvFileWriter writer = new CsvFileWriter(this.SpectrumFile))
            //using (CsvFileWriter writer_L = new CsvFileWriter(this.SpectrumFile_L)) // 不使用
            //using (CsvFileWriter writer_R = new CsvFileWriter(this.SpectrumFile_R)) // 不使用
            {
                for (int frame = 0; ; frame++)
                {
                    int wavPartPos = MPF_GetWavPartPos(frame, wavDat);
                    //int wavPartPos = (int)((frame * 1.0 / Consts.FPS + Consts.AUDIO_DELAY_SEC) * wavDat.WavHz);

                    if (wavDat.Length <= wavPartPos)
                    {
                        break;
                    }

                    if (frame % 200 == 0)
                    {
                        Ground.I.Logger.Info("MSF_frame: " + frame);

                        this.CheckCancel();
                    }

                    wavDat.SetWavPart(wavPartPos);

                    SpectrumGraph graph = new SpectrumGraph(hz => wavDat.GetSpectrum(hz));
                    //SpectrumGraph graph_L = new SpectrumGraph(hz => wavDat.GetSpectrum_L(hz)); // 不使用
                    //SpectrumGraph graph_R = new SpectrumGraph(hz => wavDat.GetSpectrum_R(hz)); // 不使用

                    CsvUtils.WriteRow(writer, graph);
                    //CsvUtils.WriteRow(writer_L, graph_L); // 不使用
                    //CsvUtils.WriteRow(writer_R, graph_R); // 不使用
                }
            }
            Ground.I.Logger.Info("MakeSpectrumFile.3");
#endif
        }
Beispiel #9
0
        public static void CreateExcelFileForInputContents(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                           InputInfo inputInfo)
        {
            DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath));
            FileUtils.DeleteFileIfExists(filePath);

            var head = new List <string>();
            var rows = new List <List <string> >();

            var relatedidentityes = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent,
                                                                           publishmentSystemInfo.PublishmentSystemId, inputInfo.InputId);
            var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent,
                                                                             DataProvider.InputContentDao.TableName, relatedidentityes);

            if (tableStyleInfoList.Count == 0)
            {
                throw new Exception("表单无字段,无法导出");
            }

            foreach (var tableStyleInfo in tableStyleInfoList)
            {
                head.Add(tableStyleInfo.DisplayName);
            }

            if (inputInfo.IsReply)
            {
                head.Add("回复");
            }
            head.Add("添加时间");

            var contentIdList = DataProvider.InputContentDao.GetContentIdListWithChecked(inputInfo.InputId);

            foreach (var contentId in contentIdList)
            {
                var contentInfo = DataProvider.InputContentDao.GetContentInfo(contentId);
                if (contentInfo != null)
                {
                    var row = new List <string>();

                    foreach (var tableStyleInfo in tableStyleInfoList)
                    {
                        var value = contentInfo.Attributes.Get(tableStyleInfo.AttributeName);

                        if (!string.IsNullOrEmpty(value))
                        {
                            value = InputParserUtility.GetContentByTableStyle(value, publishmentSystemInfo,
                                                                              ETableStyle.InputContent, tableStyleInfo);
                        }

                        row.Add(StringUtils.StripTags(value));
                    }

                    if (inputInfo.IsReply)
                    {
                        row.Add(StringUtils.StripTags(contentInfo.Reply));
                    }
                    row.Add(DateUtils.GetDateAndTimeString(contentInfo.AddDate));

                    rows.Add(row);
                }
            }

            CsvUtils.Export(filePath, head, rows);
        }
Beispiel #10
0
        public static void CreateExcelFileForTrackingContents(string filePath, string startDateString,
                                                              string endDateString, PublishmentSystemInfo publishmentSystemInfo, int nodeId, int contentId, int totalNum,
                                                              bool isDelete)
        {
            DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath));
            FileUtils.DeleteFileIfExists(filePath);

            var head = new List <string>
            {
                "目标页面",
                "上级栏目",
                "上上级栏目",
                "IP地址",
                "访问时间",
                "访问来源"
            };
            var rows = new List <List <string> >();

            var target      = string.Empty;
            var upChannel   = string.Empty;
            var upupChannel = string.Empty;

            if (contentId != 0)
            {
                var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeId);
                target    = BaiRongDataProvider.ContentDao.GetValue(tableName, contentId, ContentAttribute.Title);
                upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, nodeId);
                if (nodeId != publishmentSystemInfo.PublishmentSystemId)
                {
                    upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                          NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, nodeId));
                }
            }

            var begin = DateUtils.SqlMinValue;

            if (!string.IsNullOrEmpty(startDateString))
            {
                begin = TranslateUtils.ToDateTime(startDateString);
            }
            var end = TranslateUtils.ToDateTime(endDateString);

            var ipAddresses =
                DataProvider.TrackingDao.GetContentIpAddressArrayList(publishmentSystemInfo.PublishmentSystemId, nodeId,
                                                                      contentId, begin, end);
            var trackingInfoArrayList =
                DataProvider.TrackingDao.GetTrackingInfoArrayList(publishmentSystemInfo.PublishmentSystemId, nodeId,
                                                                  contentId, begin, end);

            var ipAddressWithNumSortedList = new SortedList();

            foreach (string ipAddress in ipAddresses)
            {
                if (ipAddressWithNumSortedList[ipAddress] != null)
                {
                    ipAddressWithNumSortedList[ipAddress] = (int)ipAddressWithNumSortedList[ipAddress] + 1;
                }
                else
                {
                    ipAddressWithNumSortedList[ipAddress] = 1;
                }
            }

            foreach (TrackingInfo trackingInfo in trackingInfoArrayList)
            {
                if (contentId == 0)
                {
                    if (trackingInfo.PageContentId != 0)
                    {
                        var tableName = NodeManager.GetTableName(publishmentSystemInfo, trackingInfo.PageNodeId);
                        target = BaiRongDataProvider.ContentDao.GetValue(tableName, trackingInfo.PageContentId,
                                                                         ContentAttribute.Title);
                        upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                            trackingInfo.PageNodeId);
                        if (trackingInfo.PageNodeId != publishmentSystemInfo.PublishmentSystemId)
                        {
                            upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                                  NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId,
                                                                                          trackingInfo.PageNodeId));
                        }
                    }
                    else if (trackingInfo.PageNodeId != 0)
                    {
                        target = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                         trackingInfo.PageNodeId);
                        if (trackingInfo.PageNodeId != publishmentSystemInfo.PublishmentSystemId)
                        {
                            var upChannelId = NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId,
                                                                      trackingInfo.PageNodeId);
                            upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, upChannelId);
                            if (upChannelId != publishmentSystemInfo.PublishmentSystemId)
                            {
                                upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                                      NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, upChannelId));
                            }
                        }
                    }
                }
                var ipAddress  = trackingInfo.IpAddress;
                var accessDate = trackingInfo.AccessDateTime.ToString(DateUtils.FormatStringDateTime);
                var referrer   = trackingInfo.Referrer;

                rows.Add(new List <string>
                {
                    target,
                    upChannel,
                    upupChannel,
                    ipAddress,
                    accessDate,
                    referrer
                });
            }

            CsvUtils.Export(filePath, head, rows);

            if (isDelete)
            {
                DataProvider.TrackingDao.DeleteAll(publishmentSystemInfo.PublishmentSystemId);
            }
        }
Beispiel #11
0
        public void ExportAppointmentContentCsv(string filePath, List <AppointmentContentInfo> appointmentContentInfolList, string appointmentTitle, int appointmentId)
        {
            var appointmentInfo = DataProviderWx.AppointmentDao.GetAppointmentInfo(appointmentId);

            var head = new List <string>();

            head.Add("序号");
            head.Add("预约名称");
            if (appointmentInfo.IsFormRealName == "True")
            {
                head.Add(appointmentInfo.FormRealNameTitle);
            }
            if (appointmentInfo.IsFormMobile == "True")
            {
                head.Add(appointmentInfo.FormMobileTitle);
            }
            if (appointmentInfo.IsFormEmail == "True")
            {
                head.Add(appointmentInfo.FormEmailTitle);
            }
            head.Add("预约时间");
            head.Add("预约状态");
            head.Add("留言");
            var configExtendInfoList = DataProviderWx.ConfigExtendDao.GetConfigExtendInfoList(PublishmentSystemId, appointmentId, EKeywordTypeUtils.GetValue(EKeywordType.Appointment));

            foreach (var cList in configExtendInfoList)
            {
                head.Add(cList.AttributeName);
            }

            var rows = new List <List <string> >();

            var index = 1;

            foreach (var applist in appointmentContentInfolList)
            {
                var row = new List <string>();

                row.Add((index++).ToString());
                row.Add(appointmentTitle);
                if (appointmentInfo.IsFormRealName == "True")
                {
                    row.Add(applist.RealName);
                }
                if (appointmentInfo.IsFormMobile == "True")
                {
                    row.Add(applist.Mobile);
                }
                if (appointmentInfo.IsFormEmail == "True")
                {
                    row.Add(applist.Email);
                }
                row.Add(DateUtils.GetDateAndTimeString(applist.AddDate));
                row.Add(EAppointmentStatusUtils.GetText(EAppointmentStatusUtils.GetEnumType(applist.Status)));
                row.Add(applist.Message);

                var settingsXml = applist.SettingsXml.Replace("{", "").Replace("}", "");
                var arr         = settingsXml.Split(',');
                if (arr[0] != "")
                {
                    for (var i = 0; i < arr.Length; i++)
                    {
                        var arr1 = arr[i].Replace("\"", "").Split(':');
                        row.Add(arr1[1]);
                    }
                }
                rows.Add(row);
            }

            CsvUtils.Export(filePath, head, rows);
        }
 private bool MustEnquoute(string str)
 {
     return(options.ForceQuoteValues || CsvUtils.StrMustAddQuoutes(str));
 }
Beispiel #13
0
        public string ToCsv()
        {
            var wholeNumberFields = new string[] { Fields.WildlifeRecordId, Fields.SubmissionObjectId, Fields.RowNum, Fields.ServiceArea, Fields.Species };

            return(CsvUtils.ConvertToCsv <WildlifeReportExportDto>(this, wholeNumberFields));
        }
Beispiel #14
0
 protected virtual string ConvertToString(object value, CultureInfo cultureInfo = null)
 {
     cultureInfo = cultureInfo ?? GetPersistentCultureInfo();
     return(CsvUtils.ConvertToString(value, CsvOptions.CsvFlags, cultureInfo));
 }
Beispiel #15
0
        public static List <InputContentInfo> GetInputContentsByCsvFile(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                                        InputInfo inputInfo)
        {
            var contentInfoList = new List <InputContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count > 0)
            {
                var relatedidentityes = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent,
                                                                               publishmentSystemInfo.PublishmentSystemId, inputInfo.InputId);
                var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent,
                                                                                 DataProvider.InputContentDao.TableName, relatedidentityes);

                var nameValueCollection = new NameValueCollection();

                foreach (var styleInfo in tableStyleInfoList)
                {
                    nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
                }

                nameValueCollection["回复"]   = InputContentAttribute.Reply.ToLower();
                nameValueCollection["添加时间"] = InputContentAttribute.AddDate.ToLower();

                var attributeNames = new List <string>();
                foreach (var columnName in head)
                {
                    if (!string.IsNullOrEmpty(nameValueCollection[columnName]))
                    {
                        attributeNames.Add(nameValueCollection[columnName]);
                    }
                    else
                    {
                        attributeNames.Add(columnName);
                    }
                }

                foreach (var row in rows)
                {
                    if (row.Count != attributeNames.Count)
                    {
                        continue;
                    }

                    var contentInfo = new InputContentInfo(0, inputInfo.InputId, 0, true, string.Empty, string.Empty,
                                                           DateTime.Now, string.Empty);

                    for (var i = 0; i < attributeNames.Count; i++)
                    {
                        var attributeName = attributeNames[i];
                        if (!string.IsNullOrEmpty(attributeName))
                        {
                            var value = row[i];
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
 public DungeonResources([Optional, DefaultParameterValue("Rules/Dungeon-Instances")] string sourcePath)
 {
     string[,] strArray = CsvUtils.Deserialize(ResourceUtil.LoadSafe <TextAsset>(sourcePath, false).text);
     for (int i = 0; i < strArray.GetLength(1); i++)
     {
         if (strArray[0, i] != null)
         {
             int      num4;
             RowEntry entry = new RowEntry();
             int      num2  = 0;
             entry.Id               = strArray[num2++, i];
             entry.Name             = _.L(strArray[num2++, i], null, false);
             entry.LevelRequirement = base.parseInt(strArray[num2++, i]);
             entry.ExploreCost      = base.parseInt(strArray[num2++, i]);
             entry.BaseDifficulty   = base.parseInt(strArray[num2++, i]);
             entry.EnergyCost       = base.parseInt(strArray[num2++, i]);
             entry.FloorCount       = ConfigDungeons.DEFAULT_DUNGEON_ROOM_COUNT;
             num2++;
             entry.PrimaryMinionType   = base.parseEnumType <CharacterType>(strArray[num2++, i]);
             entry.SecondaryMinionType = base.parseEnumType <CharacterType>(strArray[num2++, i]);
             List <KeyValuePair <string, int> > list = base.parseStringIntList(strArray[num2++, i], 0x22c);
             entry.BossPool = new Dictionary <string, int>();
             for (int j = 0; j < list.Count; j++)
             {
                 KeyValuePair <string, int> pair  = list[j];
                 KeyValuePair <string, int> pair2 = list[j];
                 entry.BossPool.Add(pair.Key, pair2.Value);
             }
             entry.BossType   = strArray[num2++, i];
             entry.FtueBoss   = ((list.Count <= 0) || !(entry.BossType != "Elite")) ? null : list[0].Key;
             entry.Theme      = base.parseEnumType <DungeonThemeType>(strArray[num2++, i]);
             entry.Mood       = strArray[num2++, i];
             entry.MapStyle   = strArray[num2++, i];
             entry.LootPool   = base.parseStringList(strArray[num2++, i]);
             entry.LayoutPool = base.parseStringList(strArray[num2++, i]);
             Dungeon dungeon = new Dungeon();
             dungeon.Id                  = entry.Id;
             dungeon.Name                = entry.Name;
             dungeon.LevelRequirement    = entry.LevelRequirement;
             dungeon.ExploreCost         = entry.ExploreCost;
             dungeon.EnergyCost          = entry.EnergyCost;
             dungeon.LootPool            = entry.LootPool;
             dungeon.BaseDifficulty      = entry.BaseDifficulty;
             dungeon.FloorCount          = entry.FloorCount;
             dungeon.LayoutPool          = entry.LayoutPool;
             dungeon.Theme               = entry.Theme;
             dungeon.Mood                = GameLogic.Binder.DungeonMoodResources.getMood(entry.Mood);
             dungeon.MapStyle            = entry.MapStyle;
             dungeon.PrimaryMinionType   = entry.PrimaryMinionType;
             dungeon.SecondaryMinionType = entry.SecondaryMinionType;
             dungeon.FtueBoss            = entry.FtueBoss;
             dungeon.BossPool            = entry.BossPool;
             dungeon.EliteTag            = entry.BossType == "Elite";
             bool flag = int.TryParse(dungeon.Id, out num4);
             if (!flag || (this.m_orderedRegularDungeons.Count < ConfigDungeons.MAX_DUNGEON_COUNT))
             {
                 base.m_resources.Add(dungeon.Id, dungeon);
             }
             if (flag && (this.m_orderedRegularDungeons.Count < ConfigDungeons.MAX_DUNGEON_COUNT))
             {
                 this.m_orderedRegularDungeons.Add(dungeon);
             }
             if (!this.m_dungeonThemeMinionCharacterTypes.ContainsKey(dungeon.Theme))
             {
                 this.m_dungeonThemeMinionCharacterTypes.Add(dungeon.Theme, new List <CharacterType>());
             }
             List <CharacterType> list2 = this.m_dungeonThemeMinionCharacterTypes[dungeon.Theme];
             if (!list2.Contains(entry.PrimaryMinionType))
             {
                 list2.Add(entry.PrimaryMinionType);
             }
             if (!list2.Contains(entry.SecondaryMinionType))
             {
                 list2.Add(entry.SecondaryMinionType);
             }
         }
     }
     this.createDebugDungeon();
 }
Beispiel #17
0
        static void Main(string[] args)
        {
            CsvUtils          utils = new CsvUtils();
            ColumnOperations  co    = new ColumnOperations();
            OutputOperations  oo    = new OutputOperations();
            LineOperations    lo    = new LineOperations();
            CellOperations    cop   = new CellOperations();
            AddressOperations aop   = new AddressOperations();
            StringOperations  sop   = new StringOperations();



            string fileName = "source.csv";
            // string sourcePath = @"C:\Users\brendan.sapience\Documents\git\AAE-MetaBot--CSV\Documentation\Tests";
            // string targetPath = @"C:\IQBot Input";

            string sourcePath = @"C:\Users\Administrator\Desktop\customers\Dell";
            string targetPath = @"C:\Users\Administrator\Desktop\customers\Dell\RES";

            // Use Path class to manipulate file and directory paths.
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile   = System.IO.Path.Combine(targetPath, fileName);

            System.IO.File.Copy(sourceFile, destFile, true);

            String FilePath = targetPath + @"\" + fileName;



            co.Split_Column_Content_based_on_matches(FilePath, "Material_Description", @"(?::|;)(?: )*([A-Za-z0-9]{7})", "Result", "SN");
            //co.Delete_Row(FilePath, 1);
            Console.ReadKey();

            String OutputStr = co.Split_Column_Content_based_on_groups(FilePath, "NovaConta1", @"([A-Za-z]+)\s([A-Za-z]+)\s(\d+)\s([A-Z]+\s+\d+)\s(\d+)\s(\d+)\s(\d+,\d+)\s(.+?)\s(\d+.\d+,\d+)\s+(.+?\s+\d+)\sValor da Parcela (.*?) Nome (.*GB)\s(.*)\s(R.*)", "NovaConta6", "Conta1SUB");


            //String OutputStr = co.Split_Column_Content_based_on_matches(FilePath, "Total", @"\d*,*\d+.\d+", "Total","Subtotal_");

            Console.Write(OutputStr);
            Console.ReadKey();

            String Out = cop.Does_Cell_Content_Match_Regex(FilePath, "Billing_Address", 1, @"\b\d{5}\b(?:[-\s]\d{4})?");

            Console.Write(Out + "\n");
            Out = cop.Does_Cell_Content_Match_Regex(FilePath, "Billing_Address", 2, @"\b\d{5}\b(?:[-\s]\d{4})?");
            Console.Write(Out + "\n");
            Out = cop.Does_Cell_Content_Match_Regex(FilePath, "Billing_Address", 3, @"\b\d{5}\b(?:[-\s]\d{4})?");
            Console.Write(Out + "\n");
            Out = cop.Does_Cell_Content_Match_Regex(FilePath, "Billing_Address", 4, @"\b\d{5}\b(?:[-\s]\d{4})?");
            Console.Write(Out + "\n");
            Out = cop.Does_Cell_Content_Match_Regex(FilePath, "Billing_Address", 5, @"\b\d{5}\b(?:[-\s]\d{4})?");
            Console.Write(Out + "\n");
            Out = cop.Does_Cell_Content_Match_Regex(FilePath, "Billing_Address", 6, @"\b\d{5}\b(?:[-\s]\d{4})?");
            Console.Write(Out + "\n");
            Console.ReadKey();

            //String JsonStr = oo.Get_Output_As_Json(FilePath,"SingleValues", "Before,one,test,two,four,New", "Items", "");
            //Console.Write(JsonStr+"\n");
            //Console.ReadKey();

            String Output = "";

            // Test: Change the content of a cell to the "Match" of a regular expression applied to it: .+ (.*) Trn.*
            //Output = cop.Transform_Cell_Content(FilePath, "Before", 2, "(test).+");
            //Console.WriteLine("Transforming Cell Content: " + Output);

            // Test: Change the content of a column to the "Match" of a regular expression applied to it
            //Output = co.Transform_Column_Content(FilePath, "Before", "(test).+");
            //Console.WriteLine("Transforming Column Content: "+ Output);
            //Console.ReadKey();

            // Test: Change the content of a cell
            // String Msg2 = cop.Set_Cell_Content(FilePath, "one", 2, "\"Test, hello?!\"");
            // Console.Write("Debug:"+Msg2 + "\n");
            // Console.ReadKey();

            // Test: copy the "Match" from a regular expression to another column (for 1 cell)
            //String Msg = cop.Copy_Cell_Content_To_Other_Column(FilePath, "Before", 2, ".+", "New");
            //co.Copy_Column_Content_To_Other_Column(FilePath, "Description", ".+ (Credit|Debit)", "Desc_Type");
            //Console.WriteLine("Copying content from columns / cells to other columns: "+ Msg);
            //Console.ReadKey();

            String Msg1 = co.Copy_Column_Content_To_Other_Column(FilePath, "Before", "^(test).+$", "New");

            Console.WriteLine("Copying content from columns / cells to other columns: " + Msg1);
            Console.ReadKey();


            co.Replace_String_In_Column_Content(FilePath, "Invoice_Date", "/", "");
            Console.ReadKey();

            co.Remove_String_In_Column_Content(FilePath, "Invoice_Date", "20");
            Console.ReadKey();

            co.Rename_Column(FilePath, "Description", "Description2");
            Console.ReadKey();

            co.Rename_Column(FilePath, "Description2", "Description");
            Console.ReadKey();

            // test: get Columns and Lines number
            int NbColumns = co.Get_Number_Of_Columns(FilePath);
            int NbLines   = lo.Get_Number_Of_Lines(FilePath);

            Console.WriteLine("Number of [Columns|Lines]: [" + NbColumns + "|" + NbLines + "]");

            // Test: get column names
            String ColNames = co.Get_Column_Names(FilePath);

            Console.WriteLine("Column Names: [" + ColNames + "]");

            // Test: get the content of a specific line
            String LineContent = lo.Get_Line_Content(FilePath, 2);

            Console.WriteLine("Line Content: [" + LineContent + "]");

            // Test: delete lines where Amount column contains "Page or 2018"
            int NbLinesDeleted = lo.Delete_Line_If_Cell_Matches_Pattern(FilePath, "Description", @"Page.*|2018.*");

            Console.WriteLine("Lines Deleted: " + NbLinesDeleted);

            // Test: add a "-" in front of values in column Amount if column Description contains "Debit"
            int NbCellsMods = co.Append_If_Column_Matches_Pattern(FilePath, "Description", ".*Debit.*", "Item_Amount", "-", false);

            Console.WriteLine("Cells modified: " + NbCellsMods);

            // Test: delete column named "Not_Real" (no such column)
            int idx = co.Delete_Column(FilePath, "Not_Real");

            Console.WriteLine("Column Index for Column Not_Real: " + idx);

            // Test: delete column named "Vendor_Name"
            idx = co.Delete_Column(FilePath, "Vendor_Name");
            Console.WriteLine("Column Index for Column Vendor_Name: " + idx);

            // Test: get the index of a particular column
            idx = co.Get_Column_Index(FilePath, "Invoice_Total");
            Console.WriteLine("Index for Column Invoice_Total: " + idx);

            // Test: insert a new column Before an existing one
            int IdxColumnBefore = co.Add_Column_Before(FilePath, "Invoice_Number", "Invoice_Type", "Standard");

            Console.WriteLine("Inserting Before column with index: " + IdxColumnBefore);

            // Test: insert a new column After an existing one
            int IdxColumnAfter = co.Add_Column_After(FilePath, "Item_Amount", "Desc_Type", "<Data>");

            Console.WriteLine("Inserting After column with index: " + IdxColumnAfter);

            int IdxColumnAfter1 = co.Add_Column_After(FilePath, "Desc_Type", "New_Col_1", "<Data>");

            Console.WriteLine("Inserting After column with index: " + IdxColumnAfter1);

            // Test: get the content of a cell
            String CellContent = cop.Get_Cell_Content(FilePath, "Description", 2);

            Console.WriteLine("Cell Content: " + CellContent);

            // Test: Change the content of a cell
            cop.Set_Cell_Content(FilePath, "New_Col_1", 2, "\"Test, hello?!\"");

            // Test: Change the content of a cell to the "Match" of a regular expression applied to it: .+ (.*) Trn.*
            String NewValue = cop.Transform_Cell_Content(FilePath, "New_Col_1", 2, "Test, (.*)");

            Console.WriteLine("New Cell Content: " + NewValue);

            // Test: Change the content of a column to the "Match" of a regular expression applied to it
            co.Transform_Column_Content(FilePath, "Description", ".+ (Pro.* (?:Credit|Debit))");
            Console.WriteLine("Transforming Column Content.");

            // Test: keep lines where Amount column contains "Page "
            int NbLinesKept = lo.Keep_Line_If_Cell_Matches_Pattern(FilePath, "Description", @"Product.*");

            Console.WriteLine("Lines Kept: " + NbLinesKept);

            // Test: copy the "Match" from a regular expression to another column (for 1 cell)
            cop.Copy_Cell_Content_To_Other_Column(FilePath, "Description", 1, ".+ (Credit|Debit)", "New_Col_1");
            co.Copy_Column_Content_To_Other_Column(FilePath, "Description", ".+ (Credit|Debit)", "Desc_Type");
            Console.WriteLine("Copying content from columns / cells to other columns.");

            // Test: Change the value of a cell within a range for a given column
            cop.Save_Cell_Value_On_Range(FilePath, "New_Col_1", 3, 6, "\"New Ranged Value, here\"");
            Console.WriteLine("Change Cell Values based on Range");

            // Test: Swap 2 columns
            co.Switch_Columns(FilePath, "New_Col_1", "Invoice_Number");
            Console.WriteLine("Swapping Columns.");

            // Test: Force the order of columns and rearrange if necessary
            co.Enforce_Column_Order(FilePath, "Invoice_Type,New_Col_1,Invoice_Date,Invoice_Total,Invoice_Number,Item_Number,Item_Amount,Desc_Type,Description");
            Console.WriteLine("Enforcing Column Order.");

            Console.ReadKey();
        }
        public string ToCsv()
        {
            var wholeNumberFields = new string[] { Fields.Username, Fields.UserType };

            return(CsvUtils.ConvertToCsv <ActivityCodeSearchExportDto>(this, wholeNumberFields));
        }
Beispiel #19
0
        public static List <ContentInfo> GetContentsByCsvFile(string filePath, SiteInfo siteInfo,
                                                              ChannelInfo nodeInfo)
        {
            var contentInfoList = new List <ContentInfo>();

            CsvUtils.Import(filePath, out var head, out var rows);

            if (rows.Count <= 0)
            {
                return(contentInfoList);
            }

            var styleInfoList       = ContentUtility.GetAllTableStyleInfoList(TableStyleManager.GetContentStyleInfoList(siteInfo, nodeInfo));
            var nameValueCollection = new NameValueCollection();

            foreach (var styleInfo in styleInfoList)
            {
                nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
            }

            var attributeNames = new List <string>();

            foreach (var columnName in head)
            {
                attributeNames.Add(!string.IsNullOrEmpty(nameValueCollection[columnName])
                    ? nameValueCollection[columnName]
                    : columnName);
            }

            foreach (var row in rows)
            {
                if (row.Count != attributeNames.Count)
                {
                    continue;
                }

                var dict = new Dictionary <string, object>();

                for (var i = 0; i < attributeNames.Count; i++)
                {
                    var attributeName = attributeNames[i];
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        dict[attributeName] = row[i];
                    }
                }

                var contentInfo = new ContentInfo(dict);

                if (!string.IsNullOrEmpty(contentInfo.Title))
                {
                    contentInfo.SiteId       = siteInfo.Id;
                    contentInfo.ChannelId    = nodeInfo.Id;
                    contentInfo.LastEditDate = DateTime.Now;

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
Beispiel #20
0
        //---------------------------------------------



        #region Private Methods
        private void autoDetectFieldDelimiter(string path)
        {
            cbDelimiter.SelectedItem = CsvUtils.DetectFieldDelimiterChar(tbDatapath.Text, Encoding.Default);
        }
Beispiel #21
0
        public string ToCsv()
        {
            var wholeNumberFields = new string[] { Fields.WorkReportId, Fields.SubmissionObjectId, Fields.RowNum, Fields.ServiceArea };

            return(CsvUtils.ConvertToCsv <WorkReportExportDto>(this, wholeNumberFields));
        }
Beispiel #22
0
        public IHttpActionResult Export()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var pollInfo = PollManager.GetPollInfo(request);
                if (pollInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var itemInfoList = ItemManager.GetItemInfoList(pollInfo.Id);
                var totalCount   = itemInfoList.Sum(x => x.Count);

                var head = new List <string> {
                    "序号", "标题", "票数", "占比"
                };

                var rows = new List <List <string> >();

                var index = 1;
                foreach (var itemInfo in itemInfoList)
                {
                    double percent;
                    if (totalCount == 0)
                    {
                        percent = 0;
                    }
                    else
                    {
                        var d = Convert.ToDouble(itemInfo.Count) / Convert.ToDouble(totalCount) * 100;
                        percent = Math.Round(d, 2);
                    }
                    var row = new List <string>
                    {
                        index++.ToString(),
                        itemInfo.Title,
                        itemInfo.Count.ToString(),
                        percent + "%"
                    };

                    rows.Add(row);
                }

                var fileName = "投票统计.csv";
                var filePath = Context.UtilsApi.GetTemporaryFilesPath(fileName);

                CsvUtils.Export(filePath, head, rows);

                var url = Context.UtilsApi.GetRootUrl($"SiteFiles/TemporaryFiles/{fileName}");

                return(Ok(new
                {
                    Value = url
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #23
0
        public void GetFilesNamesTest()
        {
            var filesNames = CsvUtils.GetFilesNames(HISTORICAL_PRICES_PATH);

            Assert.AreEqual(22, filesNames.Count);
        }