Ejemplo n.º 1
0
        protected void DownloadFiles()
        {
            ChangeStatusMessage("Downloading...");

            AcquireFilesResults results = m_conn.FileManager.AcquireFiles(m_aquireFilesSettings);
            IEnumerable <FileAcquisitionResult> fileResults = results.FileResults;
            var failedFileResults = fileResults.Where(r => r.Exception != null);

            if (!failedFileResults.Any())
            {
                return;
            }

            if (m_failOnError)
            {
                throw failedFileResults.First().Exception; // Throw the first error
            }
            int errorCount = 0;

            foreach (var failedFileResult in failedFileResults)
            {
                ++errorCount;
                if (errorCount < MAX_ERRORS_PRINTED)
                {
                    m_commandReporter.Log("Error downloading file " + failedFileResult.File.EntityName);
                    m_commandReporter.Log(failedFileResult.Exception.ToString());
                    m_commandReporter.Log("-----------------------------------------------" + Environment.NewLine);
                }
                else if (errorCount == MAX_ERRORS_PRINTED)
                {
                    m_commandReporter.Log("Max error logging limit (" + MAX_ERRORS_PRINTED + ") reached.  Further errors will not be logged.");
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public static Autodesk.Connectivity.WebServices.File AddOrUpdateFile(
            string localPath, string fileName, Folder vaultFolder, Connection conn)
        {
            string vaultPath = vaultFolder.FullName + "/" + fileName;

            Autodesk.Connectivity.WebServices.File[] result = conn.WebServiceManager.DocumentService.FindLatestFilesByPaths(
                vaultPath.ToSingleArray());

            Autodesk.Connectivity.WebServices.File retVal = null;
            if (result == null || result.Length == 0 || result[0].Id < 0)
            {
                VDF.Vault.Currency.Entities.Folder vdfFolder = new VDF.Vault.Currency.Entities.Folder(
                    conn, vaultFolder);

                // using a stream so that we can set a different file name
                using (FileStream stream = new FileStream(localPath, FileMode.Open, FileAccess.Read))
                {
                    VDF.Vault.Currency.Entities.FileIteration newFile = conn.FileManager.AddFile(
                        vdfFolder, fileName, "Thunderdome deployment",
                        System.IO.File.GetLastWriteTime(localPath), null, null,
                        FileClassification.None, false, stream);

                    retVal = newFile;
                }
            }
            else
            {
                VDF.Vault.Currency.Entities.FileIteration vdfFile = new VDF.Vault.Currency.Entities.FileIteration(conn, result[0]);

                AcquireFilesSettings settings = new AcquireFilesSettings(conn);
                settings.AddEntityToAcquire(vdfFile);
                settings.DefaultAcquisitionOption = AcquireFilesSettings.AcquisitionOption.Checkout;
                AcquireFilesResults results = conn.FileManager.AcquireFiles(settings);

                if (results.FileResults.First().Exception != null)
                {
                    throw results.FileResults.First().Exception;
                }

                vdfFile = results.FileResults.First().File;
                vdfFile = conn.FileManager.CheckinFile(vdfFile, "Thunderdome deployment", false,
                                                       null, null, false, null, FileClassification.None, false, localPath.ToVDFPath());

                retVal = vdfFile;
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        private void CheckForUpdates(string serverName, string vaultName, Connection conn)
        {
            if (m_restartPending)
            {
                return;
            }

            Settings settings = Settings.Load();

            // user previously indicated not to download updates and not to be prompted
            if (settings.NeverDownload)
            {
                return;
            }

            string defaultFolder = conn.WebServiceManager.KnowledgeVaultService.GetVaultOption(DEFAULT_FOLDER_OPTION);

            if (defaultFolder == null || defaultFolder.Length == 0)
            {
                return;
            }
            if (!defaultFolder.EndsWith("/"))
            {
                defaultFolder += "/";
            }

            string deploymentPath = defaultFolder + PACKAGE_NAME;

            Autodesk.Connectivity.WebServices.File [] files = conn.WebServiceManager.DocumentService.FindLatestFilesByPaths(
                deploymentPath.ToSingleArray());

            if (files == null || files.Length == 0 || files[0].Id <= 0 || files[0].Cloaked)
            {
                return; // no package found
            }
            VaultEntry entry = settings.GetOrCreateEntry(serverName, vaultName);

            if (entry != null && entry.LastUpdate >= files[0].CkInDate)
            {
                return;  // we are up to date
            }
            StringBuilder updateList = new StringBuilder();

            string          deploymentXml   = conn.WebServiceManager.KnowledgeVaultService.GetVaultOption(DEPLOYMENT_CONFIG_OPTION);
            DeploymentModel deploymentModel = DeploymentModel.Load(deploymentXml);

            if (deploymentModel == null || deploymentModel.Containers == null)
            {
                return;
            }

            foreach (DeploymentContainer container in deploymentModel.Containers)
            {
                updateList.AppendLine(container.DisplayName);

                foreach (DeploymentItem item in container.DeploymentItems)
                {
                    updateList.AppendLine("- " + item.DisplayName);
                }

                updateList.AppendLine();
            }

            AskDialog    ask    = new AskDialog(updateList.ToString());
            DialogResult result = ask.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (ask.AskResult == AskDialog.AskResultEnum.No)
                {
                    return;
                }
                else if (ask.AskResult == AskDialog.AskResultEnum.Never)
                {
                    settings.NeverDownload = true;
                    settings.Save();
                    return;
                }
            }
            else
            {
                return;
            }

            // if we got here, the user cliecked yes.


            string tempPath = Path.Combine(Path.GetTempPath(), "Thunderdome");

            if (!tempPath.EndsWith("\\"))
            {
                tempPath += "\\";
            }

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            DirectoryInfo dirInfo = Directory.CreateDirectory(tempPath);

            UtilSettings utilSettings = new UtilSettings();

            utilSettings.TempFolder = tempPath;

            // the first arg should be the EXE path
            utilSettings.VaultClient = Environment.GetCommandLineArgs()[0];

            string zipPath = Path.Combine(tempPath, PACKAGE_NAME);

            VDF.Vault.Currency.Entities.FileIteration vdfFile = new VDF.Vault.Currency.Entities.FileIteration(conn, files[0]);
            VDF.Currency.FilePathAbsolute             vdfPath = new VDF.Currency.FilePathAbsolute(zipPath);
            AcquireFilesSettings acquireSettings = new AcquireFilesSettings(conn, false);

            acquireSettings.AddFileToAcquire(vdfFile, AcquireFilesSettings.AcquisitionOption.Download, vdfPath);
            AcquireFilesResults acquireResults = conn.FileManager.AcquireFiles(acquireSettings);

            foreach (FileAcquisitionResult acquireResult in acquireResults.FileResults)
            {
                if (acquireResult.Exception != null)
                {
                    throw acquireResult.Exception;
                }
            }

            // clear the read-only bit
            System.IO.File.SetAttributes(zipPath, FileAttributes.Normal);

            FastZip zip = new FastZip();

            zip.ExtractZip(zipPath, tempPath, null);

            MasterController mc = new MasterController(conn, vaultName);

            mc.SetMoveOperations(tempPath, utilSettings);

            utilSettings.Save();

            MessageBox.Show("Updates downloaded. " +
                            "You need exit the Vault client to complete the update process. " + Environment.NewLine +
                            "The Vault Client will restart when the update is complete.",
                            "Exit Required");

            m_restartPending = true;

            entry.LastUpdate = files[0].CkInDate;
            settings.Save();
        }