Esempio n. 1
0
        private void DoRowData(ISheet sheet, XivRow row, List <string> data, StringBuilder sb)
        {
            for (int i = 0; i < sheet.Header.ColumnCount; i++)
            {
                var o = row.GetRaw(i);

                if (o is Quad)
                {
                    var q = (Quad)o;
                    data.Add(q.ToInt64().ToString());
                    continue;
                }

                if (IsUnescaped(o))
                {
                    data.Add(o.ToString());
                    continue;
                }

                string d = o.ToString();
                if (string.IsNullOrEmpty(d))
                {
                    d = "NULL";
                }
                else
                {
                    d = $"'{d.Replace("'", "\\'")}'";
                }
                data.Add(d);
            }

            sb.AppendLine($"  ( {string.Join(", ", data)} ),");
        }
        protected virtual IExpression EvaluateSheet(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            IExpression[] evalArgs = element.Arguments.Select(_ => _.TryEvaluate(parameters)).ToArray();
            if (evalArgs.Length < 2)
            {
                throw new InvalidOperationException();
            }
            string sheetName = evalArgs[0].ToString();
            int    rowKey    = ToInteger(evalArgs[1]);
            int    colKey    = 0;

            if (evalArgs.Length > 2)
            {
                colKey = ToInteger(evalArgs[2]);
            }

            XivRow row   = Data.GetSheet(sheetName)[rowKey];
            object value = row[colKey];

            if (value is INode)
            {
                EvaluationParameters innerParams = new EvaluationParameters(parameters);
                innerParams.InputParameters.Clear();
                for (int i = 3; i < evalArgs.Length; ++i)
                {
                    innerParams.InputParameters[i - 2] = evalArgs[i];
                }


                value = EvaluationHelper.TryEvaluate((INode)value, innerParams);
            }

            return(new GenericExpression(new ObjectWithDisplay(value, row)));
        }
Esempio n. 3
0
        private object ProcessSingleColumn(RelationalColumn column, XivRow row)
        {
            if (column.Name != null)
            {
                if (column.ValueType == "Item" && _Columns.Count > 0 && (_Columns.Peek()?.Name?.ToLower()?.StartsWith("amount")).GetValueOrDefault())
                {
                    var amountCol = _Columns.Dequeue();

                    if (row[column.Index] != null)
                    {
                        var itemName   = row[column.Index].ToString();
                        var itemAmount = row[amountCol.Index].ToString();

                        if (string.IsNullOrWhiteSpace(itemName) && (string.IsNullOrWhiteSpace(itemAmount) || itemAmount == "0"))
                        {
                            return(null);
                        }

                        return(new JObject {
                            { "item", itemName },
                            { "amount", itemAmount }
                        });
                    }
                }
                else if (row[column.Index] != null)
                {
                    return(row[column.Index].ToString());
                }
            }
            return(null);
        }
Esempio n. 4
0
 public ObjectWrapper(XivRow row)
 {
     this.row = row;
 }
        protected virtual IExpression EvaluateSheetWithAttributive(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            IExpression[] evalArgs = element.Arguments.Select(_ => _.TryEvaluate(parameters)).ToArray();
            if (evalArgs.Length < 3)
            {
                throw new InvalidOperationException();
            }

            Ex.Language lang = TagToLanguageMap[element.Tag];

            string sheetName         = evalArgs[0].ToString();
            int    attributiveRowKey = ToInteger(evalArgs[1]);
            int    rowKey            = ToInteger(evalArgs[2]);

            int columnKey = 0;

            if (evalArgs.Length > 3)
            {
                columnKey = ToInteger(evalArgs[3]);
            }

            int attributiveColumnKey = AttributiveColumnOffsets[element.Tag];

            if (evalArgs.Length > 4)
            {
                attributiveColumnKey += ToInteger(evalArgs[4]);
            }

            XivRow row = Data.GetSheet(sheetName)[rowKey];
            object value;

            if (row is Ex.IMultiRow)
            {
                value = ((Ex.IMultiRow)row)[columnKey, lang];
            }
            else
            {
                value = row[columnKey];
            }

            XivRow attributiveRow = Data.GetSheet(AttributiveSheetName)[attributiveRowKey];
            object attributiveValue;

            if (attributiveRow is Ex.IMultiRow)
            {
                attributiveValue = ((Ex.IMultiRow)attributiveRow)[attributiveColumnKey, lang];
            }
            else
            {
                attributiveValue = attributiveRow[attributiveColumnKey];
            }

            EvaluationParameters innerParams = new EvaluationParameters(parameters);

            innerParams.InputParameters.Clear();
            for (int i = 5; i < evalArgs.Length; ++i)
            {
                innerParams.InputParameters[i - 2] = evalArgs[i];
            }

            if (value is INode)
            {
                value = EvaluationHelper.TryEvaluate((INode)value, innerParams);
            }
            if (attributiveValue is INode)
            {
                attributiveValue = EvaluationHelper.TryEvaluate((INode)attributiveValue, innerParams);
            }

            return(new SurroundedExpression(new ObjectWithDisplay(attributiveValue, attributiveRow), new ObjectWithDisplay(value, row), null));
        }