Exemplo n.º 1
0
        private void btnTestConnection_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor           = Cursors.WaitCursor;
                lblStatusMessage.Text = string.Empty;

                if (!IsValidNetworkSetting())
                {
                    return;
                }

                // Test the network configuration on the UI (may or may not be saved).
                //NetWorkSetting _NetworkSetting = new NetWorkSetting();
                if (_NetworkSetting == null)
                {
                    _NetworkSetting = new NetWorkSetting();
                }
                SaveFields(_NetworkSetting);

                if (DnsServiceManager.LogIn(_NetworkSetting))
                {
                    MessageBox.Show("Connection Successful", Util.ConnectionOKStatus, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(_NetworkSetting.NetworkMessage, Util.ConnectionFailedStatus, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                PopulateDataMarts(ref _NetworkSetting);
                EnableDMControls(_NetworkSetting.IsAuthenticated);
                return;
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Exemplo n.º 2
0
        private void PopulateDataMarts(ref NetWorkSetting ns)
        {
            try
            {
                if (!DnsServiceManager.LogIn(ns))
                {
                    return;
                }

                // Find matching existing datamarts and update their info. Append new datamarts and remove deleted ones.
                var newDMs = ns.GetDataMartsByUser().EmptyIfNull();
                if ((dgvDataMarts.DataSource as IEnumerable <DataMartDescription>).NullOrEmpty())
                {
                    dgvDataMarts.DataSource = newDMs;
                }
                else
                {
                    (from oldDataMarts in dgvDataMarts.DataSource as IEnumerable <DataMartDescription>
                     join newDataMarts in newDMs on oldDataMarts.DataMartId equals newDataMarts.DataMartId
                     select new { oldDM = oldDataMarts, newDM = newDataMarts }).ForEach(d =>
                    {
                        // Append new datamarts.
                        // For each existing datamart, find matching existing model and update their info.
                        d.oldDM.DataMartName     = d.newDM.DataMartName;
                        d.oldDM.OrganizationId   = d.newDM.OrganizationId;
                        d.oldDM.OrganizationName = d.newDM.OrganizationName;

                        if (d.oldDM.ModelList != null && d.newDM.ModelList != null)
                        {
                            (from oldModel in d.oldDM.ModelList.Cast <ModelDescription>()
                             join newModel in d.newDM.ModelList.Cast <ModelDescription>() on oldModel.ModelId equals newModel.ModelId
                             select new { oldModel = oldModel, newModel = newModel }).ForEach(m =>
                            {
                                m.oldModel.ModelName        = m.newModel.ModelName;
                                m.oldModel.ModelDisplayName = m.newModel.ModelDisplayName;
                            });
                        }
                    });

                    var ds = new List <DataMartDescription>();
                    ds.AddRange(dgvDataMarts.DataSource as IEnumerable <DataMartDescription>);

                    ds.AddRange(from newDataMart in newDMs
                                where !ds.Any(es => (es.DataMartId == newDataMart.DataMartId))
                                select newDataMart);

                    ds.RemoveAll(r => !newDMs.Any(es => es.DataMartId == r.DataMartId));

                    dgvDataMarts.DataSource = ds;
                }

                dgvDataMarts.Refresh();
                if (ns.DataMartList != null && ns.DataMartList.Count > 0)
                {
                    Configuration.Instance.LoadModels(ns);

                    btnEdit.Enabled      = btnRefreshDMlist.Enabled = true;
                    btnApply.Enabled     = btnOk.Enabled = true;
                    dgvDataMarts.Enabled = true;
                }
                else
                {
                    dgvDataMarts.Enabled = false;
                    btnEdit.Enabled      = false;
                    MessageBox.Show("No network DataMart(s) found", Application.ProductName);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }