Exemple #1
0
        /// <summary>
        /// Deletes the page and all of it's related regions.
        /// </summary>
        /// <returns></returns>
        public virtual bool DeleteAll()
        {
            // Since we can have multiple rows for all id's, get everything.
            List <Region>   regions    = Region.GetAllByPageId(Page.Id);
            List <Property> properties = Property.GetAllByParentId(Page.Id);
            List <Page>     pages      = Page.Get("page_id=@0", Page.Id);

            using (IDbTransaction tx = Database.OpenConnection().BeginTransaction()) {
                // Call OnDelete for all extensions
                Extensions.ForEach(e => e.Body.OnManagerDelete(Page));

                // Call OnDelete for all regions
                Regions.ForEach(r => r.Body.OnManagerDelete(Page));

                // Delete all entities
                regions.ForEach(r => r.Delete(tx));
                properties.ForEach(p => p.Delete(tx));
                pages.ForEach(p => p.Delete(tx));
                Permalink.Delete(tx);

                // Change global last modified
                Web.ClientCache.SetSiteLastModified(tx);

                tx.Commit();
            }
            return(true);
        }
        /// <summary>
        /// Saves the model.
        /// </summary>
        /// <returns>Weather the operation succeeded</returns>
        public bool SaveAll()
        {
            using (IDbTransaction tx = Database.OpenTransaction()) {
                List <object> args  = new List <object>();
                string        sql   = "";
                var           isNew = Template.IsNew;

                // Delete all unattached properties
                args.Add(Template.Id);
                Template.Properties.Each((n, p) => {
                    sql += (sql != "" ? "," : "") + "@" + (n + 1).ToString();
                    args.Add(p);
                });
                Property.Execute("DELETE FROM property WHERE property_parent_id IN (" +
                                 "SELECT page_id FROM page WHERE page_template_id = @0) " +
                                 (sql != "" ? "AND property_name NOT IN (" + sql + ")" : ""), tx, args.ToArray());

                // Save the template
                Template.Save(tx);

                // Update all regiontemplates with the id if this is an insert
                if (isNew)
                {
                    Regions.ForEach(r => r.TemplateId = Template.Id);
                }

                // Delete removed regions templates
                sql = "";
                args.Clear();
                args.Add(Template.Id);
                var pos = 1;
                foreach (var reg in Regions)
                {
                    if (reg.Id != Guid.Empty)
                    {
                        sql += (sql != "" ? "," : "") + "@" + pos.ToString();
                        args.Add(reg.Id);
                        pos++;
                    }
                }
                RegionTemplate.Execute("DELETE FROM regiontemplate WHERE regiontemplate_template_id = @0 " +
                                       (sql != "" ? "AND regiontemplate_id NOT IN (" + sql + ")" : ""), tx, args.ToArray());
                // Save the regions
                foreach (var reg in Regions)
                {
                    reg.Save(tx);
                }
                tx.Commit();
            }
            // Reload regions
            Regions = RegionTemplate.Get("regiontemplate_template_id = @0", Template.Id,
                                         new Params()
            {
                OrderBy = "regiontemplate_seqno"
            });

            return(true);
        }
Exemple #3
0
 /// <summary>
 /// Clears the regions.
 /// </summary>
 public void ClearRegions()
 {
     Regions
     .ForEach(
         region =>
     {
         region.Player = new Player {
             PlayerType = PlayerType.Unknown
         };
         region.NbrOfArmies = 0;
     }
         );
 }
        protected override void ProcessRecord()
        {
            if (Regions?.Count > 0 && AllRegions)
            {
                throw new ArgumentException("Exactly one of Regions, AllRegions should be specified.");
            }

            if ((Regions == null || Regions.Count == 0) && !AllRegions)
            {
                throw new ArgumentException("Exactly one of Regions, AllRegions should be specified.");
            }

            string buildIdString = new NewPFMultiplayerServer {
                ProductionEnvironmentUrl = ProductionEnvironmentUrl
            }.GetBuildId(BuildName, BuildId);

            HashSet <AzureRegion> regionsList = new HashSet <AzureRegion>();

            if (AllRegions)
            {
                GetBuildResponse response = Instance.GetBuildAsync(new GetBuildRequest()
                {
                    BuildId = buildIdString
                }).Result.Result;
                response.RegionConfigurations.ForEach(x => regionsList.Add(x.Region.Value));
            }
            else
            {
                Regions.ForEach(x => regionsList.Add(x));
            }

            List <MultiplayerServerSummary> serverSummaries = new List <MultiplayerServerSummary>();

            foreach (AzureRegion region in regionsList)
            {
                serverSummaries.AddRange(GetMultiplayerServers(buildIdString, region));
            }

            WriteObject(serverSummaries);
        }
Exemple #5
0
        /// <summary>
        /// Marks the starting regions.
        /// </summary>
        /// <param name="regions">The regions.</param>
        public void MarkStartingRegions(String[] regions)
        {
            // Reset all marked starting regions
            Regions
            .ForEach(
                region =>
            {
                if (region.RegionStatus == RegionStatus.PossibleStartingRegion)
                {
                    region.RegionStatus = RegionStatus.Initialized;
                }
            });

            regions
            .ToList()
            .ForEach(
                regionId =>
            {
                Regions
                .Get(regionId)
                .RegionStatus = RegionStatus.PossibleStartingRegion;
            }
                );
        }
Exemple #6
0
        /// <summary>
        /// Saves the page and all of it's related regions.
        /// </summary>
        /// <param name="publish">If the page should be published</param>
        /// <returns>If the operation succeeded</returns>
        public virtual bool SaveAll(bool draft = true)
        {
            using (IDbTransaction tx = Database.OpenConnection().BeginTransaction()) {
                try {
                    bool permalinkfirst = Page.IsNew;

                    // Save permalink first if the page is new
                    if (permalinkfirst)
                    {
                        if (Permalink.IsNew && String.IsNullOrEmpty(Permalink.Name))
                        {
                            Permalink.Name = Permalink.Generate(!String.IsNullOrEmpty(Page.NavigationTitle) ?
                                                                Page.NavigationTitle : Page.Title);
                            var param = SysParam.GetByName("HIERARCHICAL_PERMALINKS");
                            if (param != null && param.Value == "1" && Page.ParentId != Guid.Empty)
                            {
                                var parent = Page.GetSingle(Page.ParentId, true);
                                Permalink.Name = parent.Permalink + "/" + Permalink.Name;
                            }
                        }
                        Permalink.Save(tx);
                    }

                    // Save page
                    if (draft)
                    {
                        Page.Save(tx);
                    }
                    else
                    {
                        Page.SaveAndPublish(tx);
                    }

                    // Save regions & properties
                    Regions.ForEach(r => {
                        r.IsDraft = r.IsPageDraft = true;

                        // Call OnSave
                        r.Body.OnManagerSave(Page);

                        r.Save(tx);
                        if (!draft)
                        {
                            if (Region.GetScalar("SELECT COUNT(region_id) FROM region WHERE region_id=@0 AND region_draft=0", r.Id) == 0)
                            {
                                r.IsNew = true;
                            }
                            r.IsDraft = r.IsPageDraft = false;
                            r.Save(tx);
                        }
                    });
                    Properties.ForEach(p => {
                        p.IsDraft = true;
                        p.Save(tx);
                        if (!draft)
                        {
                            if (Property.GetScalar("SELECT COUNT(property_id) FROM property WHERE property_id=@0 AND property_draft=0", p.Id) == 0)
                            {
                                p.IsNew = true;
                            }
                            p.IsDraft = false;
                            p.Save(tx);
                        }
                    });

                    // Save extensions
                    foreach (var ext in Extensions)
                    {
                        // Call OnSave
                        ext.Body.OnManagerSave(Page);

                        ext.ParentId = Page.Id;
                        ext.Save(tx);
                        if (!draft)
                        {
                            if (Extension.GetScalar("SELECT COUNT(extension_id) FROM extension WHERE extension_id=@0 AND extension_draft=0", ext.Id) == 0)
                            {
                                ext.IsNew = true;
                            }
                            ext.IsDraft = false;
                            ext.Save(tx);
                        }
                    }

                    // Save permalink last if the page isn't new
                    if (!permalinkfirst)
                    {
                        Permalink.Save(tx);
                    }

                    // Change global last modified
                    if (!draft)
                    {
                        Web.ClientCache.SetSiteLastModified(tx);
                    }

                    // Clear cache for all post regions if we're publishing
                    if (!String.IsNullOrEmpty(Page.Permalink) && !draft)
                    {
                        foreach (var reg in Regions)
                        {
                            if (reg.Body is Extend.Regions.PostRegion)
                            {
                                ((Extend.Regions.PostRegion)reg.Body).ClearCache(Page, reg);
                            }
                        }
                    }

                    tx.Commit();

                    if (IsSite)
                    {
                        using (var db = new DataContext()) {
                            var site = db.SiteTrees.Where(s => s.Id == Page.SiteTreeId).Single();
                            site.MetaTitle       = SiteTree.MetaTitle;
                            site.MetaDescription = SiteTree.MetaDescription;
                            db.SaveChanges();
                        }
                        if (!draft)
                        {
                            PageModel.RemoveSitePageFromCache(Page.SiteTreeId);
                            WebPages.WebPiranha.RegisterDefaultHostNames();
                        }
                    }
                } catch { tx.Rollback(); throw; }
            }
            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Saves the page and all of it's related regions.
        /// </summary>
        /// <param name="publish">Weather the page should be published</param>
        /// <returns>Weather the operation succeeded</returns>
        public virtual bool SaveAll(bool draft = true)
        {
            using (IDbTransaction tx = Database.OpenConnection().BeginTransaction()) {
                try {
                    bool permalinkfirst = Page.IsNew;

                    // Save permalink first if the page is new
                    if (permalinkfirst)
                    {
                        if (Permalink.IsNew)
                        {
                            Permalink.Name = Permalink.Generate(!String.IsNullOrEmpty(Page.NavigationTitle) ?
                                                                Page.NavigationTitle : Page.Title);
                        }
                        Permalink.Save(tx);
                    }

                    // Save page
                    if (draft)
                    {
                        Page.Save(tx);
                    }
                    else
                    {
                        Page.SaveAndPublish(tx);
                    }

                    // Save regions & properties
                    Regions.ForEach(r => {
                        r.IsDraft = r.IsPageDraft = true;
                        r.Save(tx);
                        if (!draft)
                        {
                            if (Region.GetScalar("SELECT COUNT(region_id) FROM region WHERE region_id=@0 AND region_draft=0", r.Id) == 0)
                            {
                                r.IsNew = true;
                            }
                            r.IsDraft = r.IsPageDraft = false;
                            r.Save(tx);
                        }
                    });
                    Properties.ForEach(p => {
                        p.IsDraft = true;
                        p.Save(tx);
                        if (!draft)
                        {
                            if (Property.GetScalar("SELECT COUNT(property_id) FROM property WHERE property_id=@0 AND property_draft=0", p.Id) == 0)
                            {
                                p.IsNew = true;
                            }
                            p.IsDraft = false;
                            p.Save(tx);
                        }
                    });

                    // Save permalink last if the page isn't new
                    if (!permalinkfirst)
                    {
                        Permalink.Save(tx);
                    }

                    // Change global last modified
                    if (!draft)
                    {
                        Web.ClientCache.SetSiteLastModified(tx);
                    }

                    tx.Commit();
                } catch { tx.Rollback(); throw; }
            }
            return(true);
        }