示例#1
0
        public List <Domain> ListByUser(User user)
        {
            List <Domain> result = new List <Domain>();

            result.Add(new Domain()
            {
                Id = IDGenerator.GetDomainId(AppSettings.DefaultLocalHost), DomainName = AppSettings.DefaultLocalHost
            });

            //HashSet<string> alldomains = new HashSet<string>();

            //alldomains.Add(AppSettings.DefaultLocalHost);

            //var FromHostFile = LocalHostDomains();
            //foreach (var item in FromHostFile)
            //{
            //    if (!item.Value.ToLower().EndsWith(AppSettings.DefaultLocalHost))
            //    {
            //        alldomains.Add(item.Value);
            //    }
            //}

            var all = this.domainstore.All();

            foreach (var item in all.Where(o => o.OrganizationId == user.CurrentOrgId))
            {
                if (!string.IsNullOrEmpty(item.DomainName) && !item.DomainName.ToLower().EndsWith(AppSettings.DefaultLocalHost))
                {
                    result.Add(item);
                }
            }

            return(result);
        }
示例#2
0
        public Domain Get(string NameOrGuid)
        {
            Guid key;

            if (!System.Guid.TryParse(NameOrGuid, out key))
            {
                key = IDGenerator.GetDomainId(NameOrGuid);
            }
            return(Get(key));
        }
示例#3
0
        public List <Binding> GetByDomain(string topDomain)
        {
            Guid domainid;

            if (!Guid.TryParse(topDomain, out domainid))
            {
                domainid = IDGenerator.GetDomainId(topDomain);
            }
            return(GetByDomain(domainid));
        }
示例#4
0
        public void AddOrUpdate(string rootDomain, string subDomain, Guid webSiteId, Guid organizationId, bool defaultbinding = false, int port = 0)
        {
            Guid domainid = default(Guid);

            if (!string.IsNullOrEmpty(rootDomain))
            {
                domainid = IDGenerator.GetDomainId(rootDomain);
            }

            if (!AppSettings.IsOnlineServer && domainid != default(Guid))
            {
                var domain = GlobalDb.Domains.Get(domainid);
                if (domain == null)
                {
                    WindowsHost.AddOrUpdate(rootDomain, "127.0.0.1");
                    GlobalDb.Domains.AddOrUpdate(new Domain()
                    {
                        DomainName     = rootDomain,
                        OrganizationId = organizationId
                    });
                }
            }

            Binding binding = new Binding
            {
                DomainId           = domainid,
                OrganizationId     = organizationId,
                SubDomain          = string.IsNullOrEmpty(subDomain) ? null : subDomain.ToLower(),
                WebSiteId          = webSiteId,
                DefaultPortBinding = defaultbinding,
                Port = port
            };

            var old = this.Get(binding.Id);

            if (old != null)
            {
                throw new Exception("binding already exists");
            }
            else
            {
                AddOrUpdate(binding);
            }
        }
示例#5
0
        public bool Delete(Domain Domain)
        {
            try
            {
                var records = WindowsHost.GetList().Where(it => it.Domain.EndsWith(Domain.DomainName));
                foreach (var item in records)
                {
                    WindowsHost.Delete(item.Domain);
                    var domainid = IDGenerator.GetDomainId(item.Domain);
                    this.domainstore.Delete(domainid);
                }

                var id = IDGenerator.GetDomainId(Domain.DomainName);
                this.domainstore.Delete(id);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#6
0
        public List <Domain> ListByOrg(Guid OrganizationId)
        {
            List <Domain> result = new List <Domain>();

            result.Add(new Domain()
            {
                Id = IDGenerator.GetDomainId(AppSettings.DefaultLocalHost), DomainName = AppSettings.DefaultLocalHost
            });


            var all = this.domainstore.All();

            foreach (var item in all.Where(o => o.OrganizationId == OrganizationId))
            {
                if (!string.IsNullOrEmpty(item.DomainName) && !item.DomainName.ToLower().EndsWith(AppSettings.DefaultLocalHost))
                {
                    result.Add(item);
                }
            }

            return(result);
        }
示例#7
0
        public CreateServerPage()
        {
            InitializeComponent();
            backbtn.Content = Data.Language.Hardcoded.GetValue("back");
            saveBtn.Content = Data.Language.Hardcoded.GetValue("save");
            serverViewModel = new NewServerViewModel
            {
                Title      = Data.Language.Hardcoded.GetValue("+ New Server"),
                AddCommand = new DelegateCommand <NewServerViewModel>(vm =>
                {
                    if (!vm.IsValid())
                    {
                        MessageBox.Show(vm.Error);
                        return;
                    }
                    var isBindingToDomain = rbDomain.IsChecked.Value;
                    var messageText       = Data.Language.Hardcoded.GetValue("Domain or port number are required");

                    string name          = null;
                    System.Guid domainid = default(System.Guid);
                    bool defaultbinding  = false;
                    string subDomain     = null;
                    int port             = 0;
                    if (isBindingToDomain)
                    {
                        if (string.IsNullOrEmpty(vm.Domain))
                        {
                            MessageBox.Show(messageText);
                            return;
                        }
                        DomainResult domainresult = null;

                        domainresult = DomainHelper.Parse(vm.Domain);
                        var domain   = new Domain
                        {
                            DomainName     = domainresult.Domain,
                            OrganizationId = GlobalDb.Users.DefaultUser.CurrentOrgId
                        };
                        GlobalDb.Domains.AddOrUpdate(domain);
                        if (domainresult != null && !string.IsNullOrEmpty(domainresult.Domain))
                        {
                            name      = domainresult.Domain;
                            domainid  = IDGenerator.GetDomainId(domainresult.Domain);
                            subDomain = domainresult.SubDomain;
                        }
                        else
                        {
                            MessageBox.Show("Domain is not right");
                            return;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(vm.Port))
                        {
                            int.TryParse(vm.Port, out port);
                        }
                        if (port <= 0)
                        {
                            MessageBox.Show(messageText);
                            return;
                        }
                        name           = "Port" + vm.Port.ToString();
                        defaultbinding = true;
                    }

                    // add new website.
                    WebSite site = new WebSite
                    {
                        Name          = name,
                        LocalRootPath = vm.Path
                    };
                    GlobalDb.WebSites.AddOrUpdate(site);

                    var bind = new Data.Models.Binding
                    {
                        DomainId           = domainid,
                        SubDomain          = subDomain,
                        WebSiteId          = site.Id,
                        DefaultPortBinding = defaultbinding,
                        Port = port
                    };

                    GlobalDb.Bindings.AddOrUpdate(bind);

                    this.Redirect(new ServerPage());
                })
            };
            DataContext = serverViewModel;
        }