Artemis.ViewModels.Profiles.LayerEditorViewModel.CanClose C# (CSharp) Метод

CanClose() публичный Метод

public CanClose ( Action callback ) : void
callback Action
Результат void
        public override async void CanClose(Action<bool> callback)
        {
            // Create a fake layer and apply the properties to it
            LayerPropertiesViewModel?.ApplyProperties();
            // TODO: EventPropVM must have layer too
            if (EventPropertiesViewModel != null)
                ProposedLayer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
            ProposedLayer.Properties.Conditions.Clear();
            foreach (var conditionViewModel in LayerConditionVms)
                ProposedLayer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);

            // If not a keyboard, ignore size and position
            if (ProposedLayer.LayerType.DrawType != DrawType.Keyboard || !ProposedLayer.LayerType.ShowInEdtor)
            {
                ProposedLayer.Properties.Width = Layer.Properties.Width;
                ProposedLayer.Properties.Height = Layer.Properties.Height;
                ProposedLayer.Properties.X = Layer.Properties.X;
                ProposedLayer.Properties.Y = Layer.Properties.Y;
                ProposedLayer.Properties.Contain = Layer.Properties.Contain;
            }
            
            // Ignore the children, can't just temporarily add them to the proposed layer because
            // that would upset the child layers' relations (sounds like Dr. Phil amirite?)
            var currentObj = Clone(Layer);
            currentObj.Children.Clear();

            // Apply the IsEvent boolean
            currentObj.SetupCondition();
            ProposedLayer.SetupCondition();

            var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
            var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);

            if (current.Equals(proposed))
            {
                callback(true);
                return;
            }

            var close = await DialogService
                .ShowQuestionMessageBox("Unsaved changes", "Do you want to discard your changes?");
            callback(close.Value);
        }
    }