Beispiel #1
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);
        }
Beispiel #2
0
        public Command(ICommandReporter commandReporter, string username, string password, string server, string vault, string outputFolder,
                       bool useWorkingFolder, bool failOnError, CancellationToken ct)
        {
            if (commandReporter == null)
            {
                throw new ArgumentNullException("commandReporter)");
            }

            m_commandReporter = commandReporter;
            m_vault           = vault;

            // add the vault name to the local path.  This prevents users from accedently
            // wiping out their C drive or something like that.
            m_useWorkingFolder = useWorkingFolder;
            if (!m_useWorkingFolder)
            {
                m_outputFolder = UseWorkingFolder ? outputFolder : Path.Combine(outputFolder, VaultName);
            }

            m_failOnError = failOnError;
            m_ct          = ct;

            ChangeStatusMessage("Logging in...");
            Func <string, LoginStates, bool> progressCallback = (m, s) => !m_ct.IsCancellationRequested;
            LogInResult result = Library.ConnectionManager.LogIn(server, vault, username, password, AuthenticationFlags.ReadOnly, progressCallback);

            ThrowIfCancellationRequested();
            m_conn = result.Connection;
            if (!result.Success && result.Exception != null)
            {
                throw result.Exception;
            }
            else if (!result.Success && result.ErrorMessages.Any())
            {
                throw new Exception(result.ErrorMessages.Values.FirstOrDefault());
            }
            else if (!result.Success)
            {
                throw new Exception("Unknown Error");
            }

            m_aquireFilesSettings = CreateAcquireFileSettings();
        }
Beispiel #3
0
        private AcquireFilesSettings CreateAcquireFileSettings()
        {
            var aquireFilesSettings = new AcquireFilesSettings(m_conn);
            var optionsResolution   = aquireFilesSettings.OptionsResolution;

            optionsResolution.OverwriteOption = AcquireFilesSettings.AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll;

            var updateReferencesModel = optionsResolution.UpdateReferencesModel;

            updateReferencesModel.UpdateVaultStatus = true;

            var extensibilityOptions = aquireFilesSettings.OptionsExtensibility;

            extensibilityOptions.ProgressHandler = new DownloadProgressReporter(this);

            var threadingOptions = aquireFilesSettings.OptionsThreading;

            threadingOptions.CancellationToken = CancellationTokenSource.CreateLinkedTokenSource(new[] { m_ct });
            return(aquireFilesSettings);
        }
Beispiel #4
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();
        }