Esempio n. 1
0
        private int StringCompare(object a, object b)
        {
            string fa;

            try
            {
                //fa = _name == null ? (string)a : (string)a[_name];
                fa = (string)(_name == null ? a : CoreReflector.GetValue(a, _name));
            }
            catch (Exception ex)
            {
            }

            string fb;

            try
            {
                //fb = _name == null ? (string)b : (string)b[_name];
                fa = (string)(_name == null ? b : CoreReflector.GetValue(b, _name));
            }
            catch (Exception ex)
            {
            }

            //return ObjectUtil.stringCompare(fa, fb, _caseInsensitive);
            return(0);            // TEMP
        }
Esempio n. 2
0
        private int NumericCompare(object a, object b)
        {
            float fa;

            try
            {
                //fa = _name == null ? (float)a : (float)a[_name];
                fa = _name == null ? (float)a : (float)CoreReflector.GetValue(a, _name);
            }
            catch (Exception ex)
            {
            }

            float fb;

            try
            {
                //fb = null == _name ? (float)b : (float)b[_name];
                fb = null == _name ? (float)b : (float)CoreReflector.GetValue(b, _name);
            }
            catch (Exception ex)
            {
            }

            //return ObjectUtil.numericCompare(fa, fb);
            return(0);            // TEMP
        }
Esempio n. 3
0
        private int DateCompare(object a, object b)
        {
            DateTime fa;

            try
            {
                //fa = _name == null ? (a as DateTime) : a[_name] as Date;
                fa = (DateTime)(_name == null ? a : CoreReflector.GetValue(a, _name));
            }
            catch (Exception ex)
            {
            }

            DateTime fb;

            try
            {
                //fb = _name == null ? (b as DateTime?) : b[_name] as Date;
                fb = (DateTime)(_name == null ? b : CoreReflector.GetValue(b, _name));
            }
            catch (Exception ex)
            {
            }

            //return ObjectUtil.dateCompare(fa, fb);
            return(0);            //TEMP
        }
Esempio n. 4
0
        private void ClearSkinParts()
        {
            if (null == _thisType) // not yet added
            {
                return;
            }

            var partDict = SkinPartCache.Instance.Get(_thisType);

            if (null != partDict)
            {
                foreach (var id in partDict.Keys)
                {
                    var p = CoreReflector.GetValue(this, id);

                    if (!(p is IFactory))
                    {
                        PartRemoved(id, p);
                    }
                    else
                    {
                        //var len:int = numDynamicParts(id);
                        //for (var j:int = 0; j < len; j++)
                        //    removeDynamicPartInstance(id, getDynamicPartAt(id, j));
                    }

                    CoreReflector.SetValue(this, id, null);
                }
            }
        }
        /**
         *  Create an instance of a dynamic skin part.
         *  Dynamic skin parts should always be instantiated by this method,
         *  rather than directly by calling the <code>newInstance()</code> method on the factory.
         *  This method creates the part, but does not add it to the display list.
         *  The component must call the <code>Group.addElement()</code> method, or the appropriate
         *  method to add the skin part to the display list.
         *
         *  Param: partName The name of the part.
         */
        /// <summary>
        ///
        /// </summary>
        /// <param name="partName"></param>
        /// <returns></returns>
        protected object CreateDynamicPartInstance(string partName)
        {
            IFactory factory = (IFactory)CoreReflector.GetValue(Skin, partName);

            if (null != factory)
            {
                DisplayObject instance = (DisplayObject)factory.NewInstance();

                // Add to the dynamic parts cache
                if (null == _dynamicPartsCache)
                {
                    _dynamicPartsCache = new Dictionary <string, List <object> >();
                }

                if (!_dynamicPartsCache.ContainsKey(partName))
                {
                    _dynamicPartsCache[partName] = new List <object>();
                }

                _dynamicPartsCache[partName].Add(instance);

                // Send notification
                PartAdded(partName, instance);

                return(instance);
            }

            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// Used for deffered parts
        /// </summary>
        /// <param name="e"></param>
        private void SkinPropertyChangeHandler(Event e)
        {
            if (null != SkinParts)
            {
                PropertyChangeEvent pce = (PropertyChangeEvent)e;
                string skinPartID       = pce.Property;
                if (SkinParts.ContainsKey(skinPartID))
                {
                    var part = CoreReflector.GetValue(Skin, skinPartID);

                    if (pce.NewValue == null)
                    {
                        if (!(part is IFactory))
                        {
                            PartRemoved(skinPartID, part);
                        }
                        CoreReflector.SetValue(this, skinPartID, pce.NewValue);
                    }
                    else
                    {
                        part = pce.NewValue;
                        if (!(part is IFactory))
                        {
                            PartAdded(skinPartID, part);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public FadeInUp2()
        {
            Name = "Fade in up";
            Add(

                new SetProperty("Visible", true)
            {
                Name = "Setting Visible"
            },

                new SetProperty("Alpha", 0f)
            {
                Name = "Setting Alpha"
            },

                new SetPropertyFunc(delegate(object target)
            {
                CoreReflector.SetValue(target, "Y", (float)CoreReflector.GetValue(target, "Y") + Offset * 2);
            }),

                new Sequence(

                    new Parallel(
                        new Tween
            {
                Property   = "Alpha",
                Duration   = 0.3f,
                Easer      = Linear.EaseIn,
                StartValue = 0f,
                //StartValueReader = new PropertyReader("Alpha"),
                EndValue = 1f
            },
                        new Tween
            {
                Property = "Y",
                Duration = 0.5f,
                Easer    = Expo.EaseOut,
                StartValueReaderFunction = StartValueReaderFunc,
                EndValueReaderFunction   = EndValueReaderFunc
            }
                        ),

                    new Tween
            {
                Property = "Y",
                Duration = 0.5f,
                Easer    = Expo.EaseInOut,
                StartValueReaderFunction = StartValueReaderFunc,
                EndValueReaderFunction   = EndValueReaderFunc
            }
                    )

                //new Action(delegate { Debug.Log("Finished"); })
                );
        }
Esempio n. 8
0
        ///<summary>
        ///</summary>
        ///<param name="item"></param>
        ///<param name="labelField"></param>
        ///<param name="labelFunction"></param>
        ///<returns></returns>
        public static string ItemToLabel(object item, string labelField /*=null*/, LabelFunction labelFunction /*=null*/)
        {
            if (null != labelFunction)
            {
                return(labelFunction(item));
            }

            // early check for Strings
            if (item is string)
            {
                return((string)item);
            }

            if (item != null)
            {
                try
                {
                    //if (item[labelField] != null)
                    //    item = item[labelField];
                    var val = CoreReflector.GetValue(item, labelField);
                    if (null != val)
                    {
                        item = val;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(string.Format(@"Cannot read value ""{0}"" from object {1}:
    {2}", labelField, item, ex));
                }
            }

            // late check for strings if item[labelField] was valid
            if (item is string)
            {
                return((string)item);
            }

            try
            {
                if (null != item)
                {
                    return(item.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format(@"Cannot convert to string: ""{0}"":
    {1}", item, ex));
            }

            return(" ");
        }
Esempio n. 9
0
        /// <summary>
        /// Reads the property
        /// </summary>
        /// <returns></returns>
        public object Read()
        {
            object value = CoreReflector.GetValue(Target, Property);

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Value read [{0}, {1}]: {2}", Target, Property, value));
            }
#endif

            return(value);
        }
Esempio n. 10
0
        internal static object GetProxyMemberValue(Type proxyType, string memberName)
        {
            object singleton = GetProxySingleton(proxyType);

            try
            {
                return(CoreReflector.GetValue(singleton, memberName));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Cannot get member named [{0}] on singleton instance of type [{1}]", memberName, proxyType), ex);
            }
        }
Esempio n. 11
0
        public int Compare(T xWord, T yWord)
        {
            // GetEaser property values
            object xValue = CoreReflector.GetValue(xWord, _sortField);
            object yValue = CoreReflector.GetValue(yWord, _sortField);

            // Determine sort order
            if (_descending)
            {
                return(CompareDescending(xValue, yValue));
            }

            return(CompareAscending(xValue, yValue));
        }
Esempio n. 12
0
        /**
         *
         *  This method allows us to determine what underlying data type we need to
         *  perform comparisions on and set the appropriate compare method.
         *  If an option like numeric is set it will take precedence over this aspect.
         */
        internal void InitCompare(object obj)
        {
            // if the compare function is not already set then we can set it
            if (!UsingCustomCompareFunction)
            {
                if (null != Numeric)
                {
                    _compareFunction = NumericCompare;
                }
                else if (_caseInsensitive || (Numeric is bool && (bool)Numeric == false))
                {
                    _compareFunction = StringCompare;
                }
                else
                {
                    // we need to introspect the data a little bit
                    object value = null;
                    if (!string.IsNullOrEmpty(_name))
                    {
                        try
                        {
                            //value = obj[_name];
                            value = CoreReflector.GetValue(obj, _name);
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch (Exception ex)
                        {
                        }
                    }
                    //this needs to be an == null check because !value will return true
                    //where value == 0 or value == false
                    if (value == null)
                    {
                        value = obj;
                    }

                    var typ = value.GetType();

                    if (typ == typeof(string))
                    {
                        _compareFunction = StringCompare;
                    }
                    else if (typ == typeof(object))
                    {
                        if (value is DateTime)
                        {
                            _compareFunction = DateCompare;
                        }
                        else
                        {
                            _compareFunction = StringCompare;
                            string test = null;
                            try
                            {
                                test = value.ToString();
                            }
// ReSharper disable once EmptyGeneralCatchClause
                            catch (Exception ex)
                            {
                            }
                            if (null == test /* || test == "[object Object]"*/)
                            {
                                _compareFunction = NullCompare;
                            }
                        }
                    }
                    else if (typ == typeof(bool) || typ == typeof(float))
                    {
                        _compareFunction = NumericCompare;
                    }

                    /*switch (typ)
                     *  {
                     *          case "string":
                     *                  _compareFunction = stringCompare;
                     *          break;
                     *          case "object":
                     *                  if (value is Date)
                     *                  {
                     *                          _compareFunction = dateCompare;
                     *                  }
                     *                  else
                     *                  {
                     *                          _compareFunction = stringCompare;
                     *                          var test:String;
                     *                          try
                     *                          {
                     *                                  test = value.toString();
                     *                          }
                     *                          catch(error2:Error)
                     *                          {
                     *                          }
                     *                          if (!test || test == "[object Object]")
                     *                          {
                     *                                  _compareFunction = nullCompare;
                     *                          }
                     *                  }
                     *          break;
                     *          case "xml":
                     *                  _compareFunction = xmlCompare;
                     *          break;
                     *          case "boolean":
                     *          case "number":
                     *                  _compareFunction = numericCompare;
                     *          break;
                     *  }*/
                }         // else
            }             // if
        }
Esempio n. 13
0
        private void FindSkinParts()
        {
            if (null == _thisType)
            {
                _thisType = GetType();
            }

            var parts = SkinParts.Keys;

            foreach (var id in parts)
            {
                object part = null;

                /**
                 * 1. If this is a mapper skin,
                 * */
                if (_isMapperSkin)
                {
                    part = Skin.GetChildComponent(id);
                    //if (null != part)
                    //    Debug.Log("Found mapper skin part: " + part);
                    //else
                    //    Debug.Log(Skin + " -> Couldn't find mapper skin part: " + id);
                }

                else
                {
                    if (CoreReflector.HasMember(Skin, id))
                    {
                        try
                        {
                            part = CoreReflector.GetValue(Skin, id);
                        }
                        catch (InvalidCastException /* ex*/)
                        {
                            Debug.LogError(string.Format("Cannot cast the skin part to InteractiveComponent. Skin: {0}; Part: {1}", Skin, id));
                        }
                    }

                    //else
                    //    Debug.LogWarning("Couldn't find member: " + id);
                }

                if (SkinParts[id]) // == true (required part)
                {
                    if (null == part)
                    {
                        throw new Exception("Required skin part not found: " + id);
                    }
                }

                if (null != part)
                {
                    /**
                     * Note: we've been having a hard-core bug here (20131216)!
                     * The system FREEZED when using Panel with children in designer
                     * For instance, a panel had a single button child as a content child (not tool or control bar child)
                     * This is also the source of bug whereever we add a child prior to adding itself to the display list (both designer and code)
                     * I think it might be related to styles and StyleProtoChain process (?)
                     * This shoould - of course - be fixed
                     * The problem with designer was in ComponentAdapter ("Produce" method):
                     * _component.AddEventListener(FrameworkEvent.PREINITIALIZE, InitializeHandler)
                     * During the PREINITILIZE, child components have not yet been created - so the skin wasn't created
                     * When I changed it to INITILIZE, it started to work properly:
                     * _component.AddEventListener(FrameworkEvent.INITIALIZE, InitializeHandler)                     *
                     * */

                    /*if (id == "ContentGroup")
                     *  Debug.LogWarning("ContentGroup: " + part);*/

                    //CoreReflector.SetValue(this, id, part);
                    MemberWrapper wrapper = new MemberWrapper(GetType(), id);
                    wrapper.SetValue(this, part);

                    // If the assigned part has already been instantiated, call partAdded() here,
                    // but only for static parts.

                    try
                    {
                        /* Note: this fails, because the wrapper wraps around the Skin's property, not the Panel's */
                        //var p = CoreReflector.GetValue(this, id);
                        wrapper = new MemberWrapper(GetType(), id);
                        var p = wrapper.GetValue(this);

                        // TODO: we should get the value silently here, because not to disturb the DoubleGroup.Modified flag
                        //Debug.Log("Just added: " + p);

                        // If the assigned part has already been instantiated, call partAdded() here,
                        // but only for static parts.
                        if (null != p && !(p is IFactory))
                        {
                            PartAdded(id, p);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        throw ex;
                    }
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Reads the value from the given object
 /// TODO: use the one from Core utils?
 /// </summary>
 /// <param name="target"></param>
 /// <param name="variableName"></param>
 /// <returns></returns>
 public static object ReadValue(object target, string variableName)
 {
     //return target.GetType().GetProperty(variableName).GetValue(target, Index);
     return(CoreReflector.GetValue(target, variableName));
 }