Ejemplo n.º 1
0
        void SaveResxFiles()
        {
            var cultures = NarrationInformationList.SelectMany(e => e.Culture_Text_Dict.Keys).Distinct();

            foreach (var culture in cultures)
            {
                var narrationResX = new ResourcesResXInformation();
                narrationResX.ResourceResXFileFullPath = ExportResxFileBasePath + ResourcesResXInformation.GetResXFileExtension(culture);
                narrationResX.ResourcesResXInformationOneRecordList = NarrationInformationList.Select(e => new ResourcesResXInformationOneRecord()
                {
                    Key     = e.PropertyIdentifier + "_TextKey",
                    Value   = e.Culture_Text_Dict[culture],
                    Comment = e.Culture_Text_Dict[""]
                }).ToList();
                narrationResX.OverwriteResourcesFile();
            }
        }
        public void CreateList()
        {
            InputRecordList = new List <HostApplicationsResourcesStringsOneRecord>();
            var headerCellString_ColumnIndex_Dict = new Dictionary <string, int>();
            var cultureList = new List <string>();

            using (var inputStream = new FileStream(InputFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var book   = new XSSFWorkbook(inputStream);
                var sheet  = book.GetSheetAt(0);
                var header = sheet.GetRow(0);
                for (int colIndex = 0; colIndex < header.LastCellNum; colIndex++)
                {
                    var headerCellString = header.GetCell(colIndex).ToString();
                    headerCellString_ColumnIndex_Dict[headerCellString] = colIndex;
                    if (headerCellString.Contains("Value"))
                    {
                        cultureList.Add(headerCellString.Replace("Value_", ""));
                    }
                }

                var h = new HostApplicationsResourcesStringsOneRecord();
                for (int rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++)
                {
                    var item  = new HostApplicationsResourcesStringsOneRecord();
                    var row   = sheet.GetRow(rowIndex);
                    var cells = row.Cells;
                    item.Index                    = int.Parse(row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.Index)));
                    item.UseOnWindows             = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.UseOnWindows)) == "true";
                    item.UseOnAndroid             = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.UseOnAndroid)) == "true";
                    item.RelativeFolderPath       = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.RelativeFolderPath));
                    item.Namespace                = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.Namespace));
                    item.OwnerClass               = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.OwnerClass));
                    item.TargetObjectIdentifier00 = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.TargetObjectIdentifier00));
                    item.TargetObjectIdentifier01 = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.TargetObjectIdentifier01));
                    item.Property                 = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.Property));
                    item.ResourceKeyOnWindows     = row.GetCellString(headerCellString_ColumnIndex_Dict, nameof(h.ResourceKeyOnWindows));
                    foreach (var culture in cultureList)
                    {
                        var value = row.GetCellString(headerCellString_ColumnIndex_Dict, "Value_" + culture);
                        item.ValueList.Add(value);
                    }
                    InputRecordList.Add(item);
                }
            }


            var query01 = InputRecordList.Where(e => e.UseOnWindows).GroupBy(e => e.RelativeFolderPath);

            RelativeFolderPath_GroupedInputList_Dict = query01.ToDictionary(e => e.Key, e => e.ToList());

            foreach (var RelativeFolderPath_GroupedInputList_Dict_KeyValue in RelativeFolderPath_GroupedInputList_Dict)
            {
                int cultureIndex = 0;
                foreach (var culture in cultureList)
                {
                    var path = System.IO.Path.GetDirectoryName(InputFilePath) + "/" + RelativeFolderPath_GroupedInputList_Dict_KeyValue.Key;
                    path += @"/Resources";
                    if (string.IsNullOrEmpty(culture) == false)
                    {
                        path += "." + culture;
                    }
                    path += ".resx";

                    var resXInfo = new ResourcesResXInformation();
                    resXInfo.ResourceResXFileFullPath = System.IO.Path.GetFullPath(path);
                    resXInfo.ResourcesResXInformationOneRecordList = RelativeFolderPath_GroupedInputList_Dict_KeyValue.Value.Select(e => new ResourcesResXInformationOneRecord()
                    {
                        Key     = e.ResourceKeyOnWindows,
                        Value   = e.ValueList[cultureIndex],
                        Comment = e.ValueList[0]
                    }).ToList();

                    ResourceFilePath_ResourcesResXInformation_Dict[resXInfo.ResourceResXFileFullPath] = resXInfo;
                    cultureIndex++;
                }
            }

            PartialClassPropertyDescriptionInformationList = RelativeFolderPath_GroupedInputList_Dict.Select(e1 => new PartialClassPropertyDescriptionInformation()
            {
                DefinitionCSharpFileFullPath = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(InputFilePath) + "/" + e1.Key + @"/GetPropertyFromResources.generated.cs"),
                NamespaceList = e1.Value.GroupBy(e2 => e2.Namespace).Select(e3 => new PartialClassPropertyDescriptionInformation.OneNamespace()
                {
                    NamespaceName    = e3.Key,
                    PartialClassList = e3.GroupBy(e4 => e4.OwnerClass).Select(e5 => new PartialClassPropertyDescriptionInformation.OnePartialClass()
                    {
                        ClassName = e5.Key,
                        InformationForPropertyDefinitionList = e5.ToList()
                    }).ToList()
                }).ToList()
            }).ToList();
        }