Exemplo n.º 1
0
        /// <summary>
        ///     Loads an update project.
        /// </summary>
        /// <param name="path">The path of the project file.</param>
        /// <returns>Returns the read update project.</returns>
        public static UpdateProject LoadProject(string path)
        {
            string jsonString = File.ReadAllText(path);
            JObject jObject = JObject.Parse(jsonString);
            JToken value;
            if (typeof(UpdateProject).GetProperties().All(property => jObject.TryGetValue(property.Name, out value) && property.PropertyType == value.Type.GetType()))
                return Serializer.Deserialize<UpdateProject>(jsonString);

            UpdateProject newProject = null;
            if (!jObject.TryGetValue("ConfigVersion", out value)) // Was before 1.0.0.0 Beta 2 as this property has been added there
            {
                var oldProject = Serializer.Deserialize<OldUpdateProject>(jsonString);
                newProject = new UpdateProject
                {
                    ApplicationId = oldProject.ApplicationId,
                    AssemblyVersionPath = oldProject.AssemblyVersionPath,
                    FtpDirectory = oldProject.FtpDirectory,
                    FtpHost = oldProject.FtpHost,
                    FtpUsername = oldProject.FtpUsername,
                    FtpPassword = oldProject.FtpPassword,
                    FtpPort = oldProject.FtpPort,
                    FtpProtocol = oldProject.FtpProtocol,
                    FtpTransferAssemblyFilePath = oldProject.FtpTransferAssemblyFilePath,
                    FtpUsePassiveMode = oldProject.FtpUsePassiveMode,
                    Guid = oldProject.Guid,
                    Log = oldProject.Log,
                    Name = oldProject.Name,
                    Packages = new List<UpdatePackage>(),
                    Path = oldProject.Path,
                    PrivateKey = oldProject.PrivateKey,
                    PublicKey = oldProject.PublicKey,
                    Proxy = oldProject.Proxy,
                    ProxyPassword = oldProject.ProxyPassword,
                    ProxyUsername = oldProject.ProxyUsername,
                    SaveCredentials = oldProject.SaveCredentials,
                    SqlDatabaseName = oldProject.SqlDatabaseName,
                    SqlPassword = oldProject.SqlPassword,
                    SqlUsername = oldProject.SqlUsername,
                    SqlWebUrl = oldProject.SqlWebUrl,
                    UpdateUrl = oldProject.UpdateUrl,
                    UseStatistics = oldProject.UseStatistics,
                };

                JToken packagesToken;
                jObject.TryGetValue("Packages", out packagesToken);
                if (packagesToken != null)
                {
                    var packages = packagesToken.ToObject<List<OldUpdatePackage>>();
                    for (int i = 0; i <= packages.Count - 1; ++i)
                    {
                        var newPackage = new UpdatePackage
                        {
                            Description = packages[i].Description,
                            IsReleased = packages[i].IsReleased,
                            LocalPackagePath = packages[i].LocalPackagePath
                        };

                        var developmentalStage = (int)packages[i].Version.DevelopmentalStage;
                        switch (developmentalStage)
                        {
                            case 0: // This was release
                                newPackage.Version = packages[i].Version.ToString();
                                break;
                            case 1: // This was Beta
                                newPackage.Version = new UpdateVersion(packages[i].Version.Major,
                                    packages[i].Version.Minor, packages[i].Version.Build, packages[i].Version.Revision,
                                    DevelopmentalStage.Beta, packages[i].Version.DevelopmentBuild).ToString();
                                break;
                            case 2: // This was Alpha
                                newPackage.Version = new UpdateVersion(packages[i].Version.Major,
                                    packages[i].Version.Minor, packages[i].Version.Build, packages[i].Version.Revision,
                                    DevelopmentalStage.Alpha, packages[i].Version.DevelopmentBuild).ToString();
                                break;
                        }

                        newProject.Packages.Add(newPackage);
                    }
                }
            }

            if (newProject == null)
                newProject = Serializer.Deserialize<UpdateProject>(jsonString);
            SaveProject(newProject.Path, newProject);
            return newProject;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads an update project.
        /// </summary>
        /// <param name="path">The path of the project file.</param>
        /// <returns>Returns the read update project.</returns>
        public static UpdateProject LoadProject(string path)
        {
            string  jsonString = File.ReadAllText(path);
            JObject jObject    = JObject.Parse(jsonString);
            JToken  value;

            if (
                typeof(UpdateProject).GetProperties()
                .All(
                    property =>
                    jObject.TryGetValue(property.Name, out value) &&
                    property.PropertyType == value.Type.GetType()))
            {
                return(Serializer.Deserialize <UpdateProject>(jsonString));
            }

            UpdateProject newProject = null;

            if (!jObject.TryGetValue("ConfigVersion", out value))
            // Was before 1.0.0.0 Beta 2 as this property has been added there
            {
                var oldProject = Serializer.Deserialize <OldUpdateProject>(jsonString);
                newProject = new UpdateProject
                {
                    ApplicationId               = oldProject.ApplicationId,
                    AssemblyVersionPath         = oldProject.AssemblyVersionPath,
                    FtpDirectory                = oldProject.FtpDirectory,
                    FtpHost                     = oldProject.FtpHost,
                    FtpUsername                 = oldProject.FtpUsername,
                    FtpPassword                 = oldProject.FtpPassword,
                    FtpPort                     = oldProject.FtpPort,
                    FtpProtocol                 = oldProject.FtpProtocol,
                    FtpTransferAssemblyFilePath = oldProject.FtpTransferAssemblyFilePath,
                    FtpUsePassiveMode           = oldProject.FtpUsePassiveMode,
                    Guid            = oldProject.Guid,
                    Log             = oldProject.Log,
                    Name            = oldProject.Name,
                    Packages        = new List <UpdatePackage>(),
                    Path            = oldProject.Path,
                    PrivateKey      = oldProject.PrivateKey,
                    PublicKey       = oldProject.PublicKey,
                    Proxy           = oldProject.Proxy,
                    ProxyPassword   = oldProject.ProxyPassword,
                    ProxyUsername   = oldProject.ProxyUsername,
                    SaveCredentials = oldProject.SaveCredentials,
                    SqlDatabaseName = oldProject.SqlDatabaseName,
                    SqlPassword     = oldProject.SqlPassword,
                    SqlUsername     = oldProject.SqlUsername,
                    SqlWebUrl       = oldProject.SqlWebUrl,
                    UpdateUrl       = oldProject.UpdateUrl,
                    UseStatistics   = oldProject.UseStatistics
                };

                JToken packagesToken;
                jObject.TryGetValue("Packages", out packagesToken);
                if (packagesToken != null)
                {
                    var packages = packagesToken.ToObject <List <OldUpdatePackage> >();
                    for (int i = 0; i <= packages.Count - 1; ++i)
                    {
                        var newPackage = new UpdatePackage
                        {
                            Description      = packages[i].Description,
                            IsReleased       = packages[i].IsReleased,
                            LocalPackagePath = packages[i].LocalPackagePath
                        };

                        var developmentalStage = (int)packages[i].Version.DevelopmentalStage;
                        switch (developmentalStage)
                        {
                        case 0:     // This was release
                            newPackage.Version = packages[i].Version.ToString();
                            break;

                        case 1:     // This was Beta
                            newPackage.Version = new UpdateVersion(packages[i].Version.Major,
                                                                   packages[i].Version.Minor, packages[i].Version.Build, packages[i].Version.Revision,
                                                                   DevelopmentalStage.Beta, packages[i].Version.DevelopmentBuild).ToString();
                            break;

                        case 2:     // This was Alpha
                            newPackage.Version = new UpdateVersion(packages[i].Version.Major,
                                                                   packages[i].Version.Minor, packages[i].Version.Build, packages[i].Version.Revision,
                                                                   DevelopmentalStage.Alpha, packages[i].Version.DevelopmentBuild).ToString();
                            break;
                        }

                        newProject.Packages.Add(newPackage);
                    }
                }
            }

            if (newProject == null)
            {
                newProject = Serializer.Deserialize <UpdateProject>(jsonString);
            }
            SaveProject(newProject.Path, newProject);
            return(newProject);
        }