Exemplo n.º 1
0
        public ReplayWriter(IRegion region, string gameId)
        {
            GameId = gameId;
            RegionName = region.GetType().Name;

            if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "replays")))
                Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "replays"));

            if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "replays",RegionName)))
                Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "replays",RegionName));

            if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "replays", gameId)))
                Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "replays", gameId));
        }
Exemplo n.º 2
0
        private void ExecuteRemoveActiveViewCommand()
        {
            // 1
            //var activeView = region.ActiveViews.FirstOrDefault();
            //if (activeView != null)
            //{
            //    region.Deactivate(activeView);
            //    region.Remove(activeView);

            //    if (region.Views.Count() > 0)
            //        region.Activate(region.Views.Last());
            //}

            // 2 hack
            var itemMetadataCollectionProperty = region.GetType()
                                                 .GetProperty("ItemMetadataCollection", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            var itemMetadataCollection = itemMetadataCollectionProperty.GetValue(region) as ObservableCollection <ItemMetadata>;

            //foreach (var itemMetadata in itemMetadataCollection)
            //{
            //    bool isActive = itemMetadata.IsActive;
            //    object item = itemMetadata.Item;
            //}

            var activeItemMetadata = itemMetadataCollection.FirstOrDefault(i => i.IsActive);

            if (activeItemMetadata != null)
            {
                // Debug.Assert(activeView.Equals(activeItemMetadata.Item));

                Debug.Assert(activeItemMetadata.IsActive);

                region.Deactivate(activeItemMetadata.Item);

                Debug.Assert(!activeItemMetadata.IsActive);

                region.Remove(activeItemMetadata.Item);

                if (region.Views.Count() > 0)
                {
                    region.Activate(region.Views.Last());
                }
            }
        }
Exemplo n.º 3
0
        public void Configure(IRegion region, AttributeSet attributes)
        {
            var validationErrors = _attributeMatrix.Validate <IRegion>(attributes);

            if (validationErrors != null)
            {
                var message = "There are invalid attributes on region of type " + region.GetType().DisplayName();

                if (attributes.IsRegion != null && string.IsNullOrEmpty(attributes.IsRegion.Name))
                {
                    message += " called '" + attributes.IsRegion.Name + "'.";
                }

                foreach (var error in validationErrors)
                {
                    message += Environment.NewLine + error;
                }

                throw new RegionBuilderException(message);
            }

            Configure((object)region, attributes);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="RegionHilightAdorner"/> class.
		/// </summary>
		/// <param name="adornedElement">The adorned element.</param>
		/// <param name="region">The region.</param>
		/// <param name="brush">The brush.</param>
		public RegionHilightAdorner( UIElement adornedElement, IRegion region, Brush brush )
			: base( adornedElement )
		{
			this.IsHitTestVisible = false;

			this.brush = brush;

			this.userContent = new ContentPresenter();

			this.userContent.Content = new TextBlock()
			{
				FontStyle = FontStyles.Italic,
				Text = String.Format( "{0}, {1}", region.GetType().Name, region.Name ),
				VerticalAlignment = VerticalAlignment.Bottom,
				HorizontalAlignment = HorizontalAlignment.Right,
				Margin = new Thickness( 0, 0, 4, 4 ),
				TextTrimming = TextTrimming.CharacterEllipsis,
				TextWrapping = TextWrapping.Wrap,
				FontSize = 10,
				Foreground = this.brush
			};

			this.AddVisualChild( this.userContent );
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="RegionHilightAdorner"/> class.
        /// </summary>
        /// <param name="adornedElement">The adorned element.</param>
        /// <param name="region">The region.</param>
        /// <param name="brush">The brush.</param>
        public RegionHilightAdorner(UIElement adornedElement, IRegion region, Brush brush)
            : base(adornedElement)
        {
            this.IsHitTestVisible = false;

            this.brush = brush;

            this.userContent = new ContentPresenter();

            this.userContent.Content = new TextBlock()
            {
                FontStyle           = FontStyles.Italic,
                Text                = String.Format("{0}, {1}", region.GetType().Name, region.Name),
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin              = new Thickness(0, 0, 4, 4),
                TextTrimming        = TextTrimming.CharacterEllipsis,
                TextWrapping        = TextWrapping.Wrap,
                FontSize            = 10,
                Foreground          = this.brush
            };

            this.AddVisualChild(this.userContent);
        }
Exemplo n.º 6
0
        public void RemoveElement(IRegion element)
        {
            if (element == null)
            {
                throw new ArgumentException("There is null argumentum!", nameof(element));
            }

            if (_actualRegion == element)
            {
                ToPrevItem();

                if (_actualRegion == element)
                {
                    ToNextItem();
                }

                if (_actualRegion == element)
                {
                    _actualRegion = null;
                }
            }

            elements.Remove(element);

      #if USE_traceEnabled
            if (traceEnabled)
            {
                Trace.WriteLine(">> Window.RemoveElement: " + Environment.TickCount.ToString() + " | " + element.GetType().ToString());
            }
      #endif

            element.Changed -= new ChangedEventHandler(ChangedEvent);

            if (element is Window <IViewModel> childWindow)
            {
                childWindow.parentWindow = null;
            }

            if ((_actualRegion == null) || (_actualRegion == element))
            {
                ToFirstItem();                                                                    // There isn't a previous element, this element was the first.
            }

            Refresh();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add elements by tab&validate order.
        /// </summary>
        /// <param name="element">An IRegion or IElement object to display it on this window area (part of Console).</param>
        public void AddElement(IRegion element)
        {
            if (element == null)
            {
                throw new ArgumentException("There is null argumentum!", nameof(element));
            }

            elements.Add(element);

      #if USE_traceEnabled
            if (traceEnabled)
            {
                Trace.WriteLine(">> Window.AddElement: " + Environment.TickCount.ToString() + " | " + element.GetType().ToString());
            }
      #endif

            element.Changed += new ChangedEventHandler(ChangedEvent);

            if (element is Window <IViewModel> childWindow)
            {
                childWindow._styles      = styles;
                childWindow.parentWindow = this as Window <IViewModel>;;
            }

            if (_actualRegion == null)
            {
                ToFirstItem();
            }

            Refresh();
        }
Exemplo n.º 8
0
 public ReplayServer(IRegion region, string gameId)
 {
     Core.ReplayVersion = "";
     Core.ReplayVersion = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "replays", region.GetType().Name, gameId, "replay.ver"));
     Host = new NancyHost(new HostConfiguration() { UrlReservations = new UrlReservations() { CreateAutomatically = true } }, new Uri("http://localhost:9104"));
 }