Beispiel #1
0
 /// <summary> Returns an enumerable of all registered view references. </summary>
 /// <returns>Enumerable of all registered view references</returns>
 /// <seealso cref="IViewReference"/>
 public IEnumerable <IViewReference> GetViewReferences()
 {
     for (int i = -1; ++i != iRegisteredDataViews.Count;)
     {
         DataViewContribution dataViewContribution = iRegisteredDataViews[i];
         yield return(new ViewReferenceImpl(dataViewContribution.DataViewId, dataViewContribution.DataViewLabel));
     }
 }
Beispiel #2
0
        /// <inheritdoc />
        protected override void OnInitialize()
        {
            IConfigurationElement[] configurationElements = ExtensionService.Instance.GetConfigurationElements(DataViewExtensionPointId);
            if (configurationElements.Length == 0)
            {
                _log.Warning("No data view has been contributed by any extension point!");
                return;
            }

            _log.Debug($"{configurationElements.Length} data view contributions has been found");
            for (int i = -1; ++i != configurationElements.Length;)
            {
                IConfigurationElement configurationElement = configurationElements[i];

                string id    = configurationElement["id"];
                string cls   = configurationElement["class"];
                string label = configurationElement["label"];

                if (string.IsNullOrEmpty(label))
                {
                    label = id;
                }

                _log.Debug($"Registering contribution {{id: '{id}', cls: '{cls}', label: '{label}'}}");

                if (string.IsNullOrWhiteSpace(id))
                {
                    _log.Error("Id attribute of data view extension contribution is null or empty!");
                    continue;
                }

                if (string.IsNullOrWhiteSpace(cls))
                {
                    _log.Error($"Class attribute of data view extension contribution is null or empty!. Contribution id: '{id}'");
                    continue;
                }

                IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(configurationElement);
                try {
                    Type dataViewType = TypeLoader.TypeForName(providingBundle, cls);

                    // NLS support
                    label = NLS.Localize(label, dataViewType);

                    DataViewContribution dataViewContribution = new DataViewContribution {
                        DataViewId    = id,
                        DataViewType  = dataViewType,
                        DataViewLabel = label
                    };

                    iRegisteredDataViews.Add(dataViewContribution);
                    _log.Info($"Data view contribution '{id}' registered.");
                } catch (Exception ex) {
                    _log.Error($"Error loading type '{cls}'.", ex);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns the instance of <see cref="IDataView"/> that matches the given <typeparamref name="TDataView"/> type.
        /// If the type is not known by the registry, NULL is returned. If an instance of the data view has already been created, the existing one is
        /// returned. There won't be more than one instance of a data view.
        /// </summary>
        /// <typeparam name="TDataView">Type of data view to get</typeparam>
        /// <returns>Instance of <see cref="IDataView"/> or NULL</returns>
        public TDataView GetDataView <TDataView>() where TDataView : class, IDataView
        {
            Type dataViewType = typeof(TDataView);
            DataViewContribution dataViewContribution = iRegisteredDataViews.FirstOrDefault(entry => entry.DataViewType == dataViewType);

            if (dataViewContribution == null)
            {
                return(null);
            }

            return(GetOrCreateDataView <TDataView>(dataViewType));
        }
Beispiel #4
0
        /// <summary>
        /// Returns the instance of <see cref="IDataView"/> with the given <paramref name="dataViewId"/> from the registry.
        /// If the id is not known by the registry, NULL is returned. If an instance of the data view has already been created, the existing one is
        /// returned. There won't be more than one instance of a data view.
        /// </summary>
        /// <param name="dataViewId">Id of the data view to get</param>
        /// <returns>Instance of <see cref="IDataView"/> or NULL</returns>
        public IDataView GetDataView(string dataViewId)
        {
            DataViewContribution dataViewContribution = iRegisteredDataViews.FirstOrDefault(entry => entry.DataViewId == dataViewId);

            if (dataViewContribution == null)
            {
                return(null);
            }

            Type dataViewType = dataViewContribution.DataViewType;

            return(GetOrCreateDataView <IDataView>(dataViewType));
        }