示例#1
0
        public bool UpdateHost(EnterpriseHostEdit editHost, string sessionID)
        {
            var success = false;

            using (var db = new MyrtilleEnterpriseDBContext())
            {
                if (db.Session.Any(m => m.SessionID == sessionID && m.IsAdmin && m.Expire > DateTime.Now))
                {
                    var host = db.Host.FirstOrDefault(m => m.ID == editHost.HostID);
                    if (host != null)
                    {
                        host.HostName             = editHost.HostName;
                        host.HostAddress          = editHost.HostAddress;
                        host.VMGuid               = editHost.VMGuid;
                        host.VMEnhancedMode       = editHost.VMEnhancedMode;
                        host.Protocol             = editHost.Protocol;
                        host.StartRemoteProgram   = editHost.StartRemoteProgram;
                        host.PromptForCredentials = editHost.PromptForCredentials;

                        db.SaveChanges();
                        success = true;
                    }
                }
            }

            return(success);
        }
示例#2
0
        public EnterpriseHostEdit GetHost(long hostID, string sessionID)
        {
            EnterpriseHostEdit hostEdit = null;

            using (var db = new MyrtilleEnterpriseDBContext())
            {
                if (db.Session.Any(m => m.SessionID == sessionID && m.IsAdmin && m.Expire > DateTime.Now))
                {
                    var host = db.Host.FirstOrDefault(m => m.ID == hostID);
                    if (host != null)
                    {
                        hostEdit = new EnterpriseHostEdit
                        {
                            HostID               = host.ID,
                            HostName             = host.HostName,
                            HostAddress          = host.HostAddress,
                            VMGuid               = host.VMGuid,
                            VMEnhancedMode       = host.VMEnhancedMode,
                            Protocol             = host.Protocol,
                            HostType             = host.HostType,
                            StartRemoteProgram   = host.StartRemoteProgram,
                            PromptForCredentials = host.PromptForCredentials
                        };
                    }
                }
            }

            return(hostEdit);
        }
示例#3
0
        public long?AddHost(EnterpriseHostEdit editHost, string sessionID)
        {
            long?hostId = null;

            using (var db = new MyrtilleEnterpriseDBContext())
            {
                if (db.Session.Any(m => m.SessionID == sessionID && m.IsAdmin && m.Expire > DateTime.Now) &&
                    !db.Host.Any(m => m.HostName.Equals(editHost.HostName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    var host = new Host
                    {
                        HostName             = editHost.HostName,
                        HostAddress          = editHost.HostAddress,
                        VMGuid               = editHost.VMGuid,
                        VMEnhancedMode       = editHost.VMEnhancedMode,
                        Protocol             = editHost.Protocol,
                        HostType             = editHost.HostType,
                        StartRemoteProgram   = editHost.StartRemoteProgram,
                        PromptForCredentials = editHost.PromptForCredentials
                    };

                    db.Host.Add(host);
                    db.SaveChanges();

                    hostId = host.ID;
                }
            }

            return(hostId);
        }
示例#4
0
        public bool UpdateHost(EnterpriseHostEdit editHost, string sessionID)
        {
            using (var db = new MyrtilleEnterpriseDBContext())
            {
                if (!db.Session.Any(m => m.SessionID == sessionID && m.IsAdmin && m.Expire > DateTime.Now))
                {
                    return(false);
                }

                if (db.Host.Any(m => m.HostName.Equals(editHost.HostName, StringComparison.InvariantCultureIgnoreCase) && m.ID != editHost.HostID))
                {
                    return(false);
                }

                var host = db.Host.FirstOrDefault(m => m.ID == editHost.HostID);

                if (host == null)
                {
                    return(false);
                }

                host.HostName             = editHost.HostName;
                host.HostAddress          = editHost.HostAddress;
                host.VMGuid               = editHost.VMGuid;
                host.VMEnhancedMode       = editHost.VMEnhancedMode;
                host.Protocol             = editHost.Protocol;
                host.StartRemoteProgram   = editHost.StartRemoteProgram;
                host.PromptForCredentials = editHost.PromptForCredentials;

                var currentGroups = db.HostAccessGroups
                                    .Where(m => m.HostID == editHost.HostID)
                                    .ToList();

                IEnumerable <string> groups = editHost.DirectoryGroups.Split(',').ToList();

                var hostsToDelete = currentGroups.Where(m => !groups.Any(p => p.Equals(m.AccessGroup, StringComparison.InvariantCultureIgnoreCase)));

                db.HostAccessGroups.RemoveRange(hostsToDelete);

                var hostAccess = groups
                                 .Where(m => !currentGroups.Any(p => p.AccessGroup.Equals(m, StringComparison.InvariantCultureIgnoreCase)))
                                 .Select(x => new HostAccessGroups
                {
                    HostID      = host.ID,
                    AccessGroup = x.Trim()
                });

                db.HostAccessGroups.AddRange(hostAccess.Where(m => m.AccessGroup != ""));

                db.SaveChanges();

                return(true);
            }
        }
 public bool UpdateHost(EnterpriseHostEdit editHost, string sessionID)
 {
     try
     {
         return(Channel.UpdateHost(editHost, sessionID));
     }
     catch (Exception exc)
     {
         Trace.TraceError("Failed to update host {0} ({1})", editHost.HostName, exc);
         throw;
     }
 }
示例#6
0
 public long?AddHost(EnterpriseHostEdit editHost, string sessionID)
 {
     try
     {
         Trace.TraceInformation("Add host requested, host {0}", editHost.HostName);
         return(Program._enterpriseAdapter.AddHost(editHost, sessionID));
     }catch (Exception ex)
     {
         Trace.TraceError("Failed to add host {0}, ({1})", editHost.HostName, ex);
         return(null);
     }
 }
示例#7
0
 public bool UpdateHost(EnterpriseHostEdit editHost, string sessionID)
 {
     try
     {
         Trace.TraceInformation("Update host requested, host {0}", editHost.HostName);
         return(Program._enterpriseAdapter.UpdateHost(editHost, sessionID));
     }
     catch (Exception ex)
     {
         Trace.TraceError("Failed to update host {0}, ({1})", editHost.HostName, ex);
         return(false);
     }
 }
示例#8
0
        /// <summary>
        /// create or edit a host
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SaveHostButtonClick(
            object sender,
            EventArgs e)
        {
            if (_enterpriseClient == null || _enterpriseSession == null || string.IsNullOrEmpty(hostName.Value))
            {
                return;
            }

            try
            {
                var enterpriseHost = new EnterpriseHostEdit
                {
                    HostID               = _hostId ?? 0,
                    HostType             = _hostType,
                    HostName             = hostName.Value,
                    HostAddress          = hostAddress.Value,
                    VMGuid               = vmGuid.Value,
                    VMEnhancedMode       = vmEnhancedMode.Checked,
                    DirectoryGroups      = groupsAccess.Value,
                    Protocol             = (SecurityProtocolEnum)securityProtocol.SelectedIndex,
                    StartRemoteProgram   = startProgram.Value,
                    PromptForCredentials = promptCredentials.Checked
                };

                if (_hostId != null)
                {
                    _enterpriseClient.UpdateHost(enterpriseHost, _enterpriseSession.SessionID);
                }
                else
                {
                    _enterpriseClient.AddHost(enterpriseHost, _enterpriseSession.SessionID);
                }

                // refresh the hosts list
                Response.Redirect(Request.RawUrl + (Request.RawUrl.Contains("?") ? "&" : "?") + "edit=success" + (_hostId != null ? string.Format("&hostType={0}", _hostType) : string.Empty));
            }
            catch (ThreadAbortException)
            {
                // occurs because the response is ended after redirect
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to save host ({0})", exc);
            }
        }
示例#9
0
        public long?AddHost(EnterpriseHostEdit editHost, string sessionID)
        {
            using (var db = new MyrtilleEnterpriseDBContext())
            {
                if (!db.Session.Any(m => m.SessionID == sessionID && m.IsAdmin && m.Expire > DateTime.Now))
                {
                    return(null);
                }

                if (db.Host.Any(m => m.HostName.Equals(editHost.HostName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(null);
                }

                List <string> groups = editHost.DirectoryGroups.Split(',').ToList();

                var host = new Host
                {
                    HostName             = editHost.HostName,
                    HostAddress          = editHost.HostAddress,
                    VMGuid               = editHost.VMGuid,
                    VMEnhancedMode       = editHost.VMEnhancedMode,
                    Protocol             = editHost.Protocol,
                    HostType             = editHost.HostType,
                    StartRemoteProgram   = editHost.StartRemoteProgram,
                    PromptForCredentials = editHost.PromptForCredentials,
                    Comment              = editHost.Comment,
                    Parent               = editHost.Parent
                };

                db.Host.Add(host);

                db.SaveChanges();

                var hostAccess = groups.Select(x => new HostAccessGroups
                {
                    HostID      = host.ID,
                    AccessGroup = x.Trim()
                });

                db.HostAccessGroups.AddRange(hostAccess.Where(m => m.AccessGroup != ""));
                db.SaveChanges();
                return(host.ID);
            }
        }