public CustomNodeWorkspaceModel( 
     WorkspaceInfo info, 
     NodeFactory factory)
     : this(
         factory,
         Enumerable.Empty<NodeModel>(),
         Enumerable.Empty<NoteModel>(),
         Enumerable.Empty<AnnotationModel>(),
         info) { }
 public CustomNodeWorkspaceModel( 
     WorkspaceInfo info, 
     NodeFactory factory)
     : this(
         factory,
         Enumerable.Empty<NodeModel>(),
         Enumerable.Empty<NoteModel>(),
         Enumerable.Empty<AnnotationModel>(),
         Enumerable.Empty<PresetModel>(),
         new ElementResolver(),
         info) { }
        public CustomNodeWorkspaceModel( 
            NodeFactory factory,
            IEnumerable<NodeModel> e, 
            IEnumerable<NoteModel> n, 
            IEnumerable<AnnotationModel> a,
            IEnumerable<PresetModel> presets,
            ElementResolver elementResolver, 
            WorkspaceInfo info)
            : base(e, n,a, info, factory,presets, elementResolver)
        {
            HasUnsavedChanges = false;

            CustomNodeId = Guid.Parse(info.ID);
            Category = info.Category;
            Description = info.Description;
            PropertyChanged += OnPropertyChanged;
        }
        public CustomNodeWorkspaceModel( 
            NodeFactory factory,
            IEnumerable<NodeModel> nodes, 
            IEnumerable<NoteModel> notes, 
            IEnumerable<AnnotationModel> annotations,
            IEnumerable<PresetModel> presets,
            ElementResolver elementResolver, 
            WorkspaceInfo info)
            : base(nodes, notes,annotations, info, factory,presets, elementResolver)
        {
            HasUnsavedChanges = false;

            CustomNodeId = Guid.Parse(info.ID);
            Category = info.Category;
            Description = info.Description;
            IsVisibleInDynamoLibrary = info.IsVisibleInDynamoLibrary;
            PropertyChanged += OnPropertyChanged;
        }
        public CustomNodeWorkspaceModel( 
            NodeFactory factory, 
            IEnumerable<NodeModel> e, 
            IEnumerable<NoteModel> n, 
            IEnumerable<AnnotationModel> a,
            WorkspaceInfo info,
            ElementResolver elementResolver = null) 
            : base(e, n,a,info, factory)

        {
            HasUnsavedChanges = false;

            CustomNodeId = Guid.Parse(info.ID);
            Category = info.Category;
            Description = info.Description;

            if (elementResolver != null)
            {
                ElementResolver.CopyResolutionMap(elementResolver);
            }

            PropertyChanged += OnPropertyChanged;
        }
Example #6
0
        /// <summary>
        ///     Creates a new Custom Node in the manager.
        /// </summary>
        /// <param name="name">Name of the custom node.</param>
        /// <param name="category">Category for the custom node.</param>
        /// <param name="description">Description of the custom node.</param>
        /// <param name="functionId">
        ///     Optional identifier to be used for the custom node. By default, will make a new unique one.
        /// </param>
        /// <returns>Newly created Custom Node Workspace.</returns>
        public WorkspaceModel CreateCustomNode(string name, string category, string description, Guid? functionId = null)
        {
            var newId = functionId ?? Guid.NewGuid();

            var info = new WorkspaceInfo()
            {
                Name = name,
                Category = category,
                Description = description,
                X = 0,
                Y = 0,
                ID = newId.ToString(), 
                FileName = string.Empty
            };
            var workspace = new CustomNodeWorkspaceModel(info, nodeFactory);

            RegisterCustomNodeWorkspace(workspace);
            return workspace;
        }
Example #7
0
        private bool InitializeCustomNode(
            WorkspaceInfo workspaceInfo,
            XmlDocument xmlDoc, out CustomNodeWorkspaceModel workspace)
        {
            // Add custom node definition firstly so that a recursive
            // custom node won't recursively load itself.
            SetPreloadFunctionDefinition(Guid.Parse(workspaceInfo.ID));
 
            var nodeGraph = NodeGraph.LoadGraphFromXml(xmlDoc, nodeFactory);
           
            var newWorkspace = new CustomNodeWorkspaceModel(
                nodeFactory,
                nodeGraph.Nodes,
                nodeGraph.Notes,
                nodeGraph.Annotations,
                nodeGraph.Presets,              
                workspaceInfo);

            
            RegisterCustomNodeWorkspace(newWorkspace);

            workspace = newWorkspace;
            return true;
        }
Example #8
0
 /// <summary>
 ///     Opens a Custom Node workspace from an XmlDocument, given a pre-constructed WorkspaceInfo.
 /// </summary>
 /// <param name="xmlDoc">XmlDocument representing the parsed custom node file.</param>
 /// <param name="workspaceInfo">Workspace header describing the custom node file.</param>
 /// <param name="isTestMode">
 ///     Flag specifying whether or not this should operate in "test mode".
 /// </param>
 /// <param name="workspace"></param>
 /// <returns></returns>
 public bool OpenCustomNodeWorkspace(
     XmlDocument xmlDoc, WorkspaceInfo workspaceInfo, bool isTestMode, out WorkspaceModel workspace)
 {
     CustomNodeWorkspaceModel customNodeWorkspace;
     if (InitializeCustomNode(
         workspaceInfo,
         xmlDoc,
         out customNodeWorkspace))
     {
         workspace = customNodeWorkspace;
         return true;
     }
     workspace = null;
     return false;
 }
Example #9
0
        private bool OpenHomeWorkspace(
            XmlDocument xmlDoc, WorkspaceInfo workspaceInfo, out WorkspaceModel workspace)
        {
            var nodeGraph = NodeGraph.LoadGraphFromXml(xmlDoc, NodeFactory);
            
            var newWorkspace = new HomeWorkspaceModel(
                EngineController,
                Scheduler,
                NodeFactory,
                Utils.LoadTraceDataFromXmlDocument(xmlDoc),
                nodeGraph.Nodes,
                nodeGraph.Notes,
                nodeGraph.Annotations,
                nodeGraph.Presets,
                nodeGraph.ElementResolver,
                workspaceInfo,
                DebugSettings.VerboseLogging, 
                IsTestMode
               );

            RegisterHomeWorkspace(newWorkspace);

            workspace = newWorkspace;            
            return true;
        }
Example #10
0
        private bool OpenFile(WorkspaceInfo workspaceInfo, XmlDocument xmlDoc, out WorkspaceModel workspace)
        {
            CustomNodeManager.AddUninitializedCustomNodesInPath(
                Path.GetDirectoryName(workspaceInfo.FileName),
                IsTestMode);

            var result = workspaceInfo.IsCustomNodeWorkspace
                ? CustomNodeManager.OpenCustomNodeWorkspace(xmlDoc, workspaceInfo, IsTestMode, out workspace)
                : OpenHomeWorkspace(xmlDoc, workspaceInfo, out workspace);

            workspace.OnCurrentOffsetChanged(
                this,
                new PointEventArgs(new Point2D(workspaceInfo.X, workspaceInfo.Y)));

            return result;
        }
Example #11
0
        protected WorkspaceModel(
            IEnumerable<NodeModel> e, 
            IEnumerable<NoteModel> n,
            IEnumerable<AnnotationModel> a,
            WorkspaceInfo info, 
            NodeFactory factory,
            IEnumerable<PresetModel> presets)
        {
            guid = Guid.NewGuid();

            nodes = new ObservableCollection<NodeModel>(e);
            notes = new ObservableCollection<NoteModel>(n);

            annotations = new ObservableCollection<AnnotationModel>(a);         

            // Set workspace info from WorkspaceInfo object
            Name = info.Name;
            X = info.X;
            Y = info.Y;
            FileName = info.FileName;
            Zoom = info.Zoom;

            HasUnsavedChanges = false;
            LastSaved = DateTime.Now;

            WorkspaceVersion = AssemblyHelper.GetDynamoVersion();
            undoRecorder = new UndoRedoRecorder(this);

            NodeFactory = factory;

            this.presets = new List<PresetModel>(presets);
            // Update ElementResolver from nodeGraph.Nodes (where node is CBN)
            ElementResolver = new ElementResolver();
            foreach (var node in nodes)
            {
                RegisterNode(node);

                var cbn = node as CodeBlockNodeModel;
                if (cbn != null && cbn.ElementResolver != null)
                {
                    ElementResolver.CopyResolutionMap(cbn.ElementResolver);
                }
            }

            foreach (var connector in Connectors)
                RegisterConnector(connector);

            SetModelEventOnAnnotation();
        }
Example #12
0
        /// <summary>
        ///     Attempts to migrate a workspace to the current version of Dynamo.
        /// </summary>
        /// <param name="workspaceInfo"></param>
        /// <param name="xmlDoc"></param>
        /// <returns></returns>
        public bool ProcessWorkspace(WorkspaceInfo workspaceInfo, XmlDocument xmlDoc, bool isTestMode, NodeFactory factory)
        {
            Version fileVersion = VersionFromString(workspaceInfo.Version);

            var currentVersion = AssemblyHelper.GetDynamoVersion(includeRevisionNumber: false);

            if (fileVersion > currentVersion)
            {
                bool resume = displayFutureFileMessage(
                    workspaceInfo.FileName,
                    fileVersion,
                    currentVersion);

                if (!resume)
                    return false;
            }

            var decision = ProcessWorkspace(
                xmlDoc, fileVersion, currentVersion, workspaceInfo.FileName, isTestMode, factory);

            if (decision != Decision.Abort) 
                return true;

            displayObsoleteFileMessage(workspaceInfo.FileName, fileVersion, currentVersion);
            return false;
        }
Example #13
0
        protected WorkspaceModel(
            IEnumerable<NodeModel> e, 
            IEnumerable<NoteModel> n,
            IEnumerable<AnnotationModel> a,
            WorkspaceInfo info, 
            NodeFactory factory,
            IEnumerable<PresetModel> presets,
            ElementResolver resolver)
        {
            guid = Guid.NewGuid();

            nodes = new ObservableCollection<NodeModel>(e);
            notes = new ObservableCollection<NoteModel>(n);

            annotations = new ObservableCollection<AnnotationModel>(a);         

            // Set workspace info from WorkspaceInfo object
            Name = info.Name;
            Description = info.Description;
            X = info.X;
            Y = info.Y;
            FileName = info.FileName;
            Zoom = info.Zoom;

            HasUnsavedChanges = false;
            LastSaved = DateTime.Now;

            WorkspaceVersion = AssemblyHelper.GetDynamoVersion();
            undoRecorder = new UndoRedoRecorder(this);

            NodeFactory = factory;

            this.presets = new List<PresetModel>(presets);
            ElementResolver = resolver;

            foreach (var node in nodes)
                RegisterNode(node);

            foreach (var connector in Connectors)
                RegisterConnector(connector);

            SetModelEventOnAnnotation();
        }
Example #14
0
        public HomeWorkspaceModel(
            EngineController engine, 
            DynamoScheduler scheduler, 
            NodeFactory factory,
            IEnumerable<KeyValuePair<Guid, List<string>>> traceData, 
            IEnumerable<NodeModel> e, 
            IEnumerable<NoteModel> n, 
            IEnumerable<AnnotationModel> a,
            IEnumerable<PresetModel> presets,
            ElementResolver resolver,
            WorkspaceInfo info, 
            bool verboseLogging,
            bool isTestMode)
            : base(e, n,a, info, factory,presets, resolver)
        {
            EvaluationCount = 0;

            // This protects the user from a file that might have crashed during
            // its last run.  As a side effect, this also causes all files set to
            // run auto but lacking the HasRunWithoutCrash flag to run manually.
            if (info.RunType == RunType.Automatic && !info.HasRunWithoutCrash)
            {
                info.RunType = RunType.Manual;
            }

            RunSettings = new RunSettings(info.RunType, info.RunPeriod);

            PreloadedTraceData = traceData;

            this.scheduler = scheduler;
            this.verboseLogging = verboseLogging;
            IsTestMode = isTestMode;
            EngineController = engine;

            // The first time the preloaded trace data is set, we cache
            // the data as historical. This will be used after the initial
            // run of this workspace, when the PreloadedTraceData has been
            // nulled, to check for node deletions and reconcile the trace data.
            // We do a deep copy of this data because the PreloadedTraceData is
            // later set to null before the graph update.
            var copiedData = new List<KeyValuePair<Guid, List<string>>>();
            foreach (var kvp in PreloadedTraceData)
            {
                var strings = kvp.Value.Select(string.Copy).ToList();
                copiedData.Add(new KeyValuePair<Guid, List<string>>(kvp.Key, strings));
            }
            historicalTraceData = copiedData;

        }
Example #15
0
        public static bool FromXmlDocument(
            XmlDocument xmlDoc, string path, bool isTestMode, ILogger logger, out WorkspaceInfo workspaceInfo)
        {
            try
            {
                string funName            = null;
                double cx                 = 0;
                double cy                 = 0;
                double zoom               = 1.0;
                string id                 = "";
                string category           = "";
                string description        = "";
                string version            = "";
                var    runType            = RunType.Manual;
                int    runPeriod          = RunSettings.DefaultRunPeriod;
                bool   hasRunWithoutCrash = false;

                var topNode = xmlDoc.GetElementsByTagName("Workspace");

                // legacy support
                if (topNode.Count == 0)
                {
                    topNode = xmlDoc.GetElementsByTagName("dynWorkspace");
                }

                // load the header
                foreach (XmlNode node in topNode)
                {
                    foreach (XmlAttribute att in node.Attributes)
                    {
                        if (att.Name.Equals("X"))
                        {
                            cx = double.Parse(att.Value, CultureInfo.InvariantCulture);
                        }
                        else if (att.Name.Equals("Y"))
                        {
                            cy = double.Parse(att.Value, CultureInfo.InvariantCulture);
                        }
                        else if (att.Name.Equals("zoom"))
                        {
                            zoom = double.Parse(att.Value, CultureInfo.InvariantCulture);
                        }
                        else if (att.Name.Equals("Name"))
                        {
                            funName = att.Value;
                        }
                        else if (att.Name.Equals("ID"))
                        {
                            id = att.Value;
                        }
                        else if (att.Name.Equals("Category"))
                        {
                            category = att.Value;
                        }
                        else if (att.Name.Equals("Description"))
                        {
                            description = att.Value;
                        }
                        else if (att.Name.Equals("HasRunWithoutCrash"))
                        {
                            hasRunWithoutCrash = bool.Parse(att.Value);
                        }
                        else if (att.Name.Equals("Version"))
                        {
                            version = att.Value;
                        }
                        else if (att.Name.Equals("RunType"))
                        {
                            if (!Enum.TryParse(att.Value, false, out runType))
                            {
                                runType = RunType.Manual;
                            }
                        }
                        else if (att.Name.Equals("RunPeriod"))
                        {
                            runPeriod = Int32.Parse(att.Value);
                        }
                    }
                }

                // we have a dyf and it lacks an ID field, we need to assign it
                // a deterministic guid based on its name.  By doing it deterministically,
                // files remain compatible
                if (string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(funName) && funName != "Home")
                {
                    id = GuidUtility.Create(GuidUtility.UrlNamespace, funName).ToString();
                }

                workspaceInfo = new WorkspaceInfo
                {
                    ID                 = id,
                    Name               = funName,
                    X                  = cx,
                    Y                  = cy,
                    Zoom               = zoom,
                    FileName           = path,
                    Category           = category,
                    Description        = description,
                    Version            = version,
                    RunType            = runType,
                    RunPeriod          = runPeriod,
                    HasRunWithoutCrash = hasRunWithoutCrash
                };
                return(true);
            }
            catch (Exception ex)
            {
                logger.Log(Properties.Resources.OpenWorkbenchError);
                logger.Log(ex);
                Debug.WriteLine(ex.Message + ":" + ex.StackTrace);

                //TODO(Steve): Need a better way to handle this kind of thing. -- MAGN-5712
                if (isTestMode)
                {
                    throw; // Rethrow for NUnit.
                }
                workspaceInfo = null;
                return(false);
            }
        }
Example #16
0
        public static bool FromXmlDocument(
            XmlDocument xmlDoc, string path, bool isTestMode, bool forceManualExecutionMode, ILogger logger, out WorkspaceInfo workspaceInfo)
        {
            try
            {
                string funName = null;
                double cx = 0;
                double cy = 0;
                double zoom = 1.0;
                string id = "";
                string category = "";
                string description = "";
                string version = "";
                var runType = RunType.Manual;
                int runPeriod = RunSettings.DefaultRunPeriod;
                bool hasRunWithoutCrash = false;

                var topNode = xmlDoc.GetElementsByTagName("Workspace");

                // legacy support
                if (topNode.Count == 0)
                {
                    topNode = xmlDoc.GetElementsByTagName("dynWorkspace");
                }

                // load the header
                foreach (XmlNode node in topNode)
                {
                    foreach (XmlAttribute att in node.Attributes)
                    {
                        if (att.Name.Equals("X"))
                            cx = double.Parse(att.Value, CultureInfo.InvariantCulture);
                        else if (att.Name.Equals("Y"))
                            cy = double.Parse(att.Value, CultureInfo.InvariantCulture);
                        else if (att.Name.Equals("zoom"))
                            zoom = double.Parse(att.Value, CultureInfo.InvariantCulture);
                        else if (att.Name.Equals("Name"))
                            funName = att.Value;
                        else if (att.Name.Equals("ID"))
                            id = att.Value;
                        else if (att.Name.Equals("Category"))
                            category = att.Value;
                        else if (att.Name.Equals("Description"))
                            description = att.Value;
                        else if (att.Name.Equals("HasRunWithoutCrash"))
                            hasRunWithoutCrash = bool.Parse(att.Value);
                        else if (att.Name.Equals("Version"))
                            version = att.Value;
                        else if (att.Name.Equals("RunType"))
                        {
                            if (forceManualExecutionMode || !Enum.TryParse(att.Value, false, out runType))
                            {
                                runType = RunType.Manual;
                            }
                        }
                        else if (att.Name.Equals("RunPeriod"))
                            runPeriod = Int32.Parse(att.Value);
                    }
                }

                // we have a dyf and it lacks an ID field, we need to assign it
                // a deterministic guid based on its name.  By doing it deterministically,
                // files remain compatible
                if (string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(funName) && funName != "Home")
                {
                    id = GuidUtility.Create(GuidUtility.UrlNamespace, funName).ToString();
                }

                workspaceInfo = new WorkspaceInfo
                {
                    ID = id,
                    Name = funName,
                    X = cx,
                    Y = cy,
                    Zoom = zoom,
                    FileName = path,
                    Category = category,
                    Description = description,
                    Version = version,
                    RunType  = runType,
                    RunPeriod = runPeriod,
                    HasRunWithoutCrash = hasRunWithoutCrash
                };
                return true;
            }
            catch (Exception ex)
            {
                logger.Log(Properties.Resources.OpenWorkbenchError);
                logger.Log(ex);
                Debug.WriteLine(ex.Message + ":" + ex.StackTrace);

                //TODO(Steve): Need a better way to handle this kind of thing. -- MAGN-5712
                if (isTestMode)
                    throw; // Rethrow for NUnit.

                workspaceInfo = null;
                return false;
            }
        }