Ejemplo n.º 1
0
        public override publishResult publishUpdates()
        {
            var result = new publishResult {
                Provider = this
            };

            try {
                var updates          = updatePackages;
                int maxFileCount     = updates.Count + 2;             // +2 wegen der Updatekonfiguration und dem updateInstaller
                int currentFileCount = 0;

                //Status übertragen
                onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                    currentFile     = currentFileCount,
                    currentFilename = string.Empty,
                    maxFileCount    = maxFileCount
                });

                //Stammverzeichnisse erstellen
                createRequiredDirectories();

                var          client = buildFtpClient();
                var          updateRootDirectory = getSetting(pbsFtpSetting_Directory);
                const string updateDirectory     = "updates";
                var          publishedFiles      = new List <string>();
                try {
                    //Client verbinden
                    client.Connect();

                    //Updatepakete und deren Changelogs übertragen
                    client.SetWorkingDirectory(updateRootDirectory);
                    client.SetWorkingDirectory(updateDirectory);
                    foreach (var update in updates)
                    {
                        string localFilename  = Path.Combine(localUpdateDirectory, update.getFilename());
                        string remoteFilename = update.getFilename();

                        string localChangelogFilename  = Path.Combine(localUpdateDirectory, update.getChangelogFilename());
                        string remoteChangelogFilename = update.getChangelogFilename();

                        publishedFiles.Add(update.getFilename());
                        publishedFiles.Add(update.getChangelogFilename());
                        currentFileCount++;

                        //Status übertragen
                        onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                            currentFile     = currentFileCount,
                            currentFilename = update.getFilename(),
                            maxFileCount    = maxFileCount
                        });

                        //Überprüfen ob die Datei auf dem Server mit der lokalen identisch ist););
                        if (client.FileExists(remoteFilename))
                        {
                            long localFileSize  = new FileInfo(localFilename).Length;
                            long remoteFileSite = client.GetFileSize(remoteFilename);

                            if (localFileSize == remoteFileSite)
                            {
                                continue;
                            }
                        }

                        //Updatepaket übertragen
                        using (var fsPackage = File.OpenRead(localFilename)) {
                            writeLogEntry(logLevel.Info, string.Format("Upload {0}->{1}", localFilename, remoteFilename));
                            client.Upload(fsPackage, remoteFilename);
                        }

                        //Changelog übertragen
                        using (var fsChangelog = File.OpenRead(localChangelogFilename)) {
                            writeLogEntry(logLevel.Info, string.Format("Upload {0}", remoteChangelogFilename));
                            client.Upload(fsChangelog, remoteChangelogFilename);
                        }
                        update.publishDate = DateTime.UtcNow;
                    }

                    //Updatekonfiguration übertragen
                    using (var msConfiguration = new MemoryStream(buildConfiguration())) {
                        //Status übertragen
                        currentFileCount++;
                        onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                            currentFile     = currentFileCount,
                            currentFilename =
                                configurationFilename,
                            maxFileCount = maxFileCount
                        });

                        //Arbeitsverzeichnis ändern
                        client.SetWorkingDirectory(updateRootDirectory);

                        //Upload
                        writeLogEntry(logLevel.Info, string.Format("Upload {0}", configurationFilename));
                        client.Upload(msConfiguration, configurationFilename);
                    }

                    //updateInstaller übertragen
                    //Status übertragen
                    currentFileCount++;
                    onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                        currentFile     = currentFileCount,
                        currentFilename =
                            configurationFilename,
                        maxFileCount = maxFileCount
                    });

                    bool updateInstallerUpdateRequired = true;
                    if (client.FileExists(updateInstallerRemoteFilename))
                    {
                        long localUpdateInstallerFileSize  = new FileInfo(localUpdateInstallerPath).Length;
                        long remoteUpdateInstallerFileSize = client.GetFileSize(updateInstallerRemoteFilename);

                        //updateInstaller nur aktualisieren wenn sich die Dateien unterscheiden
                        updateInstallerUpdateRequired = (localUpdateInstallerFileSize != remoteUpdateInstallerFileSize);
                    }

                    if (updateInstallerUpdateRequired)
                    {
                        // updateInstaller
                        using (var fsUpdateInstaller = File.OpenRead(localUpdateInstallerPath)) {
                            writeLogEntry(logLevel.Info, string.Format("Upload {0}", updateInstallerRemoteFilename));
                            client.Upload(fsUpdateInstaller, updateInstallerRemoteFilename);
                        }

                        // updateInstaller-Manifest (enthällt Hash zum vergleichen)
                        using (var msUpdateInstallerManifest = new MemoryStream(buildUpdateInstallerManifest())) {
                            writeLogEntry(logLevel.Info, string.Format("Upload {0}", updateInstallerManifestFilename));
                            client.Upload(msUpdateInstallerManifest, updateInstallerManifestFilename);
                        }
                    }

                    //Updateverzeichnis aufräumen
                    client.SetWorkingDirectory(updateDirectory);
                    foreach (var remoteFile in client.GetListing())
                    {
                        if (!publishedFiles.Contains(remoteFile.Name))
                        {
                            writeLogEntry(logLevel.Info, string.Format("RemoveFile {0}", remoteFile.Name));
                            client.RemoveFile(remoteFile.Name);
                        }
                    }

                    Settings.lastPublished = DateTime.Now;
                }
                finally {                 // In jedem Fall immer dafür sorgen, dass die Verbindung korrekt geschlossen wird.
                    if (client.Connected)
                    {
                        client.Disconnect();
                    }
                    client.Dispose();
                }
            }
            catch (Exception exc) {
                writeLogException(exc);
                result.Error = exc;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public override publishResult publishUpdates()
        {
            var result = new publishResult {
                Provider = this
            };

            try {
                //Benötigte Verzeichnisse erstellen
                createRequiredDirectories();

                //Für diesen Provider notwendige Updatepakete ermitteln
                var updates          = updatePackages;
                int maxFileCount     = updates.Count + 2;             // +2 wegen der Updatekonfiguration und dem updateInstaller
                int currentFileCount = 0;

                //Eine Liste mit allen Dateien die Veröffentlicht wurden, alle Dateien im Updateverzeichnis
                //die nicht auf dieser Liste stehen, werden gelöscht.
                var publishedFiles = new List <string>();


                //Updates übertragen
                foreach (var package in updates)
                {
                    currentFileCount++;

                    //Status mitteilen
                    onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                        currentFile     = currentFileCount,
                        currentFilename = package.getFilename(),
                        maxFileCount    = maxFileCount
                    });

                    publishedFiles.Add(package.getFilename());
                    publishedFiles.Add(package.getChangelogFilename());

                    string localUpdateFilename  = Path.Combine(localUpdateDirectory, package.getFilename());
                    string remoteUpdateFilename = Path.Combine(Path.Combine(targetDirectory, "updates"), package.getFilename());

                    //Wenn die entfernte Datei existiert, vergleichen wir die beiden Updatepakete, ob eine Übertragung wirklich notwendig ist.
                    if (File.Exists(remoteUpdateFilename))
                    {
                        var fiLocal  = new FileInfo(localUpdateFilename);
                        var fiRemote = new FileInfo(remoteUpdateFilename);
                        if (fiLocal.Length == fiRemote.Length)
                        {
                            continue;
                        }
                    }

                    //Updatepaket kopieren
                    writeLogEntry(logLevel.Info, string.Format("FileCopy {0} -> {1}", localUpdateFilename, remoteUpdateFilename));
                    File.Copy(localUpdateFilename, remoteUpdateFilename, true);

                    //Changelog kopieren
                    string localChangelogFilename  = Path.Combine(localUpdateDirectory, package.getChangelogFilename());
                    string remoteChangelogFilename = Path.Combine(Path.Combine(targetDirectory, "updates"),
                                                                  package.getChangelogFilename());

                    writeLogEntry(logLevel.Info, string.Format("FileCopy {0} -> {1}", localChangelogFilename, remoteChangelogFilename));
                    File.Copy(localChangelogFilename, remoteChangelogFilename, true);

                    package.publishDate = DateTime.UtcNow;
                }

                //Updatekonfiguration übertragen
                using (var fsConfiguration = new FileStream(Path.Combine(targetDirectory, configurationFilename), FileMode.Create)) {
                    //Status mitteilen
                    currentFileCount++;
                    onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                        currentFile     = currentFileCount,
                        currentFilename = configurationFilename,
                        maxFileCount    = maxFileCount
                    });

                    //Updatekonfiguration erstellen
                    byte[] configuration = buildConfiguration();
                    writeLogEntry(logLevel.Info, string.Format("WriteFile {0}", configurationFilename));
                    fsConfiguration.Write(configuration, 0, configuration.Length);
                }

                //updateInstaller aktualisieren
                currentFileCount++;
                onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
                    currentFile     = currentFileCount,
                    currentFilename = configurationFilename,
                    maxFileCount    = maxFileCount
                });
                bool updateInstallerUpdateRequired = true;
                if (File.Exists(Path.Combine(targetDirectory, updateInstallerRemoteFilename)))
                {
                    var fiLocalUpdateInstaller  = new FileInfo(localUpdateInstallerPath);
                    var fiRemoteUpdateInstaller = new FileInfo(Path.Combine(targetDirectory, updateInstallerRemoteFilename));
                    updateInstallerUpdateRequired = (fiLocalUpdateInstaller.Length != fiRemoteUpdateInstaller.Length);
                }
                if (updateInstallerUpdateRequired)
                {
                    //updateInstaller aktualisieren
                    writeLogEntry(logLevel.Info, string.Format("FileCopy {0} -> {1}", localUpdateInstallerPath, updateInstallerRemoteFilename));
                    File.Copy(localUpdateInstallerPath, Path.Combine(targetDirectory, updateInstallerRemoteFilename), true);

                    //updateInstaller Manifest aktualisieren
                    using (var fsUpdateInstallerManifest = new FileStream(Path.Combine(targetDirectory, updateInstallerManifestFilename), FileMode.Create)) {
                        byte[] updateInstallerManifest = buildUpdateInstallerManifest();
                        fsUpdateInstallerManifest.Write(updateInstallerManifest, 0, updateInstallerManifest.Length);
                    }
                }

                //Updateverzeichnis aufräumen
                foreach (string file in Directory.GetFiles(Path.Combine(targetDirectory, "updates")))
                {
                    if (!publishedFiles.Contains(Path.GetFileName(file)))
                    {
                        writeLogEntry(logLevel.Info, string.Format("FileDelete {0}", file));
                        File.Delete(file);
                    }
                }

                //Datum der letzten Veröffentlichung setzen
                Settings.lastPublished = DateTime.Now;
            }
            catch (Exception exc) {
                writeLogException(exc);
                result.Error = exc;
            }
            return(result);
        }
Ejemplo n.º 3
0
		public override publishResult publishUpdates() {
			var result = new publishResult {Provider = this};
			try {
				
				var updates = updatePackages;
				int maxFileCount = updates.Count + 2; // +2 wegen der Updatekonfiguration und dem updateInstaller
				int currentFileCount = 0;

				//Status übertragen
				onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
					currentFile = currentFileCount,
					currentFilename = string.Empty,
					maxFileCount = maxFileCount
				});

				//Stammverzeichnisse erstellen
				createRequiredDirectories();

				var client = buildFtpClient();
				var updateRootDirectory = getSetting(pbsFtpSetting_Directory);
				const string updateDirectory = "updates";
				var publishedFiles = new List<string>();
				try {

					//Client verbinden
					client.Connect();

					//Updatepakete und deren Changelogs übertragen
					client.SetWorkingDirectory(updateRootDirectory);
					client.SetWorkingDirectory(updateDirectory);
					foreach (var update in updates) {

						string localFilename = Path.Combine(localUpdateDirectory, update.getFilename());
						string remoteFilename = update.getFilename();

						string localChangelogFilename = Path.Combine(localUpdateDirectory, update.getChangelogFilename());
						string remoteChangelogFilename = update.getChangelogFilename();

						publishedFiles.Add(update.getFilename());
						publishedFiles.Add(update.getChangelogFilename());
						currentFileCount++;

						//Status übertragen
						onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
							currentFile = currentFileCount,
							currentFilename = update.getFilename(),
							maxFileCount = maxFileCount
						});

						//Überprüfen ob die Datei auf dem Server mit der lokalen identisch ist););
						if (client.FileExists(remoteFilename)) {
							long localFileSize = new FileInfo(localFilename).Length;
							long remoteFileSite = client.GetFileSize(remoteFilename);

							if (localFileSize == remoteFileSite)
								continue;
						}

						//Updatepaket übertragen
						using (var fsPackage = File.OpenRead(localFilename)) {
							writeLogEntry(logLevel.Info, string.Format("Upload {0}->{1}", localFilename, remoteFilename));
							client.Upload(fsPackage, remoteFilename);
						}

						//Changelog übertragen
						using (var fsChangelog = File.OpenRead(localChangelogFilename)) {
							writeLogEntry(logLevel.Info, string.Format("Upload {0}", remoteChangelogFilename));
							client.Upload(fsChangelog, remoteChangelogFilename);
						}
						update.publishDate = DateTime.UtcNow;
					}

					//Updatekonfiguration übertragen
					using (var msConfiguration = new MemoryStream(buildConfiguration())) {

						//Status übertragen
						currentFileCount++;
						onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
							currentFile = currentFileCount,
							currentFilename =
								configurationFilename,
							maxFileCount = maxFileCount
						});

						//Arbeitsverzeichnis ändern
						client.SetWorkingDirectory(updateRootDirectory);

						//Upload
						writeLogEntry(logLevel.Info, string.Format("Upload {0}", configurationFilename));
						client.Upload(msConfiguration, configurationFilename);
					}

					//updateInstaller übertragen
					//Status übertragen
					currentFileCount++;
					onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
						currentFile = currentFileCount,
						currentFilename =
							configurationFilename,
						maxFileCount = maxFileCount
					});

					bool updateInstallerUpdateRequired = true;
					if (client.FileExists(updateInstallerRemoteFilename)) {
						long localUpdateInstallerFileSize = new FileInfo(localUpdateInstallerPath).Length;
						long remoteUpdateInstallerFileSize = client.GetFileSize(updateInstallerRemoteFilename);

						//updateInstaller nur aktualisieren wenn sich die Dateien unterscheiden
						updateInstallerUpdateRequired = (localUpdateInstallerFileSize != remoteUpdateInstallerFileSize);
					}

					if (updateInstallerUpdateRequired) {
						// updateInstaller
						using (var fsUpdateInstaller = File.OpenRead(localUpdateInstallerPath)) {
							writeLogEntry(logLevel.Info, string.Format("Upload {0}", updateInstallerRemoteFilename));
							client.Upload(fsUpdateInstaller, updateInstallerRemoteFilename);
						}

						// updateInstaller-Manifest (enthällt Hash zum vergleichen)
						using (var msUpdateInstallerManifest = new MemoryStream(buildUpdateInstallerManifest())) {
							writeLogEntry(logLevel.Info, string.Format("Upload {0}", updateInstallerManifestFilename));
							client.Upload(msUpdateInstallerManifest, updateInstallerManifestFilename);
						}
					}

					//Updateverzeichnis aufräumen
					client.SetWorkingDirectory(updateDirectory);
					foreach (var remoteFile in client.GetListing())
						if (!publishedFiles.Contains(remoteFile.Name)) {
							writeLogEntry(logLevel.Info, string.Format("RemoveFile {0}", remoteFile.Name));
							client.RemoveFile(remoteFile.Name);
						}

					Settings.lastPublished = DateTime.UtcNow;
				}
				finally { // In jedem Fall immer dafür sorgen, dass die Verbindung korrekt geschlossen wird.
					if (client.Connected)
						client.Disconnect();
					client.Dispose();
				}

			}
			catch (Exception exc) {
				writeLogException(exc);
				result.Error = exc;
			}
			return result;
		}
Ejemplo n.º 4
0
		public override publishResult publishUpdates() {
			var result = new publishResult {Provider = this};
			try {
				//Benötigte Verzeichnisse erstellen
				createRequiredDirectories();

				//Für diesen Provider notwendige Updatepakete ermitteln
				var updates = updatePackages;
				int maxFileCount = updates.Count + 2; // +2 wegen der Updatekonfiguration und dem updateInstaller
				int currentFileCount = 0;

				//Eine Liste mit allen Dateien die Veröffentlicht wurden, alle Dateien im Updateverzeichnis
				//die nicht auf dieser Liste stehen, werden gelöscht.
                var publishedFiles = new List<string>();


				//Updates übertragen               
				foreach(var package in updates) {
					currentFileCount++;
					
					//Status mitteilen
					onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
					                                                                           	currentFile = currentFileCount,
					                                                                           	currentFilename = package.getFilename(),
					                                                                           	maxFileCount = maxFileCount
					                                                                           });

					publishedFiles.Add(package.getFilename());
					publishedFiles.Add(package.getChangelogFilename());

					string localUpdateFilename = Path.Combine(localUpdateDirectory, package.getFilename());
					string remoteUpdateFilename = Path.Combine(Path.Combine(targetDirectory, "updates"), package.getFilename());

					//Wenn die entfernte Datei existiert, vergleichen wir die beiden Updatepakete, ob eine Übertragung wirklich notwendig ist.
					if(File.Exists(remoteUpdateFilename)) {
						var fiLocal = new FileInfo(localUpdateFilename);
						var fiRemote = new FileInfo(remoteUpdateFilename);
						if(fiLocal.Length == fiRemote.Length)
							continue;
					}

					//Updatepaket kopieren
					writeLogEntry(logLevel.Info, string.Format("FileCopy {0} -> {1}", localUpdateFilename, remoteUpdateFilename));
					File.Copy(localUpdateFilename, remoteUpdateFilename, true);

					//Changelog kopieren
					string localChangelogFilename = Path.Combine(localUpdateDirectory, package.getChangelogFilename());
					string remoteChangelogFilename = Path.Combine(Path.Combine(targetDirectory, "updates"),
					                                              package.getChangelogFilename());

					writeLogEntry(logLevel.Info, string.Format("FileCopy {0} -> {1}", localChangelogFilename, remoteChangelogFilename));
					File.Copy(localChangelogFilename, remoteChangelogFilename, true);

					package.publishDate = DateTime.UtcNow;
				}

				//Updatekonfiguration übertragen
				using(var fsConfiguration = new FileStream(Path.Combine(targetDirectory, configurationFilename), FileMode.Create)) {

					//Status mitteilen
					currentFileCount++;
					onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
					                                                                           	currentFile = currentFileCount,
					                                                                           	currentFilename = configurationFilename,
					                                                                           	maxFileCount = maxFileCount
					                                                                           });

					//Updatekonfiguration erstellen
					byte[] configuration = buildConfiguration();
					writeLogEntry(logLevel.Info, string.Format("WriteFile {0}", configurationFilename));
					fsConfiguration.Write(configuration, 0, configuration.Length);
				}

				//updateInstaller aktualisieren
				currentFileCount++;
				onPublishUpdateProgressChanged(new publishUpdateProgressChangedEventArgs {
				                                                                         	currentFile = currentFileCount,
				                                                                         	currentFilename = configurationFilename,
				                                                                         	maxFileCount = maxFileCount
				                                                                         });
				bool updateInstallerUpdateRequired = true;
				if(File.Exists(Path.Combine(targetDirectory, updateInstallerRemoteFilename))) {
					var fiLocalUpdateInstaller = new FileInfo(localUpdateInstallerPath);
					var fiRemoteUpdateInstaller = new FileInfo(Path.Combine(targetDirectory, updateInstallerRemoteFilename));
					updateInstallerUpdateRequired = (fiLocalUpdateInstaller.Length != fiRemoteUpdateInstaller.Length);
				}
				if(updateInstallerUpdateRequired) {
					//updateInstaller aktualisieren
					writeLogEntry(logLevel.Info,string.Format("FileCopy {0} -> {1}", localUpdateInstallerPath, updateInstallerRemoteFilename));
					File.Copy(localUpdateInstallerPath, Path.Combine(targetDirectory, updateInstallerRemoteFilename), true);

					//updateInstaller Manifest aktualisieren                   
					using(var fsUpdateInstallerManifest = new FileStream(Path.Combine(targetDirectory, updateInstallerManifestFilename), FileMode.Create)) {
						byte[] updateInstallerManifest = buildUpdateInstallerManifest();
						fsUpdateInstallerManifest.Write(updateInstallerManifest, 0, updateInstallerManifest.Length);
					}
				}

				//Updateverzeichnis aufräumen
				foreach (string file in Directory.GetFiles(Path.Combine(targetDirectory, "updates")))
					if (!publishedFiles.Contains(Path.GetFileName(file))) {
						writeLogEntry(logLevel.Info, string.Format("FileDelete {0}", file));
						File.Delete(file);
					}

				//Datum der letzten Veröffentlichung setzen
				Settings.lastPublished = DateTime.UtcNow;

			}
			catch(Exception exc) {
				writeLogException(exc);
				result.Error = exc;
			}
			return result;
		}