/// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PublishClicked(object sender, EventArgs e)
        {
            PublishButton.Text           = "Publishing ...";
            PublishButton.Enabled        = false;
            PublishProgressBar.Visible   = true;
            PublishProgressLabel.Visible = true;

            VirtualPathTextBox.Enabled      = false;
            LocalFolderBrowseButton.Enabled = false;

            Publisher = new PublishBuildTask();
            Publisher.Start(VirtualPathTextBox.Text, LocalFolderTextBox.Text);
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            VirtualPath = VirtualFileSystem.Normalize(VirtualPath);

            if (!Directory.Exists(LocalPath))
            {
                IpcClient.Respond("FAILED: Path does not exists: {0}");
                return;
            }

            if (!Program.NetClient.IsConnected)
            {
                IpcClient.Respond("FAILED: No connection to server.");
                return;
            }

            if (!Program.NetClient.Permissions.HasPermission(UserPermissionType.Write, "", false, true))
            {
                IpcClient.Respond("FAILED: Permission denied to manage builds.");
                return;
            }

            PublishBuildTask     Publisher         = new PublishBuildTask();
            BuildPublishingState OldPublisherState = BuildPublishingState.Unknown;
            int OldPublisherProgress = 0;

            Publisher.Start(VirtualPath, LocalPath);

            Program.PumpLoop(
                () =>
            {
                if (!Program.NetClient.IsConnected)
                {
                    IpcClient.Respond("FAILED: Lost connection to server.");
                    return(true);
                }

                if (Publisher != null && (Publisher.State != OldPublisherState || (int)Publisher.Progress != OldPublisherProgress))
                {
                    OldPublisherState    = Publisher.State;
                    OldPublisherProgress = (int)Publisher.Progress;

                    switch (Publisher.State)
                    {
                    case BuildPublishingState.CopyingFiles:
                        {
                            IpcClient.Respond(string.Format("Copying files to storage: {0}%", OldPublisherProgress));
                            break;
                        }

                    case BuildPublishingState.ScanningFiles:
                        {
                            IpcClient.Respond(string.Format("Scanning local files: {0}%", OldPublisherProgress));
                            break;
                        }

                    case BuildPublishingState.UploadingManifest:
                        {
                            IpcClient.Respond("Uploading manfiest to server.");
                            break;
                        }

                    case BuildPublishingState.FailedVirtualPathAlreadyExists:
                        {
                            IpcClient.Respond(string.Format("FAILED: Build already exists at path '{0}'.", VirtualPath));
                            return(true);
                        }

                    case BuildPublishingState.PermissionDenied:
                        {
                            IpcClient.Respond(string.Format("FAILED: Permission denied to path '{0}'.", VirtualPath));
                            return(true);
                        }

                    case BuildPublishingState.FailedGuidAlreadyExists:
                        {
                            IpcClient.Respond("FAILED: Manifest with same GUID already exists.");
                            return(true);
                        }

                    case BuildPublishingState.Success:
                        {
                            Publisher.Commit();
                            Publisher = null;
                            IpcClient.Respond("SUCCESS: Build added successfully.");
                            return(true);
                        }

                    case BuildPublishingState.Failed:
                    default:
                        {
                            IpcClient.Respond("FAILED: Undefined reason.");
                            return(true);
                        }
                    }
                }

                return(false);
            }
                );
        }
Exemple #3
0
        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PushUpdateClicked(object sender, EventArgs e)
        {
            using (OpenFileDialog Dialog = new OpenFileDialog())
            {
                Dialog.Title  = "Select Update File";
                Dialog.Filter = "Installer File (*.msi)|*.msi";
                //Dialog.InitialDirectory = Environment.CurrentDirectory;
                Dialog.CheckFileExists = true;
                Dialog.ShowHelp        = true;

                if (Dialog.ShowDialog(this) == DialogResult.OK)
                {
                    string msiVersion = InstallUtils.GetMsiProperty(Dialog.FileName, "ProductVersion");
                    if (msiVersion.Length == 0)
                    {
                        MessageBox.Show("Failed to retrieve version data from msi.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    BuildsRecievedHandler Handler = null;
                    Handler = (RootPath, Builds) =>
                    {
                        Program.NetClient.OnBuildsRecieved -= Handler;

                        // Find the next sequential build index.
                        string NewVirtualPath = RootPath + "/" + msiVersion;

                        bool Exists = false;
                        foreach (NetMessage_GetBuildsResponse.BuildInfo Build in Builds)
                        {
                            if (Build.VirtualPath.ToUpper() == NewVirtualPath.ToUpper())
                            {
                                Exists = true;
                                break;
                            }
                        }

                        if (Exists)
                        {
                            MessageBox.Show("Version is already uploaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        // Publish a folder.
                        string TempFolder = FileUtils.GetTempDirectory();
                        File.Copy(Dialog.FileName, Path.Combine(TempFolder, "installer.msi"));

                        // Publish the build.
                        PublishBuildTask Publisher = new PublishBuildTask();
                        Publisher.Start(NewVirtualPath, TempFolder);

                        Task.Run(
                            () =>
                        {
                            bool PublishComplete = false;
                            while (!PublishComplete)
                            {
                                switch (Publisher.State)
                                {
                                case BuildPublishingState.CopyingFiles:
                                case BuildPublishingState.ScanningFiles:
                                case BuildPublishingState.UploadingManifest:
                                    {
                                        // Ignore
                                        break;
                                    }

                                case BuildPublishingState.Success:
                                    {
                                        Invoke((MethodInvoker)(() => { Publisher.Commit(); }));
                                        Publisher       = null;
                                        PublishComplete = true;
                                        break;
                                    }

                                default:
                                    {
                                        Publisher       = null;
                                        PublishComplete = true;
                                        break;
                                    }
                                }

                                Thread.Sleep(1000);
                            }
                        }
                            );
                    };

                    Program.NetClient.OnBuildsRecieved += Handler;
                    Program.NetClient.RequestBuilds("$Internal$/Updates");
                }
            }
        }