Пример #1
0
        protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope propertyScope)
        {
            if (key.ToString() == "getSystem")
            {
                var f = new Func<string, ISystem>(s => getSystem(s));
                return Marshal(f);
            }

            var methodInfo = _instance.GetType().GetMethod(key.ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            if (methodInfo != null)
            {
                var del = methodInfo.CreateDelegate(Expression.GetDelegateType(

                        (from parameter in methodInfo.GetParameters() select parameter.ParameterType)
                        .Concat(new[] { methodInfo.ReturnType })
                        .ToArray()), _instance);

                return Marshal(del);
            }

            methodInfo = _instance.GetType().GetMethod(key.ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            if (methodInfo != null)
            {
                var del = methodInfo.CreateDelegate(Expression.GetDelegateType(

                        (from parameter in methodInfo.GetParameters() select parameter.ParameterType)
                        .Concat(new[] { methodInfo.ReturnType })
                        .ToArray()));

                return Marshal(del);
            }

            return base.GetProperty(key, forWrite, propertyScope);
        }
        private bool ValidateModifiableEntity(ValidationContext validationContext, ModifiableEntity mod)
        {
            bool isValid = true;
            PropertyScope propertyScope = new PropertyScope();
            validationContext.KeyBuilders.Push(propertyScope);

            var entity = mod as Entity;
            using (entity == null ? null : entity.Mixins.OfType<CorruptMixin>().Any(c => c.Corrupt) ? Corruption.AllowScope() : Corruption.DenyScope())
            {
                foreach (var kvp in PropertyConverter.GetPropertyConverters(mod.GetType()))
                {
                    if (kvp.Value.AvoidValidate)
                        continue;

                    propertyScope.PropertyName = kvp.Key;
                    if (SignumValidate(validationContext, kvp.Value.GetValue(mod)) ?? true)
                    {
                        isValid = false;
                    }

                    string error = kvp.Value.PropertyValidator.PropertyCheck(mod);

                    if (error != null)
                    {
                        string key = CalculateKey(validationContext);
                        if (validationContext.ModelState.IsValidField(key))
                        {
                            isValid = false;
                            validationContext.ModelState.AddModelError(key, error);
                        }
                    }
                }
            }
            
            if (entity != null && entity.Mixins.Any())
            {
                propertyScope.PropertyName = "mixins";
                PropertyScope mixinScope = new PropertyScope();
                validationContext.KeyBuilders.Push(mixinScope);
                foreach (var mixin in entity.Mixins)
                {
                    mixinScope.PropertyName = mixin.GetType().Name;
                    if (!ValidateModifiableEntity(validationContext, mixin))
                        isValid = false;
                }
                validationContext.KeyBuilders.Pop();
            }

            validationContext.KeyBuilders.Pop();
            return isValid;
        }
Пример #3
0
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ScrollableItemsAttribute attribute)
        {
            using (var propertyScope = new PropertyScope(property, label))
            {
                if (!propertyScope.IsVisible)
                {
                    return;
                }

                EditorGUI.indentLevel++;
                DrawSettingsBody(property, attribute, out var size, out var indexRange);
                DrawElementsBody(property, attribute, size, indexRange);
                EditorGUI.indentLevel--;
            }
        }
Пример #4
0
        internal override void RemoveExecutionPolicy(PropertyScope scope, string shellId)
        {
            string scopeDirectory = psHomeConfigDirectory;

            // Defaults to system wide.
            if (PropertyScope.CurrentUser == scope)
            {
                scopeDirectory = appDataConfigDirectory;
            }

            string fileName  = Path.Combine(scopeDirectory, configFileName);
            string valueName = string.Concat(shellId, ":", "ExecutionPolicy");

            RemoveValueFromFile <string>(fileName, valueName);
        }
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReferencePickerAttribute attribute)
        {
            using (var propertyScope = new PropertyScope(property, label))
            {
                if (!propertyScope.IsVisible)
                {
                    return;
                }

                EditorGUI.indentLevel++;
                CreateTypeProperty(property);
                ToolboxEditorGui.DrawPropertyChildren(property);
                EditorGUI.indentLevel--;
            }
        }
Пример #6
0
        internal override void SetExecutionPolicy(PropertyScope scope, string shellId, string executionPolicy)
        {
            string scopeDirectory = psHomeConfigDirectory;

            // Defaults to system wide.
            if (PropertyScope.CurrentUser == scope)
            {
                scopeDirectory = GetCurrentUserConfigDirectory();
            }

            string fileName  = Path.Combine(scopeDirectory, configFileName);
            string valueName = string.Concat(shellId, ":", "ExecutionPolicy");

            WriteValueToFile <string>(fileName, valueName, executionPolicy);
        }
Пример #7
0
        protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope propertyScope)
        {
            if (propertyScope <= PropertyScope.Own && key.ValueType != JSValueType.Symbol)
            {
                var keyString = key.ToString();
                key = keyString;

                object value;
                if (_expandoObject.TryGetValue(keyString, out value))
                {
                    return(Marshal(value));
                }
            }

            return(base.GetProperty(key, forWrite, propertyScope));
        }
Пример #8
0
 private static object SetPropertyMethod(BrokeredMessage message, PropertyScope scope, string name, object value)
 {
     if (value is DBNull)
     {
         value = null;
     }
     if (scope == PropertyScope.System)
     {
         return(SetPropertyExpression.SetSystemProperty(message, name, value));
     }
     if (scope != PropertyScope.User)
     {
         throw new ArgumentException(SRClient.FilterScopeNotSupported(scope), "scope");
     }
     return(SetPropertyExpression.SetUserProperty(message, name, value));
 }
Пример #9
0
        static SerializedDictionaryDrawer()
        {
            storage = new DrawerDataStorage <ReorderableListBase, CreationArgs>(false, (p, a) =>
            {
                var pairsProperty = a.pairsProperty;
                var errorProperty = a.errorProperty;

                var list = new ToolboxEditorList(pairsProperty, "Pair", true, true, false);
                list.drawHeaderCallback += (rect) =>
                {
                    //cache preprocessed label to get prefab related functions
                    var label = EditorGUI.BeginProperty(rect, null, p);
                    //create additional warning message if there is key collision
                    if (errorProperty.boolValue)
                    {
                        label.image = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
                        label.text += string.Format(" [{0}]", Style.warningMessage);
                    }
                    EditorGUI.LabelField(rect, label);
                    EditorGUI.EndProperty();
                };
                list.drawFooterCallback += (rect) =>
                {
                    list.DrawStandardFooter(rect);
                };
                list.drawElementCallback += (rect, index, isActive, isFocused) =>
                {
                    var element = pairsProperty.GetArrayElementAtIndex(index);
                    var content = list.GetElementContent(element, index);

                    using (var propertyScope = new PropertyScope(element, content))
                    {
                        if (!propertyScope.IsVisible)
                        {
                            return;
                        }

                        //draw key/value children and use new, shortened labels
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(element.FindPropertyRelative("key"), new GUIContent("K"));
                        EditorGUILayout.PropertyField(element.FindPropertyRelative("value"), new GUIContent("V"));
                        EditorGUI.indentLevel--;
                    }
                };
                return(list);
            });
        }
Пример #10
0
        private bool ValidateLite(ValidationContext validationContext, Lite <Entity> lite)
        {
            if (lite.EntityOrNull == null)
            {
                return(true);
            }

            PropertyScope propertyScope = new PropertyScope {
                PropertyName = "entity"
            };

            validationContext.KeyBuilders.Push(propertyScope);
            var isValid = ValidateModifiableEntity(validationContext, lite.Entity);

            validationContext.KeyBuilders.Pop();
            return(isValid);
        }
Пример #11
0
            protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope propertyScope)
            {
                if (forWrite)
                {
                    Console.WriteLine("Getting write accessor for \"" + key + "\"");
                    return(new WriteAccessor(key.ToString()));
                }
                else
                {
                    switch (key.ValueType)
                    {
                    case JSValueType.Integer:
                    {
                        return((int)key.Value);
                    }

                    case JSValueType.String:
                    {
                        var value = key.Value.ToString();
                        switch (value)
                        {
                        case "0":
                        {
                            return("nil");
                        }

                        case "1":
                        {
                            return("one");
                        }

                        case "2":
                        {
                            return("two");
                        }
                        }
                        goto default;
                    }

                    default:
                    {
                        return("Dummy for key \"" + key + "\" with type \"" + key.ValueType + "\"");
                    }
                    }
                }
            }
        private bool ValidateProperties(ModelMetadata metadata, ValidationContext validationContext)
        {
            bool          isValid       = true;
            PropertyScope propertyScope = new PropertyScope();

            validationContext.KeyBuilders.Push(propertyScope);
            foreach (ModelMetadata childMetadata in validationContext.MetadataProvider.GetMetadataForProperties(metadata.Model, metadata.RealModelType))
            {
                propertyScope.PropertyName = childMetadata.PropertyName;
                if (!ValidateNodeAndChildren(childMetadata, validationContext, metadata.Model, validators: null))
                {
                    isValid = false;
                }
            }
            validationContext.KeyBuilders.Pop();
            return(isValid);
        }
Пример #13
0
        /// <summary>
        /// Draws property in default way but each single property is handled by custom action.
        /// 'Default way' means it will create foldout-based property if children are visible.
        /// Uses built-in layouting system.
        /// </summary>
        public static void DrawDefaultProperty(SerializedProperty property, GUIContent label,
                                               Action <SerializedProperty, GUIContent> drawParentAction, Action <SerializedProperty> drawElementAction)
        {
            if (!property.hasVisibleChildren)
            {
                drawParentAction(property, label);
                return;
            }

            //draw standard foldout with built-in operations (like prefabs handling)
            //native steps to re-create:
            // - get foldout rect
            // - begin property using EditorGUI.BeginProperty method
            // - read current drag events
            // - draw foldout
            // - close property using EditorGUI.EndProperty method
            using (var propertyScope = new PropertyScope(property, label))
            {
                if (!propertyScope.IsVisible)
                {
                    return;
                }

                var enterChildren = true;
                //cache all needed property references
                var targetProperty = property.Copy();
                var endingProperty = property.GetEndProperty();

                EditorGUI.indentLevel++;
                //iterate over all children (but only 1 level depth)
                while (targetProperty.NextVisible(enterChildren))
                {
                    if (SerializedProperty.EqualContents(targetProperty, endingProperty))
                    {
                        break;
                    }

                    enterChildren = false;
                    //handle current property using Toolbox features
                    drawElementAction(targetProperty.Copy());
                }

                EditorGUI.indentLevel--;
            }
        }
Пример #14
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var propScope = new PropertyScope(position, label, property))
                using (var changeScope = new ChangeCheckScope())
                {
                    var controlPosition = PrefixLabel(position, propScope.content);

                    var floatFieldWidth = Mathf.Min(EditorGUIUtility.fieldWidth, controlPosition.width);
                    var sliderPosition  = new Rect(controlPosition)
                    {
                        width = controlPosition.width - floatFieldWidth - SLIDER_SPACING
                    };

                    const float marker1 = .8f;
                    const float marker2 = .95f;

                    DrawMarkers(sliderPosition,
                                (marker1, new Color(1.00000f, 0.60392f, 0.01961f, MARKER_ALPHA)),
                                (marker2, new Color(1.00000f, 0.25490f, 0.20784f, MARKER_ALPHA)));

                    var newVal = Slider(controlPosition,
                                        GUIContent.none,
                                        property.floatValue,
                                        0, 1);

                    if (!Event.current.control && !Event.current.alt)
                    {
                        var dist1 = (newVal - marker1) * sliderPosition.width;
                        var dist2 = (newVal - marker2) * sliderPosition.width;
                        if (0 < dist1 && dist1 < 4)
                        {
                            newVal = marker1;
                        }
                        if (0 < dist2 && dist2 < 4)
                        {
                            newVal = marker2;
                        }
                    }

                    if (changeScope.changed)
                    {
                        property.floatValue = newVal;
                    }
                }
        }
        public async Task <IHttpActionResult> Build(PropertyScope scope, string target)
        {
            var nodesToBuild = new Dictionary <PropertyScope, ICollection <string> >();

            this.GetTargetsFromScope(
                nodesToBuild,
                scope,
                target);
            if (nodesToBuild.Count < 1)
            {
                return(this.NotFound());
            }

            var build = await this.BuildService.CreateBuild();

            BackgroundJob.Enqueue(() => this.NodeService.BuildNode(build.Id, nodesToBuild));
            return(this.Ok(build));
        }
Пример #16
0
 public PropertyModel(string propertyName, string typeName, bool requireInit = true, ValueModel valueModel = null, PropertyScope propertyScope = PropertyScope.Get)
 {
     Name = String.IsNullOrWhiteSpace(propertyName) ?
            throw new ArgumentNullException("Class name can not be empty, null or whitespace.", nameof(propertyName))
     : propertyName;
     TypeName = String.IsNullOrWhiteSpace(typeName) ?
                throw new ArgumentNullException("Class type name can not be empty, null or whitespace.", nameof(typeName))
         : typeName;
     if (valueModel != null)
     {
         if (valueModel.TypeName != TypeName)
         {
             throw new ArgumentException("Value type does not match with property type.");
         }
     }
     Value = valueModel;
     RequireInitialization = requireInit;
     Scope = propertyScope;
 }
Пример #17
0
        internal override void SetExecutionPolicy(PropertyScope scope, string shellId, string executionPolicy)
        {
            string      regKeyName = Utils.GetRegistryConfigurationPath(shellId);
            RegistryKey scopedKey  = Registry.LocalMachine;

            // Override if set to another value;
            if (PropertyScope.CurrentUser == scope)
            {
                scopedKey = Registry.CurrentUser;
            }

            using (RegistryKey key = scopedKey.CreateSubKey(regKeyName))
            {
                if (null != key)
                {
                    key.SetValue("ExecutionPolicy", executionPolicy, RegistryValueKind.String);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// This value is not writable via the API and must be set using a text editor.
        /// </summary>
        /// <param name="scope"></param>
        /// <returns>Value if found, null otherwise. The behavior matches ModuleIntrinsics.GetExpandedEnvironmentVariable().</returns>
        internal override string GetModulePath(PropertyScope scope)
        {
            string scopeDirectory = psHomeConfigDirectory;

            // Defaults to system wide.
            if (PropertyScope.CurrentUser == scope)
            {
                scopeDirectory = appDataConfigDirectory;
            }

            string fileName = Path.Combine(scopeDirectory, configFileName);

            string modulePath = ReadValueFromFile <string>(fileName, Constants.PSModulePathEnvVar);

            if (!string.IsNullOrEmpty(modulePath))
            {
                modulePath = Environment.ExpandEnvironmentVariables(modulePath);
            }
            return(modulePath);
        }
Пример #19
0
        internal override void SetExecutionPolicy(PropertyScope scope, string shellId, string executionPolicy)
        {
            string scopeDirectory = psHomeConfigDirectory;

            // Defaults to system wide.
            if (PropertyScope.CurrentUser == scope)
            {
                // Exceptions are not caught so that they will propagate to the
                // host for display to the user.
                // CreateDirectory will succeed if the directory already exists
                // so there is no reason to check Directory.Exists().
                Directory.CreateDirectory(appDataConfigDirectory);
                scopeDirectory = appDataConfigDirectory;
            }

            string fileName  = Path.Combine(scopeDirectory, configFileName);
            string valueName = string.Concat(shellId, ":", "ExecutionPolicy");

            WriteValueToFile <string>(fileName, valueName, executionPolicy);
        }
Пример #20
0
        internal protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
        {
            if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
            {
                var keyString = key.ToString();

                if (keyString == "prototype") // Все прокси-прототипы read-only и non-configurable. Это и оптимизация, и устранение необходимости навешивания атрибутов
                {
                    return(prototype);
                }

                if (key._valueType != JSValueType.String)
                {
                    key = keyString;
                }

                JSValue res;
                if (forWrite || (keyString != "toString" && keyString != "constructor"))
                {
                    res = _staticProxy.GetProperty(key, forWrite && memberScope == PropertyScope.Own, memberScope);
                    if (res.Exists || (memberScope == PropertyScope.Own && forWrite))
                    {
                        if (forWrite && res.NeedClone)
                        {
                            res = _staticProxy.GetProperty(key, true, memberScope);
                        }

                        return(res);
                    }

                    res = __proto__.GetProperty(key, forWrite, memberScope);
                    if (memberScope == PropertyScope.Own && (res._valueType != JSValueType.Property || (res._attributes & JSValueAttributesInternal.Field) == 0))
                    {
                        return(notExists); // если для записи, то первая ветка всё разрулит и сюда выполнение не придёт
                    }
                    return(res);
                }
            }

            return(base.GetProperty(key, forWrite, memberScope));
        }
Пример #21
0
        /// <summary>
        /// Recursively validate the properties of the given <paramref name="metadata"/>.
        /// </summary>
        /// <param name="metadata">The <see cref="ModelMetadata"/> for the object to validate.</param>
        /// <param name="validationContext">The <see cref="BodyModelValidatorContext"/>.</param>
        /// <returns>
        /// <see langword="true"/> if validation succeeds for all properties in <paramref name="metadata"/>;
        /// <see langword="false"/> otherwise.
        /// </returns>
        protected virtual bool ValidateProperties(
            ModelMetadata metadata,
            BodyModelValidatorContext validationContext
            )
        {
            if (metadata == null)
            {
                throw Error.ArgumentNull("metadata");
            }
            if (validationContext == null)
            {
                throw Error.ArgumentNull("validationContext");
            }

            bool          isValid       = true;
            PropertyScope propertyScope = new PropertyScope();

            validationContext.KeyBuilders.Push(propertyScope);
            foreach (
                ModelMetadata childMetadata in validationContext.MetadataProvider.GetMetadataForProperties(
                    metadata.Model,
                    metadata.RealModelType
                    )
                )
            {
                propertyScope.PropertyName = childMetadata.PropertyName;
                if (
                    !ValidateNodeAndChildren(
                        childMetadata,
                        validationContext,
                        metadata.Model,
                        validators: null
                        )
                    )
                {
                    isValid = false;
                }
            }
            validationContext.KeyBuilders.Pop();
            return(isValid);
        }
Пример #22
0
        /// <summary>
        /// Existing Key = HKCU and HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
        /// Proposed value = Existing default execution policy if not already specified
        ///
        /// Schema:
        /// {
        ///     "shell ID string","ExecutionPolicy" : "execution policy string"
        /// }
        ///
        /// TODO: In a single config file, it might be better to nest this. It is unnecessary complexity until a need arises for more nested values.
        /// </summary>
        /// <param name="scope">Whether this is a system-wide or per-user setting.</param>
        /// <param name="shellId">The shell associated with this policy. Typically, it is "Microsoft.PowerShell"</param>
        /// <returns>The execution policy if found. Null otherwise.</returns>
        internal override string GetExecutionPolicy(PropertyScope scope, string shellId)
        {
            string execPolicy     = null;
            string scopeDirectory = psHomeConfigDirectory;

            // Defaults to system wide.
            if (PropertyScope.CurrentUser == scope)
            {
                scopeDirectory = appDataConfigDirectory;
            }

            string fileName      = Path.Combine(scopeDirectory, configFileName);
            string valueName     = string.Concat(shellId, ":", "ExecutionPolicy");
            string rawExecPolicy = ReadValueFromFile <string>(fileName, valueName);

            if (!String.IsNullOrEmpty(rawExecPolicy))
            {
                execPolicy = rawExecPolicy;
            }
            return(execPolicy);
        }
Пример #23
0
        private int GetValue(PropertyScope scope)
        {
            switch (scope)
            {
            case PropertyScope.Public:
                return(4);

            case PropertyScope.Protected:
                return(3);

            case PropertyScope.Internal:
                return(2);

            case PropertyScope.Private:
                return(1);

            case PropertyScope.NotAvailable:
            default:
                return(0);
            }
        }
Пример #24
0
        protected internal override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope propertyScope)
        {
            if (key.ValueType == JSValueType.Symbol || propertyScope >= PropertyScope.Super)
            {
                return(base.GetProperty(key, forWrite, propertyScope));
            }

            var keyString        = key.ToString();
            var targetDictionary = _target as IDictionary <string, object>;

            if (!forWrite)
            {
                if (!targetDictionary.ContainsKey(keyString))
                {
                    return(undefined);
                }

                return(Marshal(targetDictionary[keyString]));
            }

            return(new ValueWrapper(this, keyString));
        }
Пример #25
0
        internal override void RemoveExecutionPolicy(PropertyScope scope, string shellId)
        {
            string      regKeyName = Utils.GetRegistryConfigurationPath(shellId);
            RegistryKey scopedKey  = Registry.LocalMachine;

            // Override if set to another value;
            if (PropertyScope.CurrentUser == scope)
            {
                scopedKey = Registry.CurrentUser;
            }

            using (RegistryKey key = scopedKey.OpenSubKey(regKeyName, true))
            {
                if (key != null)
                {
                    if (key.GetValue("ExecutionPolicy") != null)
                    {
                        key.DeleteValue("ExecutionPolicy");
                    }
                }
            }
        }
Пример #26
0
        public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary <string, VariableDescriptor> variables, CodeContext codeContext, InternalCompilerMessageCallback message, FunctionInfo stats, Options opts)
        {
            if (stats != null)
            {
                stats.UseGetMember = true;
            }
            base.Build(ref _this, expressionDepth, variables, codeContext, message, stats, opts);
            if (_right is Constant)
            {
                cachedMemberName = _right.Evaluate(null);
                if (stats != null && cachedMemberName.ToString() == "arguments")
                {
                    stats.ContainsArguments = true;
                }
            }

            if (_left is Super)
            {
                memberScope = (codeContext & CodeContext.InStaticMember) != 0 ? PropertyScope.Super : PropertyScope.PrototypeOfSuperclass;
            }

            return(false);
        }
Пример #27
0
 internal protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
 {
     if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
     {
         int    index  = 0;
         double dindex = Tools.JSObjectToDouble(key);
         if (!double.IsInfinity(dindex) &&
             !double.IsNaN(dindex) &&
             ((index = (int)dindex) == dindex) &&
             ((index = (int)dindex) == dindex) &&
             index < (_oValue.ToString()).Length &&
             index >= 0)
         {
             return(this[index]);
         }
         var namestr = key.ToString();
         if (namestr == "length")
         {
             return(length);
         }
     }
     return(base.GetProperty(key, forWrite, memberScope)); // обращение идёт к Объекту String, а не к значению string, поэтому члены создавать можно
 }
Пример #28
0
        protected override void SetProperty(JSValue name, JSValue value, PropertyScope propertyScope, bool throwOnError)
        {
            if (name.ToString() == "OnTick")
            {
                OnTick += (d) =>
                {
                    var arg = new Arguments();
                    arg.Add(Marshal(d));
                    var func = (value.Value as NiL.JS.BaseLibrary.Function);
                    func.Call(arg);
                };
                return;
            }

            base.SetProperty(name, value, propertyScope, throwOnError);
        }
Пример #29
0
        protected internal override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
        {
            if (forWrite)
            {
                cloneValues();
            }

            if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
            {
                forWrite &= (_attributes & JSValueAttributesInternal.Immutable) == 0;
                if (key._valueType == JSValueType.Integer)
                {
                    switch (key._iValue)
                    {
                    case 0:
                        return(a0 ?? (!forWrite ? notExists : (a0 = new JSValue()
                        {
                            _valueType = JSValueType.NotExistsInObject
                        })));

                    case 1:
                        return(a1 ?? (!forWrite ? notExists : (a1 = new JSValue()
                        {
                            _valueType = JSValueType.NotExistsInObject
                        })));

                    case 2:
                        return(a2 ?? (!forWrite ? notExists : (a2 = new JSValue()
                        {
                            _valueType = JSValueType.NotExistsInObject
                        })));

                    case 3:
                        return(a3 ?? (!forWrite ? notExists : (a3 = new JSValue()
                        {
                            _valueType = JSValueType.NotExistsInObject
                        })));

                    case 4:
                        return(a4 ?? (!forWrite ? notExists : (a4 = new JSValue()
                        {
                            _valueType = JSValueType.NotExistsInObject
                        })));
                    }
                }
                switch (key.ToString())
                {
                case "0":
                    return(a0 ?? (!forWrite ? notExists : (a0 = new JSValue()
                    {
                        _valueType = JSValueType.NotExistsInObject
                    })));

                case "1":
                    return(a1 ?? (!forWrite ? notExists : (a1 = new JSValue()
                    {
                        _valueType = JSValueType.NotExistsInObject
                    })));

                case "2":
                    return(a2 ?? (!forWrite ? notExists : (a2 = new JSValue()
                    {
                        _valueType = JSValueType.NotExistsInObject
                    })));

                case "3":
                    return(a3 ?? (!forWrite ? notExists : (a3 = new JSValue()
                    {
                        _valueType = JSValueType.NotExistsInObject
                    })));

                case "4":
                    return(a4 ?? (!forWrite ? notExists : (a4 = new JSValue()
                    {
                        _valueType = JSValueType.NotExistsInObject
                    })));

                case "length":
                {
                    if (_lengthContainer == null)
                    {
                        _lengthContainer = new _LengthContainer(this)
                        {
                            _valueType  = JSValueType.Integer,
                            _iValue     = length,
                            _attributes = JSValueAttributesInternal.DoNotEnumerate | JSValueAttributesInternal.Reassign
                        }
                    }
                    ;
                    return(_lengthContainer);
                }

                case "callee":
                {
                    if (callee == null)
                    {
                        callee = NotExistsInObject;
                    }

                    if (forWrite && (callee._attributes & JSValueAttributesInternal.SystemObject) != 0)
                    {
                        callee             = callee.CloneImpl(false);
                        callee._attributes = JSValueAttributesInternal.DoNotEnumerate;
                    }
                    return(callee);
                }

                case "caller":
                {
                    if (caller == null)
                    {
                        caller = NotExistsInObject;
                    }

                    if (forWrite && (caller._attributes & JSValueAttributesInternal.SystemObject) != 0)
                    {
                        caller             = caller.CloneImpl(false);
                        callee._attributes = JSValueAttributesInternal.DoNotEnumerate;
                    }
                    return(caller);
                }
                }
            }

            return(base.GetProperty(key, forWrite, memberScope));
        }
Пример #30
0
 internal protected JSValue GetProperty(string name, bool forWrite, PropertyScope propertyScope)
 {
     return(GetProperty((JSValue)name, forWrite, propertyScope));
 }
Пример #31
0
 public JSValue GetProperty(string name, PropertyScope propertyScope)
 {
     return(GetProperty((JSValue)name, false, propertyScope));
 }
        private bool ValidateLite(ValidationContext validationContext, Lite<Entity> lite)
        {
            if (lite.EntityOrNull == null)
                return true;

            PropertyScope propertyScope = new PropertyScope { PropertyName = "entity" };
            validationContext.KeyBuilders.Push(propertyScope);
            var isValid = ValidateModifiableEntity(validationContext, lite.Entity);
            validationContext.KeyBuilders.Pop();
            return isValid;
        }
Пример #33
0
        private bool ValidateModifiableEntity(ValidationContext validationContext, ModifiableEntity mod)
        {
            if (mod is Entity && validationContext.Visited.Contains(mod))
            {
                return(true);
            }

            validationContext.Visited.Add(mod);

            bool          isValid       = true;
            PropertyScope propertyScope = new PropertyScope();

            validationContext.KeyBuilders.Push(propertyScope);

            var entity = mod as Entity;

            using (entity == null ? null : entity.Mixins.OfType <CorruptMixin>().Any(c => c.Corrupt) ? Corruption.AllowScope() : Corruption.DenyScope())
            {
                foreach (var kvp in PropertyConverter.GetPropertyConverters(mod.GetType()))
                {
                    if (kvp.Value.AvoidValidate)
                    {
                        continue;
                    }

                    propertyScope.PropertyName = kvp.Key;
                    if (SignumValidate(validationContext, kvp.Value.GetValue(mod)) ?? true)
                    {
                        isValid = false;
                    }

                    string error = kvp.Value.PropertyValidator.PropertyCheck(mod);

                    if (error != null)
                    {
                        string key = CalculateKey(validationContext);
                        if (validationContext.ModelState.IsValidField(key))
                        {
                            isValid = false;
                            validationContext.ModelState.AddModelError(key, error);
                        }
                    }
                }
            }

            if (entity != null && entity.Mixins.Any())
            {
                propertyScope.PropertyName = "mixins";
                PropertyScope mixinScope = new PropertyScope();
                validationContext.KeyBuilders.Push(mixinScope);
                foreach (var mixin in entity.Mixins)
                {
                    mixinScope.PropertyName = mixin.GetType().Name;
                    if (!ValidateModifiableEntity(validationContext, mixin))
                    {
                        isValid = false;
                    }
                }
                validationContext.KeyBuilders.Pop();
            }

            validationContext.KeyBuilders.Pop();

            validationContext.Visited.Remove(mod);
            return(isValid);
        }
Пример #34
0
 protected override JSValue GetProperty(JSValue name, bool forWrite, PropertyScope memberScope) {
   if(_owner == null) {
     return JSValue.Undefined;
   }
   if(name.ToString() == "toJSON") {
     return base.GetProperty(name, forWrite, memberScope);
   }
   string pName = name.ToString();
   if(_decl.pins.ContainsKey(pName)) {
     Topic r = _owner.GetI(pName, forWrite, _owner, true);
     if(r == null) {
       return JSValue.Undefined;
     }
     return r._value;
   } else {
     return base.GetProperty(name, forWrite, memberScope);
   }
 }
 private bool ValidateProperties(ModelMetadata metadata, ValidationContext validationContext)
 {
     bool isValid = true;
     PropertyScope propertyScope = new PropertyScope();
     validationContext.KeyBuilders.Push(propertyScope);
     foreach (ModelMetadata childMetadata in validationContext.MetadataProvider.GetMetadataForProperties(metadata.Model, metadata.RealModelType))
     {
         propertyScope.PropertyName = childMetadata.PropertyName;
         if (!ValidateNodeAndChildren(childMetadata, validationContext, metadata.Model))
         {
             isValid = false;
         }
     }
     validationContext.KeyBuilders.Pop();
     return isValid;
 }
Пример #36
0
 internal abstract void SetExecutionPolicy(PropertyScope scope, string shellId, string executionPolicy);
        private bool ValidateMList(ValidationContext validationContext, IMListPrivate mlist)
        {
            bool isValid = true;
            Type elementType = mlist.GetType().ElementType();
            ModelMetadata elementMetadata = validationContext.MetadataProvider.GetMetadataForType(null, elementType);

            ElementScope elementScope = new ElementScope() { Index = 0 };
            validationContext.KeyBuilders.Push(elementScope);

            PropertyScope property = new PropertyScope { PropertyName = "element" };
            validationContext.KeyBuilders.Push(property);

            foreach (object element in (IEnumerable)mlist)
            {
                elementMetadata.Model = element;
                if (!ValidateNodeAndChildren(elementMetadata, validationContext, mlist))
                {
                    isValid = false;
                }
                elementScope.Index++;
            }
            validationContext.KeyBuilders.Pop();

            validationContext.KeyBuilders.Pop();
            return isValid;
        }
Пример #38
0
 protected override void SetProperty(JSValue key, JSValue value, PropertyScope memberScope, bool throwOnError) {
   string pName = key.ToString();
   if(_decl.pins.ContainsKey(pName)) {
     if(_owner == null) {
       return;
     }
     Topic r = _owner.GetI(pName, true, _owner, true);
     r.SetI(value.Clone(), _owner);
   } else {
     base.SetProperty(key, value, memberScope, throwOnError);
   }
 }