Beispiel #1
0
        private void ImportScript(object sender, RoutedEventArgs e)
        {
            ImportScript import = new ImportScript();

            import.AvailableScripts = viewmodel.Scripts;

            var result = import.ShowDialog();

            if (result == true)
            {
                foreach (var dependency in import.asset.Dependencies)
                {
                    if (!viewmodel.ScriptDependencies.ContainsKey(dependency.Name))
                    {
                        viewmodel.ScriptDependencies.Add(dependency.Name, new List <ScriptAsset>());
                    }

                    viewmodel.ScriptDependencies[dependency.Name].Add(import.asset);
                }

                viewmodel.Scripts.Add(import.asset);
            }
            else
            {
                if (!string.IsNullOrEmpty(import.Errors))
                {
                    viewmodel.LogEvent(import.Errors);
                }
            }
        }
Beispiel #2
0
        private void EditScript(object sender, RoutedEventArgs e)
        {
            if (viewmodel.SelectedScript == null)
            {
                return;
            }

            string oldName     = viewmodel.SelectedScript.Name;
            string oldImported = viewmodel.SelectedScript.ImportedFilename;
            string oldSource   = viewmodel.SelectedScript.SourceFilename;

            ImportScript import = new ImportScript();

            import.setAsset(viewmodel.SelectedScript);
            import.isEditMode = true;

            import.AvailableScripts = viewmodel.Scripts;

            var result = import.ShowDialog();

            if (result == true)
            {
                //remove all dependencies then add the current/new ones
                //simpler than checking which dependency was recently removed/added
                foreach (var dependency in import.asset.Dependencies)
                {
                    if (viewmodel.ScriptDependencies.ContainsKey(dependency.Name))
                    {
                        viewmodel.ScriptDependencies[dependency.Name].Remove(import.asset);
                    }
                }

                if (oldName != import.asset.Name)
                {
                    var newName = import.asset.Name;

                    import.asset.Name = oldName;

                    //we changed the name, delete the old asset then create a new one
                    System.IO.File.Delete(oldImported);
                    System.IO.File.Delete(System.IO.Path.ChangeExtension(oldImported, "pdb"));

                    import.asset.Name = newName;
                }
                else
                {
                    metadataHandler.updateDependents(viewmodel.SelectedScript);
                }


                foreach (var dependency in import.asset.Dependencies)
                {
                    if (!viewmodel.ScriptDependencies.ContainsKey(dependency.Name))
                    {
                        viewmodel.ScriptDependencies.Add(dependency.Name, new List <ScriptAsset>());
                    }

                    viewmodel.ScriptDependencies[dependency.Name].Add(import.asset);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(import.Errors))
                {
                    viewmodel.LogEvent(import.Errors);
                }
            }
        }