public Element Activate(ElementDescriptor descriptor, Action <Element> initialize = null)
        {
            _elementEventHandler.Creating(new ElementCreatingContext {
                ElementDescriptor = descriptor
            });

            var element = Activate(descriptor.ElementType);

            element.Descriptor     = descriptor;
            element.T              = T;
            element.Data           = new ElementDataDictionary();
            element.ExportableData = new ElementDataDictionary();

            if (initialize != null)
            {
                initialize(element);
            }

            _elementEventHandler.Created(new ElementCreatedContext {
                Element           = element,
                ElementDescriptor = descriptor
            });

            return(element);
        }
Example #2
0
        private static void UpdateAnchors(ElementWindow elementWindow, List <IElement> elements)
        {
            ElementDescriptor mainDescriptor = elementWindow.ElementDescriptor;

            foreach (IElement element in elements)
            {
                ElementDescriptor elementDescriptor = element.ElementDescriptor;
                FrameworkElement  control           = (FrameworkElement)element;

                if (elementDescriptor.Anchor1.HasValue)
                {
                    System.Drawing.Point elementPos = elementDescriptor.Pos.GetValueOrDefault();
                    System.Drawing.Size  windowSize = mainDescriptor.Size.GetValueOrDefault();

                    double offset1X = elementPos.X - (windowSize.Width * elementDescriptor.Anchor1.Value.X / 100);
                    double offset1Y = elementPos.Y - (windowSize.Height * elementDescriptor.Anchor1.Value.Y / 100);
                    double left     = (elementWindow.ActualWidth * elementDescriptor.Anchor1.Value.X / 100) + offset1X;
                    double top      = (elementWindow.ActualHeight * elementDescriptor.Anchor1.Value.Y / 100) + offset1Y;
                    Canvas.SetLeft(control, left);
                    Canvas.SetTop(control, top);

                    if (elementDescriptor.Anchor2.HasValue)
                    {
                        System.Drawing.Size elementSize = elementDescriptor.Size.GetValueOrDefault();

                        double offset2X = (elementPos.X + elementSize.Width) - (windowSize.Width * elementDescriptor.Anchor2.Value.X / 100);
                        double offset2Y = (elementPos.Y + elementSize.Height) - (windowSize.Height * elementDescriptor.Anchor2.Value.Y / 100);
                        control.Width  = (elementWindow.ActualWidth * elementDescriptor.Anchor2.Value.X / 100) + offset2X - left;
                        control.Height = (elementWindow.ActualHeight * elementDescriptor.Anchor2.Value.Y / 100) + offset2Y - top;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// 查看给定元素的本体元素数据模式
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public ElementDataSchema GetElementDataSchema(ElementDescriptor element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            ElementDataSchema dataSchema;

            if (ElementDataSchemaDic.TryGetValue(element, out dataSchema))
            {
                return(dataSchema);
            }
            else
            {
                var           db = this.GetEntityDb(element.Ontology);
                DbTableColumn column;
                string        columnId = string.Format("[{0}][{1}][{2}]", element.Ontology.Ontology.EntitySchemaName, element.Ontology.Ontology.EntityTableName, element.Element.FieldCode);
                if (!element.Host.Rdbs.DbTableColumns.TryGetDbTableColumn(db, columnId, out column))
                {
                    var msg = "实体库中不存在" + columnId + "列";
                    element.Host.LoggingService.Error(msg);
                    return(null);
                }
                dataSchema = new ElementDataSchema(column);
                ElementDataSchemaDic.Add(element, dataSchema);
                return(dataSchema);
            }
        }
        public PrimitiveManager(MDL0Polygon *polygon, AssetStorage assets, IMatrixNode[] nodes)
        {
            byte *[] pAssetList = new byte *[12];
            byte *[] pOutList   = new byte *[12];
            int      id;

            //This relies on the header being accurate!
            _pointCount = polygon->_numVertices;

            //Grab asset lists in sequential order.
            //This involves checking IDs and creating buffers for the pre-processed data.
            //Also gets data addresses from pre-decoded assets so they can be parsed further
            //All buffers are stored in the _faceData array

            if ((id = polygon->_vertexId) >= 0)
            {
                pAssetList[0] = (byte *)assets.Assets[0][id].Address;
                pOutList[0]   = (byte *)(_faceData[0] = new UnsafeBuffer(2 * _pointCount)).Address;
            }
            //Save vertices for last

            if ((id = polygon->_normalId) >= 0)
            {
                pAssetList[1] = (byte *)assets.Assets[1][id].Address;
                pOutList[1]   = (byte *)(_faceData[1] = new UnsafeBuffer(12 * _pointCount)).Address;
            }

            for (int i = 0, x = 2; i < 2; i++, x++)
            {
                if ((id = ((bshort *)polygon->_colorIds)[i]) >= 0)
                {
                    pAssetList[x] = (byte *)assets.Assets[2][id].Address;
                    pOutList[x]   = (byte *)(_faceData[x] = new UnsafeBuffer(4 * _pointCount)).Address;
                }
            }

            for (int i = 0, x = 4; i < 8; i++, x++)
            {
                if ((id = ((bshort *)polygon->_uids)[i]) >= 0)
                {
                    pAssetList[x] = (byte *)assets.Assets[3][id].Address;
                    pOutList[x]   = (byte *)(_faceData[x] = new UnsafeBuffer(8 * _pointCount)).Address;
                }
            }


            //Compile decode script
            ElementDescriptor desc = new ElementDescriptor(polygon);

            //Extract primitives, using our descriptor and asset lists
            fixed(byte **pOut = pOutList)
            fixed(byte **pAssets = pAssetList)
            ExtractPrimitives((byte *)polygon->PrimitiveData, ref desc, pOut, pAssets);

            //Compile vertex list using influences from node cache
            _vertices = desc.Finish((Vector3 *)pAssetList[0], nodes);
        }
Example #5
0
        /// <summary>
        /// This constructor initializes a partion with one class for each element
        /// </summary>
        /// <param name="maxIndex">A tuple containing the maximal index</param>
        protected PartitionInfoArrayInt(Int32 maxIndex)
        {
            Info = new ElementDescriptor[maxIndex];

            for (Int32 i = 0; i < Info.Length; i++)
            {
                Info[i].NextElementID    = i; // one element partition class i, element i pointing to itself
                Info[i].RepresentativeID = i; // and element i being its own representative
            }
        }
Example #6
0
        private List <(ElementDescriptor Element, ulong Position)> ReadSeekHeads(EbmlReader ebmlReader)
        {
            List <(ElementDescriptor, ulong)> availableElements = null;
            ElementDescriptor desc;
            ElementDescriptor availDesc = null;
            ulong             pos       = 0;

            ebmlReader.EnterContainer();
            while (ebmlReader.ReadNext())
            {
                if (_descriptorsMap.TryGetValue(ebmlReader.ElementId.EncodedValue, out desc))
                {
                    if (desc.Name == "Seek")
                    {
                        ebmlReader.EnterContainer();
                        try
                        {
                            while (ebmlReader.ReadNext())
                            {
                                if (_descriptorsMap.TryGetValue(ebmlReader.ElementId.EncodedValue, out desc))
                                {
                                    if (desc.Name == "SeekID")
                                    {
                                        byte[] data = new byte[ebmlReader.ElementSize];
                                        ebmlReader.ReadBinary(data, 0, data.Length);
                                        MemoryStream mem  = new MemoryStream(data);
                                        byte[]       temp = new byte[data.Length];
                                        VInt         id   = VInt.Read(mem, data.Length, temp);
                                        _descriptorsMap.TryGetValue(id.EncodedValue, out availDesc);
                                    }
                                    else if (desc.Name == "SeekPosition")
                                    {
                                        pos = ebmlReader.ReadUInt();
                                    }
                                }
                            }

                            if (availableElements == null)
                            {
                                availableElements = new List <(ElementDescriptor, ulong)>();
                            }
                            if (availDesc != null && pos > 0)
                            {
                                availableElements.Add((availDesc, pos));
                            }
                        }
                        catch { }
                    }
                    ebmlReader.LeaveContainer();
                }
            }
            ebmlReader.LeaveContainer();
            return(availableElements);
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="element"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static InfoItem Create(ElementDescriptor element, string value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     return(new InfoItem(element.Element.Code, value)
     {
         Element = element
     });
 }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="element"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static InfoItem Create(ElementDescriptor element, string value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     return new InfoItem(element.Element.Code, value)
     {
         Element = element
     };
 }
Example #9
0
 public ElementDescriptor[] readElementDescriptors(BinaryReader reader, int number)
 {
     ElementDescriptor[] elements = new ElementDescriptor[number];
     for (int i = 0; i < number; i++)
     {
         int            nameIndex      = readLittleEndianShort(reader);
         DataDescriptor dataDescriptor = readDataDescriptor(reader);
         elements[i] = new ElementDescriptor(nameIndex, dataDescriptor);
     }
     return(elements);
 }
Example #10
0
        void Transform(string xsltPath, TextWriter output)
        {
            XslCompiledTransform xslt;

            if (!_stylesheets.TryGetValue(xsltPath, out xslt))
            {
                _stylesheets[xsltPath] = xslt = new XslCompiledTransform();
                xslt.Load(xsltPath);
            }

            xslt.Transform(new ObjectNavigator(ElementDescriptor.CreateFor(Model)), GetArguments(), output);
        }
Example #11
0
	public void initRandomElement () {
		int rand = Random.Range(0, ElementDescriptor.getElementsCount());
		switch (rand) {
			case 0: initElement(ElementType.FIRE); break;
			case 1: initElement(ElementType.WATER); break;
			case 2: initElement(ElementType.EARTH); break;
			case 3: initElement(ElementType.AIR); break;
			case 4: initElement(ElementType.LIGHT); break;
			case 5: initElement(ElementType.DARK); break;
			default: Debug.Log("Unknown element type");break;
		}
	}
 private XElement GetXsdContolValue(ElementDescriptor element, XNamespace xsd, XNamespace targetNamespace)
 {
     try
     {
         ControlValuePropertyAttribute controlValue = (ControlValuePropertyAttribute)(element.ElementType.GetCustomAttributes(typeof(ControlValuePropertyAttribute), true).First());
         return(GetXsdSequence(element.ElementType.GetProperty(controlValue.PropertyName), xsd, targetNamespace));
     }
     catch (Exception)
     {
     }
     return(null);
 }
Example #13
0
        /// <summary>
        /// Create completions for attribute names.
        /// </summary>
        private IEnumerable <XmlResourceCompletion> CreateAttributeCompletions(ElementDescriptor elementDescriptor)
        {
            var provider = DescriptorProvider;

            if (provider == null)
            {
                return(Enumerable.Empty <XmlResourceCompletion>());
            }
            var names  = elementDescriptor.Attributes.Select(x => x.Name);
            var prefix = "android";

            return(names.OrderBy(x => x).Select(x => new XmlResourceCompletion(glyphService, x, string.Format("{0}:{1}=\"\"", prefix, x), x, 1, XmlResourceCompletionType.Attribute)));
        }
Example #14
0
        public static bool LocateElement(this EbmlReader reader, ElementDescriptor descriptor)
        {
            while (reader.ReadNext())
            {
                var identifier = reader.ElementId;

                if (identifier == descriptor.Identifier)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #15
0
        public void PopulateElementDescriptor(MappingDataNode node, ISerializationManager serializationManager)
        {
            MappingDataNode original = (MappingDataNode)serializationManager.WriteValue(ElementDescriptor.GetType(), ElementDescriptor);

            foreach (var key in node.Keys)
            {
                original.Remove(key);
            }

            MappingDataNode newNode = original.Merge(node);

            ElementDescriptor = (ElementDescriptor)serializationManager.Read(ElementDescriptor.GetType(), newNode);
            UpdateElementDescriptor();
        }
Example #16
0
    private ElementType getRandomType(ElementType[] exclusion)
    {
        ElementType elementType = ElementType.FIRE;
        int         rand        = Random.Range(0, ElementDescriptor.getElementsCount());

        if (exclusion == null)
        {
            switch (rand)
            {
            case 0: elementType = ElementType.FIRE; break;

            case 1: elementType = ElementType.WATER; break;

            case 2: elementType = ElementType.EARTH; break;

            case 3: elementType = ElementType.AIR; break;

            case 4: elementType = ElementType.LIGHT; break;

            case 5: elementType = ElementType.DARK; break;

            default: Debug.Log("Unknown element type"); break;
            }
        }
        else
        {
            while (elementType == exclusion[0] || elementType == exclusion[1])
            {
                rand = Random.Range(0, ElementDescriptor.getElementsCount());
                switch (rand)
                {
                case 0: elementType = ElementType.FIRE; break;

                case 1: elementType = ElementType.WATER; break;

                case 2: elementType = ElementType.EARTH; break;

                case 3: elementType = ElementType.AIR; break;

                case 4: elementType = ElementType.LIGHT; break;

                case 5: elementType = ElementType.DARK; break;

                default: Debug.Log("Unknown element type"); break;
                }
            }
        }
        return(elementType);
    }
Example #17
0
        private Action <EbmlReader> MakeElementDumper(ElementDescriptor element)
        {
            Func <EbmlReader, string> dump = null;

            switch (element.Type)
            {
            case ElementType.AsciiString:
                dump = reader => reader.ReadAscii();
                break;

            case ElementType.Binary:
                dump = _ => "binary data";
                break;

            case ElementType.Date:
                dump = r => r.ReadDate().ToString();
                break;

            case ElementType.Float:
                dump = r => r.ReadFloat().ToString();
                break;

            case ElementType.SignedInteger:
                dump = r => r.ReadInt().ToString();
                break;

            case ElementType.UnsignedInteger:
                dump = r => r.ReadUInt().ToString();
                break;

            case ElementType.Utf8String:
                dump = r => r.ReadUtf();
                break;

            default:
                dump = _ => string.Format("unknown (id:{0})", element.Type.ToString());
                break;
            }

            return(reader =>
            {
                if (reader.ElementId == element.Identifier)
                {
                    Console.WriteLine("{0}: {1}", element.Name, dump(reader));
                }
            });
        }
Example #18
0
        public static IElement CreateElementFromDescriptor(ElementDescriptor elementDescriptor)
        {
            IElement element;

            if (elementDescriptor is ElementDescriptorChild)
            {
                element = new ElementChild();
            }
            else if (elementDescriptor is ElementDescriptorInput)
            {
                element = new ElementInput();
            }
            else if (elementDescriptor is ElementDescriptorButton)
            {
                element = new ElementButton();
            }
            else if (elementDescriptor is ElementDescriptorOutput)
            {
                element = new ElementOutput();
            }
            else if (elementDescriptor is ElementDescriptorInfo)
            {
                element = new ElementInfo();
            }
            else if (elementDescriptor is ElementDescriptorMap)
            {
                element = new ElementMap();
            }
            else if (elementDescriptor is ElementDescriptorBrowser)
            {
                element = new ElementBrowser();
            }
            else
            {
                throw new Exception("Invalid descriptor");
            }

            SetSharedAttributes(element, elementDescriptor);
            element.ElementDescriptor = elementDescriptor;

            return(element);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var objectElementDescriptor = (IObjectElementDescriptor)value;
            var elementDescriptor       = new ElementDescriptor(
                objectElementDescriptor.Type,
                objectElementDescriptor.TemplateCode,
                objectElementDescriptor.Properties,
                objectElementDescriptor.Constraints);

            var json = JObject.FromObject(elementDescriptor, serializer);

            json[Tokens.ValueToken] = JToken.FromObject(objectElementDescriptor.Value, serializer);
            json[Tokens.IdToken]    = objectElementDescriptor.Id;

            var versionedObjectElementDescriptor = (IVersionedObjectElementDescriptor)value;

            json[Tokens.VersionIdToken] = versionedObjectElementDescriptor.VersionId;
            json["lastModified"]        = versionedObjectElementDescriptor.LastModified;
            json.WriteTo(writer);
        }
Example #20
0
        private static void SetSharedAttributes(IElement element, ElementDescriptor elementDescriptor)
        {
            UIElement        uiElement        = (UIElement)element;
            FrameworkElement frameworkElement = uiElement as FrameworkElement;

            System.Drawing.Point pos = elementDescriptor.Pos.GetValueOrDefault();

            Canvas.SetLeft(uiElement, pos.X);
            Canvas.SetTop(uiElement, pos.Y);
            if (frameworkElement != null)
            {
                System.Drawing.Size size = elementDescriptor.Size.GetValueOrDefault();

                frameworkElement.Width  = size.Width;
                frameworkElement.Height = size.Height;
            }

            if (elementDescriptor.BackgroundColor.HasValue)
            {
                System.Drawing.Color color = elementDescriptor.BackgroundColor.Value;
                Brush brush = new SolidColorBrush(Color.FromRgb(color.R, color.G, color.B));

                if (uiElement is Panel)
                {
                    ((Panel)uiElement).Background = brush;
                }
                else if (uiElement is Control)
                {
                    ((Control)uiElement).Background = brush;
                }
            }

            if (elementDescriptor.IsVisible.HasValue)
            {
                uiElement.Visibility = elementDescriptor.IsVisible.Value ? Visibility.Visible : Visibility.Hidden;
            }
        }
Example #21
0
 /// <summary>
 /// 查看给定元素的本体元素数据模式
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public ElementDataSchema GetElementDataSchema(ElementDescriptor element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     ElementDataSchema dataSchema;
     if (ElementDataSchemaDic.TryGetValue(element, out dataSchema))
     {
         return dataSchema;
     }
     else
     {
         var db = this.GetEntityDb(element.Ontology);
         DbTableColumn column;
         string columnId = string.Format("[{0}][{1}][{2}]", element.Ontology.Ontology.EntitySchemaName, element.Ontology.Ontology.EntityTableName, element.Element.FieldCode);
         if (!element.Host.Rdbs.DbTableColumns.TryGetDbTableColumn(db, columnId, out column))
         {
             var msg = "实体库中不存在" + columnId + "列";
             element.Host.LoggingService.Error(msg);
             return null;
         }
         dataSchema = new ElementDataSchema(column);
         ElementDataSchemaDic.Add(element, dataSchema);
         return dataSchema;
     }
 }
Example #22
0
 public ElementDescriptor[] readElementDescriptors(BinaryReader reader, int number)
 {
     ElementDescriptor[] elements = new ElementDescriptor[number];
     for (int i = 0; i < number; i++)
     {
         int nameIndex = readLittleEndianShort(reader);
         DataDescriptor dataDescriptor = readDataDescriptor(reader);
         elements[i] = new ElementDescriptor(nameIndex, dataDescriptor);
     }
     return elements;
 }
Example #23
0
            private XElement GetXsdContolValue(ElementDescriptor element, XNamespace xsd, XNamespace targetNamespace)
            {
                try
                {
                    ControlValuePropertyAttribute controlValue = (ControlValuePropertyAttribute)(element.ElementType.GetCustomAttributes(typeof(ControlValuePropertyAttribute), true).First());
                    return GetXsdSequence(element.ElementType.GetProperty(controlValue.PropertyName), xsd, targetNamespace);
                }
                catch (Exception)
                {

                }
                return null;

            }
Example #24
0
 public ShortNameToken(char name, ElementDescriptor desc)
     : base(desc.WithLengthChangedBy(1))
 {
     Name = name;
 }
Example #25
0
 public BuildTask(ElementDescriptor Descriptor)
     : base(Descriptor)
 {
 }
            private Type GetElementType(DataTypes dt, BinaryReader br, DeserializationManager manager, bool allowOpenTypes, out DataTypeDescriptor existingDescriptor)
            {
                existingDescriptor = null;
                switch (dt & ~DataTypes.Store7BitEncoded)
                {
                case DataTypes.Bool:
                    return(Reflector.BoolType);

                case DataTypes.Int8:
                    return(Reflector.SByteType);

                case DataTypes.UInt8:
                    return(Reflector.ByteType);

                case DataTypes.Int16:
                    return(Reflector.ShortType);

                case DataTypes.UInt16:
                    return(Reflector.UShortType);

                case DataTypes.Int32:
                    return(Reflector.IntType);

                case DataTypes.UInt32:
                    return(Reflector.UIntType);

                case DataTypes.Int64:
                    return(Reflector.LongType);

                case DataTypes.UInt64:
                    return(Reflector.ULongType);

                case DataTypes.Char:
                    return(Reflector.CharType);

                case DataTypes.String:
                    return(Reflector.StringType);

                case DataTypes.Single:
                    return(Reflector.FloatType);

                case DataTypes.Double:
                    return(Reflector.DoubleType);

                case DataTypes.Decimal:
                    return(Reflector.DecimalType);

                case DataTypes.DateTime:
                    return(Reflector.DateTimeType);

                case DataTypes.DBNull:
                    return(Reflector.DBNullType);

                case DataTypes.IntPtr:
                    return(Reflector.IntPtrType);

                case DataTypes.UIntPtr:
                    return(Reflector.UIntPtrType);

                case DataTypes.Version:
                    return(typeof(Version));

                case DataTypes.Guid:
                    return(Reflector.GuidType);

                case DataTypes.TimeSpan:
                    return(Reflector.TimeSpanType);

                case DataTypes.DateTimeOffset:
                    return(Reflector.DateTimeOffsetType);

                case DataTypes.Uri:
                    return(typeof(Uri));

                case DataTypes.BitArray:
                    return(Reflector.BitArrayType);

                case DataTypes.BitVector32:
                    return(typeof(BitVector32));

                case DataTypes.BitVector32Section:
                    return(typeof(BitVector32.Section));

                case DataTypes.StringBuilder:
                    return(typeof(StringBuilder));

                case DataTypes.Object:
                    return(Reflector.ObjectType);

                case DataTypes.Void:
                    return(Reflector.VoidType);

                case DataTypes.RuntimeType:
                    return(Reflector.RuntimeType);

                case DataTypes.Pointer:
                    return(ElementDescriptor.DecodeType(br, manager, allowOpenTypes).MakePointerType());

                case DataTypes.ByRef:
                    return(ElementDescriptor.DecodeType(br, manager, allowOpenTypes).MakeByRefType());

                case DataTypes.BinarySerializable:
                case DataTypes.RawStruct:
                case DataTypes.RecursiveObjectGraph:
                    existingDescriptor = manager.ReadType(br, allowOpenTypes);
                    return(existingDescriptor.Type);

                default:
                    // nullable
                    if (IsNullable(dt))
                    {
                        IsNullable = true;
                        Type underlyingType = GetElementType(dt & ~DataTypes.Nullable, br, manager, allowOpenTypes, out existingDescriptor);
                        return(Reflector.NullableType.GetGenericType(underlyingType));
                    }

                    // enum
                    if (IsEnum(dt))
                    {
                        existingDescriptor = manager.ReadType(br, allowOpenTypes);
                        return(existingDescriptor.Type);
                    }

                    return(Throw.SerializationException <Type>(Res.BinarySerializationCannotDecodeDataType(DataTypeToString(ElementDataType))));
                }
            }
Example #27
0
 protected Token(ElementDescriptor descriptor)
 {
     Descriptor = descriptor;
 }
Example #28
0
 public PositionalArgumentToken(string value, ElementDescriptor desc)
     : base(desc.WithLengthChangedBy(value.Length))
 {
     Value = value;
 }
Example #29
0
 protected Token(ElementDescriptor descriptor)
 {
     Descriptor = descriptor;
 }
Example #30
0
 public T ActivateElement <T>(ElementDescriptor descriptor, Action <T> initialize = null) where T : Element
 {
     return(_factory.Activate(descriptor, initialize));
 }
Example #31
0
 public ShortNameToken(char name, ElementDescriptor desc) : base(desc.WithLengthChangedBy(1))
 {
     Name = name;
 }
Example #32
0
 /// <summary>
 /// 判断本节点是否具有对给定的本体元素执行给定的类型的动作的权限
 /// </summary>
 /// <param name="element">本体元素码</param>
 /// <param name="actionCode">动作码</param>
 /// <returns>True表示有权限,False表示无权限</returns>
 public AllowType GetElementPermission(ElementDescriptor element, Verb actionCode)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (actionCode == null)
     {
         throw new ArgumentNullException("actionCode");
     }
     if (element == element.Ontology.IdElement)
     {
         return AllowType.ExplicitAllow;
     }
     var nodeElementActions = element.GetActions(this);
     if (!nodeElementActions.ContainsKey(actionCode))
     {
         return AllowType.NotAllow;
     }
     if (nodeElementActions[actionCode].IsAllowed)
     {
         return AllowType.ImplicitAllow;
     }
     else
     {
         return AllowType.NotAllow;
     }
 }
Example #33
0
 public bool IsInfoIdElement(ElementDescriptor element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     return AcDomain.NodeHost.Nodes.IsInfoIdElement(this, element);
 }
            /// <summary>
            /// Decodes self and element types
            /// </summary>
            internal Type DecodeType(BinaryReader br, DeserializationManager manager, bool allowOpenTypes = false)
            {
                DataTypeDescriptor existingDescriptor;

                // Simple or impure type. Handling generics occurs in recursive ReadType if needed.
                if (CollectionDataType == DataTypes.Null)
                {
                    Type       = GetElementType(ElementDataType, br, manager, allowOpenTypes, out existingDescriptor);
                    StoredType = existingDescriptor?.StoredType;
                    return(Type);
                }

                Type result;

                // generic type definition
                if (ElementDataType == DataTypes.GenericTypeDefinition)
                {
                    result = GetCollectionType(CollectionDataType);
                }
                else
                {
                    // simple collection element or dictionary key: Since in DataTypes the element is encoded together with the collection
                    // the element type descriptor was not created in the constructor. We create it now.
                    if (ElementDataType != DataTypes.Null)
                    {
                        ElementDescriptor            = new DataTypeDescriptor(ElementDataType, GetElementType(ElementDataType, br, manager, allowOpenTypes, out existingDescriptor), this);
                        ElementDescriptor.StoredType = existingDescriptor?.StoredType;
                    }
                    // complex element type: recursive decoding
                    else
                    {
                        ElementDescriptor.DecodeType(br, manager, allowOpenTypes);
                    }

                    // Dictionary TValue
                    if (IsDictionary)
                    {
                        ValueDescriptor.DecodeType(br, manager, allowOpenTypes);
                    }

                    if (IsArray)
                    {
                        // 0 means zero based 1D array
                        Rank = br.ReadByte();
                        return(Type = Rank == 0
                            ? ElementDescriptor.Type.MakeArrayType()
                            : ElementDescriptor.Type.MakeArrayType(Rank));
                    }

                    result = GetCollectionType(CollectionDataType);
                    bool isNullable = IsNullable = result.IsNullable();
                    if (!result.ContainsGenericParameters)
                    {
                        return(Type = result);
                    }

                    Type typeDef = isNullable ? result.GetGenericArguments()[0] : result;
                    result = typeDef.GetGenericArguments().Length == 1
                        ? typeDef.GetGenericType(ElementDescriptor.Type)
                        : typeDef.GetGenericType(ElementDescriptor.Type, ValueDescriptor.Type);
                    result = isNullable ? Reflector.NullableType.GetGenericType(result) : result;
                }

                if (result.IsGenericTypeDefinition)
                {
                    result = manager.HandleGenericTypeDef(br, new DataTypeDescriptor(result), allowOpenTypes, false).Type;
                }
                return(Type = result);
            }
Example #35
0
 public PositionalArgumentToken(string value, ElementDescriptor desc) : base(desc.WithLengthChangedBy(value.Length))
 {
     Value = value;
 }
Example #36
0
 public Element ActivateElement(ElementDescriptor descriptor, Action <Element> initialize = null)
 {
     return(_factory.Activate(descriptor, initialize));
 }
Example #37
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public DiscriminateResult IsNeedAudit(MessageContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            var requestType = context.Command.MessageType;
            // 如果是事件则不需要审核
            if (requestType == MessageType.Event || requestType == MessageType.Undefined)
            {
                return DiscriminateResult.No;
            }
            // 如果未验证通过则不需要审核
            if (context.Ontology == null)
            {
                return DiscriminateResult.No;
            }
            // Level1Action 如果本体动作不需要审核则不审核
            #region Level1Action
            ActionState action;
            if (!context.Ontology.Actions.TryGetValue(context.Command.Verb, out action))
            {
                throw new GeneralException("非法的动作类型");
            }
            var auditType = action.AuditType;
            switch (auditType)
            {
                case AuditType.Invalid:
                    return new DiscriminateResult(false, "意外的审核类型Invalid");
                case AuditType.ExplicitAudit:
                    return DiscriminateResult.Yes;
                case AuditType.ImplicitAudit:
                    break;
                case AuditType.NotAudit:
                    return DiscriminateResult.No;
                default:
                    return new DiscriminateResult(false, "意外的审核类型" + auditType.ToName());
            }
            #endregion
            // Level2ElementAction 如果所有本体元素都不需要审核则不审核
            #region Level2ElementAction
            if (context.InfoTuplePair == null)
            {
                return DiscriminateResult.No;
            }
            var isAudit = false;
            foreach (var elementActionDic in context.InfoTuplePair.ValueTuple.Select(a => a.Element.Element.ElementActions))
            {
                if (elementActionDic.ContainsKey(context.Command.Verb))
                {
                    continue;
                }
                var elementAction = elementActionDic[context.Command.Verb];
                switch (elementAction.AuditType)
                {
                    case AuditType.Invalid:
                        return new DiscriminateResult(false, "意外的审核类型Invalid");
                    case AuditType.ExplicitAudit:
                        isAudit = true;
                        return DiscriminateResult.Yes;
                    case AuditType.ImplicitAudit:
                        break;
                    case AuditType.NotAudit:
                        break;
                    default:
                        return new DiscriminateResult(false, "意外的审核类型" + auditType.ToName());
                }
            }
            if (isAudit)
            {
                return DiscriminateResult.Yes;
            }
            #endregion
            // Level3ClientAction 如果来源节点的这个本体动作不需要审核则不审核
            #region Level3ClientAction
            if (context.ClientAgent.GetOntologyAudit(context.Ontology, context.Command.Verb) == AuditType.NotAudit)
            {
                return DiscriminateResult.No;
            }
            #endregion
            // Level4ClientElementAction 如果来自来源节点的当前命令的所有涉及元素不需要审核则不审核
            #region Level4ClientElementAction
            var isA = false;
            ElementDescriptor auditElement = null;
            foreach (var valueItem in context.InfoTuplePair.ValueTuple)
            {
                isA = context.ClientAgent.GetElementAudit(valueItem.Element, context.Command.Verb) != AuditType.NotAudit;
                if (isA)
                {
                    auditElement = valueItem.Element;
                    break;
                }
            }
            if (!isA)
            {
                return DiscriminateResult.No;
            }
            #endregion
            if (context.Ontology.Ontology.IsCataloguedEntity)
            {
                // Level5CatalogAction 如果是目录型本体且当前实体所属的目录的这个本体动作不需要审核则不审核
                #region Level5CatalogAction
                CatalogState org;
                if (!context.Host.CatalogSet.TryGetCatalog(context.CatalogCode, out org))
                {
                    throw new GeneralException("非法的目录码" + context.CatalogCode);
                }
                OntologyCatalogState ontologyOrg;
                if (!context.Ontology.Catalogs.TryGetValue(org, out ontologyOrg))
                {
                    context.Exception = new GeneralException("非法的目录码。非法的目录码的命令应该未验证通过,不应该走到这一步");
                    throw context.Exception;
                }
                var orgActions = ontologyOrg.CatalogActions;
                if (!orgActions.ContainsKey(context.Command.Verb) || orgActions[context.Command.Verb].AuditType == AuditType.NotAudit)
                {
                    return DiscriminateResult.No;
                }
                else
                {
                    string msg = string.Empty;
                    if (auditElement != null && !auditElement.Element.Code.Equals("ZZJGM", StringComparison.OrdinalIgnoreCase))
                    {
                        msg = "在" + org.Name + "下" + action.Name + context.Ontology.Ontology.Name + auditElement.Element.Name + "需要审核。审核消息已发出,请等待管理员处理";
                    }
                    else
                    {
                        msg = "在" + org.Name + "下" + action.Name + context.Ontology.Ontology.Name + "需要审核。审核消息已发出,请等待管理员处理";
                    }
                    return new DiscriminateResult(true, msg);
                }
                #endregion

                // Level6EntityAction

                // Level7EntityElementAction
            }
            return new DiscriminateResult(true, "需要审核");
        }
Example #38
0
 public IEnumerable <IElementDriver> GetDrivers(ElementDescriptor descriptor)
 {
     return(descriptor.GetDrivers());
 }
Example #39
0
 public LongNameToken(string name, ElementDescriptor desc)
     : base(desc.WithLengthChangedBy(name.Length))
 {
     Name = name;
 }
Example #40
0
 public InterfaceElement(ElementDescriptor elementDescriptor)
 {
     ElementDescriptor = elementDescriptor;
 }
Example #41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="element"></param>
 /// <param name="actionCode"></param>
 /// <returns></returns>
 public AuditType GetElementAudit(ElementDescriptor element, Verb actionCode)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (actionCode == null)
     {
         throw new ArgumentNullException("actionCode");
     }
     var nodeElementActions = element.GetActions(this);
     if (!nodeElementActions.ContainsKey(actionCode))
     {
         return AuditType.NotAudit;
     }
     return nodeElementActions[actionCode].IsAudit ? AuditType.ImplicitAudit : AuditType.NotAudit;
 }