private void AddPropertyExecute(object obj)
        {
            ICollectionView cv = CollectionViewSource.GetDefaultView(PropertyValues);

            var item = cv.CurrentItem as NdfPropertyValue;

            if (item == null)
            {
                return;
            }

            var type = NdfType.Unset;

            foreach (NdfObject instance in Object.Class.Instances)
            {
                foreach (NdfPropertyValue propertyValue in instance.PropertyValues)
                {
                    if (propertyValue.Property.Id == item.Property.Id)
                    {
                        if (propertyValue.Type != NdfType.Unset)
                        {
                            type = propertyValue.Type;
                        }
                    }
                }
            }

            if (type == NdfType.Unset || type == NdfType.Unknown)
            {
                return;
            }

            item.Value = NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(type)], type, item.Manager);
        }
Example #2
0
        public NdfMap(MapValueHolder key, MapValueHolder value, NdfBinary mgr)
            : base(NdfType.Map, value)
        {
            Key     = key;
            Manager = mgr;

            _typeSelection.AddRange(NdfTypeManager.GetTypeSelection());
        }
Example #3
0
        public AddCollectionItemViewModel(NdfBinary mgr, Window view)
        {
            Manager = mgr;
            View    = view;

            OkCommand     = new ActionCommand(OkCommandExecute, () => Type != NdfType.Unset);
            CancelCommand = new ActionCommand(CancelCommandExecute);

            _typeSelection.AddRange(NdfTypeManager.GetTypeSelection());
        }
        private NdfValueWrapper GetCopiedValue(IValueHolder toCopy)
        {
            NdfValueWrapper copiedValue = null;

            switch (toCopy.Value.Type)
            {
            case NdfType.ObjectReference:
                var origInst = toCopy.Value as NdfObjectReference;

                if (origInst != null && !origInst.Instance.IsTopObject)
                {
                    copiedValue = new NdfObjectReference(origInst.Class, CopyInstance(origInst.Instance).Id);
                }
                else
                {
                    copiedValue = NdfTypeManager.GetValue(toCopy.Value.GetBytes(), toCopy.Value.Type, toCopy.Manager);
                }

                break;

            case NdfType.List:
            case NdfType.MapList:
                var copiedItems = new List <CollectionItemValueHolder>();
                var collection  = toCopy.Value as NdfCollection;
                if (collection != null)
                {
                    copiedItems.AddRange(collection.Select(entry => new CollectionItemValueHolder(GetCopiedValue(entry), toCopy.Manager)));
                }
                copiedValue = new NdfCollection(copiedItems);
                break;

            case NdfType.Map:
                var map = toCopy.Value as NdfMap;
                if (map != null)
                {
                    copiedValue = new NdfMap(new MapValueHolder(GetCopiedValue(map.Key), toCopy.Manager),
                                             new MapValueHolder(GetCopiedValue(map.Value as IValueHolder), toCopy.Manager), toCopy.Manager);
                }
                break;

            default:
                copiedValue = NdfTypeManager.GetValue(toCopy.Value.GetBytes(), toCopy.Value.Type, toCopy.Manager);
                break;
            }

            return(copiedValue);
        }
Example #5
0
        private void GetValueForType(bool keyOrValue)
        {
            if (keyOrValue)
            {
                Key =
                    new MapValueHolder(
                        NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(KeyType)], KeyType, Manager), Manager);
            }
            else
            {
                Value =
                    new MapValueHolder(
                        NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(ValueType)], ValueType, Manager), Manager);
            }

            OnPropertyChanged("IsKeyNull");
            OnPropertyChanged("IsValueNull");
        }
        private void RemovePropertyExecute(object obj)
        {
            ICollectionView cv = CollectionViewSource.GetDefaultView(PropertyValues);

            var item = cv.CurrentItem as NdfPropertyValue;

            if (item == null || item.Type == NdfType.Unset || item.Type == NdfType.Unknown)
            {
                return;
            }

            MessageBoxResult result = MessageBox.Show("Do you want to set this property to null?", "Confirmation",
                                                      MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                item.Value = NdfTypeManager.GetValue(new byte[0], NdfType.Unset, item.Manager);
            }
        }
Example #7
0
        private void AddRowOfCommonTypeExecute(object obj)
        {
            var cv = CollectionViewSource.GetDefaultView(Value);

            if (cv == null)
            {
                return;
            }

            NdfType type =
                Value.GroupBy(x => x.Value.Type).OrderByDescending(gp => gp.Count()).Select(x => x.First().Value.Type).
                Single();

            var wrapper =
                new CollectionItemValueHolder(NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(type)], type, NdfbinManager), NdfbinManager);

            if (IsInsertMode)
            {
                if (cv.CurrentItem == null)
                {
                    return;
                }

                var val = cv.CurrentItem as CollectionItemValueHolder;

                if (val == null)
                {
                    return;
                }

                Value.Insert(cv.CurrentPosition + 1, wrapper);
            }
            else
            {
                Value.Add(wrapper);
            }

            cv.MoveCurrentTo(wrapper);
        }
Example #8
0
 private void GetValueForType()
 {
     Wrapper = new CollectionItemValueHolder(NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(Type)], Type, Manager), Manager);
 }
        /// <summary>
        /// Reads the value of a Property inside a object instance.
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="binary"></param>
        /// <returns>A NdfValueWrapper Instance.</returns>
        protected NdfValueWrapper ReadValue(Stream ms, NdfBinary binary)
        {
            uint            contBufferlen;
            NdfValueWrapper value;
            var             buffer = new byte[4];

            ms.Read(buffer, 0, buffer.Length);
            NdfType type = NdfTypeManager.GetType(buffer);

            if (type == NdfType.Unknown)
            {
                throw new InvalidDataException("Unknown datatypes are not supported!");
            }



            if (type == NdfType.Reference)
            {
                ms.Read(buffer, 0, buffer.Length);
                type = NdfTypeManager.GetType(buffer);
            }

            switch (type)
            {
            case NdfType.Unknown:
            case NdfType.WideString:
            case NdfType.List:
            case NdfType.MapList:
            case NdfType.Blob:
            case NdfType.ZipBlob:
                ms.Read(buffer, 0, buffer.Length);
                contBufferlen = BitConverter.ToUInt32(buffer, 0);

                if (type == NdfType.ZipBlob)
                {
                    if (ms.ReadByte() != 1)
                    {
                        throw new InvalidDataException("has to be checked.");
                    }
                }
                break;

            default:
                contBufferlen = NdfTypeManager.SizeofType(type);
                break;
            }

            switch (type)
            {
            case NdfType.MapList:
            case NdfType.List:
                NdfCollection lstValue = type == NdfType.List ? new NdfCollection() : new NdfMapList();

                for (int i = 0; i < contBufferlen; i++)
                {
                    CollectionItemValueHolder res;
                    if (type == NdfType.List)
                    {
                        res = new CollectionItemValueHolder(ReadValue(ms, binary), binary);
                    }
                    else
                    {
                        res = new CollectionItemValueHolder(
                            new NdfMap(
                                new MapValueHolder(ReadValue(ms, binary), binary),
                                new MapValueHolder(ReadValue(ms, binary), binary),
                                binary), binary);
                    }

                    lstValue.Add(res);
                }

                value = lstValue;
                break;

            case NdfType.Map:
                value = new NdfMap(
                    new MapValueHolder(ReadValue(ms, binary), binary),
                    new MapValueHolder(ReadValue(ms, binary), binary),
                    binary);
                break;

            default:
                var contBuffer = new byte[contBufferlen];
                ms.Read(contBuffer, 0, contBuffer.Length);

                value = NdfTypeManager.GetValue(contBuffer, type, binary);
                break;
            }

            return(value);
        }
        /// <summary>
        /// Reads the value of a Property inside a object instance.
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="triggerBreak"></param>
        /// <param name="prop"></param>
        /// <returns>A NdfValueWrapper Instance.</returns>
        protected NdfValueWrapper ReadValue(MemoryStream ms, out bool triggerBreak, NdfPropertyValue prop)
        {
            var             buffer = new byte[4];
            uint            contBufferlen;
            NdfValueWrapper value;

            triggerBreak = false;

            ms.Read(buffer, 0, buffer.Length);
            var type = NdfTypeManager.GetType(buffer);

            if (type == NdfType.Reference)
            {
                ms.Read(buffer, 0, buffer.Length);
                type = NdfTypeManager.GetType(buffer);
            }

            switch (type)
            {
            case NdfType.WideString:
            case NdfType.List:
            case NdfType.MapList:
                ms.Read(buffer, 0, buffer.Length);
                contBufferlen = BitConverter.ToUInt32(buffer, 0);
                break;

            default:
                contBufferlen = NdfTypeManager.SizeofType(type);
                break;
            }

            if (type == NdfType.Unknown)
            {
                //var t = _unknownTypes.SingleOrDefault(x => Utils.ByteArrayCompare(x, buffer));

                //if (t == default(byte[]))
                //{
                //    _unknownTypes.Add(buffer);
                //    _unknownTypesCount.Add(1);
                //}
                //else
                //    _unknownTypesCount[_unknownTypes.IndexOf(t)]++;

                triggerBreak = true;
                return(new NdfUnkown(buffer, ms.Position));
            }

            if (type == NdfType.List || type == NdfType.MapList)
            {
                NdfCollection lstValue;

                if (type == NdfType.List)
                {
                    lstValue = new NdfCollection(ms.Position);
                }
                else
                {
                    lstValue = new NdfMapList(ms.Position);
                }

                CollectionItemValueHolder res;

                for (int i = 0; i < contBufferlen; i++)
                {
                    if (type == NdfType.List)
                    {
                        res = new CollectionItemValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset);
                    }
                    else
                    {
                        res = new CollectionItemValueHolder(
                            new NdfMap(
                                new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                                new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                                ms.Position),
                            this, prop.InstanceOffset);
                    }

                    lstValue.Add(res);

                    if (triggerBreak)
                    {
                        break;
                    }
                }

                value = lstValue;
            }
            else if (type == NdfType.Map)
            {
                value = new NdfMap(
                    new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                    new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                    ms.Position);
            }
            else
            {
                var contBuffer = new byte[contBufferlen];
                ms.Read(contBuffer, 0, contBuffer.Length);

                if (prop != null)
                {
                    prop.ValueData = contBuffer;
                }

                value = NdfTypeManager.GetValue(contBuffer, type, this, ms.Position - contBuffer.Length);
            }

            return(value);
        }