예제 #1
0
        public DataPackage UpdateRepeatProperty(ObjectIdentity objectIdentity)
        {
            PropertyProfile propertyProfile = new PropertyProfile();

            // Setting the filter to ALL can cause errors if the DataObject
            // passed to the operation contains system properties, so to be safe
            // set the filter to ALL_NON_SYSTEM unless you explicitly want to update
            // a system property
            propertyProfile.FilterMode = PropertyFilterMode.ALL_NON_SYSTEM;
            DemoServiceContext.SetProfile(propertyProfile);

            DataObject dataObject = new DataObject(objectIdentity);

            String[] moreDangers = { "snakes", "sharks" };
            ArrayProperty <string> keywordProperty = new StringArrayProperty("keywords", moreDangers);

            Console.WriteLine("Appending additional strings 'snakes' and 'sharks' to object keywords.");

            ValueAction appendAction = new ValueAction(ValueActionType.INSERT, 0);
            ValueAction deleteAction = new ValueAction(ValueActionType.APPEND, 1);

            keywordProperty.SetValueActions(appendAction, deleteAction);
            PropertySet properties = new PropertySet();

            properties.Set(keywordProperty);
            dataObject.Properties = properties;

            OperationOptions operationOptions = null;

            return(objectService.Update(new DataPackage(dataObject), operationOptions));
        }
예제 #2
0
파일: Property.cs 프로젝트: kamilion/WISP
        public static Property Clone(Property target)
        {
            Property prop = null;
            int id = target.PropertyId;
            PropertyBag bag = target.Owner;

            switch (target.PropertyType)
            {
                case (int)PropertyKind.WispObject:
                    prop = new WispProperty(target.Name, id, ((WispProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.WispArray:
                    prop = new WispArrayProperty(target.Name, id, ((WispArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Int32:
                    prop = new Int32Property(target.Name, id, ((Int32Property)target).Value, bag);
                    break;
                case (int)PropertyKind.String:
                    prop = new StringProperty(target.Name, id, ((StringProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Bool:
                    prop = new BoolProperty(target.Name, id, ((BoolProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Guid:
                    prop = new GuidProperty(target.Name, id, ((GuidProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Single:
                    prop = new SingleProperty(target.Name, id, ((SingleProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Int32Array:
                    prop = new Int32ArrayProperty(target.Name, id, ((Int32ArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.StringArray:
                    prop = new StringArrayProperty(target.Name, id, ((StringArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.DateTime:
                    prop = new DateTimeProperty(target.Name, id, ((DateTimeProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.GuidArray:
                    prop = new GuidArrayProperty(target.Name, id, ((GuidArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Double:
                    prop = new DoubleProperty(target.Name, id, ((DoubleProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Byte:
                    prop = new ByteProperty(target.Name, id, ((ByteProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Component:
                    prop = new ComponentProperty(target.Name, id, ((ComponentProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.SingleArray:
                    prop = new SingleArrayProperty(target.Name, id, ((SingleArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Int64:
                    prop = new Int64Property(target.Name, id, ((Int64Property)target).Value, bag);
                    break;
                case (int)PropertyKind.ComponentArray:
                    prop = new ComponentArrayProperty(target.Name, id, ((ComponentArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.DateTimeArray:
                    prop = new DateTimeArrayProperty(target.Name, id, ((DateTimeArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.ByteArray:
                    prop = new ByteArrayProperty(target.Name, id, ((ByteArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.DoubleArray:
                    prop = new DoubleArrayProperty(target.Name, id, ((DoubleArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Int16Array:
                    prop = new Int16ArrayProperty(target.Name, id, ((Int16ArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.Int16:
                    prop = new Int16Property(target.Name, id, ((Int16Property)target).Value, bag);
                    break;
                case (int)PropertyKind.Int64Array:
                    prop = new Int64ArrayProperty(target.Name, id, ((Int64ArrayProperty)target).Value, bag);
                    break;
                case (int)PropertyKind.BoolArray:
                    prop = new BoolArrayProperty(target.Name, id, ((BoolArrayProperty)target).Value, bag);
                    break;
            }
            prop.Name = target.Name;
            return prop;
        }
예제 #3
0
        /// <summary>
        /// 解析普通属性
        /// </summary>
        private void ResolveDefaultProperty()
        {
            var errorFalg = false;
            /* [0] 属性定义行 */
            /* 属性定义样式 */

            /*
             *  int,float,string,bool: TYPE#PROPERTY_NAME(类型#属性名称#特殊设置)
             */
            var propertyRaw = scriptRawData.GetRow(0);
            /* 读取一次属性后,到下一个属性步进值,需要根据当前属性数据占用范围来计算 */
            /* 像Array或Array2D这样的数据占用的宽度会更大 */
            var dataSourceColumnIndex = 0;

            for (var columnIndex = 0; columnIndex < propertyRaw.Length; columnIndex++)
            {
                var propertyRawData = propertyRaw[columnIndex];
                var propertyData    = propertyRawData.Split(Helper.SETTING_SPLIT);
                if (propertyData[0].Equals(RawData.FILLING_DATA))
                {
                    continue;
                }
                /* 整竖行都是空,则忽略该竖行 */
                var columnIsEmpty = true;
                for (var y = 0; y < scriptRawData.height; y++)
                {
                    columnIsEmpty &= string.IsNullOrEmpty(scriptRawData[columnIndex, y]);
                    if (!columnIsEmpty)
                    {
                        break;
                    }
                }
                if (columnIsEmpty)
                {
                    dataSourceColumnIndex++;
                    continue;
                }
                if (string.IsNullOrEmpty(propertyRawData))
                {
                    continue;
                }
                var property = default(IProperty);
                var range    = new RawRange(1, dataSourceColumnIndex, 1, scriptRawData.height - 1);
                /* @开头,为自定义类型 */
                if (propertyData[0].StartsWith("@"))
                {
                    property = new DynamicProperty();
                }
                else
                {
                    /* 基础模式 */
                    if (generateData.scriptSetting.scriptObjectDataType == ScriptObjectDataType.BASE)
                    {
                        /* 数组模式 */
                        if (propertyData.Length == 3 && int.TryParse(propertyData[2], out var width))
                        {
                            switch (propertyData[0])
                            {
                            case "int":
                                property = new IntArrayProperty();
                                break;

                            case "float":
                                property = new FloatArrayProperty();
                                break;

                            case "string":
                                property = new StringArrayProperty();
                                break;

                            case "bool":
                                property = new BooleanArrayProperty();
                                break;

                            default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                            }
                            range.width = Convert.ToInt32(width);
                            /* 为了适应数据宽度超过属性栏宽度 */
                            columnIndex += range.width - 1;
                        }
                        /* 字典模式 */
                        else if (propertyData.Length == 3 && propertyData[2].ToLower().StartsWith("key"))
                        {
                            switch (propertyData[0])
                            {
                            case "int":
                                property = new IntKeyProperty();
                                break;

                            case "float":
                                property = new FloatKeyProperty();
                                break;

                            case "string":
                                property = new StringKeyProperty();
                                break;

                            default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                            }
                        }
                        /* 普通模式 */
                        else
                        {
                            switch (propertyData[0])
                            {
                            case "int":
                                property = new IntProperty();
                                break;

                            case "float":
                                property = new FloatProperty();
                                break;

                            case "string":
                                property = new StringProperty();
                                break;

                            case "bool":
                                property = new BooleanProperty();
                                break;

                            default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                            }
                        }
                    }
                    /* 二维数组模式 */
                    else if (generateData.scriptSetting.scriptObjectDataType == ScriptObjectDataType.ARRAY2D)
                    {
                        switch (propertyData[0])
                        {
                        case "int":
                            property = new IntArray2DProperty();
                            break;

                        case "float":
                            property = new FloatArray2DProperty();
                            break;

                        case "string":
                            property = new StringArray2DProperty();
                            break;

                        case "bool":
                            property = new BooleanArray2DProperty();
                            break;

                        default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                        }
                        range.width = Convert.ToInt32(propertyData[2]);
                    }
                    else if (generateData.scriptSetting.scriptObjectDataType == ScriptObjectDataType.ARRAY2DWITHNAME)
                    {
                        switch (propertyData[0])
                        {
                        case "int":
                            property = new IntArray2DWithnameProperty();
                            break;

                        case "float":
                            property = new FloatArray2DWithnameProperty();
                            break;

                        case "string":
                            property = new StringArray2DWithnameProperty();
                            break;

                        case "bool":
                            property = new BooleanArray2DWithnameProperty();
                            break;

                        default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                        }
                        /* +1为名称占用宽度 */
                        range.width = Convert.ToInt32(propertyData[2]) + 1;
                    }
                    else
                    {
                        throw new System.Exception($"未定义的类型\"{generateData.scriptSetting.scriptObjectDataType}\"");
                    }
                }
                property.InitProperty(propertyData, scriptRawData.GetRangeRawData(range));
                if (recordPropertyMap.ContainsKey(property.propertyName))
                {
                    CSVLoaderWindow.window.ShowNotification(new GUIContent($"文件\"{generateData.scriptSetting.scriptName}\"存在相同属性名称{property.propertyName}"));
                    generateData.SetState(BlockState.ERROR);
                    errorFalg = true;
                    break;
                }
                recordPropertyMap.Add(property.propertyName, property);
                dataSourceColumnIndex += range.width;

                if (property is DynamicProperty)
                {
                    // var dynamicProperty = property as DynamicProperty;
                    // generateData.dynamicDataMap.Add(dynamicProperty.dynamicTypeFullname, new GenerateData());
                    // generateData.dynamicDataList
                    // var dynamicPropertyInfo = new DynamicPropertyInfo();
                    // dynamicPropertyInfo.dynamicProperty = dynamicProperty;
                    // dynamicPropertyInfo.hasScripts = generateData.CheckHaveSameScript(dynamicProperty.dynamicTypeFullname, false);
                }
            }

            /* true: 字典模式 */

            var dictionaryFlag = false;

            foreach (var property in recordPropertyMap.Values)
            {
                if (property is IDictionaryKey)
                {
                    dictionaryFlag = true;
                    break;
                }
            }
            if (dictionaryFlag)
            {
                var keyCount = 0;
                foreach (var property in recordPropertyMap.Values)
                {
                    if (!(property is IDictionaryKey))
                    {
                        continue;
                    }
                    var key = property as IDictionaryKey;
                    if (key.keyFlag)
                    {
                        keyCount++;
                    }
                }
                if (keyCount <= 0)
                {
                    throw new System.Exception($"\"{generateData.csvFileInfo.Name}\"为字典类型,但未选择key");
                }
                else if (keyCount > 1)
                {
                    throw new System.Exception($"\"{generateData.csvFileInfo.Name}\"定义了多个属性作为key");
                }
            }
            if (!errorFalg)
            {
                GenerateScriptContent();
            }
        }
        public DataPackage UpdateRepeatProperty(ObjectIdentity objectIdentity)
        {
            PropertyProfile propertyProfile = new PropertyProfile();

            // Setting the filter to ALL can cause errors if the DataObject
            // passed to the operation contains system properties, so to be safe 
            // set the filter to ALL_NON_SYSTEM unless you explicitly want to update
            // a system property
            propertyProfile.FilterMode = PropertyFilterMode.ALL_NON_SYSTEM;
            DemoServiceContext.SetProfile(propertyProfile);

            DataObject dataObject = new DataObject(objectIdentity);

            String[] moreDangers = { "snakes", "sharks" };
            ArrayProperty<string> keywordProperty = new StringArrayProperty("keywords", moreDangers);
            Console.WriteLine("Appending additional strings 'snakes' and 'sharks' to object keywords.");

            ValueAction appendAction = new ValueAction(ValueActionType.INSERT, 0);
            ValueAction deleteAction = new ValueAction(ValueActionType.APPEND, 1);
            keywordProperty.SetValueActions(appendAction, deleteAction);
            PropertySet properties = new PropertySet();
            properties.Set(keywordProperty);
            dataObject.Properties = properties;

            OperationOptions operationOptions = null;
            return objectService.Update(new DataPackage(dataObject), operationOptions);
        }