Ejemplo n.º 1
0
        void IEditableObject.EndEdit()
        {
            if (Updates.Count > 0)
            {
                //removes any operations that act on the same metadata key, only the last update is added to the chain
                CompactUpdates();

                var chain = new TransactionChain();
                foreach (var detail in Updates)
                {
                    switch (detail.Type)
                    {
                    case UpdateMetadataType.AddOrUpdateValue:
                        Metadata.Add(detail.NewKey, detail.NewValue, ref chain);
                        if (UIMetadata.ContainsKey(detail.NewKey))
                        {
                            UIMetadata[detail.NewKey] = detail.NewValue;
                        }
                        else
                        {
                            UIMetadata.Add(detail.NewKey, detail.NewValue);
                        }
                        OnNotifyPropertyChanged(detail.NewKey);
                        break;

                    case UpdateMetadataType.Delete:
                        if (Metadata.ContainsKey(detail.NewKey))
                        {
                            Metadata[detail.NewKey].MetadataSet.Delete(ref chain);
                            Metadata.Remove(detail.NewKey);
                        }

                        if (UIMetadata.ContainsKey(detail.NewKey))
                        {
                            UIMetadata.Remove(detail.NewKey);
                        }
                        break;

                    case UpdateMetadataType.UpdateKey:
                        if (Metadata.ContainsKey(detail.Key))
                        {
                            var metadataSet = Metadata[detail.Key];
                            metadataSet.SetName(detail.NewKey, ref chain);
                            if (!metadataSet.Value.Equals(detail.NewValue))
                            {
                                metadataSet.SetValue(detail.NewValue, ref chain);
                            }
                            Metadata.Remove(detail.Key);
                            Metadata.Add(detail.NewKey, metadataSet);
                            UIMetadata.Remove(detail.Key);
                            UIMetadata.Add(detail.NewKey, detail.NewValue);
                        }
                        break;
                    }
                }
                MapManager.ExecuteTransaction(chain);
                Updates = new List <UpdateMetadataDetail>();
            }
        }
Ejemplo n.º 2
0
 private string GetMetadataValue(string key)
 {
     if (UIMetadata.ContainsKey(key))
     {
         return(UIMetadata[key]);
     }
     return(string.Empty);
 }
Ejemplo n.º 3
0
        private int?GetIntMetadataValue(string key)
        {
            if (UIMetadata.ContainsKey(key))
            {
                var stringValue = UIMetadata[key];
                int result;

                if (int.TryParse(stringValue, out result))
                {
                    return(result);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public MultipleNodesProperties(List <NodeProperties> nodes)
        {
            NodeProperties = nodes;
            var count = 0;

            foreach (var node in nodes)
            {
                foreach (var uiMetadata in node.UIMetadata)
                {
                    if (!UIMetadata.ContainsKey(uiMetadata.Key))
                    {
                        if (count == 0)
                        {
                            UIMetadata.Add(uiMetadata.Key, uiMetadata.Value);
                        }
                        else
                        {
                            UIMetadata.Add(uiMetadata.Key, string.Empty);
                        }
                    }
                    else if (UIMetadata[uiMetadata.Key] != uiMetadata.Value)
                    {
                        UIMetadata[uiMetadata.Key] = string.Empty;
                    }
                }

                if (count > 0)
                {
                    var copy = UIMetadata.ToList();
                    foreach (var keyValuePair in copy)
                    {
                        if (!node.UIMetadata.ContainsKey(keyValuePair.Key))
                        {
                            UIMetadata[keyValuePair.Key] = string.Empty;
                        }
                    }
                }
                count++;
            }
        }