Ejemplo n.º 1
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = false;

            string partnerLink     = string.Empty;
            string requestingOrgId = (string)cboMyOrg.SelectedValue;

            if (ValidateForm())
            {
                //try to initiate permission request
                if (chkRequestPermission.Checked)
                {
                    //await Task.Run(async () =>
                    //{
                    try
                    {
                        partnerLink = await remoteRepository.RequestPartnerPermission(tbEmail.Text.Trim(), requestingOrgId);
                    }
                    catch (Exception exc)
                    {
                        Logger.Log(exc);
                        partnerLink = string.Empty;
                    }
                    //});

                    if (string.IsNullOrEmpty(partnerLink))
                    {
                        MessageBox.Show("Unable to initiate partner request.  Check your network connection.");
                        return;
                    }
                }

                using (IUnitOfWorkDataProvider p = AppStorage.GetUnitOfWorkDataProvider())
                {
                    Organization org = new Organization();

                    if (orgId == 0)
                    {
                        //initiate contact request
                        org.RemoteID          = string.Empty;
                        org.PartnerLink       = partnerLink;
                        org.Created           = DateTime.Now;
                        org.PermissionGranted = false;
                        org.FilesETag         = "";
                        org.FilesETagDate     = DateTime.Now;
                        p.Organizations.Add(org);
                    }
                    else
                    {
                        org         = p.Organizations.FindSingle(o => o.Id == orgId);
                        org.Updated = DateTime.Now;
                        p.Organizations.Update(org);
                    }

                    org.Email        = tbEmail.Text.Trim();
                    org.Name         = tbOrganization.Text.Trim();
                    org.DataSourceId = 1;
                    p.SaveChanges();
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Ejemplo n.º 2
0
        private async void Main_Load(object sender, EventArgs e)
        {
            _loading = true;
            try
            {
                string arguments = "Application loading with arguments: ";
                foreach (var s in Environment.GetCommandLineArgs())
                {
                    arguments += s + " ";
                }
                Logger.Log("INFO", arguments);
                Logger.Log("INFO", "Main_Load");

                this.WindowState = FormWindowState.Minimized;

                initRemoteRepo();

                downloadSettingsControl.AutoSaveChanges = true;

                string downloadFolderSetting = "";

                using (IUnitOfWorkDataProvider dp = AppStorage.GetUnitOfWorkDataProvider())
                {
                    downloadFolderSetting = dp.Settings.GetDownloadFolder();
                }

                if (string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(refreshToken) || string.IsNullOrEmpty(downloadFolderSetting))
                {
                    Logger.Log("INFO", "Launching setup form");
                    setupForm = new FirstLaunchForm();
                    focusApplication();
                    if (setupForm.ShowDialog() == DialogResult.OK)
                    {
                        activitySummaryControl.SetStatusMessage("Connected", Color.Green);
                        await activitySummaryControl.Initialize(remoteDataRepository, false);

                        setupForm = null;
                        focusApplication();
                    }
                    else
                    {
                        Application.Exit();
                    }
                }
                else
                {
                    await activitySummaryControl.Initialize(remoteDataRepository, true);

                    var args = Environment.GetCommandLineArgs();
                    //if started from startup then minimize
                    if (args.Length >= 2 && args[1] == "-minimized")
                    {
                        Logger.Log("INFO", "Starting minimized");
                        this.WindowState = FormWindowState.Minimized;
                        this.Hide();
                    }
                    else
                    {
                        Logger.Log("INFO", "Starting normal");
                        this.WindowState = FormWindowState.Normal;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                Application.Exit();
            }
            _loading = false;
        }