コード例 #1
0
ファイル: DynamoModel.cs プロジェクト: jimmplan/Dynamo
        internal void OpenCustomNodeAndFocus( WorkspaceHeader workspaceHeader )
        {
            // load custom node
            var manager = dynSettings.Controller.CustomNodeManager;
            var info = manager.AddFileToPath(workspaceHeader.FileName);
            var funcDef = manager.GetFunctionDefinition(info.Guid);
            funcDef.AddToSearch();

            var ws = funcDef.WorkspaceModel;
            ws.Zoom = workspaceHeader.Zoom;
            ws.HasUnsavedChanges = false;

            if (!this.Workspaces.Contains(ws))
            {
                this.Workspaces.Add(ws);
            }

            var vm = dynSettings.Controller.DynamoViewModel.Workspaces.First(x => x.Model == ws);
            vm.OnCurrentOffsetChanged(this, new PointEventArgs(new Point(workspaceHeader.X, workspaceHeader.Y)));

            this.CurrentWorkspace = ws;
        }
コード例 #2
0
ファイル: DynamoModel.cs プロジェクト: jbenoit44/Dynamo
        internal void OpenCustomNodeAndFocus(WorkspaceHeader workspaceHeader)
        {
            // load custom node
            var manager = CustomNodeManager;
            var info = manager.AddFileToPath(workspaceHeader.FileName);
            var funcDef = manager.GetFunctionDefinition(info.Guid);
            if (funcDef == null) // Fail to load custom function.
                return;

            if (funcDef.IsProxy && info != null)
            {
                funcDef = manager.ReloadFunctionDefintion(info.Guid);
                if (funcDef == null)
                {
                    return;
                }
            }

            funcDef.AddToSearch(this.SearchModel);

            var ws = funcDef.WorkspaceModel;
            ws.Zoom = workspaceHeader.Zoom;
            ws.HasUnsavedChanges = false;

            if (!this.Workspaces.Contains(ws))
            {
                this.Workspaces.Add(ws);
            }

            var vm = this.Workspaces.First(x => x == ws);
            vm.OnCurrentOffsetChanged(this, new PointEventArgs(new Point(workspaceHeader.X, workspaceHeader.Y)));

            this.CurrentWorkspace = ws;
        }
コード例 #3
0
ファイル: WorkspaceHeader.cs プロジェクト: Steell/Dynamo
        public static bool FromXmlDocument(
            XmlDocument xmlDoc, string path, bool isTestMode, ILogger logger, out WorkspaceHeader workspaceInfo)
        {
            try
            {
                string funName     = null;
                double cx          = 0;
                double cy          = 0;
                double zoom        = 1.0;
                string id          = "";
                string category    = "";
                string description = "";
                string version     = "";

                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("Version"))
                        {
                            version = 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 WorkspaceHeader
                {
                    ID          = id,
                    Name        = funName,
                    X           = cx,
                    Y           = cy,
                    Zoom        = zoom,
                    FileName    = path,
                    Category    = category,
                    Description = description,
                    Version     = version
                };
                return(true);
            }
            catch (Exception ex)
            {
                logger.Log("There was an error opening the workspace.");
                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);
            }
        }