Beispiel #1
0
 public EnumAsNameMarshaller(System.Type type)
 {
     this.type = type;
     try {
         values = Net.Vpc.Upa.Impl.Util.PlatformUtils.GetEnumValues(type);
         int max = 1;
         foreach (object @object in values)
         {
             int x = (System.Convert.ToString(@object)).Length;
             if (x > max)
             {
                 max = x;
             }
         }
         persistentDataType = new Net.Vpc.Upa.Types.StringType((type).FullName, 0, max, true);
     } catch (System.Exception e) {
         throw new System.Exception("RuntimeException", e);
     }
 }
Beispiel #2
0
 protected internal virtual object GenerateValue(Net.Vpc.Upa.Field field)
 {
     try {
         Net.Vpc.Upa.Types.StringType dataType = (Net.Vpc.Upa.Types.StringType)field.GetDataType();
         string goodChars = null;
         foreach (Net.Vpc.Upa.Types.TypeValueValidator valueValidator in dataType.GetValueValidators())
         {
             if (valueValidator is Net.Vpc.Upa.Types.StringTypeCharValidator)
             {
                 Net.Vpc.Upa.Types.StringTypeCharValidator s = (Net.Vpc.Upa.Types.StringTypeCharValidator)valueValidator;
                 if (s.IsPositive())
                 {
                     goodChars = s.GetChars();
                     break;
                 }
             }
         }
         if (goodChars == null)
         {
             goodChars = Net.Vpc.Upa.Impl.Util.IdentifierUtils.ALPHA_NUM_CHARS;
         }
         //prefer alphabetic at start
         //prefer alphanumeric at end
         //prefer no successive ponctuation
         // if too match difiicult (>100) do any thing
         System.Text.StringBuilder alpha = new System.Text.StringBuilder();
         System.Text.StringBuilder num   = new System.Text.StringBuilder();
         System.Text.StringBuilder ponct = new System.Text.StringBuilder();
         for (int i = 0; i < (goodChars).Length; i++)
         {
             char c = goodChars[i];
             if (char.IsLetter(c))
             {
                 alpha.Append(c);
             }
             else if (char.IsDigit(c))
             {
                 num.Append(c);
             }
             else
             {
                 ponct.Append(c);
             }
         }
         for (int i = 0; i < 100; i++)
         {
             string k  = Net.Vpc.Upa.Impl.Util.IdentifierUtils.GenerateID(dataType.GetMin(), dataType.GetMax(), alpha.ToString(), goodChars, alpha.ToString() + num.ToString());
             bool   ok = true;
             for (int j = 1; j < (k).Length - 2; j++)
             {
                 if (ponct.ToString().IndexOf(k[j]) >= 0 && ponct.ToString().IndexOf(k[j + 1]) >= 0)
                 {
                     ok = false;
                     break;
                 }
             }
             if (ok)
             {
                 return(k);
             }
         }
         return(Net.Vpc.Upa.Impl.Util.IdentifierUtils.GenerateID(dataType.GetMin(), dataType.GetMax(), goodChars, goodChars, goodChars));
     } catch (Net.Vpc.Upa.Types.ConstraintsException e) {
         return(null);
     }
 }