Esempio n. 1
0
        /// <summary>
        /// 保存至xlsx
        /// </summary>
        public void SaveXlsx()
        {
            string voName = typeof(T).Name;

            if (EditorGamingMapData.m_VoNameDic != null && !EditorGamingMapData.m_VoNameDic.ContainsKey(voName))
            {
                return;
            }
            List <string> fileNameList = EditorGamingMapData.m_VoNameDic[voName];

            if (fileNameList == null || fileNameList.Count != 2)
            {
                return;
            }

            string         path     = EditorConfigData.GetExcelFilePath(fileNameList[0]);
            FileInfo       fileInfo = new FileInfo(path);
            ExcelPackage   ep       = new ExcelPackage(fileInfo);
            ExcelWorksheet sheet    = ep.Workbook.Worksheets[1];

            for (int iSheet = ACTUALDATA_ROW; iSheet <= sheet.Dimension.End.Row; iSheet++)
            {
                object value = sheet.Cells[iSheet, 1].Value;
                if (value == null)
                {
                    sheet.DeleteRow(iSheet, 1, true);
                    iSheet--;
                    continue;
                }

                int id = 0;
                int.TryParse(sheet.Cells[iSheet, 1].Value.ToString(), out id);
                if (!voDir.ContainsKey(id))
                {
                    sheet.DeleteRow(iSheet, 1, true);
                    iSheet--;
                }
            }

            int rowCount = sheet.Dimension.End.Row;
            int colCount = sheet.Dimension.End.Column;

            for (int iVo = 0; iVo < voList.Count; iVo++)
            {
                T   vo  = voList[iVo];
                int row = GetValueRow(sheet, vo.ID);
                if (row == -1)
                {
                    rowCount++;
                    sheet.InsertRow(rowCount, colCount);
                    row = rowCount;
                }
                vo.SetSheetData(sheet, row);
            }
            ep.SaveAs(fileInfo);
        }
Esempio n. 2
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            try
            {
                string voName = typeof(T).Name;
                if (EditorGamingMapData.m_VoNameDic != null && !EditorGamingMapData.m_VoNameDic.ContainsKey(voName))
                {
                    return;
                }
                List <string> fileNameList = EditorGamingMapData.m_VoNameDic[voName];
                if (fileNameList == null || fileNameList.Count != 2)
                {
                    return;
                }
                //ESheetReader reader = EditorConfigData.GetXlsxFileSheetReader(fileNameList[0], fileNameList[1]);
                ESheetReader reader = EditorConfigData.GetCSVFileSheetReader(fileNameList[0], fileNameList[1]);
                if (reader == null)
                {
                    return;
                }

                voDir    = new Dictionary <int, T>();
                voList   = new List <T>();
                voStrDir = new Dictionary <string, T>();
                T tmp;
                for (int i = ACTUALDATA_ROW - 1; i < reader.GetRowCount(); i++)
                {
                    tmp = Activator.CreateInstance <T>();
                    tmp.CopyFrom(i, reader);

                    if (!string.IsNullOrEmpty(tmp.strID))
                    {
                        if (!voStrDir.ContainsKey(tmp.strID))
                        {
                            voStrDir.Add(tmp.strID, tmp);
                            voList.Add(tmp);
                        }
                    }
                    else
                    {
                        if (!voDir.ContainsKey(tmp.ID) && tmp.ID > 0)
                        {
                            voDir.Add(tmp.ID, tmp);
                            voList.Add(tmp);
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 保存至csv
        /// </summary>
        public void SaveCSV()
        {
            string voName = typeof(T).Name;

            if (EditorGamingMapData.m_VoNameDic != null && !EditorGamingMapData.m_VoNameDic.ContainsKey(voName))
            {
                return;
            }
            List <string> fileNameList = EditorGamingMapData.m_VoNameDic[voName];

            if (fileNameList == null || fileNameList.Count != 2)
            {
                return;
            }

            string          path     = EditorConfigData.GetExcelFilePath(fileNameList[0]);
            FileInfo        fileInfo = new FileInfo(path);
            ExcelTextFormat format   = new ExcelTextFormat();

            format.Delimiter     = ',';
            format.EOL           = "\n";
            format.TextQualifier = '"';
            format.Encoding      = new UTF8Encoding();

            string fileData = string.Empty;

            using (StreamReader reader = new StreamReader(path, Encoding.UTF8))
            {
                fileData = reader.ReadToEnd();
            }

            fileData = fileData.Replace("\r", "");

            System.String[][] resultdata = null;//保存title
            using (ExcelPackage ep = new ExcelPackage())
            {
                ExcelWorksheet sheet = ep.Workbook.Worksheets.Add(fileNameList[1]);
                sheet.Cells["A1"].LoadFromText(fileData, format);
                int columnMin   = sheet.Dimension.Start.Column;
                int rowMin      = sheet.Dimension.Start.Row;
                int columnCount = sheet.Dimension.End.Column; //工作区结束列
                int rowCount    = sheet.Dimension.End.Row;    //工作区结束行号
                resultdata = new System.String[ACTUALDATA_ROW - 1][];

                for (int i = rowMin; i <= ACTUALDATA_ROW - 1; i++)
                {
                    resultdata[i - 1] = new System.String[columnCount];
                    for (int j = columnMin; j <= columnCount; j++)
                    {
                        ExcelRange data = sheet.Cells[i, j];
                        if (data != null && data.Value != null)
                        {
                            resultdata[i - 1][j - 1] = data.Value.ToString();
                        }
                    }
                }

                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }

                using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write))
                {
                    using (var stream = new MemoryStream(256))
                    {
                        using (var writer = new StreamWriter(fs, Encoding.UTF8))
                        {
                            if (resultdata != null)
                            {
                                for (int iResult = 0; iResult < resultdata.Length; iResult++)
                                {
                                    for (int jResult = 0; jResult < resultdata[iResult].Length; jResult++)
                                    {
                                        writer.Write(resultdata[iResult][jResult]);
                                        if (jResult != resultdata[iResult].Length - 1)
                                        {
                                            writer.Write(",");
                                        }
                                    }
                                    writer.Write("\n");
                                }
                            }

                            for (int iVo = 0; iVo < voList.Count; iVo++)
                            {
                                T           vo = voList[iVo];
                                FieldInfo[] fi = typeof(T).GetFields();
                                WriteObjectToLine <T>(vo, fi, writer);
                                //if (iVo != voList.Count - 1)
                                {
                                    writer.Write("\n");
                                }
                            }
                            writer.Flush();
                        }
                    }
                }
            }
        }
        private static EditorConfigCodeAnalysisConfig LoadInternal(IEnumerable <string> paths)
        {
            Dictionary <string, bool>             refactorings = null;
            Dictionary <string, bool>             codeFixes    = null;
            Dictionary <string, ReportDiagnostic> categories   = null;
            Dictionary <string, string>           options      = null;
            bool?analyzersEnabledByDefault = null;

            ImmutableDictionary <string, string>           allOptions      = ImmutableDictionary <string, string> .Empty;
            ImmutableDictionary <string, ReportDiagnostic> analyzerOptions = ImmutableDictionary <string, ReportDiagnostic> .Empty;

            foreach (string path in paths)
            {
                EditorConfigData config = LoadFile(path);

                if (config.Options.Count > 0)
                {
                    allOptions = allOptions.SetItems(config.Options);
                }

                if (config.AnalyzerOptions.Count > 0)
                {
                    analyzerOptions = analyzerOptions.SetItems(config.AnalyzerOptions);
                }
            }

            foreach (KeyValuePair <string, string> option in allOptions)
            {
                Match match = Regexes.RefactoringOption.Match(option.Key);

                if (match.Success)
                {
                    if (bool.TryParse(option.Value, out bool enabled))
                    {
                        string key = match.Groups["id"].Value;
                        (refactorings ??= new Dictionary <string, bool>()).Add(key, enabled);
                    }
                }
                else
                {
                    match = Regexes.CodeFixOption.Match(option.Key);

                    if (match.Success)
                    {
                        if (bool.TryParse(option.Value, out bool enabled))
                        {
                            string key = match.Groups["id"].Value;
                            (codeFixes ??= new Dictionary <string, bool>()).Add(key, enabled);
                        }
                    }
                    else
                    {
                        match = Regexes.CategoryOption.Match(option.Key);

                        if (match.Success)
                        {
                            ReportDiagnostic?reportDiagnostic = ParseReportDiagnostic(option.Value);

                            if (reportDiagnostic != null)
                            {
                                string category = match.Groups["category"].Value;
                                (categories ??= new Dictionary <string, ReportDiagnostic>()).Add(category, reportDiagnostic.Value);
                            }
                        }
                        else if (option.Key == ConfigOptionKeys.AnalyzersEnabledByDefault)
                        {
                            if (bool.TryParse(option.Value, out bool enabled))
                            {
                                analyzersEnabledByDefault = enabled;
                            }
                        }
                        else
                        {
                            (options ??= new Dictionary <string, string>()).Add(option.Key, option.Value);
                        }
                    }
                }
            }

            return(new EditorConfigCodeAnalysisConfig(
                       options,
                       analyzerOptions,
                       categories,
                       refactorings,
                       codeFixes,
                       analyzersEnabledByDefault: analyzersEnabledByDefault));