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 CreateSecretTransform(Net.Vpc.Upa.PersistenceUnit pu, Net.Vpc.Upa.Types.DataType source, Net.Vpc.Upa.Types.SecretTransformConfig p) { if (p == null) { p = new Net.Vpc.Upa.Types.SecretTransformConfig(); } object s = p.GetSecretStrategy(); if (s == null) { s = Net.Vpc.Upa.SecretStrategyType.DEFAULT; } if (s is Net.Vpc.Upa.SecretStrategyType) { switch (((Net.Vpc.Upa.SecretStrategyType)s)) { case Net.Vpc.Upa.SecretStrategyType.BASE64: { s = Net.Vpc.Upa.Impl.Transform.Base64SecretStrategy.INSTANCE; break; } case Net.Vpc.Upa.SecretStrategyType.DEFAULT: { s = new Net.Vpc.Upa.Impl.Transform.DefaultSecretStrategy(); break; } default: { throw new Net.Vpc.Upa.Exceptions.UPAException("Unsupported", s); } } } else if (s is string) { string ss = (string)s; if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(ss)) { s = (Net.Vpc.Upa.SecretStrategy)pu.GetFactory().CreateObject <T>((string)s); } else { //use default s = new Net.Vpc.Upa.Impl.Transform.DefaultSecretStrategy(); } } else if (s is System.Type) { s = (Net.Vpc.Upa.SecretStrategy)pu.GetFactory().CreateObject <object>((System.Type)s); } else if (s is Net.Vpc.Upa.SecretStrategy) { s = (Net.Vpc.Upa.SecretStrategy)s; } else { throw new System.ArgumentException("Unsupported SecretStrategy " + s); } Net.Vpc.Upa.SecretStrategy st = (Net.Vpc.Upa.SecretStrategy)s; st.Init(pu, p.GetEncodeKey(), p.GetDecodeKey()); p.SetSecretStrategy(st); if (!(source is Net.Vpc.Upa.Types.ByteArrayType)) { Net.Vpc.Upa.Types.DataTypeTransform t = null; t = CreateByteArrayEncoderTransform(pu, source, null); Net.Vpc.Upa.Impl.Transform.SecretDataTypeTransform t2 = new Net.Vpc.Upa.Impl.Transform.SecretDataTypeTransform(st, t.GetTargetType(), p.GetSize()); return(t.Chain(t2)); } return(new Net.Vpc.Upa.Impl.Transform.SecretDataTypeTransform(st, source, p.GetSize())); }
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); } }