public virtual Net.Vpc.Upa.Types.DataTypeTransform CreateTypeTransform(Net.Vpc.Upa.PersistenceUnit pu, Net.Vpc.Upa.Types.DataType source, Net.Vpc.Upa.Types.DataTypeTransformConfig transformConfig) { if (transformConfig == null) { return(null); } if (transformConfig is Net.Vpc.Upa.Types.DataTypeTransform) { return((Net.Vpc.Upa.Types.DataTypeTransform)transformConfig); } else if ((transformConfig is Net.Vpc.Upa.Types.CustomExpressionDataTypeTransform)) { Net.Vpc.Upa.Types.CustomExpressionDataTypeTransform c = (Net.Vpc.Upa.Types.CustomExpressionDataTypeTransform)transformConfig; return(CreateTypeTransform(pu, source, CreateDataTypeTransformConfigArray(c.GetExpression()))); } else if ((transformConfig is Net.Vpc.Upa.Types.CustomTypeDataTypeTransform)) { Net.Vpc.Upa.Types.CustomTypeDataTypeTransform c = (Net.Vpc.Upa.Types.CustomTypeDataTypeTransform)transformConfig; return(pu.GetFactory().CreateObject <T>(c.GetCustomType())); } else if ((transformConfig is Net.Vpc.Upa.Types.CustomInstanceDataTypeTransform)) { Net.Vpc.Upa.Types.CustomInstanceDataTypeTransform c = (Net.Vpc.Upa.Types.CustomInstanceDataTypeTransform)transformConfig; Net.Vpc.Upa.Types.DataTypeTransform i = c.GetInstance(); return(i); } else if (transformConfig is Net.Vpc.Upa.PasswordTransformConfig) { Net.Vpc.Upa.PasswordTransformConfig p = (Net.Vpc.Upa.PasswordTransformConfig)transformConfig; return(CreatePasswordTransform(pu, source, p)); } else if (transformConfig is Net.Vpc.Upa.Types.SecretTransformConfig) { Net.Vpc.Upa.Types.SecretTransformConfig p = (Net.Vpc.Upa.Types.SecretTransformConfig)transformConfig; return(CreateSecretTransform(pu, source, p)); } else if (transformConfig is Net.Vpc.Upa.Types.StringEncoderTransformConfig) { Net.Vpc.Upa.Types.StringEncoderTransformConfig p = (Net.Vpc.Upa.Types.StringEncoderTransformConfig)transformConfig; return(CreateStringEncoderTransform(pu, source, p)); } else if (transformConfig is Net.Vpc.Upa.Types.ByteArrayEncoderTransformConfig) { Net.Vpc.Upa.Types.ByteArrayEncoderTransformConfig p = (Net.Vpc.Upa.Types.ByteArrayEncoderTransformConfig)transformConfig; return(CreateByteArrayEncoderTransform(pu, source, p)); } else if (transformConfig is Net.Vpc.Upa.Types.CharArrayEncoderTransformConfig) { Net.Vpc.Upa.Types.CharArrayEncoderTransformConfig p = (Net.Vpc.Upa.Types.CharArrayEncoderTransformConfig)transformConfig; return(CreateCharArrayEncoderTransform(pu, source, p)); } throw new Net.Vpc.Upa.Exceptions.UPAException("Unsupported Transform Method", source); }
public virtual Net.Vpc.Upa.Types.DataTypeTransform CreateStringEncoderTransform(Net.Vpc.Upa.PersistenceUnit pu, Net.Vpc.Upa.Types.DataType source, Net.Vpc.Upa.Types.StringEncoderTransformConfig p) { if (p == null) { p = new Net.Vpc.Upa.Types.StringEncoderTransformConfig(); } Net.Vpc.Upa.Types.ByteArrayEncoder toStringEncoder = null; int baseSize = 0; object encoderObject = p.GetEncoder(); if (encoderObject == null) { encoderObject = Net.Vpc.Upa.Config.StringEncoderType.DEFAULT; } if (source is Net.Vpc.Upa.Types.IntType) { toStringEncoder = Net.Vpc.Upa.Impl.Transform.IntToStringByteArrayEncoder.INSTANCE; baseSize = 255; } else if (source is Net.Vpc.Upa.Types.LongType) { toStringEncoder = Net.Vpc.Upa.Impl.Transform.LongToStringByteArrayEncoder.INSTANCE; baseSize = 255; } else if (source is Net.Vpc.Upa.Types.DoubleType) { toStringEncoder = Net.Vpc.Upa.Impl.Transform.DoubleToStringByteArrayEncoder.INSTANCE; baseSize = 255; } else if (source is Net.Vpc.Upa.Types.FloatType) { toStringEncoder = Net.Vpc.Upa.Impl.Transform.FloatToStringByteArrayEncoder.INSTANCE; baseSize = 255; } else if (source is Net.Vpc.Upa.Types.ByteArrayType) { toStringEncoder = Net.Vpc.Upa.Impl.Transform.IdentityByteArrayEncoder.INSTANCE; baseSize = ((Net.Vpc.Upa.Types.ByteArrayType)source).GetMaxSize() == null ? ((int)(0)) : (((Net.Vpc.Upa.Types.ByteArrayType)source).GetMaxSize()).Value; if (encoderObject == Net.Vpc.Upa.Config.StringEncoderType.DEFAULT) { encoderObject = Net.Vpc.Upa.Config.StringEncoderType.HEXADECIMAL; } } else if (source is Net.Vpc.Upa.Types.EnumType) { Net.Vpc.Upa.Types.EnumType et = (Net.Vpc.Upa.Types.EnumType)source; toStringEncoder = new Net.Vpc.Upa.Impl.Transform.EnumToStringByteArrayEncoder(source.GetPlatformType()); //should we baseSize = 3; foreach (object @value in et.GetValues()) { if (@value != null) { int cs = (System.Convert.ToString(@value)).Length; if (cs > baseSize) { baseSize = cs; } } } } else { throw new System.ArgumentException("Unsupported"); } if (baseSize <= 0) { baseSize = 255; } Net.Vpc.Upa.Types.StringEncoder encoder = null; if (encoderObject is Net.Vpc.Upa.Config.StringEncoderType) { Net.Vpc.Upa.Config.StringEncoderType set = (Net.Vpc.Upa.Config.StringEncoderType)encoderObject; if (set == Net.Vpc.Upa.Config.StringEncoderType.DEFAULT) { set = Net.Vpc.Upa.Config.StringEncoderType.PLAIN; } if (set == Net.Vpc.Upa.Config.StringEncoderType.CUSTOM) { throw new System.ArgumentException("Unsupported"); } switch (set) { case Net.Vpc.Upa.Config.StringEncoderType.BASE64: { encoder = Net.Vpc.Upa.Impl.Transform.Base64Encoder.INSTANCE; if (p.GetSize() <= 0) { p.SetSize(baseSize * 4 / 3 + 2); } break; } case Net.Vpc.Upa.Config.StringEncoderType.HEXADECIMAL: { encoder = Net.Vpc.Upa.Impl.Transform.HexaEncoder.INSTANCE; if (p.GetSize() <= 0) { p.SetSize(baseSize * 2); } break; } case Net.Vpc.Upa.Config.StringEncoderType.PLAIN: { encoder = Net.Vpc.Upa.Impl.Transform.PlainStringEncoder.INSTANCE; if (p.GetSize() <= 0) { p.SetSize(baseSize); } break; } case Net.Vpc.Upa.Config.StringEncoderType.XML: { if (p.GetSize() <= 0) { p.SetSize(baseSize); } throw new System.ArgumentException("Unsupported yet " + set + " Encoder"); } case Net.Vpc.Upa.Config.StringEncoderType.JSON: { if (p.GetSize() <= 0) { p.SetSize(baseSize); } throw new System.ArgumentException("Unsupported yet " + set + " Encoder"); } default: { throw new System.ArgumentException("Unsupported yet " + set + " Encoder"); } } } else if (encoderObject is string) { return(pu.GetFactory().CreateObject <T>((string)encoderObject)); } else if (encoderObject is System.Type) { return((Net.Vpc.Upa.Types.DataTypeTransform)pu.GetFactory().CreateObject <object>((System.Type)encoderObject)); } else { throw new System.ArgumentException("Unsupported Encoder " + encoderObject); } return(new Net.Vpc.Upa.Impl.Transform.StringEncoderDataTypeTransform(encoder, source, p.GetSize(), toStringEncoder)); }
private Net.Vpc.Upa.Types.DataTypeTransformConfig CreateDataTypeTransformConfig(string name, string[] args) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (name.Equals("ToByteArray", System.StringComparison.InvariantCultureIgnoreCase)) { Net.Vpc.Upa.Types.StringEncoderTransformConfig c = new Net.Vpc.Upa.Types.StringEncoderTransformConfig(); if (args.Length == 0) { return(c); } else if (args.Length == 1) { Net.Vpc.Upa.Config.StringEncoderType t = default(Net.Vpc.Upa.Config.StringEncoderType); try { t = (Net.Vpc.Upa.Config.StringEncoderType)(System.Enum.Parse(typeof(Net.Vpc.Upa.Config.StringEncoderType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.Config.StringEncoderType)) { c.SetEncoder(t); } else { c.SetEncoder(args[0]); } return(c); } else { throw new System.ArgumentException("ToString: Invalid argument count"); } } if (name.Equals("ToByteArray", System.StringComparison.InvariantCultureIgnoreCase)) { Net.Vpc.Upa.Types.ByteArrayEncoderTransformConfig c = new Net.Vpc.Upa.Types.ByteArrayEncoderTransformConfig(); if (args.Length == 0) { return(c); } else if (args.Length == 1) { c.SetEncoder(args[0]); return(c); } else { throw new System.ArgumentException("ToByteArray: Invalid argument count"); } } if (name.Equals("Converter", System.StringComparison.InvariantCultureIgnoreCase)) { if (args.Length == 1) { return(new Net.Vpc.Upa.Types.CustomTypeDataTypeTransform(args[0])); } else { throw new System.ArgumentException("Config: Invalid argument count"); } } if (name.Equals("Password", System.StringComparison.InvariantCultureIgnoreCase)) { if (args.Length == 0) { return(new Net.Vpc.Upa.PasswordTransformConfig()); } else if (args.Length == 1) { Net.Vpc.Upa.PasswordTransformConfig c = new Net.Vpc.Upa.PasswordTransformConfig(); Net.Vpc.Upa.PasswordStrategyType t = default(Net.Vpc.Upa.PasswordStrategyType); try { t = (Net.Vpc.Upa.PasswordStrategyType)(System.Enum.Parse(typeof(Net.Vpc.Upa.PasswordStrategyType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.PasswordStrategyType)) { c.SetCipherStrategy(t); } else { c.SetCipherStrategy(args[0]); } return(c); } else if (args.Length == 2) { Net.Vpc.Upa.PasswordTransformConfig c = new Net.Vpc.Upa.PasswordTransformConfig(); Net.Vpc.Upa.PasswordStrategyType t = default(Net.Vpc.Upa.PasswordStrategyType); try { t = (Net.Vpc.Upa.PasswordStrategyType)(System.Enum.Parse(typeof(Net.Vpc.Upa.PasswordStrategyType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.PasswordStrategyType)) { c.SetCipherStrategy(t); } else { c.SetCipherStrategy(args[0]); } c.SetCipherValue(args[1]); return(c); } else { throw new System.ArgumentException("Password: Invalid argument count"); } } if (name.Equals("Secret", System.StringComparison.InvariantCultureIgnoreCase)) { if (args.Length == 0) { return(new Net.Vpc.Upa.Types.SecretTransformConfig()); } else if (args.Length == 1) { Net.Vpc.Upa.Types.SecretTransformConfig c = new Net.Vpc.Upa.Types.SecretTransformConfig(); Net.Vpc.Upa.SecretStrategyType t = default(Net.Vpc.Upa.SecretStrategyType); try { t = (Net.Vpc.Upa.SecretStrategyType)(System.Enum.Parse(typeof(Net.Vpc.Upa.SecretStrategyType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.SecretStrategyType)) { c.SetSecretStrategy(t); } else { c.SetSecretStrategy(args[0]); } return(c); } else if (args.Length == 2) { Net.Vpc.Upa.Types.SecretTransformConfig c = new Net.Vpc.Upa.Types.SecretTransformConfig(); Net.Vpc.Upa.SecretStrategyType t = default(Net.Vpc.Upa.SecretStrategyType); try { t = (Net.Vpc.Upa.SecretStrategyType)(System.Enum.Parse(typeof(Net.Vpc.Upa.SecretStrategyType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.SecretStrategyType)) { c.SetSecretStrategy(t); } else { c.SetSecretStrategy(args[0]); } c.SetSize(System.Convert.ToInt32(args[1])); return(c); } else if (args.Length == 3) { Net.Vpc.Upa.Types.SecretTransformConfig c = new Net.Vpc.Upa.Types.SecretTransformConfig(); Net.Vpc.Upa.SecretStrategyType t = default(Net.Vpc.Upa.SecretStrategyType); try { t = (Net.Vpc.Upa.SecretStrategyType)(System.Enum.Parse(typeof(Net.Vpc.Upa.SecretStrategyType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.SecretStrategyType)) { c.SetSecretStrategy(t); } else { c.SetSecretStrategy(args[0]); } c.SetSize(System.Convert.ToInt32(args[1])); c.SetEncodeKey(args[2]); c.SetDecodeKey(args[2]); return(c); } else if (args.Length == 4) { Net.Vpc.Upa.Types.SecretTransformConfig c = new Net.Vpc.Upa.Types.SecretTransformConfig(); Net.Vpc.Upa.SecretStrategyType t = default(Net.Vpc.Upa.SecretStrategyType); try { t = (Net.Vpc.Upa.SecretStrategyType)(System.Enum.Parse(typeof(Net.Vpc.Upa.SecretStrategyType), args[0].ToUpper())); } catch (System.Exception e) { } // if (t != default(Net.Vpc.Upa.SecretStrategyType)) { c.SetSecretStrategy(t); } else { c.SetSecretStrategy(args[0]); } c.SetSize(System.Convert.ToInt32(args[1])); c.SetEncodeKey(args[2]); c.SetDecodeKey(args[3]); return(c); } else { throw new System.ArgumentException("Password: Invalid argument count"); } } else { throw new System.ArgumentException("Invalid converter " + name); } }