public void WriteTo(Stream aStream)
        {
            if (FormatVersion != FormatConstants.GMVersion80 && FormatVersion != FormatConstants.GMVersion81)
            {
                throw new Exceptions.UnsupportedVersion(0, FormatVersion);
            }

            using (GMBinaryWriter writer = new GMBinaryWriter(aStream, CompressionMode)) {
                writer.Write(FormatConstants.GMMagicNumber);
                writer.Write(FormatVersion);

                Settings.WriteTo(writer);
                Triggers.WriteTo(writer);
                Constants.WriteTo(writer);
                Sounds.WriteTo(writer);
                Sprites.WriteTo(writer);
                Backgrounds.WriteTo(writer);
                Paths.WriteTo(writer);
                Scripts.WriteTo(writer);
                Fonts.WriteTo(writer);
                TimeLines.WriteTo(writer);
                Objects.WriteTo(writer);
                Rooms.WriteTo(writer);
                Includes.WriteTo(writer);
                m_extensions.WriteTo(writer);
                Information.WriteTo(writer);
                m_creationCodes.WriteTo(writer);
                m_roomOrder.WriteTo(writer);
                ResourceTree.WriteTo(writer);
            }
        }
Esempio n. 2
0
        } // end of GetEarliestSlot

        #endregion

        #region GetAllSlotTimes

        /// <summary>
        /// Loops through all time lines in the window and returns all slots possible in these time lines
        /// </summary>
        /// <param name="currentTime">Time the request is made</param>
        /// <param name="request">slot request to be booked</param>
        /// <param name="latestTime">Latest time for a booking</param>
        /// <returns>All available slots for the request within the specified time window</returns>
        public List <Slot> GetAllSlotTimes(DateTime currentTime, SlotRequest request, DateTime latestTime)
        {
            CutTimeLines(currentTime);

            // if current time lines do not cover the entire period extra time lines are added
            while (TimeLines.Last().EndTime < latestTime)
            {
                AddSingleTimeLine();
            } // end while

            List <Slot> allSlots = new List <Slot>();

            // loop through all time lines and add possible slots
            for (int i = 0; i < TimeLines.Count; i++)
            {
                if (TimeLines[i].StartTime >= latestTime)
                {
                    break;
                }

                if (TimeLines[i].StartTime <= request.EarliestTime)
                {
                    allSlots.AddRange(TimeLines[i].GetAllSlotTime(request, ConstraintsWithinTimeLine));
                }
                else
                {
                    break;
                } // end if
            }     // end for

            return(allSlots);
        } // end of GetAllSlotTimes
        /// <summary>
        /// Метод для отрисовки расписания
        /// </summary>
        private void DrawSchedule()
        {
            var machines      = (Schedule ?? throw new ArgumentNullException()).Select(m => m.Machine).Distinct().OrderBy(m => m.Name).ToList();
            var y             = 10;
            var timeLinePoint = 0;

            foreach (var machine in machines)
            {
                TextItems.Add(new TextDetails(10, y - 35, 50, 50, machine.Name));
                RectItems.Add(new RectItem(10, y, 50, 50, "Black"));
                var batches = Schedule.Where(m => m.Machine.Id == machine.Id).Select(b => b.Batch).ToList();
                var x       = 65;
                foreach (var b in batches)
                {
                    var color = b.NomenclatureId switch
                    {
                        0 => "Gold",
                        1 => "Silver",
                        2 => "LightSteelBlue",
                        _ => "Black"
                    };
                    timeLinePoint += machine.TimeDictionary[b.NomenclatureId];
                    var widthFromTime = machine.TimeDictionary[b.NomenclatureId] + 15;
                    TextItems.Add(new TextDetails(x + widthFromTime, y + 32, 20, 20, timeLinePoint.ToString()));
                    TextItems.Add(new TextDetails(x, y, widthFromTime, 20, b.Nomenclature.Name.Substring(0, 3)));
                    RectItems.Add(new RectItem(x, y, widthFromTime, 50, color));
                    x += widthFromTime + 2;
                }
                TimeLines.Add(new TimeLine(10, y + 23, x + 10, y + 23));
                y            += 90;
                timeLinePoint = 0;
            }
        }
    }
Esempio n. 4
0
        } // end of TimeLineConfiguration

        #endregion

        //--------------------------------------------------------------------------------------------------
        // Public Methods implementing the booking model interface
        //--------------------------------------------------------------------------------------------------

        #region GetEarliestSlot

        /// <summary>
        /// Loops through time lines and looks for the earliest slot
        /// for the request
        /// </summary>
        /// <param name="currentTime">Time the request is made</param>
        /// <param name="request">slot request to be booked</param>
        /// <returns>The earliest slot for the request</returns>
        public Slot GetEarliestSlot(DateTime currentTime, SlotRequest request)
        {
            CutTimeLines(currentTime);

            // if earliest time is later than latest time of all time lines
            // new time lines are added
            while (TimeLines.Last().EndTime < request.EarliestTime)
            {
                AddSingleTimeLine();
            } // end while

            Slot slotFound = null;

            // loop through all time lines to find a slot
            for (int i = 0; i < TimeLines.Count; i++)
            {
                if (TimeLines[i].StartTime >= request.EarliestTime)
                {
                    if ((slotFound = TimeLines[i].GetEarliestSlotTime(request, ConstraintsWithinTimeLine)) != null)
                    {
                        break;
                    }
                } // end if
            }     // end for

            // if all time lines are full or constraints do not allow extra bookings
            // new time lines are added as long as booking is possible
            while (slotFound == null)
            {
                AddSingleTimeLine();
                slotFound = TimeLines.Last().GetEarliestSlotTime(request, ConstraintsWithinTimeLine);
            } // end while

            return(slotFound);
        } // end of GetEarliestSlot
Esempio n. 5
0
 public void Dispose()
 {
     Lines.Clear();
     TimeLines.Values.ToList().ForEach(line => line.Dispose());
     TimeLines.Clear();
     Averager.Dispose();
     LineMaker.Dispose();
 }
Esempio n. 6
0
 public void ClearLines()
 {
     TimeLines.Values.ToList().ForEach(line => line.Clear());
     TimeLines.Clear();
     Averager.Clear();
     LineMaker.Clear();
     Lines.Clear();
 }
Esempio n. 7
0
 public void AddTimeLine(LineType type, TimeLine <KeyValuePair <DateTime, decimal> > line)
 {
     if (TimeLines.ContainsKey(type))
     {
         TimeLines[type] = line;
     }
     else
     {
         TimeLines.Add(type, line);
     }
 }
Esempio n. 8
0
        } // end of ConstraintsWithinTimeLine

        #endregion

        //--------------------------------------------------------------------------------------------------
        // Private Methods
        //--------------------------------------------------------------------------------------------------

        #region AddSingleTimeLine

        /// <summary>
        /// Extendes the list of time lines by a new single time line using the time line generator
        /// </summary>
        private void AddSingleTimeLine()
        {
            SinglePerDayTimeLine currentTimeLine;

            if (TimeLines.Count == 0)
            {
                currentTimeLine = TimeLineConfiguration.GetFirstTimeLine(CurrentEndTime);
            }
            else
            {
                currentTimeLine = TimeLines.Last();
            }

            _timeLines.Add(TimeLineConfiguration.GetNextTimeLine(currentTimeLine));
        } // end of AddSingleTimeLine
Esempio n. 9
0
        public CalendarWeek(DateTime weekStartDateTime)
        {
            WeekStartDateTime = weekStartDateTime;

            var weekDates = Enumerable.Range(0, 7)
                            .Select(offset => weekStartDateTime.AddDays(offset))
                            .ToList();

            SpansAcrossTwoMonths = weekDates.First().Month != weekDates.Last().Month;
            SpansAcrossTwoYears  = weekDates.First().Year != weekDates.Last().Year;

            weekDates.ForEach(cd =>
            {
                TimeLines.Add(new TimeLine(cd, new TimeSpan(24, 0, 0)));
            });
        }
Esempio n. 10
0
        } // end of GeneralBookingModel

        #endregion

        #region Initialize

        /// <summary>
        /// Initialization of the booking model, the time lines are filled with the minimum number
        /// </summary>
        /// <param name="startTime">Start time of the booking model</param>
        public void Initialize(DateTime startTime)
        {
            _currentStartTime = startTime;

            DateTime currentTime = startTime;

            SinglePerDayTimeLine currentTimeLine = TimeLineConfiguration.GetFirstTimeLine(currentTime);

            _timeLines.Add(currentTimeLine);

            while (TimeLines.Count < MinimumActiveTimeLinesKept)
            {
                currentTimeLine = TimeLineConfiguration.GetNextTimeLine(currentTimeLine);
                _timeLines.Add(currentTimeLine);
            } // end while
            _currentEndTime = TimeLines.Last().EndTime;
        }     // end of Initialize
Esempio n. 11
0
        } // end of AddSingleTimeLine

        #endregion

        #region CutTimeLines

        /// <summary>
        /// Cuts time lines that are in the past and hence not bookable any more
        /// Retains a minimum number of time lines
        /// </summary>
        /// <param name="currentTime"></param>
        private void CutTimeLines(DateTime currentTime)
        {
            if (TimeLines.Count == 0)
            {
                return;
            }

            while (TimeLines.First().EndTime <= currentTime)
            {
                _timeLines.RemoveAt(0);

                if (TimeLines.Count < MinimumActiveTimeLinesKept)
                {
                    AddSingleTimeLine();
                }
            } // end while
        }     // end of AddSingleTimeLine
Esempio n. 12
0
        public void TimeLine_Load(Stream _s)
        {
            int num  = _s.ReadInteger();
            int num2 = _s.ReadInteger();

            for (int i = 0; i < num2; i++)
            {
                Stream stream = _s;
                if (num == 800)
                {
                    stream = _s.ReadStreamC();
                }
                bool flag = stream.ReadBoolean();
                KeyValuePair <string, GMTimeLine> item = default(KeyValuePair <string, GMTimeLine>);
                if (flag)
                {
                    string     key   = stream.ReadString();
                    GMTimeLine value = new GMTimeLine(this, stream);
                    item = new KeyValuePair <string, GMTimeLine>(key, value);
                }
                TimeLines.Add(item);
            }
        }
Esempio n. 13
0
        public void InverseData()
        {
            if (this.Labels.Count == 0)
            {
                return;
            }

            string[] labels = new string[Labels.Count];
            this.Labels.CopyTo(labels);

            this.Labels.Clear();
            for (int i = labels.Length - 1; i >= 0; i--)
            {
                this.Labels.Add(labels[i]);
            }

            _times.Reverse();

            if (TimeLines != null)
            {
                TimeLines.Reverse();
            }
        }
        public void ReadFrom(Stream aStream)
        {
            using (GMBinaryReader reader = new GMBinaryReader(aStream)) {
                int magicNumber = reader.ReadInt32();
                if (magicNumber != FormatConstants.GMMagicNumber)
                {
                    throw new Exceptions.UnknownFormat();
                }

                int version = reader.ReadInt32();
                if (version != FormatConstants.GMVersion80 && version != FormatConstants.GMVersion81)
                {
                    throw new Exceptions.UnsupportedVersion(aStream.Position - 4, version);
                }

                FormatVersion = version;

                Settings.ReadFrom(reader);
                Triggers.ReadFrom(reader);
                Constants.ReadFrom(reader);
                Sounds.ReadFrom(reader);
                Sprites.ReadFrom(reader);
                Backgrounds.ReadFrom(reader);
                Paths.ReadFrom(reader);
                Scripts.ReadFrom(reader);
                Fonts.ReadFrom(reader);
                TimeLines.ReadFrom(reader);
                Objects.ReadFrom(reader);
                Rooms.ReadFrom(reader);
                Includes.ReadFrom(reader);
                m_extensions.ReadFrom(reader);
                Information.ReadFrom(reader);
                m_creationCodes.ReadFrom(reader);
                m_roomOrder.ReadFrom(reader);
                ResourceTree.ReadFrom(reader);
            }
        }
        private async void FillTimeLine()
        {
            var anyScene = _scenes.FirstOrDefault();

            for (int i = 0; i < anyScene.Areas.Count; i++)
            {
                TimeLines.Add(i + 1, new TimeLinePointCollection());
            }


            var rnd = new Random();

            while (_startDate < _endDate)
            {
                for (int i = 0; i < anyScene.Areas.Count; i++)
                {
                    var timeLinePoint = new TimeLinePoint()
                    {
                        Area     = anyScene.Areas[i].Number,
                        DateTime = _startDate,
                        Lon      = anyScene.Areas[i].LonLat.Lon,
                        Lat      = anyScene.Areas[i].LonLat.Lat,
                        Meteo    = (await _weatherService.GetPastWeatherForLocationAsync(anyScene.Areas[i].LonLat.ToString(), _startDate)).Now,
                        Map      = 0
                    };

                    TimeLines[timeLinePoint.Area].Add(timeLinePoint);
                }

                _startDate = _startDate.AddDays(_interval);
            }

            foreach (var scene in Scenes)
            {
                for (int i = 0; i < scene.Areas.Count; i++)
                {
                    try
                    {
                        var timeLinePoint = new TimeLinePoint()
                        {
                            Area     = scene.Areas[i].Number,
                            DateTime = scene.TimeStamp,
                            Lat      = scene.Areas[i].LonLat.Lat,
                            Lon      = scene.Areas[i].LonLat.Lon,
                            Meteo    = 0,
                            Map      = scene.Areas[i].UnitPoints.Select(x => x.PictureTemperature).Average()
                        };

                        TimeLines[timeLinePoint.Area].Add(timeLinePoint);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            foreach (var timeLine in TimeLines)
            {
                await _dbService.InsertTimeLinePoints(timeLine.Value.ToList());
            }
        }
Esempio n. 16
0
        public void RenderTop(IRenderContext rc, PlotModel model, OxyRect rect)
        {
            if (TimeLines == null)
            {
                return;
            }

            OxyRect  bound = rect;
            TimeLine live, seperator, forecast;

            TimeLines.GetLive(out live);
            TimeLines.GetSeperator(out seperator);
            TimeLines.GetForecast(out forecast);
            if (Theme != null)
            {
                AxisStyle style = Theme.GetStyle(ThemeMode) as AxisStyle;
                TitleColor    = Helper.ConvertColorToOxyColor(style.TitleColor);
                TextColor     = Helper.ConvertColorToOxyColor(style.LabelColor);
                TicklineColor = Helper.ConvertColorToOxyColor(style.LineColor);
            }
            if (seperator != null)
            {
                double x = this.TransformX(seperator.Index);
                if (live != null)
                {
                    double lx = this.TransformX(live.Index);

                    double center_x = 0;
                    if (lx > x)
                    {
                        center_x = bound.Right - (bound.Right - x) / 2;
                    }
                    else
                    {
                        center_x = bound.Left + (x - bound.Left) / 2;
                    }

                    if (!string.IsNullOrEmpty(live.GetTimeStyleDesc()))
                    {
                        OxySize text_size = rc.MeasureText(live.GetTimeStyleDesc());
                        double  y         = bound.Top;
                        rc.DrawText(new ScreenPoint(center_x - text_size.Width / 2, y), live.GetTimeStyleDesc(), TextColor);
                    }
                }

                if (forecast != null)
                {
                    double lx       = this.TransformX(forecast.Index);
                    double center_x = 0;
                    if (lx > x)
                    {
                        center_x = bound.Right - (bound.Right - x) / 2;
                    }
                    else
                    {
                        center_x = bound.Left + (x - bound.Left) / 2;
                    }


                    if (!string.IsNullOrEmpty(forecast.GetTimeStyleDesc()))
                    {
                        OxySize text_size = rc.MeasureText(forecast.GetTimeStyleDesc());
                        double  y         = bound.Top;
                        rc.DrawText(new ScreenPoint(center_x - text_size.Width / 2, y), forecast.GetTimeStyleDesc(), TextColor);
                    }
                }
            }
        }