Ejemplo n.º 1
0
        /// <summary>
        /// Opens a file and returns the corresponding MDViewModel
        /// </summary>
        /// <param name="info">The string location of the file</param>
        /// <returns>The <see cref="MDViewModel"/> for the file.</returns>
        public ContentViewModel OpenContent(object info, object param)
        {
            var location = info as string;

            if (location != null)
            {
                SceneDataModel model = null;
                SceneViewModel vm    = VEFModule.UnityContainer.Resolve(typeof(SceneViewModel), "") as SceneViewModel;
                var            view  = VEFModule.UnityContainer.Resolve(typeof(SceneView), "") as SceneView;

                try
                {
                    ISceneService       sceneService      = VEFModule.UnityContainer.Resolve(typeof(ISceneService), "") as ISceneService;
                    IProjectTreeService pfExplorerService = VEFModule.UnityContainer.Resolve(typeof(IProjectTreeService), "") as IProjectTreeService;

                    //          string[] split = Regex.Split(info.ToString(), ":##:");
                    //if (split.Count() == 2)
                    //{
                    //    string identifier = split[0];
                    //    string ID = split[1];
                    //    if (identifier == "SceneID")
                    //    {
                    var scene = sceneService.Scenes.Where(x => x.ContentID == info.ToString());
                    if (scene.Any())
                    {
                        sceneService.SelectedScene = scene.First();
                        sceneService.SelectedScene.Open(info);
                    }
                    else //new scene
                    {
                        //    SceneDataModel newScene = new SceneDataModel() { Name = "Scene NEW", ContentID = "SceneID:##:" };
                        // newScene.Parent = parent;

                        if (pfExplorerService.SelectedItem is SceneDataModel)
                        {    // pfExplorerService.SelectedItem.Items.Add(newScene);
                            var newScene = pfExplorerService.SelectedItem as SceneDataModel;
                            if (newScene != null)
                            {
                                sceneService.Scenes.Add(newScene);
                                //  sceneService.SelectedScene = newScene;
                                newScene.Open(-1);

                                model = newScene;
                            }
                        }
                    }

                    //Model details
                    if (model == null)
                    {
                        model = VEFModule.UnityContainer.Resolve(typeof(SceneDataModel), "") as SceneDataModel;
                    }

                    model.SetLocation(info);

                    //  model.SetLocation("AuftragID:##:" + info + "");

                    //      model.Document.Text = File.ReadAllText(location);
                    model.SetDirty(true);
                    //   }
                }



                catch (Exception exception)
                {
                    _loggerService.Log(exception.Message, LogCategory.Exception, LogPriority.High);
                    _loggerService.Log(exception.StackTrace, LogCategory.Exception, LogPriority.High);
                    return(null);
                }

                //Clear the undo stack
                // model.Document.UndoStack.ClearAll();

                //Set the model and view
                vm.SetModel(model);
                vm.SetView(view);
                vm.Title = model.Name ?? "Scene";//model.nae  // Path.GetFileName("Scene gefunden");
                (vm.View as UserControl).DataContext = model;

                return(vm);
            }
            return(null);
        }