public ModelElement Resolve(ModelBusReference reference)
 {
     if (reference != null)
     {
         this.modelAdapter = CreateModelBusAdapter(reference);
         return modelAdapter.ResolveElementReference(reference) as ModelElement;
     }
     return null;
 }
示例#2
0
 public ModelElement Resolve(ModelBusReference reference)
 {
     if (reference != null)
     {
         this.modelAdapter = CreateModelBusAdapter(reference);
         return(modelAdapter.ResolveElementReference(reference) as ModelElement);
     }
     return(null);
 }
 /// <summary>
 /// Unregister the observer on dispose.
 /// </summary>
 private void Dispose(bool disposing)
 {
     Debug.Assert(disposing, "ModelBusReferenceResolver finalized without being disposed!");
     if (disposing && 
         this.modelAdapter != null)
     {
         this.modelAdapter.Dispose();
         this.modelAdapter = null;
     }
 }
示例#4
0
 /// <summary>
 /// Unregister the observer on dispose.
 /// </summary>
 private void Dispose(bool disposing)
 {
     Debug.Assert(disposing, "ModelBusReferenceResolver finalized without being disposed!");
     if (disposing &&
         this.modelAdapter != null)
     {
         this.modelAdapter.Dispose();
         this.modelAdapter = null;
     }
 }
示例#5
0
        public static ModelElement ResolveAndCache(ModelBusReference reference)
        {
            if (reference == null)
            {
                return(null);
            }
            ModelBusAdapter modelAdapter = GlobalCache.AddOrGetExisting <ModelBusAdapter>(reference.ModelDisplayName, c => CreateModelBusAdapter(reference));

            return(modelAdapter.ResolveElementReference(reference) as ModelElement);
        }
        public void Open(ModelBusReference instance)
        {
            //this.modelingService.OpenModel<object>(instance);

            try
            {
                ModelBusAdapter adapter = this.modelBus.CreateAdapter(instance);
                var             view    = adapter.GetDefaultView();
                view.SetSelection(instance);
                view.Open();
                view.Show();
            }
            catch (Exception ex)
            {
                throw new ArgumentException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.ModelBusUriReferenceProvider_CantCreateAdapterFromReference,
                                                instance.ToString()), ex);
            }
        }
 protected override ModelBusView GetView(ModelBusAdapter viewOwner, ModelBusReference viewReference)
 {
     throw new NotImplementedException();
 }
 protected override ModelBusView GetView(ModelBusAdapter viewOwner, ModelBusReference viewReference)
 {
     throw new NotImplementedException();
 }
        // MBR format:
        // modelbus://logicalAdapterId/model display name/element display name/adapter reference data.
        // V3 format:
        // mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT]@[PROJECT]\[MODELFILE]
        private object ConvertToModelBusReference <T>(SerializationContext serializationContext, string input)
        {
            if (serializationContext == null)
            {
                throw new ArgumentNullException("serializationContext");
            }
            if (string.IsNullOrWhiteSpace(input) ||
                !typeof(ModelBusReference).IsAssignableFrom(typeof(T)))
            {
                return(default(T));
            }

            // filter out the schema part
            input = input.Replace(MelSchema, string.Empty);

            string[] data = input.Split(new string[] { "@" }, StringSplitOptions.RemoveEmptyEntries);
            if (data.Length != 2)
            {
                serializationContext.Result.AddMessage(BuildSerializationMessage(Properties.Resources.InvalidMoniker, input));
                return(default(T));
            }

            string[] modelData = data[0].Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
            if (modelData.Length != 3)
            {
                serializationContext.Result.AddMessage(BuildSerializationMessage(Properties.Resources.InvalidMoniker, input));
                return(default(T));
            }

            string[] locationData = data[1].Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
            if (locationData.Length != 2)
            {
                serializationContext.Result.AddMessage(BuildSerializationMessage(Properties.Resources.InvalidMoniker, input));
                return(default(T));
            }
            // set full path to model file
            if (!Path.IsPathRooted(locationData[1]))
            {
                locationData[1] = Path.Combine(Path.GetDirectoryName(serializationContext.Location), locationData[1]);
            }

            ModelBusReference result = null;
            IModelBus         bus    = serializationContext[ModelBusReferencePropertySerializer.ModelBusLoadContextKey] as IModelBus;

            if (bus != null)
            {
                using (ModelBusAdapterManager manager = bus.GetAdapterManager(LogicalAdapterId))
                {
                    ModelBusReference reference = null;
                    if (manager.TryCreateReference(out reference, Path.ChangeExtension(locationData[1], FileExtension)))
                    {
                        using (ModelBusAdapter adapter = manager.CreateAdapter(reference))
                        {
                            IModelingAdapterWithStore storeAdapter = adapter as IModelingAdapterWithStore;
                            if (storeAdapter.Store != null)
                            {
                                foreach (ModelElement mel in FilterElementsByType(storeAdapter.Store, modelData[1]))
                                {
                                    if (ValidatorUtility.GetTargetName(mel).Equals(modelData[2], StringComparison.OrdinalIgnoreCase))
                                    {
                                        return(adapter.GetElementReference(mel));
                                    }
                                }
                                // If we are still here, we could not find any match so try will all mels
                                foreach (ModelElement mel in FilterElementsByType(storeAdapter.Store, string.Empty))
                                {
                                    if (ValidatorUtility.GetTargetName(mel).Equals(modelData[2], StringComparison.OrdinalIgnoreCase))
                                    {
                                        return(adapter.GetElementReference(mel));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            serializationContext.Result.AddMessage(BuildSerializationMessage(Properties.Resources.ReferenceElementNotFound, input));
            return(result);
        }