示例#1
0
        /// <summary>
        /// Creates a new scriptable wrapper for the specified object. Use this function instead
        /// of calling the JsObject constructor.
        /// </summary>
        /// <param name="wrappableObject">The object to wrap. It's type will be used as a key
        /// in a lookup for creating the correct wrappable type.</param>
        /// <returns>A new scriptable object that has been created with a type corresponding
        /// to the wrappableObject's type.</returns>
        public static J CreateWrapper <J>(object wrappableObject, ISvgScriptEngine scriptEngine)
            where J : class, IScriptableObject
        {
            // return null if we get null
            if (wrappableObject == null || scriptEngine == null)
            {
                return(null);
            }
            if (scriptEngine.ReferenceCache == null)
            {
                scriptEngine.ReferenceCache = new JsObjectReferenceCache();
            }

            var jsRefCache = scriptEngine.ReferenceCache;

            // Check that the static table is built
            if (_jsMappedTypes == null || _jsMappedTypes.Count == 0)
            {
                InitializeWrapperTypes();
            }

            // Do we already have a wrapper for this object?
            J jsObj = null;
            IScriptableObject jsObjBase = null;

            if (jsRefCache.TryGetValue(wrappableObject, out jsObjBase) && jsObjBase != null)
            {
                jsObj = jsObjBase as J;
                if (jsObj != null)
                {
                    return(jsObj);
                }
            }

            // Return a new instance
            try
            {
                _wrapperArgs[0] = wrappableObject;
                _wrapperArgs[1] = scriptEngine;
                // Normal
                try
                {
                    jsObjBase = (IScriptableObject)_jsMappedTypes.CreateInstance(wrappableObject.GetType().Name, _wrapperArgs);
                    jsRefCache.Add(wrappableObject, jsObjBase);
                    return(jsObjBase as J);
                }
                catch (Exception)
                {
                    // Try the ancestor
                    jsObjBase = (IScriptableObject)_jsMappedTypes.CreateInstance(wrappableObject.GetType().BaseType.Name, _wrapperArgs);
                    jsRefCache.Add(wrappableObject, jsObjBase);
                    return(jsObjBase as J);
                }
            }
            catch (Exception e)
            {
                throw new SvgException(SvgExceptionType.SvgWrongTypeErr,
                                       "Could not create wrappable type for " + wrappableObject.GetType().FullName, e);
            }
        }
示例#2
0
        public List <IScriptBlock> GenerateScript(IDifferences differences, ScriptDirection direction, Options options)
        {
            var blocks = new List <IScriptBlock>(differences.Count);

            foreach (var difference in differences)
            {
                if (!difference.UseInGeneration)
                {
                    continue;
                }

                IScriptableObject sourceObj = difference.DatabaseObjectA;
                IScriptableObject targetObj = difference.DatabaseObjectB;

                DifferenceType differenceType = difference.Type;

                // If the direction FromBToA, flip it around
                if (direction == ScriptDirection.FromBToA)
                {
                    sourceObj = difference.DatabaseObjectB;
                    targetObj = difference.DatabaseObjectA;

                    // Swap the 'OnlyIn' type if it is one of them
                    if (differenceType == DifferenceType.OnlyInA)
                    {
                        differenceType = DifferenceType.OnlyInB;
                    }
                    else if (differenceType == DifferenceType.OnlyInB)
                    {
                        differenceType = DifferenceType.OnlyInA;
                    }
                }

                // Add the block/s for this difference
                switch (differenceType)
                {
                case DifferenceType.Different:
                    blocks.AddRange(sourceObj.AlterTo(targetObj, options));
                    break;

                case DifferenceType.OnlyInA:
                    blocks.Add(sourceObj.DropBlock(options));
                    break;

                case DifferenceType.OnlyInB:
                    blocks.Add(targetObj.CreateBlock(options));
                    break;
                }
            }

            // Filter out any null values before returning
            blocks = blocks.Where(block => block != null).ToList();

            return(blocks);
        }
示例#3
0
 public bool TryGetValue(object key, out IScriptableObject value)
 {
     return(_jsCachedTypes.TryGetValue(key, out value));
 }
示例#4
0
 public void Add(object key, IScriptableObject value)
 {
     _jsCachedTypes.Add(key, value);
 }
 public ScriptableProperties(IScriptableObject owner)
 {
     _owner = owner;
 }
示例#6
0
 public void RegisterScriptableObject(IScriptableObject sobj)
 {
     ScriptObj.Add(sobj.ScriptableName, sobj);
 }
示例#7
0
		public ScriptableProperties( IScriptableObject owner )
		{
			this._owner = owner;
		}
        private List <IDifference> GetDifferences(List <IDatabaseObject> itemsA, List <IDatabaseObject> itemsB, Options options)
        {
            if (itemsA == null)
            {
                return(null);
            }

            if (itemsB == null)
            {
                itemsB = new List <IDatabaseObject>();
            }

            List <IDifference> differences = new List <IDifference>();
            // Copy of Items B's objects so we can remove the objects as they match
            List <IScriptableObject> itemsBCompare = itemsB.Cast <IScriptableObject>().ToList();

            // Loop over every object in A and compare it to every object in B
            foreach (IScriptableObject itemA in itemsA)
            {
                var differenceType = DifferenceType.Equal;
                IScriptableObject equivalentObject = null;

                int loopLength = itemsBCompare.Count;
                for (int i = 0; i < loopLength; i++)
                {
                    IScriptableObject itemB = itemsBCompare[i];

                    // Check the names. If they don't have the same name they are not the same object
                    if (itemA.FullyQualifiedName == itemB.FullyQualifiedName)
                    {
                        equivalentObject = itemB;
                        itemsBCompare[i] = itemsBCompare.Last();
                        itemsBCompare.RemoveAt(loopLength - 1);
                        break;
                    }
                }

                if (equivalentObject == null)
                {
                    // If no equivalent object was found, this ony exists in A
                    differenceType = DifferenceType.OnlyInA;
                }
                else
                {
                    // Check if objects are actually equal with a deeper check
                    if (!itemA.Equals(equivalentObject, options))
                    {
                        differenceType = DifferenceType.Different;
                    }
                }

                // Add the difference to the differences list
                var difference = new Difference(differenceType, itemA.Type, itemA.FullyQualifiedName);
                difference.DatabaseObjectA = itemA;
                difference.DatabaseObjectB = equivalentObject;

                differences.Add(difference);
            }

            // Any leftover items in itemsBCompare are object OnlyInB
            foreach (var item in itemsBCompare)
            {
                var difference = new Difference(DifferenceType.OnlyInB, item.Type, item.FullyQualifiedName);
                difference.DatabaseObjectB = item as IScriptableObject;

                differences.Add(difference);
            }

            return(differences);
        }