Ejemplo n.º 1
0
        private void BuildPropertiesPanel(XtbNuGetPackage package)
        {
            scProperties.Panel1.Controls.Clear();

            var bitmap = new PictureBox
            {
                Size     = new Size(48, 48),
                Dock     = DockStyle.Left,
                SizeMode = PictureBoxSizeMode.StretchImage
            };

            try
            {
                bitmap.Load(package.Package.IconUrl?.AbsoluteUri ?? "https://raw.githubusercontent.com/wiki/MscrmTools/XrmToolBox/Images/unknown.png");
            }
            catch
            {
                byte[] bytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAFzAAABcwHEdCJ9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAVlQTFRF////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXF73CwAAAHJ0Uk5TAAEDBAUGBwsPEBEUFRYXGxwkJyorLjAxNzk+P0BBRkdKS01TVVlaW1xfYWJjZWhpbHBxcnZ3eHp8f4KGh4iJioyRkpOUnaOkpaaorrCxsrO2uLq7vsLDztLV2Nnc3d7f4+bn6Ort8fL09vf4+fr7/P3+Afu7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Image;
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    errorImage = Image.FromStream(ms);
                }
                bitmap.ErrorImage = errorImage;
            }

            var lblTitle = new Label
            {
                Dock   = DockStyle.Top,
                Text   = package.Package.Title.Replace(" for XrmToolBox", ""),
                Font   = new Font("Microsoft Sans Serif", 20F),
                Height = 32
            };

            var lblDescription = new Label
            {
                Dock   = DockStyle.Fill,
                Text   = package.Package.Description,
                Height = 16
            };

            var pnlTitle = new Panel
            {
                Height = 48,
                Dock   = DockStyle.Top
            };

            if (lblDescription.Text.Contains("\n"))
            {
                pnlTitle.Controls.AddRange(new Control[] { lblTitle, bitmap });

                var pnlDescription = new Panel
                {
                    AutoScroll        = true,
                    AutoScrollMinSize = new Size(0, 1000),
                    Dock = DockStyle.Fill
                };
                pnlDescription.Controls.Add(lblDescription);

                var lblDescriptionHeader = new Label
                {
                    Dock   = DockStyle.Top,
                    Text   = "Description",
                    Font   = new Font("Microsoft Sans Serif", 8, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Point),
                    Height = 16
                };

                scProperties.Panel1.Controls.AddRange(new Control[]
                {
                    pnlDescription,
                    lblDescriptionHeader,
                    GetPropertiesPanelInformation("Project Url", package.Package.ProjectUrl),
                    GetPropertiesPanelInformation("Downloads count", package.Package.DownloadCount.ToString()),
                    GetPropertiesPanelInformation("Latest release", package.LatestReleaseDate.ToString("yyyy/MM/dd")),
                    GetPropertiesPanelInformation("First release", package.FirstReleaseDate.ToString("yyyy/MM/dd")),
                    GetPropertiesPanelInformation("Authors", string.Join(", ", package.Package.Authors)),
                    GetPropertiesPanelInformation("Version", package.Package.Version.ToString()),
                    pnlTitle
                });
            }
            else
            {
                pnlTitle.Controls.AddRange(new Control[] { lblDescription, lblTitle, bitmap });

                scProperties.Panel1.Controls.AddRange(new Control[]
                {
                    GetPropertiesPanelInformation("Project Url", package.Package.ProjectUrl),
                    GetPropertiesPanelInformation("Downloads count", package.Package.DownloadCount.ToString()),
                    GetPropertiesPanelInformation("Latest release", package.LatestReleaseDate.ToString("yyyy/MM/dd")),
                    GetPropertiesPanelInformation("First release", package.FirstReleaseDate.ToString("yyyy/MM/dd")),
                    GetPropertiesPanelInformation("Authors", string.Join(", ", package.Package.Authors)),
                    GetPropertiesPanelInformation("Version", package.Package.Version.ToString()),
                    pnlTitle
                });
            }
        }
Ejemplo n.º 2
0
        private XtbNuGetPackage GetXtbPackage(IPackage package)
        {
            var xtbPackage = new XtbNuGetPackage(package, PackageInstallAction.None, currentVersionDownloadsCount);

            var files = package.GetFiles();

            bool install = false, update = false, otherFilesFound = false;

            var xtbDependency = package.FindDependency("XrmToolBox", null);

            if (xtbDependency != null)
            {
                var xtbDependencyVersion = xtbDependency.VersionSpec.MinVersion.Version;
                xtbPackage.Compatibilty = IsPluginDependencyCompatible(xtbDependencyVersion);
            }
            else
            {
                xtbDependency = package.FindDependency("XrmToolBoxPackage", null);
                if (xtbDependency != null)
                {
                    var xtbDependencyVersion = xtbDependency.VersionSpec.MinVersion.Version;
                    xtbPackage.Compatibilty = IsPluginDependencyCompatible(xtbDependencyVersion);
                }
                else
                {
                    xtbPackage.Compatibilty = CompatibleState.Other;
                }
            }

            var currentVersion      = new Version(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue);
            var currentVersionFound = false;

            foreach (var file in files)
            {
                var directoryName = Path.GetDirectoryName(file.EffectivePath);
                if (directoryName == null)
                {
                    continue;
                }

                if (directoryName.ToLower() == "plugins")
                {
                    // Only check version of files in the Plugins folder
                    var existingPluginFile =
                        plugins.FirstOrDefault(p => file.EffectivePath.ToLower().EndsWith(p.Name.ToLower()));
                    if (existingPluginFile == null)
                    {
                        install = true;
                    }
                    else
                    {
                        // If a file is found, we check version only if the file
                        // contains classes that implement IXrmToolBoxPlugin
                        if (!existingPluginFile.ImplementsXrmToolBoxPlugin())
                        {
                            otherFilesFound = true;
                            continue;
                        }

                        var fileVersionInfo = FileVersionInfo.GetVersionInfo(existingPluginFile.FullName);
                        var fileVersion     = new Version(fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart);

                        var existingFileVersion = fileVersion;
                        if (existingFileVersion < currentVersion)
                        {
                            currentVersion      = existingFileVersion;
                            currentVersionFound = true;
                        }
                        if (existingFileVersion < package.Version.Version)
                        {
                            update = true;
                        }
                    }
                }
            }

            if (currentVersionFound)
            {
                xtbPackage.CurrentVersion = currentVersion;
            }

            if (otherFilesFound || update)
            {
                xtbPackage.RequiresXtbRestart = true;
            }

            if (xtbPackage.Compatibilty != CompatibleState.Compatible)
            {
                xtbPackage.Action = PackageInstallAction.Unavailable;
            }
            else if (update)
            {
                xtbPackage.Action = PackageInstallAction.Update;
            }
            else if (install)
            {
                xtbPackage.Action = PackageInstallAction.Install;
            }
            else
            {
                xtbPackage.Action = PackageInstallAction.None;
            }

            return(xtbPackage);
        }
Ejemplo n.º 3
0
        public string GetPluginProjectUrlByFileName(string fileName)
        {
            XtbNuGetPackage package = GetPackageByFileName(fileName);

            return(package?.Package?.ProjectUrl?.ToString());
        }
Ejemplo n.º 4
0
        private XtbNuGetPackage GetXtbPackage(IPackage package)
        {
            var xtbPackage = new XtbNuGetPackage(package, PackageInstallAction.None);

            var files = package.GetFiles();

            bool install = false, update = false, compatible = false, otherFilesFound = false;

            var xtbDependency = package.FindDependency("XrmToolBox", null);

            if (xtbDependency != null)
            {
                var xtbDependencyVersion = xtbDependency.VersionSpec.MinVersion.Version;
                compatible = IsPluginDependencyCompatible(xtbDependencyVersion);
            }

            var currentVersion      = new Version(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue);
            var currentVersionFound = false;

            // TODO: Don't compare with all files, plugin packages may contain other dll's and exe's that have other versioning
            // How to determine actual version of existing plugin?
            foreach (var file in files)
            {
                if (Path.GetDirectoryName(file.EffectivePath).ToLower() == "plugins")
                {
                    // Only check version of files in the Plugins folder
                    var existingPluginFile =
                        plugins.FirstOrDefault(p => file.EffectivePath.ToLower().EndsWith(p.Name.ToLower()));
                    if (existingPluginFile == null)
                    {
                        install = true;
                    }
                    else
                    {
                        // If a file is found, we check version only if the file
                        // contains classes that implement IXrmToolBoxPlugin
                        if (!existingPluginFile.ImplementsXrmToolBoxPlugin())
                        {
                            otherFilesFound = true;
                            continue;
                        }

                        var existingFileVersion = new Version(FileVersionInfo.GetVersionInfo(existingPluginFile.FullName).FileVersion);
                        if (existingFileVersion < currentVersion)
                        {
                            currentVersion      = existingFileVersion;
                            currentVersionFound = true;
                        }
                        if (existingFileVersion < package.Version.Version)
                        {
                            update = true;
                        }
                    }
                }
            }

            if (currentVersionFound)
            {
                xtbPackage.CurrentVersion = currentVersion;
            }

            if (otherFilesFound || update)
            {
                xtbPackage.RequiresXtbRestart = true;
            }

            if (!compatible)
            {
                xtbPackage.Action = PackageInstallAction.Unavailable;
            }
            else if (update)
            {
                xtbPackage.Action = PackageInstallAction.Update;
            }
            else if (install)
            {
                xtbPackage.Action = PackageInstallAction.Install;
            }
            else
            {
                xtbPackage.Action = PackageInstallAction.None;
            }

            return(xtbPackage);
        }