示例#1
0
        protected override SyncAttempt <IDataType> DeserializeCore(XElement node, SyncSerializerOptions options)
        {
            var info = node.Element("Info");
            var name = info.Element("Name").ValueOrDefault(string.Empty);
            var key  = node.GetKey();

            var attempt = FindOrCreate(node);

            if (!attempt.Success)
            {
                throw attempt.Exception;
            }

            var details = new List <uSyncChange>();
            var item    = attempt.Result;

            // basic
            if (item.Name != name)
            {
                details.AddUpdate("Name", item.Name, name, "Name");
                item.Name = name;
            }

            if (item.Key != key)
            {
                details.AddUpdate("Key", item.Key, key, "Key");
                item.Key = key;
            }

            var editorAlias = info.Element("EditorAlias").ValueOrDefault(string.Empty);

            if (editorAlias != item.EditorAlias)
            {
                // change the editor type.....
                var newEditor = dataEditors.FirstOrDefault(x => x.Alias.InvariantEquals(editorAlias));
                if (newEditor != null)
                {
                    details.AddUpdate("EditorAlias", item.EditorAlias, editorAlias, "EditorAlias");
                    item.Editor = newEditor;
                }
            }

            // removing sort order - as its not used on datatypes,
            // and can change based on minor things (so gives false out of sync results)

            // item.SortOrder = info.Element("SortOrder").ValueOrDefault(0);
            var dbType = info.Element("DatabaseType").ValueOrDefault(ValueStorageType.Nvarchar);

            if (item.DatabaseType != dbType)
            {
                details.AddUpdate("DatabaseType", item.DatabaseType, dbType, "DatabaseType");
                item.DatabaseType = dbType;
            }

            // config
            if (ShouldDeserilizeConfig(name, editorAlias, options))
            {
                details.AddRange(DeserializeConfiguration(item, node));
            }

            details.AddNotNull(SetFolderFromElement(item, info.Element("Folder")));

            return(SyncAttempt <IDataType> .Succeed(item.Name, item, ChangeType.Import, details));
        }