public SettingInvalidReferenceHandling()
 {
     Name = "INVALIDREFERENCEHANDLING"; //uppercase
     Description = "Setting for invalid reference handling.";
     Type = DBString.UUID;
     Default = new DBString(BehaviourOnInvalidReference.ignore.ToString().ToUpper());
     this._Value = Default.Clone();
     Behaviour = BehaviourOnInvalidReference.ignore;
 }
예제 #2
0
 public SettingUndefAttrBehaviour()
 {
     Name            = "SETUNDEFBEHAVE";
     Description     = "Set the behave for undefined attributes.";
     Type            = DBString.UUID;
     Default         = new DBString(UndefAttributeBehaviour.allow.ToString());
     this._Value     = Default.Clone();
     Behaviour       = UndefAttributeBehaviour.allow;
 }
예제 #3
0
        private static Boolean ConvertToBestMatchingTypeReverse(ref ADBBaseObject myDBBaseObjectB, ref ADBBaseObject myDBBaseObjectA)
        {
            #region Both are not unknown

            if ((myDBBaseObjectA.Type != BasicType.Unknown) && (myDBBaseObjectB.Type != BasicType.Unknown))
            {

                #region Types matching, we can leave

                if (myDBBaseObjectA.Type == myDBBaseObjectB.Type)
                {
                    return true;
                }

                #endregion

                #region DBList and DBReference are not matchable with other types

                else if (myDBBaseObjectA is DBEdge || myDBBaseObjectA is DBReference || myDBBaseObjectB is DBEdge || myDBBaseObjectB is DBReference)
                {
                    return false;
                }

                #endregion

                #region The types does not match - so try to convert the right-handed to the left handed type

                else if (myDBBaseObjectA is DBUInt64)
                {
                    //
                    if (DBUInt64.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return true;
                    }
                    return false;
                }

                else if (myDBBaseObjectA is DBInt64)
                {
                    //
                    if (DBInt64.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return true;
                    }
                    // do not change to ConvertToBestMatchingType(ref myDBBaseObjectB, ref myDBBaseObjectA)
                    return false;
                }

                else if (myDBBaseObjectA is DBDouble)
                {
                    //
                    if (DBDouble.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return true;
                    }
                    return false;
                }

                else if (myDBBaseObjectA is DBDateTime)
                {
                    //
                    if (DBDateTime.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return true;
                    }
                    return false;
                }

                else if (myDBBaseObjectA is DBBoolean)
                {
                    //
                    if (DBDouble.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return true;
                    }
                    return false;
                }

                else if (myDBBaseObjectA is DBString)
                {
                    //
                    if (DBString.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return true;
                    }
                    return false;
                }

                #endregion

                // we couldnt find a matching type for both are not unknown
                return false;

            }

            #endregion

            #region Both are strings - thats fine

            else if (myDBBaseObjectA is DBString && myDBBaseObjectB is DBString)
            {
                return true;
            }

            #endregion

            #region only one is unknown

            else if (!(myDBBaseObjectA.Type == BasicType.Unknown && myDBBaseObjectB.Type == BasicType.Unknown))
            {

                #region myDBBaseObjectA is unknown - try to use the type of myDBBaseObjectB

                if (myDBBaseObjectA.Type == BasicType.Unknown)
                {

                    try
                    {
                        // avaoid changing a Double to Int64
                        if (myDBBaseObjectA is DBNumber
                            && (myDBBaseObjectB.Type == BasicType.Int64 || myDBBaseObjectB.Type == BasicType.UInt64))
                        {
                            if (myDBBaseObjectA.Value is Double && DBDouble.IsValid(myDBBaseObjectB.Value))
                            {
                                myDBBaseObjectA = new DBDouble(myDBBaseObjectA.Value);
                                myDBBaseObjectB = new DBDouble(myDBBaseObjectB.Value);
                                return true;
                            }
                        }

                        myDBBaseObjectA = myDBBaseObjectB.Clone(myDBBaseObjectA.Value);

                    }

                    catch
                    {
                        return false;
                    }

                }

                #endregion

                #region myDBBaseObjectB is unknown - try to use the type of myDBBaseObjectA

                else if (myDBBaseObjectB.Type == BasicType.Unknown)
                {
                    try
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                    }
                    catch
                    {
                        return false;
                    }
                }

                else
                {
                    return false;
                }

                #endregion

            }

            #endregion

            #region both are unknown

            #region One of them is expected as a Number - so try to parse both as a number

            else if (myDBBaseObjectA is DBNumber || myDBBaseObjectB is DBNumber)
            {

                if (DBInt64.IsValid(myDBBaseObjectA.Value) && DBInt64.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBInt64(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBInt64(myDBBaseObjectB.Value);
                }

                else if (DBUInt64.IsValid(myDBBaseObjectA.Value) && DBUInt64.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBUInt64(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBUInt64(myDBBaseObjectB.Value);
                }

                else if (DBDouble.IsValid(myDBBaseObjectA.Value) && DBDouble.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBDouble(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBDouble(myDBBaseObjectB.Value);
                }

                else
                {
                    return false;
                }

            }

            #endregion

            #region Try all other dataTypes

            else
            {

                // check all types beginning with the hardest and ending with string (matches all)
                if (DBDateTime.IsValid(myDBBaseObjectA.Value) && DBDateTime.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBDateTime(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBDateTime(myDBBaseObjectB.Value);
                }

                else if (DBBoolean.IsValid(myDBBaseObjectA.Value) && DBBoolean.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBBoolean(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBBoolean(myDBBaseObjectB.Value);
                }

                else if (DBEdge.IsValid(myDBBaseObjectA.Value) && DBEdge.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBEdge(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBEdge(myDBBaseObjectB.Value);
                }

                else if (DBReference.IsValid(myDBBaseObjectA.Value) && DBReference.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBReference(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBReference(myDBBaseObjectB.Value);
                }

                else if (DBString.IsValid(myDBBaseObjectA.Value) && DBString.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBString(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBString(myDBBaseObjectB.Value);
                }

                else
                {
                    return false;
                }

            }

            #endregion

            #endregion

            return true;
        }
예제 #4
0
        public static Exceptional<Boolean> ConvertToBestMatchingType(ref ADBBaseObject myDBBaseObjectA, ref ADBBaseObject myDBBaseObjectB)
        {
            #region Both are not unknown

            if ((myDBBaseObjectA.Type != BasicType.Unknown) && (myDBBaseObjectB.Type != BasicType.Unknown))
            {

                #region Types matching, we can leave

                if (myDBBaseObjectA.Type == myDBBaseObjectB.Type)
                {
                    return new Exceptional<Boolean>(true);
                }

                #endregion

                #region DBList and DBReference are not matchable with other types

                else if (myDBBaseObjectA is DBEdge || myDBBaseObjectB is DBEdge)
                {
                    return new Exceptional<Boolean>(false);
                }

                #endregion

                #region The types does not match - so try to convert the right-handed to the left handed type

                else if (myDBBaseObjectA is DBUInt64)
                {
                    //
                    if (DBUInt64.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return new Exceptional<Boolean>(true);
                    }
                    return new Exceptional<Boolean>(ConvertToBestMatchingTypeReverse(ref myDBBaseObjectA, ref myDBBaseObjectB));
                }

                else if (myDBBaseObjectA is DBInt64)
                {
                    //
                    if (DBInt64.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return new Exceptional<Boolean>(true);
                    }
                    return new Exceptional<Boolean>(ConvertToBestMatchingTypeReverse(ref myDBBaseObjectA, ref myDBBaseObjectB));
                }

                else if (myDBBaseObjectA is DBInt32)
                {
                    //
                    if (DBInt32.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return new Exceptional<Boolean>(true);
                    }
                    return new Exceptional<Boolean>(ConvertToBestMatchingTypeReverse(ref myDBBaseObjectA, ref myDBBaseObjectB));
                }

                else if (myDBBaseObjectA is DBDouble)
                {
                    //
                    if (DBDouble.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return new Exceptional<Boolean>(true);
                    }
                    return new Exceptional<Boolean>(ConvertToBestMatchingTypeReverse(ref myDBBaseObjectA, ref myDBBaseObjectB));
                }

                else if (myDBBaseObjectA is DBDateTime)
                {
                    //
                    if (DBDateTime.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return new Exceptional<Boolean>(true);
                    }
                    return new Exceptional<Boolean>(ConvertToBestMatchingTypeReverse(ref myDBBaseObjectA, ref myDBBaseObjectB));
                }

                else if (myDBBaseObjectA is DBBoolean)
                {
                    //
                    if (DBBoolean.IsValid(myDBBaseObjectB.Value))
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                        return new Exceptional<Boolean>(true);
                    }
                    return new Exceptional<Boolean>(ConvertToBestMatchingTypeReverse(ref myDBBaseObjectA, ref myDBBaseObjectB));
                }

                #endregion

                // we couldnt find a matching type for both are not unknown
                return new Exceptional<bool>(new Error_NotImplemented(new StackTrace(true), String.Format("no type conversion implemented for {0} and {1}", myDBBaseObjectA.GetType(), myDBBaseObjectB.GetType())));

            }

            #endregion

            #region Both are strings - thats fine

            else if (myDBBaseObjectA is DBString && myDBBaseObjectB is DBString)
            {
                return new Exceptional<Boolean>(true);
            }

            #endregion

            #region only one is unknown

            else if (!(myDBBaseObjectA.Type == BasicType.Unknown && myDBBaseObjectB.Type == BasicType.Unknown))
            {

                #region myDBBaseObjectA is unknown - try to use the type of myDBBaseObjectB

                if (myDBBaseObjectA.Type == BasicType.Unknown)
                {

                    // avoid changing a Double to Int64
                    if (myDBBaseObjectA is DBNumber
                        && (myDBBaseObjectB.Type == BasicType.Int64 || myDBBaseObjectB.Type == BasicType.UInt64))
                    {
                        if (myDBBaseObjectA.Value is Double && DBDouble.IsValid(myDBBaseObjectB.Value))
                        {
                            myDBBaseObjectA = new DBDouble(myDBBaseObjectA.Value);
                            myDBBaseObjectB = new DBDouble(myDBBaseObjectB.Value);
                            return new Exceptional<bool>(true);
                        }
                    }

                    try
                    {
                        myDBBaseObjectA = myDBBaseObjectB.Clone(myDBBaseObjectA.Value);
                    }
                    catch
                    {
                        return new Exceptional<bool>(new Error_DataTypeDoesNotMatch(myDBBaseObjectB.GetType().Name, myDBBaseObjectA.Value.GetType().Name));
                    }

                }

                #endregion

                #region myDBBaseObjectB is unknown - try to use the type of myDBBaseObjectA

                else if (myDBBaseObjectB.Type == BasicType.Unknown)
                {

                    // avoid changing a Double to Int64
                    if (myDBBaseObjectB is DBNumber
                        && (myDBBaseObjectA.Type == BasicType.Int64 || myDBBaseObjectA.Type == BasicType.UInt64))
                    {
                        if (myDBBaseObjectB.Value is Double && DBDouble.IsValid(myDBBaseObjectA.Value))
                        {
                            myDBBaseObjectA = new DBDouble(myDBBaseObjectA.Value);
                            myDBBaseObjectB = new DBDouble(myDBBaseObjectB.Value);
                            return new Exceptional<bool>(true);
                        }
                    }

                    try
                    {
                        myDBBaseObjectB = myDBBaseObjectA.Clone(myDBBaseObjectB.Value);
                    }
                    catch
                    {
                        return new Exceptional<bool>(new Error_DataTypeDoesNotMatch(myDBBaseObjectA.Value.GetType().ToString(), myDBBaseObjectB.GetType().ToString()));
                    }

                }

                else
                {
                    return new Exceptional<bool>(false);
                }

                #endregion

            }

            #endregion

            #region both are unknown

            #region One of them is expected as a Number - so try to parse both as a number

            else if (myDBBaseObjectA is DBNumber || myDBBaseObjectB is DBNumber)
            {

                if (DBInt64.IsValid(myDBBaseObjectA.Value) && DBInt64.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBInt64(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBInt64(myDBBaseObjectB.Value);
                }

                else if (DBUInt64.IsValid(myDBBaseObjectA.Value) && DBUInt64.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBUInt64(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBUInt64(myDBBaseObjectB.Value);
                }

                else if (DBDouble.IsValid(myDBBaseObjectA.Value) && DBDouble.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBDouble(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBDouble(myDBBaseObjectB.Value);
                }

                else
                {
                    return new Exceptional<Boolean>(false);
                }

            }

            #endregion

            #region Try all other dataTypes

            else
            {

                // check all types beginning with the hardest and ending with string (matches all)
                if (DBDateTime.IsValid(myDBBaseObjectA.Value) && DBDateTime.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBDateTime(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBDateTime(myDBBaseObjectB.Value);
                }

                else if (DBBoolean.IsValid(myDBBaseObjectA.Value) && DBBoolean.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBBoolean(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBBoolean(myDBBaseObjectB.Value);
                }

                else if (DBEdge.IsValid(myDBBaseObjectA.Value) && DBEdge.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBEdge(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBEdge(myDBBaseObjectB.Value);
                }

                else if (DBReference.IsValid(myDBBaseObjectA.Value) && DBReference.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBReference(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBReference(myDBBaseObjectB.Value);
                }

                else if (DBString.IsValid(myDBBaseObjectA.Value) && DBString.IsValid(myDBBaseObjectB.Value))
                {
                    myDBBaseObjectA = new DBString(myDBBaseObjectA.Value);
                    myDBBaseObjectB = new DBString(myDBBaseObjectB.Value);
                }

                else
                {
                    return new Exceptional<Boolean>(false);
                }

            }

            #endregion

            #endregion

            return new Exceptional<bool>(true);
        }
예제 #5
0
파일: DBString.cs 프로젝트: TheByte/sones
 private void Serialize(ref SerializationWriter mySerializationWriter, DBString myValue)
 {
     mySerializationWriter.WriteString((String)myValue.Value);
 }
예제 #6
0
파일: DBString.cs 프로젝트: TheByte/sones
        private object Deserialize(ref SerializationReader mySerializationReader, DBString myValue)
        {
            myValue._Value = mySerializationReader.ReadString();

            CalcEstimatedSize(myValue);

            return myValue;
        }
예제 #7
0
파일: DBString.cs 프로젝트: TheByte/sones
 private void CalcEstimatedSize(DBString myTypeAttribute)
 {
     //String  + BaseSize
     _estimatedSize = EstimatedSizeConstants.CalcStringSize(_Value) + GetBaseSize();
 }