Esempio n. 1
0
        public bool Initialize()
        {
            try
            {
                var proj   = new XenProjectFile(_fs);
                var loaded = proj.Load(ToolboxApp.Project.State.XenProjectFilePath);

                if (loaded == false || proj.Views == null)
                {
                    OnRecreateMenuItems(new RecreateMenuItemsEventArgs(null));
                }

                if (!loaded)
                {
                    return(false);
                }
                if (proj.Views == null)
                {
                    return(false);
                }

                var sorted = proj.Views.OrderBy(v => v.TypeName).ToArray();
                OnRecreateMenuItems(new RecreateMenuItemsEventArgs(sorted));
                return(true);
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, $"Error initializing {nameof(RegisterNewViewModel)}.");
                return(false);
            }
        }
Esempio n. 2
0
        public bool Save()
        {
            try
            {
                var persistable = Persistable.ToArray();

                if (string.IsNullOrWhiteSpace(ToolboxApp.Project.State.ProjectFolder))
                {
                    OnRecreateMenuItems(new RecreateMenuItemsEventArgs(persistable));
                    return(false);
                }

                var proj   = new XenProjectFile(_fs);
                var loaded = proj.Load(ToolboxApp.Project.State.XenProjectFilePath);

                if (!loaded)
                {
                    ToolboxApp.Log.Info($"Creating new project file: {ToolboxApp.Project.State.XenProjectFilePath}.");
                    proj.Schema = XenFormsEnvironment.ProjectFileSchema;
                }

                proj.Views = persistable;
                proj.Save(ToolboxApp.Project.State.XenProjectFilePath);

                foreach (var pv in proj.Views)
                {
                    pv.Persisted = true;
                }

                OnRecreateMenuItems(new RecreateMenuItemsEventArgs(proj.Views));
                return(true);
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, $"Error saving file: {ToolboxApp.Project.State.XenProjectFilePath}.");

                MessageBox.Show(Application.Instance.MainForm,
                                "There was an error saving the project file. Please check the log for more information.",
                                "XenForms",
                                MessageBoxButtons.OK,
                                MessageBoxType.Error);

                return(false);
            }
        }
Esempio n. 3
0
        public void Save()
        {
            try
            {
                var proj = new XenProjectFile(_fs)
                {
                    Schema     = XenFormsEnvironment.ProjectFileSchema,
                    Assemblies = IncludedAssemblies?.ToArray() ?? new ProjectAssembly[] {}
                };

                proj.Save(ToolboxApp.Project.State.XenProjectFilePath);
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, $"Error saving file: {ToolboxApp.Project.State.XenProjectFilePath}.");

                MessageBox.Show(Application.Instance.MainForm,
                                "There was an error saving the project file. Please check the log for more information.",
                                "XenForms",
                                MessageBoxButtons.OK,
                                MessageBoxType.Error);
            }
        }
Esempio n. 4
0
        public bool Show()
        {
            try
            {
                var proj   = new XenProjectFile(_fs);
                var loaded = proj.Load(ToolboxApp.Project.State.XenProjectFilePath);

                if (!loaded)
                {
                    return(false);
                }
                if (proj.Views == null)
                {
                    return(false);
                }

                // clear the views after when know that we can save some output
                Views.Clear();
                var sorted = proj.Views.OrderBy(v => v.TypeName).ToArray();

                foreach (var pv in sorted)
                {
                    pv.Deleted   = false;
                    pv.Persisted = true;
                    Views.Add(pv);
                }

                OnRecreateMenuItems(new RecreateMenuItemsEventArgs(proj.Views));
                return(true);
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, $"Error showing {nameof(RegisterNewViewModel)}.");
                return(false);
            }
        }
Esempio n. 5
0
        public void Initialize(IEnumerable <ProjectAssembly> tracking)
        {
            try
            {
                var pas        = tracking as ProjectAssembly[] ?? tracking.ToArray();
                var opas       = pas.OrderBy(a => a.FullPath).ThenBy(a => a.RelativePath).ToArray();
                var projFolder = ToolboxApp.Project.State.ProjectFolder;
                if (string.IsNullOrWhiteSpace(projFolder))
                {
                    return;
                }

                Assemblies.Clear();

                // Assemblies.AddRange() causes exception?
                foreach (var pa in opas)
                {
                    Assemblies.Add(pa);
                }

                // find assemblies in project folder
                var comparer = new ProjectAssemblyComparer();
                var allFiles = Directory.GetFiles(projFolder, $"*{SupportedFileTypes.AssemblyExtension}", SearchOption.AllDirectories);
                var found    = new List <ProjectAssembly>();

                foreach (var file in allFiles)
                {
                    var rp = file.Replace(projFolder, string.Empty);

                    var assembly = new ProjectAssembly
                    {
                        FullPath     = file,
                        RelativePath = rp,
                        FileName     = Path.GetFileName(file),
                        Directory    = Path.GetDirectoryName(rp)
                    };

                    found.Add(assembly);
                }

                var orderedFound = found.OrderBy(a => a.FullPath).ThenBy(a => a.RelativePath);

                // add assemblies in project folder
                foreach (var assembly in orderedFound)
                {
                    if (!Assemblies.Contains(assembly, comparer))
                    {
                        Assemblies.Add(assembly);
                    }
                }

                // check if project file exists and include assemblies
                if (_fs.FileExist(ToolboxApp.Project.State.XenProjectFilePath))
                {
                    var proj   = new XenProjectFile(_fs);
                    var loaded = proj.Load(ToolboxApp.Project.State.XenProjectFilePath);

                    if (!loaded)
                    {
                        ToolboxApp.Log.Warn($"Unable to load project file: {ToolboxApp.Project.State.XenProjectFilePath}.");
                    }

                    if (proj.Assemblies != null)
                    {
                        foreach (var pa in proj.Assemblies)
                        {
                            var fp = $"{ToolboxApp.Project.State.XenProjectFilePath}{pa.RelativePath}";
                            if (string.IsNullOrWhiteSpace(fp))
                            {
                                continue;
                            }

                            var match = Assemblies.FirstOrDefault(a => a.FullPath == fp);
                            if (match != null)
                            {
                                match.Include = true;
                            }
                        }
                    }
                }
                else
                {
                    ToolboxApp.Log.Info($"{ToolboxApp.Project.State.XenProjectFilePath} doesn't exist.");
                }
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, "Error retrieving project assemblies.");
            }
        }