Ejemplo n.º 1
0
 protected virtual void OnUpdateAsync(DataActionEventArgs e)
 {
     if (UpdateAsync != null)
     {
         UpdateAsync(this, e);
     }
 }
Ejemplo n.º 2
0
 protected virtual void OnCreateAsync(DataActionEventArgs e)
 {
     if (CreateAsync != null)
     {
         CreateAsync(this, e);
     }
 }
        private void mainBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            DataViewerActionArgs actionArgs = (DataViewerActionArgs)e.Argument;
            DataActionEventArgs  eventArgs  = new DataActionEventArgs(actionArgs.Data);

            switch (actionArgs.Action)
            {
            case DataViewerAction.Load:
                OnLoadAsync(eventArgs);
                break;

            case DataViewerAction.Open:
                OnOpenAsync(eventArgs);
                break;

            case DataViewerAction.New:
                OnNewAsync(eventArgs);
                break;

            case DataViewerAction.Delete:
                OnDeleteAsync(eventArgs);
                break;
            }

            DataViewerActionResult result = new DataViewerActionResult(
                eventArgs.Data,
                actionArgs.StatusGuid,
                eventArgs.Cancelled,
                eventArgs.UserMessage,
                actionArgs.Action);

            e.Result = result;
        }
Ejemplo n.º 4
0
 private void SetEmailInValues(DataActionEventArgs e)
 {
     if (!e.Values.ContainsKey("Email") && e.Values.ContainsKey("Username"))
     {
         e.Values.Add("Email", e.Values["Username"]);
     }
 }
 protected virtual void OnDeleteAsync(DataActionEventArgs e)
 {
     if (DeleteAsync != null)
     {
         DeleteAsync(this, e);
     }
 }
 protected virtual void OnNewAsync(DataActionEventArgs e)
 {
     if (NewAsync != null)
     {
         NewAsync(this, e);
     }
 }
 protected virtual void OnOpenAsync(DataActionEventArgs e)
 {
     if (OpenAsync != null)
     {
         OpenAsync(this, e);
     }
 }
Ejemplo n.º 8
0
 protected virtual void OnLoadAsync(DataActionEventArgs e)
 {
     if (LoadAsync != null)
     {
         LoadAsync(this, e);
     }
 }
Ejemplo n.º 9
0
 protected virtual void OnSaveAsync(DataActionEventArgs e)
 {
     if (SaveAsync != null)
     {
         SaveAsync(this, e);
     }
 }
Ejemplo n.º 10
0
        private void ValidateConnectionString(DataActionEventArgs e)
        {
            bool?  integratedSecurity = null;
            bool   integratedSecurityTmp;
            string connectionString = null;
            string serverName       = e.Values.ContainsKey(ServernameFieldName) ? e.Values[ServernameFieldName].ToString() : string.Empty;
            string catalog          = e.Values.ContainsKey(CatalogFieldName) ? e.Values[CatalogFieldName].ToString() : string.Empty;
            string username         = e.Values.ContainsKey(UsernameFieldName) ? e.Values[UsernameFieldName].ToString() : string.Empty;
            string password         = e.Values.ContainsKey(PasswordFieldName) ? e.Values[PasswordFieldName].ToString() : string.Empty;

            if (e.Values.ContainsKey(IntegratedSecurityFieldName))
            {
                if (bool.TryParse(e.Values[IntegratedSecurityFieldName].ToString(), out integratedSecurityTmp))
                {
                    integratedSecurity = integratedSecurityTmp;
                }
            }
            string duradosUserId = e.Values.ContainsKey(DuradosUserFieldName) ? e.Values[DuradosUserFieldName].ToString() : string.Empty;


            connectionString = GetConnection(serverName, catalog, integratedSecurity, username, password, duradosUserId);
            SqlConnection connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
            }
            catch (InvalidOperationException ex)
            {
                throw new DuradosException("Connection to Database Faild. Please check connection fields.", ex);
            }
            catch (SqlException ex)
            {
                string message = string.Empty;
                switch (ex.Class)
                {
                case 20: message += "Error Locating Server/Instance Specified.<br>";     //"Server name is missing or does not exist.<br>";
                    break;

                case 11: message += "Cannot open database.<br>";
                    break;

                case 14: message += "Loging Failed.<br>";
                    break;

                default: message += "Connection string test failed.<br>";
                    break;
                }
                throw new DuradosException(message, ex);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }
        }
 void CustomerEditorForm_LoadAsync(object sender, DataActionEventArgs e)
 {
     if (EditorMode == DataEditorMode.Update)
     {
         // Replace stale data with fresh data.
         SetEditorData(CreateAdapter <CustomerAdapter>().Get(GetEditorData <Customer>().DataID));
     }
 }
Ejemplo n.º 12
0
        private void UpdateRow(DataActionEventArgs e, string pdf)
        {
            string sql = "update " + e.View.EditableTableName + " set " + GetPdfFieldName() + " = @pdf where Id = @pk";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("pdf", pdf);
            parameters.Add("pk", Convert.ToInt32(e.PrimaryKey));
            (new SqlAccess()).ExecuteNonQuery(e.View.Database.ConnectionString, sql, parameters, null);
        }
        void CustomerEditorForm_UpdateAsync(object sender, DataActionEventArgs e)
        {
            CustomerAdapter ca = CreateAdapter <CustomerAdapter>();

            if (!ca.ExistsWithCode(GetEditorData <Customer>()))
            {
                ca.Update(GetEditorData <Customer>());
            }
            else
            {
                e.Cancelled   = true;
                e.UserMessage = "An other customer with the specified code already exists.";
            }
        }
        void WebsiteEditorForm_LoadAsync(object sender, DataActionEventArgs e)
        {
            WebsiteAdapter wa = CreateAdapter <WebsiteAdapter>();

            if (EditorMode == DataEditorMode.Update)
            {
                // Replace stale data with fresh data.
                SetEditorData(wa.Get(GetEditorData <Website>().DataID));
            }

            customerList.Clear();
            customerList.AddRange(CreateAdapter <CustomerAdapter>().GetAll());

            websiteHostNameEditorControl1.IpAddressArray = wa.GetIpAddressArray();
        }
Ejemplo n.º 15
0
        private void CreateOrUpdateAwsCron(DataActionEventArgs e)
        {
            Cron cron   = null;
            int  cronId = System.Convert.ToInt32(e.PrimaryKey);

            cron = Map.Database.Crons[cronId];
            if (e.Values.ContainsKey("active"))
            {
                if (e.Values["active"] is bool)
                {
                    cron.Active = System.Convert.ToBoolean(e.Values["active"]);
                }
            }
            CreateOrUpdateAwsCron(cron);
        }
        void CustomerViewer_DeleteAsync(object sender, DataActionEventArgs e)
        {
            WebsiteAdapter  wa = CreateAdapter <WebsiteAdapter>();
            CustomerAdapter ca = CreateAdapter <CustomerAdapter>();

            int[] indexes = e.GetData <DataViewerOpenArgs>().SelectedIndices;

            foreach (Customer customer in indexes.Select(i => customerList[i]))
            {
                bool      removeCustomer = true;
                Website[] websites       = wa.GetFromCustomer(customer.DataID);
                if (websites.Count() != 0)
                {
                    string       websiteNames = string.Join(", ", websites.Select(w => w.Name).ToArray());
                    DialogResult result       = (DialogResult)Invoke((MessageBoxInvoker) delegate
                    {
                        return(MessageBox.Show(
                                   "Removing the customer (" + customer.CodeAndName + ") " +
                                   "will remove all associated websites (" + websiteNames + "). " +
                                   "Would you like to remove this customer?",
                                   "Remove websites",
                                   MessageBoxButtons.YesNo,
                                   MessageBoxIcon.Warning));
                    });

                    removeCustomer = (result == DialogResult.Yes);
                }

                if (removeCustomer)
                {
                    CustomerDeleteResult cdr = ca.Delete(customer.DataID);
                    if (cdr.Errors.Length != 0)
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            MessageBox.Show(
                                "One or more errors occured while deleting " +
                                "customer '" + customer.CodeAndName + "'.\r\n\r\n" +
                                string.Join("\r\n", cdr.Errors.Select(error => "> " + error).ToArray()),
                                "Delete customer",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                        });
                    }
                }
            }
        }
Ejemplo n.º 17
0
        protected virtual void CreatePdf(DataActionEventArgs e)
        {
            ColumnField wordField = (ColumnField)e.View.Fields[GetWordFieldName()];

            string word = null;

            string sql = "select " + wordField.Name + " from " + e.View.Name + " where Id = " + e.PrimaryKey;

            word = (new SqlAccess()).ExecuteScalar(e.View.Database.ConnectionString, sql);

            string virtualPath = wordField.Upload.UploadVirtualPath;
            string path        = HttpContext.Server.MapPath(virtualPath);

            if (!string.IsNullOrEmpty(word))
            {
                CreatePdf(e, path, word);
            }
        }
        void WebsiteEditorForm_UpdateAsync(object sender, DataActionEventArgs e)
        {
            WebsiteAdapter wa = CreateAdapter <WebsiteAdapter>();

            if (wa.ExistsWithAnyHost(GetEditorData <Website>()))
            {
                e.UserMessage = "An other website already exists with one or more conflicting host names.";
                e.Cancelled   = true;
            }
            else if (!wa.SecurityValid(EditorData, websiteGeneralEditorControl1.OriginalPrimaryHostName))
            {
                e.UserMessage = "One or more security rules have either an invalid path or username.";
                e.Cancelled   = true;
            }

            if (!e.Cancelled)
            {
                wa.Update(GetEditorData <Website>());
            }
        }
Ejemplo n.º 19
0
        private void OpenSshSessionIfNecessary(DataActionEventArgs e)
        {
            bool usingSsh = e.Values.ContainsKey(SshUses) && !e.Values[SshUses].Equals(string.Empty) ? Convert.ToBoolean(e.Values[SshUses]) : false;

            if (usingSsh)
            {
                Durados.Security.Ssh.ITunnel tunnel = new Durados.DataAccess.Ssh.Tunnel();

                tunnel.RemoteHost = e.Values.ContainsKey(SshRemoteHost) ? e.Values[SshRemoteHost].ToString() : string.Empty;
                tunnel.User       = e.Values.ContainsKey(SshUser) ? e.Values[SshUser].ToString() : string.Empty;
                tunnel.Password   = e.Values.ContainsKey(SshPassword) ? e.Values[SshPassword].ToString() : string.Empty;
                tunnel.PrivateKey = e.Values.ContainsKey(SshPrivateKey) ? e.Values[SshPrivateKey].ToString() : string.Empty;
                tunnel.Port       = e.Values.ContainsKey(SshPort) && !e.Values[SshPort].Equals(string.Empty) ? Convert.ToInt32(e.Values[SshPort]) : 22;
                int remotePort = e.Values.ContainsKey(ProductPort) && !e.Values[ProductPort].Equals(string.Empty) ? Convert.ToInt32(e.Values[ProductPort]) : 3306;
                localPort = Maps.Instance.AssignLocalPort();

                session = new Durados.DataAccess.Ssh.ChilkatSession(tunnel, remotePort, localPort);
                session.Open();
            }
        }
Ejemplo n.º 20
0
 void WebsiteViewer_DeleteAsync(object sender, DataActionEventArgs e)
 {
     foreach (int index in e.GetData <DataViewerOpenArgs>().SelectedIndices)
     {
         Website             website = websiteList[index];
         WebsiteDeleteResult wdr     = CreateAdapter <WebsiteAdapter>().Delete(website.DataID);
         if (wdr.Errors.Length != 0)
         {
             Invoke((MethodInvoker) delegate
             {
                 MessageBox.Show(
                     "One or more errors occured while deleting " +
                     "website '" + website.Name + "'.\r\n\r\n" +
                     string.Join("\r\n", wdr.Errors.Select(error => "> " + error).ToArray()),
                     "Delete website",
                     MessageBoxButtons.OK,
                     MessageBoxIcon.Warning);
             });
         }
     }
 }
Ejemplo n.º 21
0
        private void mainBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            DataEditorActionArgs actionArgs = (DataEditorActionArgs)e.Argument;
            DataActionEventArgs  eventArgs  = new DataActionEventArgs(actionArgs.Data);

            switch (actionArgs.Action)
            {
            case DataEditorAction.Load:
                OnLoadAsync(eventArgs);
                break;

            case DataEditorAction.Save:
            case DataEditorAction.SaveClose:
            {
                OnSaveAsync(eventArgs);

                switch (editorMode)
                {
                case DataEditorMode.Create:
                    OnCreateAsync(eventArgs);
                    break;

                case DataEditorMode.Update:
                    OnUpdateAsync(eventArgs);
                    break;
                }
            }
            break;
            }

            DataEditorActionResult result = new DataEditorActionResult(
                eventArgs.Data,
                actionArgs.StatusGuid,
                eventArgs.Cancelled,
                eventArgs.UserMessage,
                actionArgs.Action);

            e.Result = result;
        }
 void ServerViewer_LoadAsync(object sender, DataActionEventArgs e)
 {
     e.ReplaceData(CreateAdapter <ServerStatusAdapter>().GetElementArray());
 }
        void ServerStatusViewer_OpenAsync(object sender, DataActionEventArgs e)
        {
            ServerStatusElement element = e.GetData <ServerStatusElement>();

            e.ReplaceData(CreateAdapter <ServerStatusAdapter>().RunActionCommand(element.ActionCommand));
        }
 void CustomerViewer_LoadAsync(object sender, DataActionEventArgs e)
 {
     e.ReplaceData(CreateAdapter <CustomerAdapter>().GetAll());
 }
Ejemplo n.º 25
0
        private void ValidateConnectionString(DataActionEventArgs e)
        {
            OpenSshSessionIfNecessary(e);

            bool?  integratedSecurity = null;
            bool   integratedSecurityTmp;
            string connectionString = null;
            string serverName       = e.Values.ContainsKey(ServernameFieldName) ? e.Values[ServernameFieldName].ToString() : string.Empty;
            string catalog          = e.Values.ContainsKey(CatalogFieldName) ? e.Values[CatalogFieldName].ToString() : string.Empty;
            string username         = e.Values.ContainsKey(UsernameFieldName) ? e.Values[UsernameFieldName].ToString() : string.Empty;
            string password         = e.Values.ContainsKey(PasswordFieldName) ? e.Values[PasswordFieldName].ToString() : string.Empty;
            bool   usesSsh          = e.Values.ContainsKey(SshUses) ? Convert.ToBoolean(e.Values[SshUses].ToString()) : false;
            bool   usesSsl          = e.Values.ContainsKey(SslUses) ? Convert.ToBoolean(e.Values[SslUses].ToString()) : false;

            string     sqlProductFieldName = e.View.GetFieldByColumnNames("SqlProductId").Name;
            SqlProduct sqlProduct          = (SqlProduct)Enum.Parse(typeof(SqlProduct), e.Values.ContainsKey(sqlProductFieldName) ? e.Values[sqlProductFieldName].ToString() : SqlProduct.SqlServer.ToString());

            if (sqlProduct == SqlProduct.MySql && !usesSsh)
            {
                localPort = e.Values.ContainsKey(ProductPortFieldName) ? Convert.ToInt32(e.Values[ProductPortFieldName]) : localPort;
            }

            if (sqlProduct == SqlProduct.Postgre && !usesSsh)
            {
                localPort = e.Values.ContainsKey(ProductPortFieldName) ? Convert.ToInt32(e.Values[ProductPortFieldName]) : localPort;
            }

            if (sqlProduct == SqlProduct.Oracle)
            {
                localPort = e.Values.ContainsKey(ProductPortFieldName) ? Convert.ToInt32(e.Values[ProductPortFieldName]) : localPort;
            }

            if (e.Values.ContainsKey(IntegratedSecurityFieldName))
            {
                if (bool.TryParse(e.Values[IntegratedSecurityFieldName].ToString(), out integratedSecurityTmp))
                {
                    integratedSecurity = integratedSecurityTmp;
                }
            }
            string duradosUserId = e.Values.ContainsKey(DuradosUserFieldName) ? e.Values[DuradosUserFieldName].ToString() : string.Empty;

            //string sqlProductFieldName = e.View.GetFieldByColumnNames("SqlProductId").Name;
            //SqlProduct sqlProduct = (SqlProduct)Enum.Parse(typeof(SqlProduct), e.Values.ContainsKey(sqlProductFieldName) ? e.Values[sqlProductFieldName].ToString() : SqlProduct.SqlServer.ToString());


            //connectionString = GetConnection(serverName, catalog, integratedSecurity, username, password, duradosUserId);
            //SqlConnection connection = new SqlConnection(connectionString);

            connectionString = GetConnection(serverName, catalog, integratedSecurity, username, password, duradosUserId, sqlProduct, localPort, usesSsh, usesSsl);
            IDbConnection connection = GetNewConnection(sqlProduct, connectionString);

            try
            {
                connection.Open();
            }
            catch (InvalidOperationException ex)
            {
                throw new DuradosException("Connection to Database Faild. Please check connection fields.", ex);
            }
            catch (SqlException ex)
            {
                //string message = string.Empty;
                //switch (ex.Class)
                //{
                //    case 20: message += "Error Locating Server/Instance Specified.<br>"; //"Server name is missing or does not exist.<br>";
                //        break;
                //    case 11: message += "Cannot open database.<br>" ;
                //        break;
                //    case 14: message += "Loging Failed.<br>";
                //        break;
                //    default: message += "Connection string test failed.<br>";
                //        break;
                //}
                throw new DuradosException(ex.Message, ex);
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                //string message = string.Empty;
                //switch (ex.Class)
                //{
                //    case 20: message += "Error Locating Server/Instance Specified.<br>"; //"Server name is missing or does not exist.<br>";
                //        break;
                //    case 11: message += "Cannot open database.<br>" ;
                //        break;
                //    case 14: message += "Loging Failed.<br>";
                //        break;
                //    default: message += "Connection string test failed.<br>";
                //        break;
                //}
                throw new DuradosException(ex.Message, ex);
            }
            catch (Npgsql.NpgsqlException ex)
            {
                throw new DuradosException(ex.Message, ex);
            }

            catch (Oracle.ManagedDataAccess.Client.OracleException ex)
            {
                throw new DuradosException(ex.Message, ex);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
                CloseSshSessionIfNecessary();
            }
        }
Ejemplo n.º 26
0
        protected virtual void CreatePdf(DataActionEventArgs e, string path, string word)
        {
            string pdf = CreatePdf(path + word);

            UpdateRow(e, pdf.Replace(path, ""));
        }
Ejemplo n.º 27
0
 void WebsiteViewer_LoadAsync(object sender, DataActionEventArgs e)
 {
     e.ReplaceData(CreateAdapter <WebsiteAdapter>().GetAll());
 }
Ejemplo n.º 28
0
        public static Cloud GetCloud(DataActionEventArgs e, Database Database)
        {
            CloudType   type        = !e.Values.ContainsKey("type") ? CloudType.Function : (CloudType)Enum.Parse(typeof(CloudType), (string)e.Values["type"]);
            string      accessKeyId = !e.Values.ContainsKey("AccessKeyId") ? null : (string)e.Values["AccessKeyId"];
            string      awsRegion   = !e.Values.ContainsKey("AwsRegion") ? null : (string)e.Values["AwsRegion"];
            CloudVendor cloudVendor = !e.Values.ContainsKey("CloudVendor") ? CloudVendor.AWS : (CloudVendor)Enum.Parse(typeof(CloudVendor), (string)e.Values["CloudVendor"]);
            string      encryptedSecretAccessKey = !e.Values.ContainsKey("EncryptedSecretAccessKey") ? null : (string)e.Values["EncryptedSecretAccessKey"];
            string      name = !e.Values.ContainsKey("Name") ? null : (string)e.Values["Name"];

            switch (cloudVendor)
            {
            case CloudVendor.Azure:
            {
                string encryptedPassword = !e.Values.ContainsKey("password") ? null : (string)e.Values["password"];
                string tenant            = !e.Values.ContainsKey("tenant") ? null : (string)e.Values["tenant"];
                string appId             = !e.Values.ContainsKey("appId") ? null : (string)e.Values["appId"];
                string subscriptionId    = !e.Values.ContainsKey("subscriptionId") ? null : (string)e.Values["subscriptionId"];
                string connectionString  = !e.Values.ContainsKey("ConnectionString") ? null : (string)e.Values["ConnectionString"];

                Cloud cloud = new AzureCloud(Database)
                {
                    AppId = appId, SubscriptionId = subscriptionId, EncryptedPassword = encryptedPassword, tenant = tenant, CloudVendor = cloudVendor, Name = name, ConnectionString = connectionString, Type = type
                };


                return(cloud);
            }

            case CloudVendor.GCP:
            {
                string projectName         = !e.Values.ContainsKey("ProjectName") ? null : (string)e.Values["ProjectName"];
                string clientEmail         = !e.Values.ContainsKey("ClientEmail") ? null : (string)e.Values["ClientEmail"];
                string encryptedPrivateKey = !e.Values.ContainsKey("EncryptedPrivateKey") ? null : (string)e.Values["EncryptedPrivateKey"];

                Cloud cloud = new GoogleCloud(Database)
                {
                    EncryptedPrivateKey = encryptedPrivateKey, ClientEmail = clientEmail, ProjectName = projectName, CloudVendor = cloudVendor, Name = name, Type = type
                };


                return(cloud);
            }

            case CloudVendor.FnProject:
            {
                string connectionString = !e.Values.ContainsKey("ConnectionString") ? null : (string)e.Values["ConnectionString"];
                string gateway          = !e.Values.ContainsKey("Gateway") ? null : (string)e.Values["Gateway"];

                Cloud cloud = new FnProjectCloud(Database)
                {
                    gateway = gateway, connectionString = connectionString, CloudVendor = cloudVendor, Name = name, Type = type
                };


                return(cloud);
            }

            case CloudVendor.OpenFaas:
            {
                string projectName      = !e.Values.ContainsKey("ProjectName") ? null : (string)e.Values["ProjectName"];
                string connectionString = !e.Values.ContainsKey("ConnectionString") ? null : (string)e.Values["ConnectionString"];
                string gateway          = !e.Values.ContainsKey("Gateway") ? null : (string)e.Values["Gateway"];

                Cloud cloud = new OpenFaasCloud(Database)
                {
                    projectName = projectName, gateway = gateway, connectionString = connectionString, CloudVendor = cloudVendor, Name = name, Type = type
                };


                return(cloud);
            }

            default:
                return(new Cloud(Database)
                {
                    AccessKeyId = accessKeyId, Region = awsRegion, CloudVendor = cloudVendor, EncryptedSecretAccessKey = encryptedSecretAccessKey, Name = name, Type = type
                });
            }


            //throw new NotImplementedException();
        }