Exemplo n.º 1
0
        /// <summary>
        /// Writes the specified string and moves the cursor to the next line.
        /// </summary>
        /// <param name="text">The string to write.</param>
        public void WriteLine(string text)
        {
            if (text.Length < charLength)
            {
                //Erase cursor:
                VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, bColor);
                VGADriver.driver.DoubleBuffer_Update();
                // Go to next line:
                LocX  = 0;
                LocY += 12;
                txt.Append(text);
                ScreenInput.Add(text);
                EndLine += 1;
                // Draw string:
                VGADriver.driver._DrawACSIIString(EndLine.ToString() + ", " + charHeight.ToString() + ", " + ScreenInput.Count.ToString(), (uint)Color.White.ToArgb(), (uint)LocX, (uint)LocY);
                VGADriver.driver.DoubleBuffer_Update();
                // Go to next line:
                //LocX = 0;
                //LocY += 14;
                //DrawCursor(LocX, LocY);
                PromptLocX  = 0;
                PromptLocY += 12;
            }
            //else
            //{
            //    //Erase cursor:
            //    VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, bColor);
            //    VGADriver.driver.DoubleBuffer_Update();
            //    string first = text.Substring(0, charLength - 1);
            //    // Go to next line:
            //    LocX = 0;
            //    LocY += 12;
            //    // Draw string:
            //    VGADriver.driver._DrawACSIIString(first, (uint)Color.White.ToArgb(), (uint)LocX, (uint)LocY);
            //    VGADriver.driver.DoubleBuffer_Update();
            //    ScreenInput.Add(first);
            //    string rest = text.Substring(charLength - 1);
            //    //Save last coordinates:
            //    LLocX = LocX + ((first.Length) * 8) - 8;
            //    LLocY = LocY;
            //    // Go to next line:
            //    LocX = 0;
            //    LocY += 12;
            //    // Draw string:
            //    VGADriver.driver._DrawACSIIString(rest, (uint)Color.White.ToArgb(), (uint)LocX, (uint)LocY);
            //    VGADriver.driver.DoubleBuffer_Update();
            //    txt.Append(text);
            //    ScreenInput.Add(rest);
            //    LocX = (rest.Length) * 8;
            //    EndLine += 2;
            //    //// Go to next line:
            //    //LocX = 0;
            //    //LocY += 12;
            //    PromptLocX = 0;
            //    PromptLocY += 24;

            //}
        }
Exemplo n.º 2
0
 public override string ToString()
 {
     if (IsHidden)
     {
         return("IL" + IlOffset.ToString("X4") + " (hidden)");
     }
     return("IL" + IlOffset.ToString("X4") + " (" +
            StartLine.ToString() + "-" + EndLine.ToString() + ") (" +
            StartCol.ToString() + "-" + EndCol.ToString() + ")");
 }
        public void Write(StringBuilder builder, EndLine endLine)
        {
            if (builder == null || endLine == null)
            {
                return;
            }

            // change to \r or \n when rendering for apple or Unix.
            builder.Append("\r\n");
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hash = (int)2166136261;
         hash = (hash * 16777619) ^ Line.GetHashCode();
         hash = (hash * 16777619) ^ EndLine.GetHashCode();
         return((hash * 16777619) ^ Covered.GetHashCode());
     }
 }
        private void ChangeAllLineDisplay(bool display)
        {
            for (int i = 0; i < Count; i++)
            {
                LineObjects[i].SetActive(display);
            }

            StartLine.SetActive(display);
            EndLine.SetActive(display);
        }
Exemplo n.º 6
0
        public override int GetHashCode( )
        {
            int hashCode = 2078777074;

            hashCode = (hashCode * -1521134295) + base.GetHashCode( );
            hashCode = (hashCode * -1521134295) + StartLine.GetHashCode( );
            hashCode = (hashCode * -1521134295) + StartColumn.GetHashCode( );
            hashCode = (hashCode * -1521134295) + EndLine.GetHashCode( );
            hashCode = (hashCode * -1521134295) + EndColumn.GetHashCode( );
            return(hashCode);
        }
Exemplo n.º 7
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash *= 23 + StartLine.GetHashCode();
         hash *= 23 + StartColumn.GetHashCode();
         hash *= 23 + EndLine.GetHashCode();
         hash *= 23 + EndColumn.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 8
0
        public override int GetHashCode()
        {
            var hashCode = 1032872879;

            hashCode = hashCode * -1521134295 + EqualityComparer <ISymbol> .Default.GetHashCode(Variable);

            hashCode = hashCode * -1521134295 + StartLine.GetHashCode();
            hashCode = hashCode * -1521134295 + EndLine.GetHashCode();
            hashCode = hashCode * -1521134295 + StartColumn.GetHashCode();
            hashCode = hashCode * -1521134295 + EndColumn.GetHashCode();
            return(hashCode);
        }
Exemplo n.º 9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hash = 17;
         hash = hash * 23 + (FileName?.GetHashCode()).GetValueOrDefault();
         hash = hash * 23 + Line.GetHashCode();
         hash = hash * 23 + Column.GetHashCode();
         hash = hash * 23 + EndLine.GetHashCode();
         hash = hash * 23 + EndColumn.GetHashCode();
         hash = hash * 23 + (Text?.GetHashCode()).GetValueOrDefault();
         return(hash);
     }
 }
Exemplo n.º 10
0
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hash = 17;
         // Suitable nullity checks etc, of course :)
         hash = hash * 23 + StartLine.GetHashCode();
         hash = hash * 23 + EndLine.GetHashCode();
         hash = hash * 23 + (Alias ?? string.Empty).GetHashCode();
         hash = hash * 23 + (Comment ?? string.Empty).GetHashCode();
         hash = hash * 23 + NodeType.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 11
0
        public override int GetHashCode()
        {
            int result = 17;

            unchecked
            {
                result = (result * 31) + StartLine.GetHashCode();
                result = (result * 31) + StartColumn.GetHashCode();
                result = (result * 31) + EndLine.GetHashCode();
                result = (result * 31) + EndColumn.GetHashCode();
                result = (result * 31) + Offset.GetHashCode();
                result = (result * 31) + Length.GetHashCode();
            }

            return(result);
        }
Exemplo n.º 12
0
Arquivo: Span.cs Projeto: shana/bebop
        public int CompareTo(Span other)
        {
            var c = StartLine.CompareTo(other.StartLine);

            if (c != 0)
            {
                return(c);
            }
            c = StartColumn.CompareTo(other.StartColumn);
            if (c != 0)
            {
                return(c);
            }
            c = EndLine.CompareTo(other.EndLine);
            if (c != 0)
            {
                return(c);
            }
            c = EndColumn.CompareTo(other.EndColumn);
            return(c);
        }
Exemplo n.º 13
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (Color != null)
         {
             hashCode = hashCode * 59 + Color.GetHashCode();
         }
         if (Smoothing != null)
         {
             hashCode = hashCode * 59 + Smoothing.GetHashCode();
         }
         if (Title != null)
         {
             hashCode = hashCode * 59 + Title.GetHashCode();
         }
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (AutoTypeNumbers != null)
         {
             hashCode = hashCode * 59 + AutoTypeNumbers.GetHashCode();
         }
         if (AutoRange != null)
         {
             hashCode = hashCode * 59 + AutoRange.GetHashCode();
         }
         if (RangeMode != null)
         {
             hashCode = hashCode * 59 + RangeMode.GetHashCode();
         }
         if (Range != null)
         {
             hashCode = hashCode * 59 + Range.GetHashCode();
         }
         if (FixedRange != null)
         {
             hashCode = hashCode * 59 + FixedRange.GetHashCode();
         }
         if (CheaterType != null)
         {
             hashCode = hashCode * 59 + CheaterType.GetHashCode();
         }
         if (TickMode != null)
         {
             hashCode = hashCode * 59 + TickMode.GetHashCode();
         }
         if (NTicks != null)
         {
             hashCode = hashCode * 59 + NTicks.GetHashCode();
         }
         if (TickVals != null)
         {
             hashCode = hashCode * 59 + TickVals.GetHashCode();
         }
         if (TickText != null)
         {
             hashCode = hashCode * 59 + TickText.GetHashCode();
         }
         if (ShowTickLabels != null)
         {
             hashCode = hashCode * 59 + ShowTickLabels.GetHashCode();
         }
         if (TickFont != null)
         {
             hashCode = hashCode * 59 + TickFont.GetHashCode();
         }
         if (TickAngle != null)
         {
             hashCode = hashCode * 59 + TickAngle.GetHashCode();
         }
         if (TickPrefix != null)
         {
             hashCode = hashCode * 59 + TickPrefix.GetHashCode();
         }
         if (ShowTickPrefix != null)
         {
             hashCode = hashCode * 59 + ShowTickPrefix.GetHashCode();
         }
         if (TickSuffix != null)
         {
             hashCode = hashCode * 59 + TickSuffix.GetHashCode();
         }
         if (ShowTickSuffix != null)
         {
             hashCode = hashCode * 59 + ShowTickSuffix.GetHashCode();
         }
         if (ShowExponent != null)
         {
             hashCode = hashCode * 59 + ShowExponent.GetHashCode();
         }
         if (ExponentFormat != null)
         {
             hashCode = hashCode * 59 + ExponentFormat.GetHashCode();
         }
         if (MinExponent != null)
         {
             hashCode = hashCode * 59 + MinExponent.GetHashCode();
         }
         if (SeparateThousands != null)
         {
             hashCode = hashCode * 59 + SeparateThousands.GetHashCode();
         }
         if (TickFormat != null)
         {
             hashCode = hashCode * 59 + TickFormat.GetHashCode();
         }
         if (TickFormatStops != null)
         {
             hashCode = hashCode * 59 + TickFormatStops.GetHashCode();
         }
         if (CategoryOrder != null)
         {
             hashCode = hashCode * 59 + CategoryOrder.GetHashCode();
         }
         if (CategoryArray != null)
         {
             hashCode = hashCode * 59 + CategoryArray.GetHashCode();
         }
         if (LabelPadding != null)
         {
             hashCode = hashCode * 59 + LabelPadding.GetHashCode();
         }
         if (LabelPrefix != null)
         {
             hashCode = hashCode * 59 + LabelPrefix.GetHashCode();
         }
         if (LabelSuffix != null)
         {
             hashCode = hashCode * 59 + LabelSuffix.GetHashCode();
         }
         if (ShowLine != null)
         {
             hashCode = hashCode * 59 + ShowLine.GetHashCode();
         }
         if (LineColor != null)
         {
             hashCode = hashCode * 59 + LineColor.GetHashCode();
         }
         if (LineWidth != null)
         {
             hashCode = hashCode * 59 + LineWidth.GetHashCode();
         }
         if (GridColor != null)
         {
             hashCode = hashCode * 59 + GridColor.GetHashCode();
         }
         if (GridWidth != null)
         {
             hashCode = hashCode * 59 + GridWidth.GetHashCode();
         }
         if (ShowGrid != null)
         {
             hashCode = hashCode * 59 + ShowGrid.GetHashCode();
         }
         if (MinorGridCount != null)
         {
             hashCode = hashCode * 59 + MinorGridCount.GetHashCode();
         }
         if (MinorGridWidth != null)
         {
             hashCode = hashCode * 59 + MinorGridWidth.GetHashCode();
         }
         if (MinorGridColor != null)
         {
             hashCode = hashCode * 59 + MinorGridColor.GetHashCode();
         }
         if (StartLine != null)
         {
             hashCode = hashCode * 59 + StartLine.GetHashCode();
         }
         if (StartLineColor != null)
         {
             hashCode = hashCode * 59 + StartLineColor.GetHashCode();
         }
         if (StartLineWidth != null)
         {
             hashCode = hashCode * 59 + StartLineWidth.GetHashCode();
         }
         if (EndLine != null)
         {
             hashCode = hashCode * 59 + EndLine.GetHashCode();
         }
         if (EndlineWidth != null)
         {
             hashCode = hashCode * 59 + EndlineWidth.GetHashCode();
         }
         if (EndlineColor != null)
         {
             hashCode = hashCode * 59 + EndlineColor.GetHashCode();
         }
         if (Tick0 != null)
         {
             hashCode = hashCode * 59 + Tick0.GetHashCode();
         }
         if (DTick != null)
         {
             hashCode = hashCode * 59 + DTick.GetHashCode();
         }
         if (ArrayTick0 != null)
         {
             hashCode = hashCode * 59 + ArrayTick0.GetHashCode();
         }
         if (ArrayDTick != null)
         {
             hashCode = hashCode * 59 + ArrayDTick.GetHashCode();
         }
         if (TickValsSrc != null)
         {
             hashCode = hashCode * 59 + TickValsSrc.GetHashCode();
         }
         if (TickTextSrc != null)
         {
             hashCode = hashCode * 59 + TickTextSrc.GetHashCode();
         }
         if (CategoryArraySrc != null)
         {
             hashCode = hashCode * 59 + CategoryArraySrc.GetHashCode();
         }
         return(hashCode);
     }
 }
Exemplo n.º 14
0
        /// <inheritdoc />
        public bool Equals([AllowNull] AAxis other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Color == other.Color ||
                     Color != null &&
                     Color.Equals(other.Color)
                     ) &&
                 (
                     Smoothing == other.Smoothing ||
                     Smoothing != null &&
                     Smoothing.Equals(other.Smoothing)
                 ) &&
                 (
                     Title == other.Title ||
                     Title != null &&
                     Title.Equals(other.Title)
                 ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     AutoTypeNumbers == other.AutoTypeNumbers ||
                     AutoTypeNumbers != null &&
                     AutoTypeNumbers.Equals(other.AutoTypeNumbers)
                 ) &&
                 (
                     AutoRange == other.AutoRange ||
                     AutoRange != null &&
                     AutoRange.Equals(other.AutoRange)
                 ) &&
                 (
                     RangeMode == other.RangeMode ||
                     RangeMode != null &&
                     RangeMode.Equals(other.RangeMode)
                 ) &&
                 (
                     Equals(Range, other.Range) ||
                     Range != null && other.Range != null &&
                     Range.SequenceEqual(other.Range)
                 ) &&
                 (
                     FixedRange == other.FixedRange ||
                     FixedRange != null &&
                     FixedRange.Equals(other.FixedRange)
                 ) &&
                 (
                     CheaterType == other.CheaterType ||
                     CheaterType != null &&
                     CheaterType.Equals(other.CheaterType)
                 ) &&
                 (
                     TickMode == other.TickMode ||
                     TickMode != null &&
                     TickMode.Equals(other.TickMode)
                 ) &&
                 (
                     NTicks == other.NTicks ||
                     NTicks != null &&
                     NTicks.Equals(other.NTicks)
                 ) &&
                 (
                     Equals(TickVals, other.TickVals) ||
                     TickVals != null && other.TickVals != null &&
                     TickVals.SequenceEqual(other.TickVals)
                 ) &&
                 (
                     Equals(TickText, other.TickText) ||
                     TickText != null && other.TickText != null &&
                     TickText.SequenceEqual(other.TickText)
                 ) &&
                 (
                     ShowTickLabels == other.ShowTickLabels ||
                     ShowTickLabels != null &&
                     ShowTickLabels.Equals(other.ShowTickLabels)
                 ) &&
                 (
                     TickFont == other.TickFont ||
                     TickFont != null &&
                     TickFont.Equals(other.TickFont)
                 ) &&
                 (
                     TickAngle == other.TickAngle ||
                     TickAngle != null &&
                     TickAngle.Equals(other.TickAngle)
                 ) &&
                 (
                     TickPrefix == other.TickPrefix ||
                     TickPrefix != null &&
                     TickPrefix.Equals(other.TickPrefix)
                 ) &&
                 (
                     ShowTickPrefix == other.ShowTickPrefix ||
                     ShowTickPrefix != null &&
                     ShowTickPrefix.Equals(other.ShowTickPrefix)
                 ) &&
                 (
                     TickSuffix == other.TickSuffix ||
                     TickSuffix != null &&
                     TickSuffix.Equals(other.TickSuffix)
                 ) &&
                 (
                     ShowTickSuffix == other.ShowTickSuffix ||
                     ShowTickSuffix != null &&
                     ShowTickSuffix.Equals(other.ShowTickSuffix)
                 ) &&
                 (
                     ShowExponent == other.ShowExponent ||
                     ShowExponent != null &&
                     ShowExponent.Equals(other.ShowExponent)
                 ) &&
                 (
                     ExponentFormat == other.ExponentFormat ||
                     ExponentFormat != null &&
                     ExponentFormat.Equals(other.ExponentFormat)
                 ) &&
                 (
                     MinExponent == other.MinExponent ||
                     MinExponent != null &&
                     MinExponent.Equals(other.MinExponent)
                 ) &&
                 (
                     SeparateThousands == other.SeparateThousands ||
                     SeparateThousands != null &&
                     SeparateThousands.Equals(other.SeparateThousands)
                 ) &&
                 (
                     TickFormat == other.TickFormat ||
                     TickFormat != null &&
                     TickFormat.Equals(other.TickFormat)
                 ) &&
                 (
                     Equals(TickFormatStops, other.TickFormatStops) ||
                     TickFormatStops != null && other.TickFormatStops != null &&
                     TickFormatStops.SequenceEqual(other.TickFormatStops)
                 ) &&
                 (
                     CategoryOrder == other.CategoryOrder ||
                     CategoryOrder != null &&
                     CategoryOrder.Equals(other.CategoryOrder)
                 ) &&
                 (
                     Equals(CategoryArray, other.CategoryArray) ||
                     CategoryArray != null && other.CategoryArray != null &&
                     CategoryArray.SequenceEqual(other.CategoryArray)
                 ) &&
                 (
                     LabelPadding == other.LabelPadding ||
                     LabelPadding != null &&
                     LabelPadding.Equals(other.LabelPadding)
                 ) &&
                 (
                     LabelPrefix == other.LabelPrefix ||
                     LabelPrefix != null &&
                     LabelPrefix.Equals(other.LabelPrefix)
                 ) &&
                 (
                     LabelSuffix == other.LabelSuffix ||
                     LabelSuffix != null &&
                     LabelSuffix.Equals(other.LabelSuffix)
                 ) &&
                 (
                     ShowLine == other.ShowLine ||
                     ShowLine != null &&
                     ShowLine.Equals(other.ShowLine)
                 ) &&
                 (
                     LineColor == other.LineColor ||
                     LineColor != null &&
                     LineColor.Equals(other.LineColor)
                 ) &&
                 (
                     LineWidth == other.LineWidth ||
                     LineWidth != null &&
                     LineWidth.Equals(other.LineWidth)
                 ) &&
                 (
                     GridColor == other.GridColor ||
                     GridColor != null &&
                     GridColor.Equals(other.GridColor)
                 ) &&
                 (
                     GridWidth == other.GridWidth ||
                     GridWidth != null &&
                     GridWidth.Equals(other.GridWidth)
                 ) &&
                 (
                     ShowGrid == other.ShowGrid ||
                     ShowGrid != null &&
                     ShowGrid.Equals(other.ShowGrid)
                 ) &&
                 (
                     MinorGridCount == other.MinorGridCount ||
                     MinorGridCount != null &&
                     MinorGridCount.Equals(other.MinorGridCount)
                 ) &&
                 (
                     MinorGridWidth == other.MinorGridWidth ||
                     MinorGridWidth != null &&
                     MinorGridWidth.Equals(other.MinorGridWidth)
                 ) &&
                 (
                     MinorGridColor == other.MinorGridColor ||
                     MinorGridColor != null &&
                     MinorGridColor.Equals(other.MinorGridColor)
                 ) &&
                 (
                     StartLine == other.StartLine ||
                     StartLine != null &&
                     StartLine.Equals(other.StartLine)
                 ) &&
                 (
                     StartLineColor == other.StartLineColor ||
                     StartLineColor != null &&
                     StartLineColor.Equals(other.StartLineColor)
                 ) &&
                 (
                     StartLineWidth == other.StartLineWidth ||
                     StartLineWidth != null &&
                     StartLineWidth.Equals(other.StartLineWidth)
                 ) &&
                 (
                     EndLine == other.EndLine ||
                     EndLine != null &&
                     EndLine.Equals(other.EndLine)
                 ) &&
                 (
                     EndlineWidth == other.EndlineWidth ||
                     EndlineWidth != null &&
                     EndlineWidth.Equals(other.EndlineWidth)
                 ) &&
                 (
                     EndlineColor == other.EndlineColor ||
                     EndlineColor != null &&
                     EndlineColor.Equals(other.EndlineColor)
                 ) &&
                 (
                     Tick0 == other.Tick0 ||
                     Tick0 != null &&
                     Tick0.Equals(other.Tick0)
                 ) &&
                 (
                     DTick == other.DTick ||
                     DTick != null &&
                     DTick.Equals(other.DTick)
                 ) &&
                 (
                     ArrayTick0 == other.ArrayTick0 ||
                     ArrayTick0 != null &&
                     ArrayTick0.Equals(other.ArrayTick0)
                 ) &&
                 (
                     ArrayDTick == other.ArrayDTick ||
                     ArrayDTick != null &&
                     ArrayDTick.Equals(other.ArrayDTick)
                 ) &&
                 (
                     TickValsSrc == other.TickValsSrc ||
                     TickValsSrc != null &&
                     TickValsSrc.Equals(other.TickValsSrc)
                 ) &&
                 (
                     TickTextSrc == other.TickTextSrc ||
                     TickTextSrc != null &&
                     TickTextSrc.Equals(other.TickTextSrc)
                 ) &&
                 (
                     CategoryArraySrc == other.CategoryArraySrc ||
                     CategoryArraySrc != null &&
                     CategoryArraySrc.Equals(other.CategoryArraySrc)
                 ));
        }
Exemplo n.º 15
0
        protected override void BuildInsertOrUpdateQueryAsMerge(SqlInsertOrUpdateStatement insertOrUpdate, string fromDummyTable)
        {
            var table       = insertOrUpdate.Insert.Into;
            var targetAlias = Convert(insertOrUpdate.SelectQuery.From.Tables[0].Alias, ConvertType.NameToQueryTableAlias).ToString();
            var sourceAlias = Convert(GetTempAliases(1, "s")[0], ConvertType.NameToQueryTableAlias).ToString();
            var keys        = insertOrUpdate.Update.Keys;

            AppendIndent().Append("MERGE INTO ");
            BuildPhysicalTable(table, null);
            StringBuilder.Append(' ').AppendLine(targetAlias);

            AppendIndent().Append("USING (SELECT ");

            ExtractMergeParametersIfCannotCombine(insertOrUpdate, keys);

            for (var i = 0; i < keys.Count; i++)
            {
                var key  = keys[i];
                var expr = key.Expression;

                if (expr is SqlParameter || expr is SqlValue)
                {
                    var exprType = SqlDataType.GetDataType(expr.SystemType);
                    var asType   = GetiSeriesType(exprType);

                    StringBuilder.Append("CAST(");
                    BuildExpression(expr, false, false);
                    StringBuilder.AppendFormat(" AS {0})", asType);
                }
                else
                {
                    BuildExpression(expr, false, false);
                }


                StringBuilder.Append(" AS ");
                BuildExpression(key.Column, false, false);

                if (i + 1 < keys.Count)
                {
                    StringBuilder.Append(", ");
                }
            }

            if (!string.IsNullOrEmpty(fromDummyTable))
            {
                StringBuilder.Append(' ').Append(fromDummyTable);
            }

            StringBuilder.Append(") ").Append(sourceAlias).AppendLine(" ON");

            AppendIndent().AppendLine("(");

            Indent++;

            for (var i = 0; i < keys.Count; i++)
            {
                var key = keys[i];

                AppendIndent();

                StringBuilder.Append(targetAlias).Append('.');
                BuildExpression(key.Column, false, false);

                StringBuilder.Append(" = ").Append(sourceAlias).Append('.');
                BuildExpression(key.Column, false, false);

                if (i + 1 < keys.Count)
                {
                    StringBuilder.Append(" AND");
                }

                StringBuilder.AppendLine();
            }

            Indent--;

            AppendIndent().AppendLine(")");

            if (insertOrUpdate.Update.Items.Any())
            {
                AppendIndent().AppendLine("WHEN MATCHED THEN");

                Indent++;
                AppendIndent().AppendLine("UPDATE ");
                BuildUpdateSet(insertOrUpdate.SelectQuery, insertOrUpdate.Update);
                Indent--;
            }

            AppendIndent().AppendLine("WHEN NOT MATCHED THEN");

            Indent++;
            BuildInsertClause(insertOrUpdate, insertOrUpdate.Insert, "INSERT", false, false);
            Indent--;

            while (EndLine.Contains(StringBuilder[StringBuilder.Length - 1]))
            {
                StringBuilder.Length--;
            }
        }
Exemplo n.º 16
0
        public static List <List <string> > CSVStandardParse(string content)
        {
            List <List <string> > ret   = new List <List <string> >();
            ParseState            state = ParseState.FieldStart;

            const char comma    = ',';
            const char quote    = '"';
            const char newline1 = '\r';
            const char newline2 = '\n';

            bool appendNewlineAtEnd = true;

            if (content.Length > 0)
            {
                var last = content[content.Length - 1];
                if (last == newline1 || last == newline2)
                {
                    appendNewlineAtEnd = false;
                }
            }

            int len = content.Length;

            if (appendNewlineAtEnd)
            {
                ++len;
            }

            List <string> currentLine = new List <string>();
            StringBuilder sb          = new StringBuilder();

            EndLine end_line = delegate() {
                currentLine.Add(sb.ToString());
                sb.Length = 0;
                ret.Add(currentLine);
                currentLine = new List <string>();
            };

            EndField end_field = delegate() {
                currentLine.Add(sb.ToString());
                sb.Length = 0;
            };

            NextCharGetter next_char = delegate(int idx) {
                if (appendNewlineAtEnd && (idx == (len - 1)))
                {
                    return(newline1);
                }
                else
                {
                    return(content[idx]);
                }
            };



            for (int i = 0; i < len; ++i)
            {
                char c = next_char(i);

                switch (state)
                {
                case ParseState.FieldStart:
                {
                    switch (c)
                    {
                    case comma:
                    {
                        end_field();
                    }
                    break;

                    case quote:
                    {
                        state = ParseState.QuoteField;
                    }
                    break;

                    case newline1:
                    {
                        if (((i + 1) < len) && newline2 == content[i + 1])
                        {
                            ++i;
                        }
                        end_line();
                    }
                    break;

                    case newline2:
                    {
                        end_line();
                    }
                    break;

                    default:
                    {
                        sb.Append(c);
                        state = ParseState.NonQuoteField;
                    }
                    break;
                    }
                }
                break;

                case ParseState.NonQuoteField:
                {
                    switch (c)
                    {
                    case comma:
                    {
                        end_field();
                        state = ParseState.FieldStart;
                    }
                    break;

                    case quote:
                    {
                        state = ParseState.Error;
                    }
                    break;

                    case newline1:
                    {
                        if (((i + 1) < len) && newline2 == content[i + 1])
                        {
                            ++i;
                        }
                        end_line();
                        state = ParseState.FieldStart;
                    }
                    break;

                    case newline2:
                    {
                        end_line();
                        state = ParseState.FieldStart;
                    }
                    break;

                    default:
                    {
                        sb.Append(c);
                    }
                    break;
                    }
                }
                break;

                case ParseState.QuoteField:
                {
                    switch (c)
                    {
                    case quote:
                    {
                        if ((i + 1) >= len)
                        {
                            end_line();
                        }
                        else
                        {
                            if (quote == content[i + 1])
                            {
                                sb.Append(quote);
                                ++i;
                            }
                            else if (comma == content[i + 1])
                            {
                                end_field();
                                ++i;
                                state = ParseState.FieldStart;
                            }
                            else if (newline1 == content[i + 1])
                            {
                                if ((i + 2) >= len)
                                {
                                    state = ParseState.Error;
                                }
                                else
                                {
                                    if (newline2 == content[i + 2])
                                    {
                                        end_line();
                                        ++i;
                                        ++i;
                                        state = ParseState.FieldStart;
                                    }
                                    else
                                    {
                                        end_line();
                                        ++i;
                                        state = ParseState.FieldStart;
                                    }
                                }
                            }
                            else if (newline2 == content[i + 1])
                            {
                                end_line();
                                ++i;
                                state = ParseState.FieldStart;
                            }
                            else
                            {
                                state = ParseState.Error;
                            }
                        }
                    }
                    break;

                    default:
                    {
                        sb.Append(c);
                    }
                    break;
                    }
                }
                break;

                case ParseState.Error:
                {
                    throw new Exception("invalid csv format!");
                }

                default:
                    break;
                }
            }

            if (ParseState.Error == state)
            {
                throw new Exception("invalid csv format!");
            }

            return(ret);
        }