예제 #1
0
        /// <summary>
        /// Defaut ctor
        /// </summary>
        private UpdateManager()
        {
            IsWorking        = false;
            State            = UpdateProcessState.NotChecked;
            UpdatesToApply   = new List <IUpdateTask>();
            ApplicationPath  = Process.GetCurrentProcess().MainModule.FileName;
            UpdateFeedReader = new NauXmlFeedReader();
            Logger           = new Logger();
            Config           = new NauConfigurations
            {
                TempFolder           = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()),
                UpdateProcessName    = "NAppUpdateProcess",
                UpdateExecutableName = "foo.exe",                                         // Naming it updater.exe seem to trigger the UAC, and we don't want that
            };

            // Need to do this manually here because the BackupFolder property is protected using the static instance, which we are
            // in the middle of creating
            string backupPath = Path.Combine(Path.GetDirectoryName(ApplicationPath) ?? string.Empty, "Backup" + DateTime.Now.Ticks);

            backupPath           = backupPath.TrimEnd(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            Config._backupFolder = Path.IsPathRooted(backupPath) ? backupPath : Path.Combine(Config.TempFolder, backupPath);
        }
예제 #2
0
        public void NauReaderCanReadFeed1()
        {
            const string NauUpdateFeed =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<Feed>
  <Title>My application</Title>
  <Link>http://myapp.com/</Link>
  <Tasks>
    <FileUpdateTask localPath=""test.dll"" updateTo=""remoteFile.dll"">
      <Description>update details</Description>
      <Conditions>
        <FileExistsCondition localPath=""otherFile.dll"" />
      </Conditions>
    </FileUpdateTask>
  </Tasks>
</Feed>";

            var reader  = new NauXmlFeedReader();
            var updates = reader.Read(NauUpdateFeed);

            Assert.IsTrue(updates.Count == 1);

            var task = updates[0] as FileUpdateTask;

            Assert.IsNotNull(task);
            Assert.IsFalse(task.CanHotSwap);
            Assert.AreEqual("test.dll", task.LocalPath);
            Assert.AreEqual("remoteFile.dll", task.UpdateTo);
            Assert.IsNull(task.Sha256Checksum);
            Assert.IsNotNull(task.Description);

            Assert.AreEqual(1, task.UpdateConditions.ChildConditionsCount);

            var cnd = task.UpdateConditions.Degrade() as FileExistsCondition;

            Assert.IsNotNull(cnd);
            Assert.AreEqual("otherFile.dll", cnd.LocalPath);
        }
예제 #3
0
        public void NauReaderCanReadFeed2()
        {
            const string NauUpdateFeed =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<Feed>
  <Title>My application</Title>
  <Link>http://myapp.com/</Link>
  <Tasks>
    <FileUpdateTask localPath=""test.dll"" updateTo=""remoteFile.dll"" hotswap=""true"">
      <Description>update details</Description>
      <Conditions>
        <FileVersionCondition what=""below"" version=""1.0.176.0"" />
      </Conditions>
    </FileUpdateTask>
  </Tasks>
</Feed>";

            var reader  = new NauXmlFeedReader();
            var updates = reader.Read(NauUpdateFeed);

            Assert.IsTrue(updates.Count == 1);

            var task = updates[0] as FileUpdateTask;

            Assert.IsNotNull(task);
            Assert.IsTrue(task.CanHotSwap);

            Assert.AreEqual(1, task.UpdateConditions.ChildConditionsCount);

            var cnd = task.UpdateConditions.Degrade() as FileVersionCondition;

            Assert.IsNotNull(cnd);
            Assert.IsNull(cnd.LocalPath);

            Assert.AreEqual("below", cnd.ComparisonType);
            Assert.AreEqual("1.0.176.0", cnd.Version);
        }