示例#1
0
        /// <summary>
        /// Attempt to create a <see cref="IXivSheet{T}"/> with a specific <c>T</c> based on the name of the sheet.
        /// </summary>
        /// <remarks>
        /// Uses the mappings in <see cref="SpecialSheetTypes"/> if present; otherwise looks for a type matching the sheet's name and creates a generic <see cref="XivSheet{T}"/>; returns <c>null</c> if neither is found.
        /// </remarks>
        /// <param name="sourceSheet"><see cref="IRelationalSheet"/> to access the source data.</param>
        /// <returns>Returns a <see cref="IXivSheet"/> if a matching one could be created; <c>null</c> otherwise.</returns>
        protected virtual IXivSheet TryCreateXivSheet(IRelationalSheet sourceSheet)
        {
            if (SpecialSheetTypes.TryGetValue(sourceSheet.Name, out XivSheetCreator specialCreator))
            {
                return(specialCreator(this, sourceSheet));
            }

            Type match = GetXivRowType(sourceSheet.Name);

            if (match == null)
            {
                return(null);
            }

            Type genericType = sourceSheet.Header.Variant == 2 ? typeof(XivSheet2 <>) : typeof(XivSheet <>);

            Type            constructedType = genericType.MakeGenericType(match);
            ConstructorInfo constructor     = constructedType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic
                | BindingFlags.Public,
                null,
                new[] {
                typeof(XivCollection), typeof(IRelationalSheet)
            },
                null);

            return((IXivSheet)constructor.Invoke(new object[] {
                this, sourceSheet
            }));
        }
示例#2
0
        public IRelationalRow FindReference(int key)
        {
            // Optimization for unlikely references.
            if (key <= 0)
            {
                return(null);
            }

            foreach (SheetDefinition sheetDef in Definition.SheetDefinitions.Where(d => d.IsGenericReferenceTarget))
            {
                IRelationalSheet sheet = GetSheet(sheetDef.Name);
                if (!sheet.Header.DataFileRanges.Any(r => r.Contains(key)))
                {
                    continue;
                }

                if (!sheet.ContainsRow(key))
                {
                    continue;
                }

                return(sheet[key]);
            }
            return(null);
        }
示例#3
0
        protected virtual void OnSheetChanged(IRelationalSheet oldValue, IRelationalSheet newValue)
        {
            this.Columns.Clear();

            if (newValue != null)
            {
                var keyPath = newValue.Header.Variant == 1 ? "Key" : "FullKey";

                //prevent multiple enumeration
                var columns = newValue.Header.Columns.ToList();

                ColumnSetToRaw = new bool[columns.Count];

                Columns.Add(new RawDataGridKeyColumn(keyPath)
                {
                    CanUserSort = true
                });

                foreach (var col in columns)
                {
                    Columns.Add(ColumnFactory.Create(col));
                }

                var source = new RawDataItemsSource(newValue);
                if (Filter != null)
                {
                    source.Filter = o => FilterMatch(o, Filter);
                }
                this.ItemsSource = source;
            }
            else
            {
                this.ItemsSource = null;
            }
        }
示例#4
0
        public static void SaveAsCsv(IRelationalSheet sheet, Language language, string path)
        {
            using (var s = new StreamWriter(path, false, Encoding.UTF8))
            {
                var indexLine = new StringBuilder("key");
                var nameLine  = new StringBuilder("#");
                var typeLine  = new StringBuilder("int32");

                var colIndices = new List <int>();
                foreach (var col in sheet.Header.Columns)
                {
                    indexLine.AppendFormat(",{0}", col.Index);
                    nameLine.AppendFormat(",{0}", col.Name);
                    typeLine.AppendFormat(",{0}", col.ValueType);

                    colIndices.Add(col.Index);
                }

                s.WriteLine(indexLine);
                s.WriteLine(nameLine);
                s.WriteLine(typeLine);

                ExdHelper.WriteRows(s, sheet, language, colIndices, false);
            }
        }
示例#5
0
        static void SaveAsCsv(IRelationalSheet sheet, string path)
        {
            using (var s = new StreamWriter(path, false, Encoding.UTF8)) {
                var indexLine = new StringBuilder("key");
                var nameLine  = new StringBuilder("#");
                var typeLine  = new StringBuilder("int32");

                var colIndices = new List <int>();
                foreach (var col in sheet.Header.Columns)
                {
                    indexLine.AppendFormat(",{0}", col.Index);
                    nameLine.AppendFormat(",{0}", col.Name);
                    typeLine.AppendFormat(",{0}", col.ValueType);

                    colIndices.Add(col.Index);
                }

                s.WriteLine(indexLine);
                s.WriteLine(nameLine);
                s.WriteLine(typeLine);

                foreach (var row in sheet.Cast <SaintCoinach.Ex.IRow>().OrderBy(_ => _.Key))
                {
                    s.Write(row.Key);
                    foreach (var col in colIndices)
                    {
                        var v = row[col];

                        if (v is SaintCoinach.Xiv.XivRow xivRow && Controls.ColumnFactory.ForceRaw)
                        {
                            v = xivRow.Key;
                        }

                        if (v == null)
                        {
                            s.Write(",");
                        }
                        else if (v is IDictionary <int, object> )
                        {
                            WriteDict(s, v as IDictionary <int, object>);
                        }
                        else if (IsUnescaped(v))
                        {
                            s.Write(",{0}", v);
                        }
                        else
                        {
                            s.Write(",\"{0}\"", v.ToString().Replace("\"", "\"\""));
                        }
                    }
                    s.WriteLine();
                }
            }
        }
示例#6
0
        public SheetUpdater(IRelationalSheet prevSheet,
                            SheetDefinition prevDefinition,
                            IRelationalSheet upSheet,
                            SheetDefinition upDefinition)
        {
            _PreviousSheet = prevSheet;
            _PreviousDefinition = prevDefinition;

            _UpdatedSheet = upSheet;
            _UpdatedDefinition = upDefinition;
        }
示例#7
0
        public SheetUpdater(IRelationalSheet prevSheet,
                            SheetDefinition prevDefinition,
                            IRelationalSheet upSheet,
                            SheetDefinition upDefinition)
        {
            _PreviousSheet      = prevSheet;
            _PreviousDefinition = prevDefinition;

            _UpdatedSheet      = upSheet;
            _UpdatedDefinition = upDefinition;
        }
        protected virtual void OnSheetChanged(IRelationalSheet oldValue, IRelationalSheet newValue)
        {
            this.Columns.Clear();

            if (newValue != null) {
                Columns.Add(new RawDataGridKeyColumn() { CanUserSort = true });

                foreach (var col in newValue.Header.Columns)
                    Columns.Add(ColumnFactory.Create(col));
            }

            this.ItemsSource = new RawDataItemsSource(newValue);
        }
示例#9
0
        /// <summary>
        /// Create a <see cref="ISheet"/> for a <see cref="Header"/>.
        /// </summary>
        /// <param name="header"><see cref="Header"/> to create the sheet for.</param>
        /// <returns>Returns the created <see cref="ISheet"/>.</returns>
        protected override ISheet CreateSheet(Header header)
        {
            IRelationalSheet baseSheet = (IRelationalSheet)base.CreateSheet(header);

            IXivSheet xivSheet = TryCreateXivSheet(baseSheet);

            if (xivSheet != null)
            {
                return(xivSheet);
            }

            if (header.Variant == 2)
            {
                return(new XivSheet2 <XivSubRow>(this, baseSheet));
            }
            return(new XivSheet <XivRow>(this, baseSheet));
        }
            public override IRow GetRow(int key, ExCollection collection)
            {
                foreach (string sheetName in SheetNames)
                {
                    IRelationalSheet sheet = (IRelationalSheet)collection.GetSheet(sheetName);
                    if (!sheet.Header.DataFileRanges.Any(r => r.Contains(key)))
                    {
                        continue;
                    }

                    IRow row = RowProducer.GetRow(sheet, key);
                    if (row != null)
                    {
                        return(row);
                    }
                }
                return(null);
            }
示例#11
0
        protected virtual void OnSheetChanged(IRelationalSheet oldValue, IRelationalSheet newValue)
        {
            this.Columns.Clear();

            if (newValue != null)
            {
                Columns.Add(new RawDataGridKeyColumn()
                {
                    CanUserSort = true
                });

                foreach (var col in newValue.Header.Columns)
                {
                    Columns.Add(ColumnFactory.Create(col));
                }
            }

            this.ItemsSource = new RawDataItemsSource(newValue);
        }
示例#12
0
        protected virtual void OnSheetChanged(IRelationalSheet oldValue, IRelationalSheet newValue)
        {
            this.Columns.Clear();

            if (newValue != null)
            {
                var keyPath = newValue.Header.Variant == 1 ? "Key" : "FullKey";

                //prevent multiple enumeration
                var columns = newValue.Header.Columns.ToList();

                if (Settings.Default.SortByOffsets)
                {
                    columns.Sort((x, y) => x.Offset.CompareTo(y.Offset));
                }

                ColumnSetToRaw = new bool[columns.Count];

                Columns.Add(new RawDataGridKeyColumn(keyPath)
                {
                    CanUserSort = true
                });

                foreach (var col in columns)
                {
                    Columns.Add(ColumnFactory.Create(col));
                }

                var source = new RawDataItemsSource(newValue);
                if (!string.IsNullOrWhiteSpace(Filter))
                {
                    source.Filter = Filter;
                }
                this.ItemsSource = source;
            }
            else
            {
                this.ItemsSource = null;
            }
        }
示例#13
0
 public XivSheet(XivCollection collection, IRelationalSheet source)
 {
     Collection = collection;
     _Source    = source;
 }
示例#14
0
 public ItemActionSheet(XivCollection collection, IRelationalSheet source) : base(collection, source)
 {
 }
示例#15
0
        private static void SaveAsJson(IRelationalSheet sheet, string path)
        {
            using (var s = new StreamWriter(path, false, Encoding.UTF8)) {
                s.WriteLine("[");

                var colIndices = new List <int>();
                var colNames   = new List <String>();
                foreach (var col in sheet.Header.Columns)
                {
                    colIndices.Add(col.Index);
                    colNames.Add(col.Name);
                }

                bool isFirst = true;
                foreach (var row in sheet.Cast <SaintCoinach.Ex.IRow>().OrderBy(_ => _.Key))
                {
                    if (isFirst)
                    {
                        isFirst = false;
                        s.Write("\t");
                    }
                    else
                    {
                        s.Write(",");
                    }
                    s.WriteLine("{");
                    string sKey = row.Key.ToString();
                    foreach (var col in colIndices)
                    {
                        var    content  = row[col];
                        string sContent = "";
                        if (content == null)
                        {
                            sContent = "";
                        }
                        else if (content is IDictionary <int, object> )
                        {
                            var dContent = content;
                            foreach (var kvp in dContent as IDictionary <int, object> )
                            {
                                sKey += "[" + kvp.Key + "]";
                                if (kvp.Value != null)
                                {
                                    string result = kvp.Value.ToString().Replace("\"", "\"\"");
                                    result    = Regex.Replace(result, @"\t|\n|\r", " ");
                                    sContent += result;
                                }
                            }
                        }
                        else if (IsUnescaped(content))
                        {
                            sContent = content.ToString();
                        }
                        else
                        {
                            string result = content.ToString().Replace("\"", "\"\"");
                            result   = Regex.Replace(result, @"\t|\n|\r", " ");
                            sContent = result;
                        }
                        s.WriteLine("\t\t\"{0}\":\"{1}\",", colNames[col], sContent);
                    }
                    s.WriteLine("\t\t\"{0}\":\"{1}\"", "Key", sKey);
                    s.Write("\t}");
                }
                s.WriteLine();
                s.WriteLine("]");
            }
        }
示例#16
0
 public XivSheet2(XivCollection collection, IRelationalSheet source) :
     base(collection, source)
 {
 }
示例#17
0
        static void SaveAsCsv(IRelationalSheet sheet, string path)
        {
            using (var s = new StreamWriter(path, false, Encoding.UTF8)) {
                var indexLine = new StringBuilder("key");
                var nameLine = new StringBuilder("#");
                var typeLine = new StringBuilder("int32");

                var colIndices = new List<int>();
                foreach (var col in sheet.Header.Columns) {
                    indexLine.AppendFormat(",{0}", col.Index);
                    nameLine.AppendFormat(",{0}", col.Name);
                    typeLine.AppendFormat(",{0}", col.ValueType);

                    colIndices.Add(col.Index);
                }

                s.WriteLine(indexLine);
                s.WriteLine(nameLine);
                s.WriteLine(typeLine);

                foreach (var row in sheet.Cast<SaintCoinach.Ex.IRow>().OrderBy(_ => _.Key)) {
                    s.Write(row.Key);
                    foreach (var col in colIndices) {
                        var v = row[col];

                        if (v == null)
                            s.Write(",");
                        else if (v is IDictionary<int, object>)
                            WriteDict(s, v as IDictionary<int, object>);
                        else if (IsUnescaped(v))
                            s.Write(",{0}", v);
                        else
                            s.Write(",\"{0}\"", v.ToString().Replace("\"", "\"\""));
                    }
                    s.WriteLine();
                }
            }
        }
            public override IRow GetRow(int key, ExCollection collection)
            {
                IRelationalSheet sheet = (IRelationalSheet)collection.GetSheet(SheetName);

                return(RowProducer.GetRow(sheet, key));
            }
 public RawDataItemsSource(IRelationalSheet sheet)
 {
     _Sheet = sheet;
 }
示例#20
0
 public RawDataItemsSource(IRelationalSheet sheet)
 {
     _Sheet = sheet;
 }
示例#21
0
 public InventoryItemSheet(XivCollection collection, IRelationalSheet source) : base(collection, source)
 {
 }
 public IRow GetRow(IRelationalSheet sheet, int key)
 {
     return(sheet.IndexedLookup(KeyColumnName, key));
 }
 public IRow GetRow(IRelationalSheet sheet, int key)
 {
     return(sheet[key]);
 }
 public IRow GetRow(IRelationalSheet sheet, int key)
 {
     return(!sheet.ContainsRow(key) ? null : sheet[key]);
 }