public static void CreatePriceScripts(PriceMap Map,
                                              SenStayPropertyIndex Units,
                                              StreamlineSeasonGroup Seasons)
        {
            var UnitIDs = Map.GetUnitIDs();

            foreach (var UnitId in UnitIDs)
            {
                var status = UnitPriceStatus.Load(UnitId);
                var prices = Map.GetPricesByUnitFilteredByStatus(
                    UnitId, Units, Seasons, status);

                var scriptCreated = PriceScripting.CreateScript(status, prices, Units, Seasons);
                if (scriptCreated == PriceScripting.ScriptStatus.NOT_CREATED)
                {
                    N.Note("PriceScript for " + UnitId + " NOT created");
                    continue;
                }
                if (scriptCreated == PriceScripting.ScriptStatus.NOT_UPDATED)
                {
                    //N.Note("PriceScript for " + UnitId + " NOT updated");
                    continue;
                }
                N.Note("PriceScript for " + UnitId + " created");
                status.TimeStamp = DateTime.UtcNow;
                status.Save();
            }
        }
Example #2
0
        public static ScriptStatus CreateScript(
            UnitPriceStatus Status,
            FilteredPriceMap Prices,
            SenStayPropertyIndex Units,
            StreamlineSeasonGroup Seasons)
        {
            var script = new PriceScript()
            {
                UnitId = Status.Unit
            };
            var unitInfo = Units.GetBySenStayID(Status.Unit);

            if (unitInfo == null)
            {
                return(ScriptStatus.NOT_CREATED);
            }

            script.StreamlineEditId = unitInfo.StreamlineEditID;

            if (Status.IsNew)
            {
                script.Commands.Add(
                    new PriceScriptCommand()
                {
                    Type             = PriceScriptCommand.TYPE_SEASON_GROUP,
                    SeasonGroupID    = Seasons.ID,
                    StreamlineEditId = unitInfo.StreamlineEditID
                }
                    );
            }

            foreach (var p in Prices.Values)
            {
                script.Commands.Add(
                    new PriceScriptCommand()
                {
                    Type     = PriceScriptCommand.TYPE_PRICE,
                    Price    = p.Price,
                    SeasonId = p.SeasonId
                }
                    );
            }

            script.Generated = DateTime.UtcNow;
            if (script.Commands.Count > 0)
            {
                script.Save();
                return(ScriptStatus.CREATED);
            }
            return(ScriptStatus.NOT_UPDATED);
        }
        public FilteredPriceMap GetPricesByUnitFilteredByStatus(
            string SenStayID,
            SenStayPropertyIndex Units,
            StreamlineSeasonGroup Seasons,
            UnitPriceStatus Status)
        {
            if (!Data.ContainsKey(SenStayID))
            {
                return(null);
            }
            var prices = Data[SenStayID];

            var NewsetTimestamp = Status.LastSyncTimeStamp;
            var list            = new FilteredPriceMap();

            foreach (var p in prices)
            {
                if (p.Tiemstamp <= Status.LastSyncTimeStamp)
                {
                    continue;
                }
                var key = p.GetKey();

                if (p.Tiemstamp > NewsetTimestamp)
                {
                    NewsetTimestamp = p.Tiemstamp;
                }

                var item = PriceProcesser.Convert(p, Units, Seasons);
                if (item == null)
                {
                    continue;
                }

                if (list.ContainsKey(key))
                {
                    if (list[key].TimeStamp < p.Tiemstamp)
                    {
                        list[key] = PriceProcesser.Convert(p, Units, Seasons);
                    }
                }
                else
                {
                    list.Add(key, PriceProcesser.Convert(p, Units, Seasons));
                }
            }
            Status.LastSyncTimeStamp = NewsetTimestamp;
            return(list);
        }