Пример #1
0
        public static ExportData DeserializeFromSheet(IDictionary <string, Type> parameters, ISheet sheet)
        {
            Dictionary <string, int> parameterIndecies = new Dictionary <string, int>();

/*            if(sheet.LastRowNum==0)
 *              return new ExportData();*/
            IRow headerRow = sheet.GetRow(0);

            if (headerRow == null)
            {
                return(new ExportData());
            }
            List <string> headers = new List <string>();

            for (int i = 0; i < headerRow.LastCellNum; i++)
            {
                headers.Add(headerRow.GetCell(i).ToString());
            }

            for (int i = 0; i < headers.Count; i++)
            {
                if (!string.IsNullOrEmpty(headers[i]) && parameters.ContainsKey(headers[i]))
                {
                    parameterIndecies[headers[i]] = i;
                }
            }
            ExportData exportData = new ExportData();

            for (int i = 1;; i++)
            {
                IRow row = sheet.GetRow(i);
                if (row == null)
                {
                    return(exportData);
                }
                ExportRow exportRow = new ExportRow();
                foreach (KeyValuePair <string, int> pair in parameterIndecies)
                {
                    if (pair.Value < row.LastCellNum)
                    {
                        exportRow.AddParameter(pair.Key, new Parameter
                        {
                            Type  = parameters[pair.Key],
                            Value = DeserializeObject(row.GetCell(pair.Value).ToString(), parameters[pair.Key])
                        });
                    }
                }
                exportData._exports.Add(exportRow);
            }
        }
Пример #2
0
        public static ExportData DeserializeFromCsv(IDictionary <string, Type> parameters, TextReader reader)
        {
            //Read header
            Dictionary <string, int> parameterIndecies = new Dictionary <string, int>();
            string header = reader.ReadLine();

            if (string.IsNullOrEmpty(header))
            {
                return(new ExportData());
            }
            string[] headers = header.Split(',');
            for (int i = 0; i < headers.Length; i++)
            {
                if (!string.IsNullOrEmpty(headers[i]) && parameters.ContainsKey(headers[i]))
                {
                    parameterIndecies[headers[i]] = i;
                }
            }
            ExportData exportData = new ExportData();

            while (true)
            {
                string row = reader.ReadLine();
                if (string.IsNullOrEmpty(row))
                {
                    return(exportData);
                }
                string[]  values    = row.Split(',');
                ExportRow exportRow = new ExportRow();
                foreach (KeyValuePair <string, int> pair in parameterIndecies)
                {
                    if (pair.Value < values.Length)
                    {
                        exportRow.AddParameter(pair.Key, new Parameter
                        {
                            Type  = parameters[pair.Key],
                            Value = DeserializeObject(values[pair.Value], parameters[pair.Key])
                        });
                    }
                }
                exportData._exports.Add(exportRow);
            }
        }
Пример #3
0
        public static void ExportPurchaseItems()
        {
            string path = EditorUtility.SaveFilePanel("Export Purchase Items", "", "", "xls");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            using (System.IO.Stream writer = File.Create(path))
            {
                ExportData exportData = new ExportData();
                foreach (PurchasableItemInfo purchasableItemInfo in InfoResolver.Resolve <FortInfo>().Purchase.GetAllPurchasableItemInfos())
                {
                    ExportRow exportRow = new ExportRow();
                    exportRow.AddParameter("Id", new Parameter
                    {
                        Value = purchasableItemInfo.Id,
                        Type  = typeof(string)
                    });
                    exportRow.AddParameter("Name", new Parameter
                    {
                        Value = purchasableItemInfo.Name,
                        Type  = typeof(string)
                    });

/*                    exportRow.AddParameter("DisplayName", new Parameter
 *                  {
 *                      Value = purchasableItemInfo.DisplayName,
 *                      Type = typeof(string)
 *                  });*/
                    exportRow.AddParameter("Description", new Parameter
                    {
                        Value = purchasableItemInfo.Description,
                        Type  = typeof(string)
                    });
                    exportRow.AddParameter("DefaultBought", new Parameter
                    {
                        Value = purchasableItemInfo.DefaultBought,
                        Type  = typeof(bool)
                    });
                    NoneLevelBasePurchasableItemInfo noneLevelBasePurchasableItemInfo = purchasableItemInfo as NoneLevelBasePurchasableItemInfo;
                    if (noneLevelBasePurchasableItemInfo != null)
                    {
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            exportRow.AddParameter(string.Format("PurchaseCost-{0}", valueDefenition), new Parameter
                            {
                                Value = noneLevelBasePurchasableItemInfo.Costs == null || noneLevelBasePurchasableItemInfo.Costs.Purchase == null ||
                                        noneLevelBasePurchasableItemInfo.Costs.Purchase.Values == null
                                    ? 0
                                    : noneLevelBasePurchasableItemInfo.Costs.Purchase[valueDefenition],
                                Type = typeof(int)
                            });
                        }
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            exportRow.AddParameter(string.Format("RentCost-{0}", valueDefenition), new Parameter
                            {
                                Value = noneLevelBasePurchasableItemInfo.Costs == null || noneLevelBasePurchasableItemInfo.Costs.Rent == null ||
                                        noneLevelBasePurchasableItemInfo.Costs.Rent.Values == null
                                    ? 0
                                    : noneLevelBasePurchasableItemInfo.Costs.Rent[valueDefenition],
                                Type = typeof(int)
                            });
                        }
                        exportRow.AddCustomExportParameter(purchasableItemInfo);
                        exportData.AddRow(exportRow);
                    }
                    else
                    {
                        exportRow.AddCustomExportParameter(purchasableItemInfo);
                        exportData.AddRow(exportRow);
                        LevelBasePurchasableItemInfo levelBasePurchasableItemInfo = purchasableItemInfo as LevelBasePurchasableItemInfo;
                        if (levelBasePurchasableItemInfo != null)
                        {
                            PurchasableLevelInfo[] purchasableLevelInfos = levelBasePurchasableItemInfo.GetPurchasableLevelInfos();
                            int index = 0;
                            foreach (PurchasableLevelInfo purchasableLevelInfo in purchasableLevelInfos)
                            {
                                ExportRow levelExportRow = new ExportRow();
                                levelExportRow.AddParameter("Id", new Parameter
                                {
                                    Value = purchasableLevelInfo.Id,
                                    Type  = typeof(string)
                                });
                                levelExportRow.AddParameter("Name", new Parameter
                                {
                                    Value = string.Format("{0}_{1}", purchasableItemInfo.Name, index++),
                                    Type  = typeof(string)
                                });

/*                                levelExportRow.AddParameter("DisplayName", new Parameter
 *                              {
 *                                  Value = purchasableLevelInfo.DisplayName,
 *                                  Type = typeof(string)
 *                              });*/
                                levelExportRow.AddParameter("Description", new Parameter
                                {
                                    Value = purchasableLevelInfo.Description,
                                    Type  = typeof(string)
                                });
                                levelExportRow.AddParameter("DefaultBought", new Parameter
                                {
                                    Value = purchasableLevelInfo.DefaultBought,
                                    Type  = typeof(bool)
                                });

                                foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                                {
                                    levelExportRow.AddParameter(string.Format("PurchaseCost-{0}", valueDefenition), new Parameter
                                    {
                                        Value = purchasableLevelInfo.Costs == null || purchasableLevelInfo.Costs.Purchase == null ||
                                                purchasableLevelInfo.Costs.Purchase.Values == null
                                            ? 0
                                            : purchasableLevelInfo.Costs.Purchase[valueDefenition],
                                        Type = typeof(int)
                                    });
                                }
                                foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                                {
                                    levelExportRow.AddParameter(string.Format("RentCost-{0}", valueDefenition), new Parameter
                                    {
                                        Value = purchasableLevelInfo.Costs == null || purchasableLevelInfo.Costs.Rent == null ||
                                                purchasableLevelInfo.Costs.Rent.Values == null
                                            ? 0
                                            : purchasableLevelInfo.Costs.Rent[valueDefenition],
                                        Type = typeof(int)
                                    });
                                }
                                levelExportRow.AddCustomExportParameter(purchasableLevelInfo);
                                exportData.AddRow(levelExportRow);
                            }
                        }
                    }
                }

                HSSFWorkbook workbook = new HSSFWorkbook();

                HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Purchasable Items");
                exportData.SerializeToSheet(sheet);
                workbook.Write(writer);
            }
        }
        public static void ExportAchievements()
        {
            string path = EditorUtility.SaveFilePanel("Export Achievements", "", "", "xls");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            using (System.IO.Stream writer = File.Create(path))
            {
                ExportData exportData = new ExportData();
                foreach (AchievementInfo achievementInfo in InfoResolver.Resolve <FortInfo>().Achievement.AchievementInfos)
                {
                    NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo =
                        achievementInfo as NoneLevelBaseAchievementInfo;
                    if (noneLevelBaseAchievementInfo != null)
                    {
                        ExportRow exportRow = new ExportRow();
                        exportRow.AddParameter("Id", new Parameter
                        {
                            Value = noneLevelBaseAchievementInfo.Id,
                            Type  = typeof(string)
                        });
                        exportRow.AddParameter("Name", new Parameter
                        {
                            Value = achievementInfo.GetType().Name,
                            Type  = typeof(string)
                        });
                        exportRow.AddParameter("Score", new Parameter
                        {
                            Value = noneLevelBaseAchievementInfo.Score,
                            Type  = typeof(int)
                        });
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            exportRow.AddParameter(valueDefenition, new Parameter
                            {
                                Value = noneLevelBaseAchievementInfo.Balance == null ||
                                        noneLevelBaseAchievementInfo.Balance.Values == null
                                    ? 0
                                    : noneLevelBaseAchievementInfo.Balance[valueDefenition],
                                Type = typeof(int)
                            });
                        }
                        exportRow.AddCustomExportParameter(noneLevelBaseAchievementInfo);
                        exportData.AddRow(exportRow);
                    }
                    else
                    {
                        LevelBaseAchievementInfo levelBaseAchievementInfo = (LevelBaseAchievementInfo)achievementInfo;
                        AchievementLevelInfo[]   achievementLevelInfos    =
                            levelBaseAchievementInfo.GetAchievementLevelInfos();
                        int index = 0;
                        foreach (AchievementLevelInfo achievementLevelInfo in achievementLevelInfos)
                        {
                            ExportRow exportRow = new ExportRow();
                            exportRow.AddParameter("Id", new Parameter
                            {
                                Value = achievementLevelInfo.Id,
                                Type  = typeof(string)
                            });
                            exportRow.AddParameter("Name", new Parameter
                            {
                                Value = string.Format("{0}_{1}", achievementInfo.GetType().Name, index++),
                                Type  = typeof(string)
                            });
                            exportRow.AddParameter("Score", new Parameter
                            {
                                Value = achievementLevelInfo.Score,
                                Type  = typeof(int)
                            });
                            foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                            {
                                exportRow.AddParameter(valueDefenition, new Parameter
                                {
                                    Value = achievementLevelInfo.Balance == null ||
                                            achievementLevelInfo.Balance.Values == null
                                        ? 0
                                        : achievementLevelInfo.Balance[valueDefenition],
                                    Type = typeof(int)
                                });
                            }
                            exportRow.AddCustomExportParameter(achievementLevelInfo);
                            exportData.AddRow(exportRow);
                        }
                    }
                }
                HSSFWorkbook workbook = new HSSFWorkbook();

                HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Achievements");
                exportData.SerializeToSheet(sheet);
                workbook.Write(writer);
            }
        }
Пример #5
0
 public void AddRow(ExportRow exportRow)
 {
     _exports.Add(exportRow);
 }