// Edit Field Value Converter SET function for Choice fields. public static void SetConvertedChoiceEditFieldValue(string fieldName, object fieldValue, ListItem item, ConversionContext context, string customCategory) { ObservableCollection<ChoiceFieldViewModel> choices = fieldValue as ObservableCollection<ChoiceFieldViewModel>; bool isCustomValue = true; string specifiedChoice = string.Empty; if (choices != null) { foreach (ChoiceFieldViewModel choiceItem in choices) { if ((choiceItem.IsChecked) || (choiceItem.Name.Equals(customCategory, StringComparison.CurrentCultureIgnoreCase))) { specifiedChoice = choiceItem.Name; isCustomValue = false; break; } } if (isCustomValue) { specifiedChoice = customCategory; } } else { specifiedChoice = customCategory; } item[fieldName] = specifiedChoice; }
public ConversionResult Convert(ConversionContext conversion) { if (conversion.HasValue==false) return conversion.Unconverted(); var converter=new NullableConverter(typeof(Nullable<>).MakeGenericType(conversion.GetType())); return conversion.Result(converter.ConvertTo(conversion, converter.UnderlyingType)); }
private void TryConvert() { var conversionContext = new ConversionContext(destinationProperty.PropertyType, destinationValue); var converter = valueConverters.FirstOrDefault(it => it.IsConvertible(conversionContext)); if (converter != null) { destinationValue = converter.Convert(conversionContext).Value; } }
public static string ConvertStatement(string java) { var statement = JavaParser.parseStatement(java); var options = new JavaConversionOptions(); var context = new ConversionContext(options); var statementSyntax = StatementVisitor.VisitStatement(context, statement); var tree = CSharpSyntaxTree.Create(statementSyntax); return tree.GetText().ToString(); }
public ConversionResult Convert(ConversionContext conversion) { if (conversion.HasValue==false) return null; if(conversion.Is<DateTime?>()) { return conversion.Result(conversion.Value.As<DateTime?>().Value.ToUniversalTime()); } return conversion.Result(conversion.Value.As<DateTime>().ToUniversalTime()); }
public bool IsConvertible(ConversionContext conversion) { var convertible=conversion.HasValue && conversion.ValueType.IsNullableType() == false && conversion.DestinationPropertyType.IsNullableType(); if(convertible) { var cnv = new NullableConverter(conversion.DestinationPropertyType); return conversion.ValueType == cnv.UnderlyingType; } return false; }
public static string ConvertMethodDeclaration(string java) { var javaClassDeclaration = @" class A { " + java + @" }"; var declaration = JavaParser.parseBodyDeclaration(javaClassDeclaration); var options = new JavaConversionOptions(); var context = new ConversionContext(options); var classDeclaration = SyntaxFactory.ClassDeclaration("A"); var statementSyntax = BodyDeclarationVisitor.VisitBodyDeclarationForClass(context, classDeclaration, (BodyDeclaration)declaration.getChildrenNodes().get(0)) .NormalizeWhitespace(); var tree = CSharpSyntaxTree.Create(statementSyntax); return tree.GetText().ToString(); }
public ConversionResult Convert(ConversionContext conversion) { try { if (IsConvertible(conversion)) return conversion.Unconverted(); var destPropType = conversion.DestinationPropertyType; if (destPropType.IsNullableType() && conversion.HasValue) destPropType = new NullableConverter(destPropType).UnderlyingType; return conversion.Result(System.Convert.ChangeType(conversion.Value, destPropType)); } catch(InvalidCastException) { //gulp return conversion.Unconverted(); } }
private ConversionResult TryListConversion(ConversionContext context) { var collectionTypeSpec = new SupportedCollectionTypeSpecification(); if (collectionTypeSpec.IsSatisfiedBy(context.DestinationPropertyType) == false || collectionTypeSpec.IsSatisfiedBy(context.Value)==false) return context.Unconverted(); var destColl = (IList)activate.CreateCollectionInstance(context.DestinationPropertyType,collectionTypeSpec.GetLength(context.Value)); var destElement = context.DestinationPropertyType.ElementType(); var srcList = (IEnumerable) context.Value; var enumerator = srcList.GetEnumerator(); int index = 0; while(enumerator.MoveNext()) { object element = enumerator.Current ?? destElement.DefaultValue(); destColl.AddElement(element,index++); } return context.Result(destColl); }
public ConversionResult Convert(ConversionContext conversion) { if (conversion.HasValue == false || conversion.ValueType == conversion.DestinationPropertyType) return conversion.Result(conversion.Value); ConversionResult result = conversion.Unconverted(); var attempts = new Func<ConversionContext, ConversionResult>[] { TryListConversion, TryNullableConversion, TrySystemConversion }; foreach (var attempt in attempts) { result = attempt(conversion); if(result is Unconverted) continue; return result; } return result; }
protected sealed override MemberDeclarationSyntax VisitForInterface(ConversionContext context, InterfaceDeclarationSyntax interfaceSyntax, BodyDeclaration declaration) { return(VisitForInterface(context, interfaceSyntax, (T)declaration)); }
public abstract MemberDeclarationSyntax VisitForInterface(ConversionContext context, InterfaceDeclarationSyntax interfaceSyntax, T declaration);
public override MemberDeclarationSyntax VisitForInterface(ConversionContext context, InterfaceDeclarationSyntax interfaceSyntax, EnumDeclaration declaration) { return(VisitForClass(context, null, declaration)); }
public abstract StatementSyntax Visit(ConversionContext context, T statement);
public override void DetermineDataType(Plan plan) { DetermineModifiers(plan); _dataType = plan.DataTypes.SystemBoolean; if (!Nodes[0].DataType.IsGeneric && !Nodes[1].DataType.IsGeneric) // Generic row comparison must be done at run-time { if (Nodes[0].DataType.Is(Nodes[1].DataType)) { Nodes[0] = Compiler.Upcast(plan, Nodes[0], Nodes[1].DataType); } else if (Nodes[1].DataType.Is(Nodes[0].DataType)) { Nodes[1] = Compiler.Upcast(plan, Nodes[1], Nodes[0].DataType); } else { ConversionContext context = Compiler.FindConversionPath(plan, Nodes[0].DataType, Nodes[1].DataType); if (context.CanConvert) { Nodes[0] = Compiler.Upcast(plan, Compiler.ConvertNode(plan, Nodes[0], context), Nodes[1].DataType); } else { context = Compiler.FindConversionPath(plan, Nodes[1].DataType, Nodes[0].DataType); Compiler.CheckConversionContext(plan, context); Nodes[1] = Compiler.Upcast(plan, Compiler.ConvertNode(plan, Nodes[1], context), Nodes[0].DataType); } } plan.Symbols.PushWindow(0); try { plan.EnterRowContext(); try { #if USENAMEDROWVARIABLES plan.Symbols.Push(new Symbol(Keywords.Left, (Schema.RowType)Nodes[0].DataType)); #else Schema.RowType leftRowType = new Schema.RowType(((Schema.RowType)Nodes[0].DataType).Columns, Keywords.Left); APlan.Symbols.Push(new Symbol(String.Empty, leftRowType)); #endif try { #if USENAMEDROWVARIABLES plan.Symbols.Push(new Symbol(Keywords.Right, (Schema.RowType)Nodes[1].DataType)); #else Schema.RowType rightRowType = new Schema.RowType(((Schema.RowType)Nodes[1].DataType).Columns, Keywords.Right); APlan.Symbols.Push(new Symbol(String.Empty, rightRowType)); #endif try { _comparisonNode = #if USENAMEDROWVARIABLES Compiler.CompileExpression(plan, Compiler.BuildRowEqualExpression(plan, Keywords.Left, Keywords.Right, ((Schema.RowType)Nodes[0].DataType).Columns, ((Schema.RowType)Nodes[1].DataType).Columns)); #else Compiler.CompileExpression(APlan, Compiler.BuildRowEqualExpression(APlan, leftRowType.Columns, rightRowType.Columns)); #endif } finally { plan.Symbols.Pop(); } } finally { plan.Symbols.Pop(); } } finally { plan.ExitRowContext(); } } finally { plan.Symbols.PopWindow(); } } }
private static void ThrowConvertExceptionIf <TExpectedType>(bool condition, EvaluationResult value, ConversionContext convContext, string errorDescription) { if (condition) { throw new ConvertException(new[] { typeof(TExpectedType) }, value, convContext.ErrorContext, errorDescription); } }
public override MemberDeclarationSyntax VisitForInterface(ConversionContext context, InterfaceDeclarationSyntax interfaceSyntax, FieldDeclaration declaration) { throw new NotImplementedException("Need to implement diversion of static fields from interface declaration to static class"); }
public bool IsConvertible(ConversionContext conversion) { DateTime ignore; return (conversion.HasValue && DateTime.TryParse(conversion.Value.ToString(), out ignore) && (conversion.DestinationPropertyType == typeof (DateTime) || conversion.DestinationPropertyType == typeof (DateTime?))); }
public ConversionResult Convert(ConversionContext conversion) { return(conversion.Result(conversion.HasValue?conversion.Value.ToString():null)); }
private bool IsDictionary(ConversionContext x) { return(typeof(IDictionary).IsAssignableFrom(x.ParameterType) && x.Value.StartsWith("|")); }
private static ConversionResult TryNullableConversion(ConversionContext context) { if (context.HasValue== false|| context.ValueType.IsNullableType() == false) return context.Unconverted(); return new NullableToNonNullableConverter().Convert(context); }
public void Save(string filename) { string folder = Path.GetDirectoryName(filename); if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); XmlConverter xmlConverter = new XmlConverter(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.AppendChild(xmlDocument.CreateXmlDeclaration("1.0", null, null)); ConversionContext context = new ConversionContext { Culture = Culture.Invariant, Device = xmlDocument }; XmlNode xmlNode = xmlConverter.ConvertTo(this, context) as XmlNode; if (xmlNode != null) { xmlDocument.AppendChild(xmlNode); xmlDocument.Save(filename); } }
public static AppSettings Load(string filename) { if (!File.Exists(filename)) throw new FileNotFoundException(filename); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(filename); XmlConverter xmlConverter = new XmlConverter(); ConversionContext context = new ConversionContext { Culture = Culture.Invariant, Device = xmlDocument }; AppSettings settings = xmlConverter.ConvertFrom(xmlDocument, context) as AppSettings; return settings; }
private static ConversionResult TrySystemConversion(ConversionContext context) { return new SystemConverter().Convert(context); }
public ConversionResult Convert(ConversionContext conversion) { return conversion.Result(conversion.DestinationPropertyType.DefaultValue()); }
public bool IsConvertible(ConversionContext conversion) { return conversion.HasValue && conversion.DestinationPropertyType is IConvertible && conversion.ValueType != conversion.DestinationPropertyType; }
public bool IsConvertible(ConversionContext conversion) { return conversion.Value is Int32 && conversion.DestinationPropertyType == typeof (String); }
public override ExpressionSyntax Visit(ConversionContext context, BinaryExpr binaryExpr) { var leftExpr = binaryExpr.getLeft(); var leftSyntax = ExpressionVisitor.VisitExpression(context, leftExpr); var rightExpr = binaryExpr.getRight(); var rightSyntax = ExpressionVisitor.VisitExpression(context, rightExpr); var op = binaryExpr.getOperator(); SyntaxKind kind = SyntaxKind.None; if (op == BinaryExpr.Operator.and) { kind = SyntaxKind.LogicalAndExpression; } else if (op == BinaryExpr.Operator.binAnd) { kind = SyntaxKind.BitwiseAndExpression; } else if (op == BinaryExpr.Operator.binOr) { kind = SyntaxKind.BitwiseOrExpression; } else if (op == BinaryExpr.Operator.divide) { kind = SyntaxKind.DivideExpression; } else if (op == BinaryExpr.Operator.equals) { kind = SyntaxKind.EqualsExpression; } else if (op == BinaryExpr.Operator.greater) { kind = SyntaxKind.GreaterThanExpression; } else if (op == BinaryExpr.Operator.greaterEquals) { kind = SyntaxKind.GreaterThanOrEqualExpression; } else if (op == BinaryExpr.Operator.less) { kind = SyntaxKind.LessThanExpression; } else if (op == BinaryExpr.Operator.lessEquals) { kind = SyntaxKind.LessThanOrEqualExpression; } else if (op == BinaryExpr.Operator.lShift) { kind = SyntaxKind.LeftShiftExpression; } else if (op == BinaryExpr.Operator.minus) { kind = SyntaxKind.SubtractExpression; } else if (op == BinaryExpr.Operator.notEquals) { kind = SyntaxKind.NotEqualsExpression; } else if (op == BinaryExpr.Operator.or) { kind = SyntaxKind.LogicalOrExpression; } else if (op == BinaryExpr.Operator.plus) { kind = SyntaxKind.AddExpression; } else if (op == BinaryExpr.Operator.remainder) { kind = SyntaxKind.ModuloExpression; } else if (op == BinaryExpr.Operator.rSignedShift) { kind = SyntaxKind.RightShiftExpression; } else if (op == BinaryExpr.Operator.rUnsignedShift) { kind = SyntaxKind.RightShiftExpression; context.Options.Warning("Use of unsigned right shift in original code; verify correctness.", binaryExpr.getBeginLine()); } else if (op == BinaryExpr.Operator.times) { kind = SyntaxKind.MultiplyExpression; } else if (op == BinaryExpr.Operator.xor) { kind = SyntaxKind.ExclusiveOrExpression; } return(SyntaxFactory.BinaryExpression(kind, leftSyntax, rightSyntax)); }
public ConversionResult Convert(ConversionContext conversion) { return(conversion.Result(DateTime.Parse(conversion.Value.ToString()))); }
public ConversionResult Convert(ConversionContext conversion) { return conversion.Result(DateTime.Parse(conversion.Value.ToString())); }
public bool IsConvertible(ConversionContext conversion) { return conversion.HasValue && conversion.ValueType.IsOneOf(dateTimeTypes) && conversion.DestinationPropertyType.IsOneOf(dateTimeTypes); }
public override ExpressionSyntax Visit(ConversionContext context, NameExpr nameExpr) => SyntaxFactory.IdentifierName(TypeHelper.EscapeIdentifier(nameExpr.getName()));
public override MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, FieldDeclaration fieldDecl) { var variables = new List <VariableDeclaratorSyntax>(); string typeName = fieldDecl.getType().toString(); foreach (var item in fieldDecl.getVariables().ToList <VariableDeclarator>()) { var id = item.getId(); string name = id.getName(); if (id.getArrayCount() > 0) { if (!typeName.EndsWith("[]")) { typeName += "[]"; } if (name.EndsWith("[]")) { name = name.Substring(0, name.Length - 2); } } var initexpr = item.getInit(); if (initexpr != null) { var initsyn = ExpressionVisitor.VisitExpression(context, initexpr); var vardeclsyn = SyntaxFactory.VariableDeclarator(name).WithInitializer(SyntaxFactory.EqualsValueClause(initsyn)); variables.Add(vardeclsyn); } else { variables.Add(SyntaxFactory.VariableDeclarator(name)); } } typeName = TypeHelper.ConvertType(typeName); var fieldSyntax = SyntaxFactory.FieldDeclaration( SyntaxFactory.VariableDeclaration( SyntaxFactory.ParseTypeName(typeName), SyntaxFactory.SeparatedList(variables, Enumerable.Repeat(SyntaxFactory.Token(SyntaxKind.CommaToken), variables.Count - 1)))); var mods = fieldDecl.getModifiers(); if (mods.HasFlag(Modifier.PUBLIC)) { fieldSyntax = fieldSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); } if (mods.HasFlag(Modifier.PROTECTED)) { fieldSyntax = fieldSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); } if (mods.HasFlag(Modifier.PRIVATE)) { fieldSyntax = fieldSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); } if (mods.HasFlag(Modifier.STATIC)) { fieldSyntax = fieldSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword)); } if (mods.HasFlag(Modifier.FINAL)) { fieldSyntax = fieldSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)); } if (mods.HasFlag(Modifier.VOLATILE)) { fieldSyntax = fieldSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.VolatileKeyword)); } return(fieldSyntax.AddComment(context, fieldDecl)); }
protected override bool InnerTo(ConversionContext context) { XvTBriefingBlock xvtBriefingBlock = null; XvTFlightGroupsBlock xvtFlightGroupBlock = null; var isMultiplayer = false; var isBoPMision = true; short[] fgIcons; context.WriteToTargetBuffer(18, true); context.SourceCursor = 2; //short i, j; context.FlightGroupCount = context.ReadSourceInt16(); short Messages = context.ReadSourceInt16(); context.WriteToTarget((short)(FGs + 2)); // [JB] Modified to +2 since generated skirmish files have two backdrops for ambient lighting context.WriteToTarget(Messages); fgIcons = new short[FGs]; context.WriteToTargetBuffer(1, 8); context.WriteToTargetBuffer(1, 11); //unknowns context.WriteToTargetBuffer(Encoding.ASCII.GetBytes("The Final Frontier"), 100); //make a nice Region name :P context.WriteToTargetBuffer(6, 0x23A); //starting hangar context.TargetCursor++; context.SourceCursor = 0x66; context.WriteToTarget(context.ReadByte()); //time limit (minutes) context.WriteToTargetBuffer(0x62, 0x23B3); //unknown context.TargetCursor = 0x23F0; //[JB] Jumping ahead to get the briefing locations before we load in the FGs. xvtBriefingBlock = new XvTBriefingBlock(context.FlightGroupCount, Messages, context); xvtFlightGroupBlock = new XvTFlightGroupsBlock(context.FlightGroupCount, context); //[JB] Now that flight groups are done, check for player count and patch in skirmish mode if (isMultiplayer && PlayerCraft > 1) { long backupPos = streams.TargetStream.Position; streams.TargetStream.Position = 0x23AC; context.WriteToTargetBuffer(4); streams.TargetStream.Position = backupPos; } #region Messages for (var i = 0; i < Messages; i++) { XvTPos = context.SourceCursor; XWAPos = streams.TargetStream.Position; streams.TargetWriter.Write(streams.SourceReader.ReadInt16()); //Message# - 1 switch (streams.SourceStream.ReadByte()) //takes care of colors if needed { case 49: streams.TargetWriter.Write(streams.SourceReader.ReadBytes(63)); //green streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(0); break; case 50: streams.TargetWriter.Write(streams.SourceReader.ReadBytes(63)); //blue streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(2); break; case 51: streams.TargetWriter.Write(streams.SourceReader.ReadBytes(63));; //yellow streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(3); break; default: context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(64)); //red streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(1); break; } streams.TargetStream.Position = XWAPos + 82; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(14)); //Sent to.. -> T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //T2 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //T1 AND/OR T2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //T3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //T4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //T3 AND/OR T4 streams.TargetStream.Position = XWAPos + 141; context.SourceCursor += 17; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //T (1/2) AND/OR (3/4) streams.TargetStream.Position = XWAPos + 132; //[JB] OriginatingFG context.WriteToTargetBuffer(System.Convert.ToByte(FGs + 1)); //[JB] Set to last FG (+2 inserted backdrops so the last new FG index is FG+1). Assigning messages to backdrops ensures the object is always present so messages always fire. streams.TargetStream.Position = XWAPos + 140; context.SourceCursor = XvTPos + 114; int msgDelaySec = streams.SourceStream.ReadByte() * 5; //[JB] Corrected delay time. context.WriteToTargetBuffer(System.Convert.ToByte(msgDelaySec % 60)); //Delay context.WriteToTargetBuffer(System.Convert.ToByte(msgDelaySec / 60)); streams.TargetStream.Position += 2; context.WriteToTargetBuffer(10); //[JB] Modified offset for second delay byte streams.TargetStream.Position += 5; context.WriteToTargetBuffer(10); //make sure the Cancel triggers are set to FALSE streams.TargetStream.Position = XWAPos + 162; context.SourceCursor = XvTPos + 116; } #endregion #region Global Goals XvTPos = context.SourceCursor; XWAPos = streams.TargetStream.Position; for (int ti = 0; ti < 10; ti++) //[JB] Converting all 10 teams just in case some triggers depend on them. { context.SourceCursor = XvTPos + (0x80 * ti); streams.TargetStream.Position = XWAPos + (0x170 * ti); context.WriteToTargetBuffer(3); context.SourceCursor++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //Prim T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT2 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetStream.Position += 2; context.SourceCursor += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 1 AND/OR 2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 3 AND/OR 4 context.SourceCursor += 17; streams.TargetStream.Position += 18; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(3)); //PT (1/2) AND/OR (3/4) -> Points streams.TargetStream.Position += 70; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //Prev T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT2 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetStream.Position += 2; context.SourceCursor += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 1 AND/OR 2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 3 AND/OR 4 context.SourceCursor += 17; streams.TargetStream.Position += 18; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(3)); //PT (1/2) AND/OR (3/4) -> Points streams.TargetStream.Position += 70; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //Sec T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //ST2 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetStream.Position += 2; context.SourceCursor += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //ST 1 AND/OR 2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //ST 3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //ST 4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //ST 3 AND/OR 4 context.SourceCursor += 17; streams.TargetStream.Position += 18; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(3)); //ST (1/2) AND/OR (3/4) -> Points streams.TargetStream.Position += 70; } context.SourceCursor = XvTPos + (0x80 * 10); //10 teams streams.TargetStream.Position = XWAPos + (0x170 * 10); #endregion #region IFF/Teams streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4870)); //well, that was simple.. #endregion #region Briefing XWAPos = streams.TargetStream.Position; long XWABriefing1 = XWAPos; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(6)); //briefing intro streams.TargetWriter.Write((short)(streams.SourceReader.ReadInt16() + 10 * Briefs[0])); // adjust length for add/moves context.SourceCursor += 2; streams.TargetStream.Position += 20 * Briefs[0] + 2; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(0x32A)); //briefing content streams.TargetStream.Position = XWAPos; var briefingLength = (short)(streams.TargetReader.ReadInt16() * 0x19 / 0x14); // adjust overall briefing length streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); streams.TargetStream.Position += 8; for (var i = 0; i < 0x320; i += 4) // work our way through length of briefing. i automatically increases by 4 per event { briefingLength = streams.TargetReader.ReadInt16(); if (briefingLength == 0x270F) { break; // stop check at t=9999, end briefing } briefingLength = (short)(briefingLength * 0x19 / 0x14); streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = streams.TargetReader.ReadInt16(); // now get the event type if (briefingLength > 8 && briefingLength < 17) // FG tags 1-8 { briefingLength = streams.TargetReader.ReadInt16(); // FG number streams.TargetStream.Position -= 2; streams.TargetWriter.Write(fgIcons[briefingLength]); // Overwrite with the Icon# i += 2; } else if (briefingLength == 7) // Zoom map command { briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 58); // X streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 88); // Y streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); i += 4; } else { streams.TargetStream.Position += 2 * BRF[briefingLength]; // skip over vars i += (short)(2 * BRF[briefingLength]); // increase length counter by skipped vars } } streams.TargetStream.Position = 0x8960 + (context.FlightGroupCount + 2) * 0xE3E + Messages * 0xA2; //[JB] FGs+2 context.WriteToTargetBuffer(1); //show the non-existant briefing streams.TargetStream.Position += 9; #endregion Briefing #region Briefing tags & strings for (var i = 0; i < 32; i++) //tags { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; for (var i = 0; i < 32; i++) //strings { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; #endregion Briefing T&S #region Briefing2 //[JB] Begin briefing 2. Basically just copy/paste the same code. if (isMultiplayer) { long XWABriefing2 = streams.TargetStream.Position; XWAPos = streams.TargetStream.Position; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(6)); //briefing intro streams.TargetWriter.Write((short)(streams.SourceReader.ReadInt16() + 10 * Briefs[1])); // adjust length for add/moves context.SourceCursor += 2; streams.TargetStream.Position += 20 * Briefs[1] + 2; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(0x32A)); //briefing content streams.TargetStream.Position = XWAPos; briefingLength = (short)(streams.TargetReader.ReadInt16() * 0x19 / 0x14); // adjust overall briefing length streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); streams.TargetStream.Position += 8; for (var i = 0; i < 0x320; i += 4) // work our way through length of briefing. i automatically increases by 4 per event { briefingLength = streams.TargetReader.ReadInt16(); if (briefingLength == 0x270F) { break; // stop check at t=9999, end briefing } briefingLength = (short)(briefingLength * 0x19 / 0x14); streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = streams.TargetReader.ReadInt16(); // now get the event type if (briefingLength > 8 && briefingLength < 17) // FG tags 1-8 { briefingLength = streams.TargetReader.ReadInt16(); // FG number streams.TargetStream.Position -= 2; streams.TargetWriter.Write(fgIcons[briefingLength]); // Overwrite with the Icon# i += 2; } else if (briefingLength == 7) // Zoom map command { briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 58); // X streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 88); // Y streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); i += 4; } else { streams.TargetStream.Position += 2 * BRF[briefingLength]; // skip over vars i += (short)(2 * BRF[briefingLength]); // increase length counter by skipped vars } } streams.TargetStream.Position = 0x8960 + (XWABriefing2 - XWABriefing1) + (FGs + 2) * 0xE3E + Messages * 0xA2; //[JB] FGs+2 context.WriteToTargetBuffer(0); //show the non-existant briefing context.WriteToTargetBuffer(1); //show the non-existant briefing streams.TargetStream.Position += 8; for (var i = 0; i < 32; i++) //tags { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; for (var i = 0; i < 32; i++) //strings { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; } else { context.SourceCursor += 0x334; //Jump to tags for (briefingLength = 0; briefingLength < 64; briefingLength++) //32 tags + 32 strings { context.SourceCursor += streams.SourceReader.ReadInt16(); } streams.TargetStream.Position += 0x4614; //Empty briefing plus empty tags/strings } #endregion Briefing2 streams.TargetStream.Position += 0x187C; //Skip EditorNotes streams.TargetStream.Position += 0x3200; //Skip BriefingStringNotes streams.TargetStream.Position += 0x1900; //Skip MessageNotes streams.TargetStream.Position += 0xBB8; //Skip EomNotes streams.TargetStream.Position += 0xFA0; //Skip Unknown streams.TargetStream.Position += 0x12C; //Skip DescriptionNotes //[JB] Briefings have variable length. Need to step over the remaining 6 XvT briefings by properly calculating how big they are. for (var i = 2; i < 8; i++) { context.SourceCursor += 0x334; //Jump to tags for (briefingLength = 0; briefingLength < 64; briefingLength++) //32 tags + 32 strings { context.SourceCursor += streams.SourceReader.ReadInt16(); } } #region FG Goal strings for (var i = 0; i < context.FlightGroupCount; i++) { for (briefingLength = 0; briefingLength < 24; briefingLength++) //8 goals * 3 strings { if (streams.SourceStream.ReadByte() == 0) { streams.TargetStream.Position++; context.SourceCursor += 63; } else { context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(64)); } } } streams.TargetStream.Position += 48; //compensate for adding the Backdrop [JB] Was 24 for one backdrop, needs to be 48 since I added an extra one. #endregion #region Global Goal strings for (var i = 0; i < 10; i++) { for (briefingLength = 0; briefingLength < 36; briefingLength++) { if (streams.SourceStream.ReadByte() == 0) { streams.TargetStream.Position++; context.SourceCursor += 63; } else { context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(64)); } } context.SourceCursor += 3072; } #endregion streams.TargetStream.Position += 3552; //skip custom order strings #region Debrief and Descrip if (!isBoPMision) { streams.TargetStream.Position += 4096; context.WriteToTargetBuffer(35); streams.TargetStream.Position += 4095; context.WriteToTargetBuffer(35); for (var i = 0; i < 1024; i++) { int d = streams.SourceStream.ReadByte(); briefingLength = (short)(1024 - i); switch (d) { case -1: i = 1024; break; case 0: i = 1024; break; case 10: context.WriteToTargetBuffer(35); break; default: context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); break; } } streams.TargetStream.Position += 3071 + briefingLength; } else { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4096)); // Debrief context.WriteToTargetBuffer(35); streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4095)); // Hints context.SourceCursor++; context.WriteToTargetBuffer(35); streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4095)); // Brief/Description } #endregion context.WriteToTargetBuffer(0); //EOF return(true); }
public override MemberDeclarationSyntax VisitForInterface(ConversionContext context, InterfaceDeclarationSyntax interfaceSyntax, InitializerDeclaration declaration) { throw new InvalidOperationException("Initializers are not valid on interfaces."); }
public abstract ExpressionSyntax Visit(ConversionContext context, T expr);
public XvTMessage(ConversionContext context) { }
protected sealed override ExpressionSyntax Visit(ConversionContext context, Expression expr) => Visit(context, (T)expr);
public override ExpressionSyntax Visit(ConversionContext context, SuperExpr expr) => SyntaxFactory.BaseExpression();
public override MemberDeclarationSyntax VisitForInterface(ConversionContext context, InterfaceDeclarationSyntax interfaceSyntax, ClassOrInterfaceDeclaration declaration) { return(VisitClassDeclaration(context, declaration)); }
protected sealed override StatementSyntax Visit(ConversionContext context, Statement statement) { return(Visit(context, (T)statement).AddComments(context, statement)); }
public static InterfaceDeclarationSyntax VisitInterfaceDeclaration(ConversionContext context, ClassOrInterfaceDeclaration javai, bool isNested = false) { string name = "I" + javai.getName(); if (!isNested) { context.RootTypeName = name; } context.LastTypeName = name; var classSyntax = SyntaxFactory.InterfaceDeclaration(name); var typeParams = javai.getTypeParameters().ToList <TypeParameter>(); if (typeParams != null && typeParams.Count > 0) { classSyntax = classSyntax.AddTypeParameterListParameters(typeParams.Select(i => SyntaxFactory.TypeParameter(i.getName())).ToArray()); } var mods = javai.getModifiers(); if (mods.HasFlag(Modifier.PRIVATE)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); } if (mods.HasFlag(Modifier.PROTECTED)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); } if (mods.HasFlag(Modifier.PUBLIC)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); } if (mods.HasFlag(Modifier.FINAL)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.SealedKeyword)); } var implements = javai.getImplements().ToList <ClassOrInterfaceType>(); if (implements != null) { foreach (var implement in implements) { classSyntax = classSyntax.AddBaseListTypes(SyntaxFactory.SimpleBaseType(TypeHelper.GetSyntaxFromType(implement))); } } var members = javai.getMembers().ToList <BodyDeclaration>(); foreach (var member in members) { var syntax = BodyDeclarationVisitor.VisitBodyDeclarationForInterface(context, classSyntax, member); if (syntax != null) { classSyntax = classSyntax.AddMembers(syntax); } } return(classSyntax); }
public abstract MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, T declaration);
public static ClassDeclarationSyntax VisitClassDeclaration(ConversionContext context, ClassOrInterfaceDeclaration javac, bool isNested = false) { string name = javac.getName(); if (!isNested) { context.RootTypeName = name; } context.LastTypeName = name; var classSyntax = SyntaxFactory.ClassDeclaration(name); var typeParams = javac.getTypeParameters().ToList <TypeParameter>(); if (typeParams != null && typeParams.Count > 0) { classSyntax = classSyntax.AddTypeParameterListParameters(typeParams.Select(i => SyntaxFactory.TypeParameter(i.getName())).ToArray()); } var mods = javac.getModifiers(); if (mods.HasFlag(Modifier.PRIVATE)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); } if (mods.HasFlag(Modifier.PROTECTED)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); } if (mods.HasFlag(Modifier.PUBLIC)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); } if (mods.HasFlag(Modifier.ABSTRACT)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.AbstractKeyword)); } if (mods.HasFlag(Modifier.FINAL)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.SealedKeyword)); } var extends = javac.getExtends().ToList <ClassOrInterfaceType>(); if (extends != null) { foreach (var extend in extends) { classSyntax = classSyntax.AddBaseListTypes(SyntaxFactory.SimpleBaseType(TypeHelper.GetSyntaxFromType(extend))); } } var implements = javac.getImplements().ToList <ClassOrInterfaceType>(); if (implements != null) { foreach (var implement in implements) { classSyntax = classSyntax.AddBaseListTypes(SyntaxFactory.SimpleBaseType(TypeHelper.GetSyntaxFromType(implement, true))); } } var members = javac.getMembers().ToList <BodyDeclaration>(); foreach (var member in members) { if (member is ClassOrInterfaceDeclaration) { var childc = (ClassOrInterfaceDeclaration)member; if (childc.isInterface()) { var childInt = VisitInterfaceDeclaration(context, childc, true); classSyntax = classSyntax.AddMembers(childInt); } else { var childClass = VisitClassDeclaration(context, childc, true); classSyntax = classSyntax.AddMembers(childClass); } } else { var syntax = BodyDeclarationVisitor.VisitBodyDeclarationForClass(context, classSyntax, member); if (syntax != null) { classSyntax = classSyntax.AddMembers(syntax); } } while (context.PendingAnonymousTypes.Count > 0) { var anon = context.PendingAnonymousTypes.Dequeue(); classSyntax = classSyntax.AddMembers(anon); } } return(classSyntax); }
protected sealed override MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, BodyDeclaration declaration) { return(VisitForClass(context, classSyntax, (T)declaration)); }
// Edit Field Value Converter SET function for Choice fields. public static void SetConvertedChoiceEditFieldValue(string fieldName, object fieldValue, ListItem item, ConversionContext context, string customCategory) { ObservableCollection <ChoiceFieldViewModel> choices = fieldValue as ObservableCollection <ChoiceFieldViewModel>; bool isCustomValue = true; string specifiedChoice = string.Empty; if (choices != null) { foreach (ChoiceFieldViewModel choiceItem in choices) { if ((choiceItem.IsChecked) || (choiceItem.Name.Equals(customCategory, StringComparison.CurrentCultureIgnoreCase))) { specifiedChoice = choiceItem.Name; isCustomValue = false; break; } } if (isCustomValue) { specifiedChoice = customCategory; } } else { specifiedChoice = customCategory; } item[fieldName] = specifiedChoice; }
public override ExpressionSyntax Visit(ConversionContext context, NameExpr nameExpr) { return(SyntaxFactory.IdentifierName(TypeHelper.ConvertIdentifierName(nameExpr.getName()))); }
public override MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, ConstructorDeclaration ctorDecl) { var ctorSyntax = SyntaxFactory.ConstructorDeclaration(classSyntax.Identifier.Value.ToString()) .WithLeadingTrivia(SyntaxFactory.CarriageReturnLineFeed); var mods = ctorDecl.getModifiers(); if (mods.HasFlag(Modifier.PUBLIC)) { ctorSyntax = ctorSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); } if (mods.HasFlag(Modifier.PROTECTED)) { ctorSyntax = ctorSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); } if (mods.HasFlag(Modifier.PRIVATE)) { ctorSyntax = ctorSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); } var parameters = ctorDecl.getParameters().ToList <Parameter>(); if (parameters != null && parameters.Count > 0) { var paramSyntaxes = new List <ParameterSyntax>(); foreach (var param in parameters) { var name = param.getId().toString(); var paramSyntax = SyntaxFactory.Parameter(SyntaxFactory.ParseToken(TypeHelper.ConvertIdentifierName(name))); if (param.isVarArgs()) { paramSyntax = paramSyntax.WithType(SyntaxFactory.ParseTypeName(TypeHelper.ConvertType(param.getType().toString()) + "[]")) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ParamsKeyword))); } else { paramSyntax = paramSyntax.WithType(SyntaxFactory.ParseTypeName(TypeHelper.ConvertType(param.getType().toString()))); } paramSyntaxes.Add(paramSyntax); } ctorSyntax = ctorSyntax.AddParameterListParameters(paramSyntaxes.ToArray()); } //chaws: var block = ctorDecl.getBlock(); var block = ctorDecl.getBody(); var statements = block.getStmts().ToList <Statement>(); // handle special case for constructor invocation if (statements != null && statements.Count > 0 && statements[0] is ExplicitConstructorInvocationStmt) { var ctorInvStmt = (ExplicitConstructorInvocationStmt)statements[0]; statements.RemoveAt(0); ArgumentListSyntax argsSyntax = null; var initargs = ctorInvStmt.getArgs().ToList <Expression>(); if (initargs != null && initargs.Count > 0) { var initargslist = new List <ArgumentSyntax>(); foreach (var arg in initargs) { var argsyn = ExpressionVisitor.VisitExpression(context, arg); initargslist.Add(SyntaxFactory.Argument(argsyn)); } argsSyntax = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(initargslist, Enumerable.Repeat(SyntaxFactory.Token(SyntaxKind.CommaToken), initargslist.Count - 1))); } ConstructorInitializerSyntax ctorinitsyn; if (ctorInvStmt.isThis()) { ctorinitsyn = SyntaxFactory.ConstructorInitializer(SyntaxKind.ThisConstructorInitializer, argsSyntax); } else { ctorinitsyn = SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer, argsSyntax); } ctorSyntax = ctorSyntax.WithInitializer(ctorinitsyn); } var statementSyntax = StatementVisitor.VisitStatements(context, statements); ctorSyntax = ctorSyntax.AddBodyStatements(statementSyntax.ToArray()); return(ctorSyntax); }
public bool IsConvertible(ConversionContext conversion) { return conversion.HasValue==false; }
public override ExpressionSyntax Visit(ConversionContext context, NullLiteralExpr expr) { return(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)); }
public ConversionResult Convert(ConversionContext conversion) { return conversion.Unconverted(); }
public bool IsConvertible(ConversionContext conversion) { return(conversion.Value is Int32 && conversion.DestinationPropertyType == typeof(String)); }
private Vertex[] ConvertMappingConditionsToVertices( ConversionContext<DomainConstraint<string, ValueCondition>> converter, DomainVariable<string, ValueCondition>[] variables) { var conditions = new Vertex[NormalizedEntityTypeMappings.Count]; for (var i = 0; i < conditions.Length; i++) { var typeMapping = NormalizedEntityTypeMappings[i]; // create conjunction representing the condition var condition = Vertex.One; for (var j = 0; j < DiscriminatorColumns.Count; j++) { var columnCondition = typeMapping.ColumnConditions[j]; if (null != columnCondition) { var conditionValue = columnCondition.ConditionValue; if (conditionValue.IsNotNullCondition) { // the 'not null' condition is not actually part of the domain (since it // covers other elements), so create a Not(value in {null}) condition var isNull = new TermExpr<DomainConstraint<string, ValueCondition>>( new DomainConstraint<string, ValueCondition>(variables[j], ValueCondition.IsNull)); var isNullVertex = converter.TranslateTermToVertex(isNull); condition = converter.Solver.And(condition, converter.Solver.Not(isNullVertex)); } else { var hasValue = new TermExpr<DomainConstraint<string, ValueCondition>>( new DomainConstraint<string, ValueCondition>(variables[j], conditionValue)); condition = converter.Solver.And(condition, converter.TranslateTermToVertex(hasValue)); } } } conditions[i] = condition; } return conditions; }
public ConversionResult Convert(ConversionContext conversion) { return conversion.Result(conversion.HasValue?conversion.Value.ToString():null); }