Esempio n. 1
0
        static void LoadData(Site site)
        {
            //Scan for pages
            string[] pageFiles = Directory.GetFiles(site.DataPath, "*.page", SearchOption.AllDirectories);
            foreach (string pageFile in pageFiles)
            {
                Page p = new Page(site.DataPath, pageFile);
                //Ignore news pages
                if (p.HasDate)
                {
                    continue;
                }

                site.Add(p);
                //Console.WriteLine("Page: " + p);
            }
            site.Pages.Sort(Page.ComparerIndex);

            //Scan for posts
            string[] postFiles = Directory.GetFiles(site.DataPath, "*.post", SearchOption.AllDirectories);
            foreach (string postFile in postFiles)
            {
                Post p = new Post(postFile);
                //Ignore non news pages
                if (p.Date == DateTime.MinValue)
                {
                    continue;
                }

                site.Add(p);
                //Console.WriteLine("News: " + p);
            }
            site.Posts.Sort(Post.ComparerLatestFirst);
        }
Esempio n. 2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            SensorForm sf = new SensorForm(site, null);

            if (DialogResult.OK == sf.ShowDialog())
            {
                site.Add(sf.sensor);
                RefreshList();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 新建站点
        /// </summary>
        public bool AddSite(Site site)
        {
            if (site.ID <= 0 || this.ReadDB.Exists <Site>(t => t.ID == site.ID))
            {
                return(this.FaildMessage("编号已经存在"));
            }
            if (string.IsNullOrEmpty(site.Name))
            {
                return(this.FaildMessage("请输入商户名"));
            }
            if (this.ReadDB.Exists <Site>(t => t.Name == site.Name))
            {
                return(this.FaildMessage("商户名重复"));
            }
            if (site.Prefix.Length != 3)
            {
                return(this.FaildMessage("前缀错误,只能三位!"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                //自动产生密钥
                Guid secretKey = Guid.NewGuid();
                site.SecretKey = secretKey.ToString();

                site.Add(db);

                db.Commit();
            }

            this.AccountInfo.Log(LogType.Site, $"新建商户{site.ID}");

            return(true);
        }
        public List <string> AddUrlString(string plink)
        {
            SPage         page   = new SPage(plink);//II
            string        url    = plink;
            HtmlWeb       webDoc = new HtmlWeb();
            HtmlDocument  doc    = webDoc.Load(url);
            List <string> p      = new List <string>();

            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//a"))
            {
                string link = node.GetAttributeValue("href", null);
                if (link != null & link != page.PageLink)
                {
                    if (p.Find(u => u == (link)) != link)
                    {
                        if (link.Contains("http") == false &
                            link.Contains("javascript:") == false &
                            link.Contains("tel:") == false)
                        {        //  p.Add(link);
                            var uri = new Uri(url, UriKind.RelativeOrAbsolute);
                            if (GetAbsoluteUrlString(url, link).Contains("http"))
                            {
                                p.Add(GetAbsoluteUrlString(url, link));
                                Site.Add(page);
                                page.Links.Add(GetAbsoluteUrlString(url, link));//II
                            }
                        }
                    }
                }
            }
            return(p);
        }
        public SiteStructureViewModel(string link)
        {
            if (link == null)
            {
                return;
            }
            string buf = "";

            i = 0;
            string sdf;

            if (link.Contains("https://") == true)
            {
                i += 8;
            }
            while (i < link.Length)
            {
                buf += link.Substring(i, 1);
                i++;
                if (link.Substring(i - 1, 1) == "/")
                {
                    i = link.Length;
                }
            }

            string       url      = "https://" + buf;
            HtmlWeb      webDoc   = new HtmlWeb();
            HtmlDocument doc      = webDoc.Load(url);
            string       siteName = doc.DocumentNode.SelectNodes("//title").FirstOrDefault().InnerText;

            MessageBox.Show(buf + " " + siteName);
            Site = new Site(siteName, buf);

            using (WCContext appContext = new WCContext())
            {
                // SPageRepository sPageRepository = new SPageRepository(appContext);
                SPageRepositoryProxy sPageRepositoryProxy = new SPageRepositoryProxy(appContext);
                Page = new SPage(link);

                Page = sPageRepositoryProxy.Insert(page);
                Site.Pages.Add(Page);                             //del
                Site.Add(Page);
                page.Links.AddRange(AddUrlString(Page.PageLink)); //del

                Links = Page.Links;                               //this page
                //AllLinks = Site.ShowLinks();
                AllLinks = new List <string>();
                AllLinks.Add(Page.PageLink);
                FindAllUrlString();
                FindAllUrlStringII();

                Links = Site.ShowLinks();   //AllLinks
                //Links = AllLinks;
            }
        }
Esempio n. 6
0
        private void GetSelectedSites()
        {
            SelectedObjects selectedObjs = (SelectedObjects)this.siteTree.Tag;

            if ((null == selectedObjs) ||
                (0 == selectedObjs.SelectedSites.Count()))
            {
                //
                // This shouldn't happen, since the Continue button is only
                // enabled if there is at least one site.
                //
                return;
            }

            Dictionary <IISServer, List <ApplicationPool> > allAppPools = new Dictionary <IISServer, List <ApplicationPool> >();

            // Clear the list of servers
            this.IISServers.Servers.Clear();

            foreach (IISServer selectedServer in selectedObjs.SelectedServers)
            {
                // first clear any sites the server has.
                selectedServer.Sites.Clear();

                // save the list of AppPools and reset the server's list.
                allAppPools.Add(selectedServer, selectedServer.AppPools);
                selectedServer.AppPools = new List <ApplicationPool>();

                // add this server back into the global list.
                this.IISServers.Servers.Add(selectedServer.Name, selectedServer);
            }

            foreach (Site selectedSite in selectedObjs.SelectedSites)
            {
                // first clear any databases the site has
                selectedSite.Databases.Clear();
                IISServer server = selectedSite.ParentServer;
                selectedSite.ParentServer = null; //prevent recursion during serialization

                // add this site back into its server's site collection.
                server.Sites.Add(selectedSite);

                // add app pools for this site back into the server's AppPool collection.
                List <ApplicationPool> appPools = allAppPools[server];
                if ((null == appPools) || (0 == appPools.Count))
                {
                    continue;
                }

                ApplicationPool ap = null;
                if (!server.AppPools.Exists(x => x.Name == selectedSite.AppPoolName))
                {
                    ap = appPools.Find(x => x.Name == selectedSite.AppPoolName);
                    if (null != ap)
                    {
                        server.AppPools.Add(ap);
                        appPools.Remove(ap); // trim the list
                    }
                }

                foreach (Helpers.Application app in selectedSite.Applications)
                {
                    if (!server.AppPools.Exists(x => x.Name == app.AppPoolName))
                    {
                        ap = appPools.Find(x => x.Name == app.AppPoolName);
                        if (null != ap)
                        {
                            server.AppPools.Add(ap);
                            appPools.Remove(ap); // trim the list
                            if (0 == appPools.Count)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            foreach (Database selectedDatabase in selectedObjs.SelectedDatabases)
            {
                // add any databases back to their respective sites.
                Site site = selectedDatabase.ParentSite;
                selectedDatabase.ParentSite = null; //prevent recursion during serialization
                site.Add(selectedDatabase);
            }
        }
        private void siteTree_AfterCheck(object sender, TreeViewEventArgs e)
        {
            TreeNode selectedNode = e.Node;
            bool     nodeChecked  = selectedNode.Checked;

            //
            // If this node has children, then sync their checked status.
            //
            if ((null != selectedNode.Nodes) && (selectedNode.Nodes.Count != 0))
            {
                foreach (TreeNode child in selectedNode.Nodes)
                {
                    if (child.Checked != selectedNode.Checked && ((null == child.Tag) || ("AddDB" != child.Tag)))
                    {
                        child.Checked = selectedNode.Checked;
                    }
                }
            }

            if ((selectedNode == this.siteTree.TopNode) ||
                (null == this.siteTree.Tag))
            {
                return;
            }

            SelectedObjects selectedObjs = (SelectedObjects)this.siteTree.Tag;
            Type            objectType   = selectedNode.Tag.GetType();

            //
            // Add or remove selected items from the selected objects list.
            //

            if (nodeChecked)
            {
                if (typeof(string) == objectType && selectedNode.Tag == "AddDB")
                {
                    AddDbConnectionDialog dbDialog = new AddDbConnectionDialog();
                    if (dbDialog.ShowDialog() == DialogResult.OK)
                    {
                        string dbConnectionString = dbDialog.textBoxDbConnectionString.Text.Trim();
                        try
                        {
                            var dbConn = new DbConnectionStringBuilder {
                                ConnectionString = dbConnectionString
                            };
                            // dbConn.ConnectionString = dbConnectionString;
                            if (dbConn.ContainsKey("Provider") && (dbConn["Provider"].ToString() == "SQLOLEDB" || dbConn["Provider"].ToString().Contains("SQLNCLI")))
                            {
                                dbConn.Remove("Provider");
                            }

                            var sqlConn = new SqlConnectionStringBuilder(dbConn.ConnectionString);


                            //sqlConn.ConnectionString = dbConnectionString;
                            Site     site = (Site)selectedNode.Parent.Tag;
                            Database db   = new Database("", sqlConn.InitialCatalog, sqlConn.ConnectionString)
                            {
                                ParentSite = site
                            };
                            site.Add(db);
                            selectedNode.Tag = db;
                            objectType       = typeof(Database);
                        }
                        catch (System.ArgumentException ex)
                        {
                            MessageBox.Show("Invalid connection string.\r\n\r\nValid connection string should be like\r\n 'Data Source=<servername>; Initial Catalog=<intialCatalog>; Trusted_Connection=<Yes|No>'");
                            selectedNode.Tag     = "AddDB";
                            selectedNode.Checked = false;
                            return;
                        }
                    }
                    else
                    {
                        selectedNode.Tag     = "AddDB";
                        selectedNode.Checked = false;
                        return;
                    }
                }
                //
                // If this is a child node, and it's been checked, make sure its
                // parent nodes are checked.
                //
                TreeNode nodeParent = selectedNode.Parent;
                while (null != nodeParent)
                {
                    if (!nodeParent.Checked)
                    {
                        nodeParent.Checked = true;
                    }
                    nodeParent = nodeParent.Parent;
                }

                if (typeof(Site) == objectType)
                {
                    if (!selectedObjs.SelectedSites.Contains((Site)selectedNode.Tag))
                    {
                        selectedObjs.SelectedSites.Add((Site)selectedNode.Tag);
                    }
                    // It's actually not possible to check (enable) anything
                    // in the tree without at least one site being checked.
                    this.StartButton.Enabled = true;
                }
                else if (typeof(Database) == objectType)
                {
                    if (!selectedObjs.SelectedDatabases.Contains((Database)selectedNode.Tag))
                    {
                        selectedObjs.SelectedDatabases.Add((Database)selectedNode.Tag);
                    }
                }
                else if (typeof(IISServer) == objectType)
                {
                    if (!selectedObjs.SelectedServers.Contains((IISServer)selectedNode.Tag))
                    {
                        selectedObjs.SelectedServers.Add((IISServer)selectedNode.Tag);
                    }
                }
            }
            else
            {
                if (typeof(Site) == objectType)
                {
                    if (selectedObjs.SelectedSites.Contains((Site)selectedNode.Tag))
                    {
                        selectedObjs.SelectedSites.Remove((Site)selectedNode.Tag);
                    }
                }
                else if (typeof(Database) == objectType)
                {
                    if (selectedObjs.SelectedDatabases.Contains((Database)selectedNode.Tag))
                    {
                        selectedObjs.SelectedDatabases.Remove((Database)selectedNode.Tag);
                    }
                }
                else if (typeof(IISServer) == objectType)
                {
                    if (!selectedObjs.SelectedServers.Contains((IISServer)selectedNode.Tag))
                    {
                        selectedObjs.SelectedServers.Remove((IISServer)selectedNode.Tag);
                    }
                }
                this.StartButton.Enabled = (0 != selectedObjs.SelectedSites.Count());
            }
            return;
        }
Esempio n. 8
0
        /// <summary>
        /// 新建站点
        /// </summary>
        public bool AddSite(Site site)
        {
            if (site.ID <= 0 || this.ReadDB.Exists <Site>(t => t.ID == site.ID))
            {
                return(this.FaildMessage("编号已经存在"));
            }
            if (string.IsNullOrEmpty(site.Name))
            {
                return(this.FaildMessage("请输入商户名"));
            }
            if (this.ReadDB.Exists <Site>(t => t.Name == site.Name))
            {
                return(this.FaildMessage("商户名重复"));
            }

            site.Setting = new Site.SiteSetting()
            {
                Currencies = new[] { site.Currency },
                Languages  = new[] { site.Language }
            };

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                site.Add(db);

                // 复制PC模板到商户模板
                if (site.PCTemplate != 0)
                {
                    db.AddCallback(() =>
                    {
                        site.PCTemplate = ViewAgent.Instance().CopySystemTemplate(site.ID, site.PCTemplate);
                    });
                }

                // 复制H5模板到商户模板
                if (site.H5Template != 0)
                {
                    db.AddCallback(() =>
                    {
                        site.H5Template = ViewAgent.Instance().CopySystemTemplate(site.ID, site.H5Template);
                    });
                }

                // 复制APP模板到商户模板
                if (site.APPTemplate != 0)
                {
                    db.AddCallback(() =>
                    {
                        site.APPTemplate = ViewAgent.Instance().CopySystemTemplate(site.ID, site.APPTemplate);
                    });
                }

                new SiteDetail()
                {
                    SiteID   = site.ID,
                    AdminURL = this.CreateDefaultAdminUrl(db, site.Name)
                }.Add(db);

                this.CreateDefaultAdmin(db, site.ID);

                db.Commit();
            }

            site.Update(this.WriteDB, t => t.PCTemplate, t => t.H5Template, t => t.APPTemplate);

            this.AccountInfo.Log(LogType.Site, $"新建商户{site.ID}");

            return(true);
        }
Esempio n. 9
0
 public int AddSite(Site site)
 {
     site.Updatetime = DateTime.UtcNow;
     return(_site.Add(site));
 }