Beispiel #1
0
        private void cmnuProperties_Click(object sender, EventArgs e)
        {
            if (olvApplications.SelectedObject == null)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            try
            {
                RpcApplication app = (RpcApplication)olvApplications.SelectedObject;

                IGeGeekRpc     proxy     = XmlRpcProxyGen.Create <IGeGeekRpc>();
                string         xml       = proxy.GetApplication(app.ShareId);
                ApplicationJob resultJob = ApplicationJob.LoadOneFromXml(xml);

                using (ApplicationJobDialog dialog = new ApplicationJobDialog())
                {
                    dialog.ApplicationJob = resultJob;
                    dialog.ReadOnly       = true;
                    dialog.ShowDialog(this);
                }
            }
            catch (XmlRpcException)
            {
                MessageBox.Show(this, "Failed loading the selected application.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (WebException)
            {
                MessageBox.Show(this, "Failed loading the selected application.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void bOK_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            try
            {
                foreach (RpcApplication app in this.olvApplications.SelectedObjects)
                {
                    IGeGeekRpc     proxy     = XmlRpcProxyGen.Create <IGeGeekRpc>();
                    string         xml       = proxy.GetApplication(app.ShareId);
                    ApplicationJob resultJob = ApplicationJob.LoadOneFromXml(xml);
                    // For security reasons, we remove some of the properties
                    // if it's not the users own job
                    if (!DbManager.ApplicationExists(resultJob.Guid))
                    {
                        resultJob.CanBeShared = false;
                    }

                    resultJob.Save();
                    this.ImportedApplications.Add(resultJob);

                    // Real value is determined while saving
                    if (!resultJob.CanBeShared)
                    {
                        resultJob.DownloadDate      = app.UpdatedAtDate;
                        resultJob.ExecuteCommand    = string.Empty;
                        resultJob.ExecutePreCommand = string.Empty;
                        resultJob.TargetPath        = string.Empty;
                        resultJob.PreviousLocation  = string.Empty;

                        // If possible, determine some values based on the default
                        // values for a new application.
                        string defaultXml = Settings.GetValue("DefaultApplication", "") as string;
                        if (!string.IsNullOrEmpty(defaultXml))
                        {
                            ApplicationJob defaultApp = ApplicationJob.LoadOneFromXml(defaultXml);
                            if (defaultApp != null)
                            {
                                resultJob.TargetPath        = defaultApp.TargetPath;
                                resultJob.ExecuteCommand    = defaultApp.ExecuteCommand;
                                resultJob.ExecutePreCommand = defaultApp.ExecutePreCommand;
                            }
                        }

                        resultJob.Save();
                    }
                }
            }
            catch (XmlRpcException ex)
            {
                MessageBox.Show(this, "An error occured while importing applications: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            catch (WebException ex)
            {
                MessageBox.Show(this, "Could not connect to the online database: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }