예제 #1
0
        /// <summary>
        /// Loads the specified data into an existing graph
        /// </summary>
        /// <param name="data">Graph data to load onto the graph</param>
        /// <param name="scope">Specifies the graph scope</param>
        /// <param name="graphDataFormat">Specifies the graph format (e.g., GraphML)</param>
        public void ImportLiveData(string data, string scope, GraphDataFormatBase graphDataFormat)
        {
            GraphComponents components;

            if (String.IsNullOrWhiteSpace(data))
            {
                throw new ArgumentNullException("data");
            }

            if (String.IsNullOrWhiteSpace(scope))
            {
                throw new ArgumentNullException("scope");
            }

            if (!this.graphComponentsInstances.ContainsKey(scope))
            {
                throw new InvalidOperationException("Unable to locate an existing GraphComponents with the specified scope");
            }

            // Get any existing graph compents with the specified scope
            components = this.graphComponentsInstances[scope];

            // Import the data into the provided components
            graphDataFormat.Import(data, components, CreationType.Live);

            // Fire the LiveDataLoaded event
            DispatcherHelper.UIDispatcher.BeginInvoke(() =>
                                                      SnaglEventAggregator.DefaultInstance.GetEvent <LiveDataLoadedEvent>().Publish(new DataLoadedEventArgs(components.Scope, CreationType.Live))
                                                      );
        }
예제 #2
0
        /// <summary>
        /// Imports GraphML into SnagL on a new graph
        /// </summary>
        /// <param name="data">The graph data to place on the graph</param>
        /// <param name="scope">Specifies the graphs scope</param>
        /// <param name="format">Specifies the graph data format</param>
        public void ImportData(string data, string scope, GraphDataFormatBase format)
        {
            SnaglEventAggregator.DefaultInstance.GetEvent <UI.TimeConsumingTaskExecutingEvent>().Publish(new UI.TimeConsumingTaskEventArgs());

            GraphComponents components = null;

            // Check if the provided scope is null or empty
            if (string.IsNullOrEmpty(scope))
            {
                // This is a new graph so we will generate new GraphComponents
                // for it
                components = new GraphComponents();
            }
            else
            {
                // Attempt to get the graph components instance for
                // the given scope
                components = GetGraphComponents(scope);

                // If we were unable to get an instance, create a
                // new one
                if (components == null)
                {
                    components = new GraphComponents();
                }
            }

            components.Clear();

            GlobalAttributeCollection.GetInstance(scope).Clear();

            // Import the data into the provided components
            format.Import(data, components, CreationType.Imported);

            // Check if the default instance (which is the first instance
            // created) has been initialized yet
            if (this.defaultComponentInstanceScope == string.Empty)
            {
                // TODO:  ENSURE THIS IS VALID IN THE FUTURE AS THE MAIN GRAPH MAY NOT ALWAYS POPULATE FIRST (BUT SHOULD BE)

                // Save the newly created components as the default
                this.defaultComponentInstanceScope = components.Scope;
            }

            // Now we need to update or add the components to the collection of components
            // Check if the collection has never been initialized
            if (this.graphComponentsInstances == null)
            {
                // Initialize the collection
                this.graphComponentsInstances = new Dictionary <string, GraphComponents>();
            }

            // Check if we have no items
            if (this.graphComponentsInstances.Count == 0)
            {
                // Add the components instance to the collection
                this.graphComponentsInstances.Add(components.Scope, components);
            }
            else
            {
                // Ensure that the scope doesn't already exist
                if (this.graphComponentsInstances.ContainsKey(components.Scope))
                {
                    // Update the components instance for the specified scope
                    this.graphComponentsInstances[components.Scope] = components;
                }
                else
                {
                    // Add the new instance for the specified scope
                    this.graphComponentsInstances.Add(components.Scope, components);
                }
            }

            //TODO  MAKE SURE THAT WE HAVE DATA

            // Fire the DataLoaded event
            DispatcherHelper.UIDispatcher.BeginInvoke(() =>
                                                      SnaglEventAggregator.DefaultInstance.GetEvent <DataLoadedEvent>().Publish(new DataLoadedEventArgs(components.Scope, CreationType.Imported))
                                                      );

            SnaglEventAggregator.DefaultInstance.GetEvent <TimeConsumingTaskCompletedEvent>().Publish(new TimeConsumingTaskEventArgs());
        }