public string ObjectName { get; private set; } //"user"

		public MappingWaiting(View view, CarpaccioAction carpaccioAction, string call, string objectName)
		{
			View = view;
			CarpaccioAction = carpaccioAction;
			Call = call;
			ObjectName = objectName;
		}
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            CarpaccioAction action = obj as CarpaccioAction;

            if (action == null)
            {
                return(false);
            }
            return(!(CompleteCall != null ? CompleteCall != action.CompleteCall : action.CompleteCall != null));
        }
    /**
     * Called when a view loaded and call a mapping function
     *
     * @param view         the calling view
     * @param mappedObject If available, the object to map with the view. Else add the view to mappingWaitings
     */
    public void CallMappingOnView(CarpaccioAction action, View view, Object mappedObject) {

        if (action.IsCallMapping) {

            CarpaccioLogger.d(TAG, "callMappingOnView mapping=" + mappedObject + " action=" + action.CompleteCall + " view=" + view.GetType().Name);

            string arg = action.Args[0]; //only map the first argument

            string objectName;

            string call;
            if (arg.Contains(".")) { //"$user.getName()"
                call = arg.Substring(1, arg.Length - 1); // "user.getName()"
                objectName = call.Substring(0, arg.IndexOf('.') - 1); // "user"
            } else {
                objectName = arg.Substring(1, arg.Length - 1); // "user"
                call = objectName; // "user"
            }

            //if you already have the object
            if (mappedObject != null) {
                string value = Evaluate(mappedObject, call);

                CarpaccioLogger.d(TAG, "callMappingOnView evaluate(" + call + ")" + " on " + mappedObject.GetType().Name + " returned " + value);

                action.Values = new[]{value}; //TODO

                MappingManagerCallback.CallActionOnView(action, view);
            } else {
                //add to waiting
                List<MappingWaiting> waitings = MappingWaitings.GetOrDefault(objectName) ?? new List<MappingWaiting>(); //["user"] = List<MappingWaiting>
	            waitings.Add(new MappingWaiting(view, action, call, objectName));

                CarpaccioLogger.d(TAG, "added to waiting " + call + " for " + view.GetType().Name);

                MappingWaitings.AddOrUpdate(objectName, waitings);
            }
        }
    }