Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        private void PerformImport(string _scope, GraphDataFormatBase format)
        {
            string importData = string.Empty;

            System.Windows.Controls.OpenFileDialog openFileDialog = new System.Windows.Controls.OpenFileDialog();

            openFileDialog.Filter = string.Format("{0} (*.{1}) | *.{1}", format.Description, format.Extension);
            openFileDialog.FilterIndex = 1;
            openFileDialog.Multiselect = false;

            bool? dialogResult = openFileDialog.ShowDialog();

            if (dialogResult == true)
            {
                // Open the file and read it into our variable
                importData = openFileDialog.File.OpenText().ReadToEnd();

                //TODO:  ADD ERROR TRAPPING HERE
                if (!string.IsNullOrEmpty(importData))
                {
                    ImportData(importData, _scope, format);
                }
            }
        }
Esempio n. 2
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))
                );
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
 /// <summary>
 /// Loads the specified data into an existing graph
 /// </summary>
 /// <param name="data">Graph data to load onto the graph</param>
 /// <param name="graphDataFormat">Specifies the graph format (e.g., GraphML)</param>
 public void ImportLiveData(string data, GraphDataFormatBase graphDataFormat)
 {
     ImportLiveData(data, this.defaultComponentInstanceScope, graphDataFormat);
 }
Esempio n. 5
0
        /// <summary>
        /// Updates the SnagL graph with the supplied data.
        /// This is a temporary delegate to deal with deferred excecution problem with a lambda expression
        /// </summary>
        /// <param name="data">Graph data to push onto the graph</param>
        /// <param name="scope">Unqiue graph scope</param>
        /// <param name="graphDataFormat">Specifies the graph data format</param>
        /// <param name="queueCount">Number of items in the queue</param>
        private static void UpdateSnaglWithLiveData(string data, string scope, GraphDataFormatBase graphDataFormat, int queueCount)
        {
            // Import the data
            GraphManager.Instance.ImportLiveData(data, scope, graphDataFormat);

            // Raise the LiveDataDequeued event
            SnaglEventAggregator.DefaultInstance.GetEvent<LiveDataDequeuedEvent>().Publish(new LiveDataEventArgs(queueCount));
        }