예제 #1
0
        private bool PublishToSavedUri(IPanoramaPublishClient publishClient, Uri panoramaSavedUri, string fileName,
            ServerList servers)
        {
            var message = TextUtil.LineSeparate(Resources.SkylineWindow_ShowPublishDlg_This_file_was_last_published_to___0_,
                Resources.SkylineWindow_ShowPublishDlg_Publish_to_the_same_location_);
            if (MultiButtonMsgDlg.Show(this, string.Format(message, panoramaSavedUri),
                    MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) != DialogResult.Yes)
                return false;

            var server = servers.FirstOrDefault(s => s.URI.Host.Equals(panoramaSavedUri.Host));
            if (server == null)
                return false;

            JToken folders;
            var folderPath = panoramaSavedUri.AbsolutePath;
            try
            {
                folders = publishClient.GetInfoForFolders(server, folderPath.TrimEnd('/').TrimStart('/'));
            }
            catch (WebException)
            {
                return false;
            }

            // must escape uri string as panorama api does not and strings are escaped in schema
            if (folders == null || !folderPath.Contains(Uri.EscapeUriString(folders["path"].ToString()))) // Not L10N
                return false;

            if (!PanoramaUtil.CheckFolderPermissions(folders) || !PanoramaUtil.CheckFolderType(folders))
                return false;

            var fileInfo = new FolderInformation(server, true);
            if (!publishClient.ServerSupportsSkydVersion(fileInfo, this, this))
                return false;

            var zipFilePath = FileEx.GetTimeStampedFileName(fileName);
            if (!ShareDocument(zipFilePath, false))
                return false;

            var serverRelativePath = folders["path"].ToString() + '/'; // Not L10N
            serverRelativePath = serverRelativePath.TrimStart('/');
            publishClient.UploadSharedZipFile(this, server, zipFilePath, serverRelativePath);
            return true; // success!
        }
예제 #2
0
        public void ShowPublishDlg(IPanoramaPublishClient publishClient)
        {
            if (publishClient == null)
                publishClient = new WebPanoramaPublishClient();

            var document = DocumentUI;
            if (!document.IsLoaded)
            {
                MessageDlg.Show(this, Resources.SkylineWindow_publishToolStripMenuItem_Click_The_document_must_be_fully_loaded_before_it_can_be_published);
                return;
            }

            string fileName = DocumentFilePath;
            if (string.IsNullOrEmpty(fileName))
            {
                if (MessageBox.Show(this, Resources.SkylineWindow_publishToolStripMenuItem_Click_The_document_must_be_saved_before_it_can_be_published,
                    Program.Name, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    return;

                if (!SaveDocumentAs())
                    return;

                fileName = DocumentFilePath;
            }

            if (!SaveDocument())
                return;

            var servers = Settings.Default.ServerList;
            if (servers.Count == 0)
            {
                DialogResult buttonPress = MultiButtonMsgDlg.Show(
                    this,
                    TextUtil.LineSeparate(
                        Resources.SkylineWindow_ShowPublishDlg_There_are_no_Panorama_servers_to_publish_to,
                        Resources.SkylineWindow_ShowPublishDlg_Press_Register_to_register_for_a_project_on_PanoramaWeb_,
                        Resources.SkylineWindow_ShowPublishDlg_Press_Continue_to_use_the_server_of_your_choice_),
                    Resources.SkylineWindow_ShowPublishDlg_Register, Resources.SkylineWindow_ShowPublishDlg_Continue,
                    true);
                if (buttonPress == DialogResult.Cancel)
                    return;

                object tag = null;
                if (buttonPress == DialogResult.Yes)
                {
                    // person intends to register
                    WebHelpers.OpenLink(this, "http://proteome.gs.washington.edu/software/Skyline/panoramaweb-signup.html"); // Not L10N
                    tag = true;
                }

                var serverPanoramaWeb = new Server(PanoramaUtil.PANORAMA_WEB, string.Empty, string.Empty);
                var newServer = servers.EditItem(this, serverPanoramaWeb, null, tag);
                if (newServer == null)
                    return;

                servers.Add(newServer);
            }
            var panoramaSavedUri = document.Settings.DataSettings.PanoramaPublishUri;
            var showPublishDocDlg = true;

            // if the document has a saved uri prompt user for acton, check servers, and permissions, then publish
            // if something fails in the attempt to publish to the saved uri will bring up the usual PublishDocumentDlg
            if (panoramaSavedUri != null && !string.IsNullOrEmpty(panoramaSavedUri.ToString()))
            {
                showPublishDocDlg = !PublishToSavedUri(publishClient, panoramaSavedUri, fileName, servers);
            }

            // if no uri was saved to publish to or user chose to view the dialog show the dialog
            if (showPublishDocDlg)
            {
                using (var publishDocumentDlg = new PublishDocumentDlg(this, servers, fileName))
                {
                    publishDocumentDlg.PanoramaPublishClient = publishClient;
                    if (publishDocumentDlg.ShowDialog(this) == DialogResult.OK)
                    {
                        if (ShareDocument(publishDocumentDlg.FileName, false))
                            publishDocumentDlg.Upload(this);
                    }
                }
            }
        }