public static bool CanPaste(EventViewmodel destEventVm, TPasteLocation location)
 {
     if (destEventVm == null)
         return false;
     Event dest = destEventVm.Event;
     lock (_clipboard.SyncRoot)
     {
         var operation = Operation;
         using (var enumerator = _clipboard.GetEnumerator())
         {
             if (!enumerator.MoveNext())
                 return false;
             if (!_canPaste(enumerator.Current, dest, location, operation))
                 return false;
             dest = enumerator.Current;
             while (enumerator.MoveNext())
             {
                 if (!_canPaste(enumerator.Current, dest, TPasteLocation.After, operation))
                     return false;
                 dest = enumerator.Current;
             }
         }
     }
     return true;
 }
Example #2
0
        public static IEvent Paste(EventPanelViewmodelBase destination, TPasteLocation location)
        {
            IEvent dest = destination.Event;

            if (CanPaste(destination, location))
            {
                var operation = _operation;
                using (var enumerator = Clipboard.GetEnumerator())
                {
                    if (!enumerator.MoveNext())
                    {
                        return(null);
                    }
                    dest = _paste(enumerator.Current, dest, location, operation);
                    while (enumerator.MoveNext())
                    {
                        dest = _paste(enumerator.Current, dest, TPasteLocation.After, operation);
                    }
                }
            }
            if (_operation == ClipboardOperation.Cut)
            {
                Clipboard.Clear();
            }
            return(dest);
        }
Example #3
0
        public static bool CanPaste(EventPanelViewmodelBase destEventVm, TPasteLocation location)
        {
            if (destEventVm?.Event == null)
            {
                return(false);
            }
            IEventProperties dest = destEventVm.Event;
            var operation         = _operation;
            var destStartType     = dest.StartType;

            if (location != TPasteLocation.Under &&
                (destStartType == TStartType.Manual || destStartType == TStartType.OnFixedTime) &&
                Clipboard.Any(e => e.EventType != TEventType.Rundown))
            {
                return(false);
            }
            using (var enumerator = Clipboard.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    return(false);
                }
                if (!_canPaste(enumerator.Current, dest, location, operation))
                {
                    return(false);
                }
                dest = enumerator.Current;
                while (enumerator.MoveNext())
                {
                    if (!_canPaste(enumerator.Current, dest, TPasteLocation.After, operation))
                    {
                        return(false);
                    }
                    dest = enumerator.Current;
                }
            }
            return(true);
        }
        static Event _paste(Event source, Event dest, TPasteLocation location, ClipboardOperation operation)
        {
            if (operation == ClipboardOperation.Cut && source.Engine == dest.Engine)
            {
                source.Remove();
                switch (location)
                {
                    case TPasteLocation.After:
                        dest.InsertAfter(source);
                        break;
                    case TPasteLocation.Before:
                        dest.InsertBefore(source);
                        break;
                    case TPasteLocation.Under:
                        dest.InsertUnder(source);
                        break;
                }
                return source;
            }

            if (operation == ClipboardOperation.Copy && source.Engine == dest.Engine)
            {
                Event newEvent = source.Clone();
                switch (location)
                {
                    case TPasteLocation.After:
                        dest.InsertAfter(newEvent);
                        break;
                    case TPasteLocation.Before:
                        dest.InsertBefore(newEvent);
                        break;
                    case TPasteLocation.Under:
                        if (dest.EventType == TEventType.Container)
                            newEvent.ScheduledTime = DateTime.UtcNow;
                        dest.InsertUnder(newEvent);
                        break;
                }
                return newEvent;
            }
            throw new ArgumentException("Event engines are different");
        }
 private static bool _canPaste(Event sourceEvent, Event destEvent, TPasteLocation location, ClipboardOperation operation)
 {
     if (sourceEvent.Engine != destEvent.Engine)
         return false;
     if (location == TPasteLocation.Under)
     {
         if (destEvent.EventType == TEventType.StillImage)
             return false;
         if ((destEvent.EventType == TEventType.Movie || destEvent.EventType == TEventType.Live) && !(sourceEvent.EventType == TEventType.StillImage || sourceEvent.EventType == TEventType.AnimationFlash))
             return false;
         if (destEvent.EventType == TEventType.Rundown && (sourceEvent.EventType == TEventType.StillImage || sourceEvent.EventType == TEventType.AnimationFlash || destEvent.SubEvents.Count > 0))
             return false;
         if (destEvent.EventType == TEventType.Container && sourceEvent.EventType != TEventType.Rundown)
             return false;
     }
     if (location == TPasteLocation.After || location == TPasteLocation.Before)
     {
         if (!(sourceEvent.EventType == TEventType.Rundown
            || sourceEvent.EventType == TEventType.Movie
            || sourceEvent.EventType == TEventType.Live)
         ||
             !(destEvent.EventType == TEventType.Rundown
            || destEvent.EventType == TEventType.Movie
            || destEvent.EventType == TEventType.Live)
            )
             return false;
     }
     if (destEvent.IsContainedIn(sourceEvent))
     {
         if (sourceEvent == destEvent && location != TPasteLocation.Under && operation == ClipboardOperation.Copy)
             return true;
         return false;
     }
     return true;
 }
 public static void Paste(EventViewmodel destination, TPasteLocation location)
 {
     Event dest = destination.Event;
     lock(_clipboard.SyncRoot)
     {
         if (CanPaste(destination, location))
         {
             var operation = Operation;
             using (var enumerator = _clipboard.GetEnumerator())
             {
                 if (!enumerator.MoveNext())
                     return;
                 dest = _paste(enumerator.Current, dest, location, operation);
                 while (enumerator.MoveNext())
                     dest = _paste(enumerator.Current, dest, TPasteLocation.After, operation);
             }
         }
         if (Operation == ClipboardOperation.Cut)
             _clipboard.Clear();
     }
 }
Example #7
0
        private static bool _canPaste(IEventProperties source, IEventProperties dest, TPasteLocation location, ClipboardOperation operation)
        {
            var sourceEvent = source as IEvent;
            var destEvent   = dest as IEvent;

            if (source == null ||
                (operation == ClipboardOperation.Cut && (destEvent == null || sourceEvent?.Engine != destEvent.Engine)) ||
                (destEvent != null && !destEvent.HaveRight(EventRight.Create)))
            {
                return(false);
            }
            if (location == TPasteLocation.Under)
            {
                if (dest.EventType == TEventType.StillImage)
                {
                    return(false);
                }
                if ((dest.EventType == TEventType.Movie || dest.EventType == TEventType.Live) && source.EventType != TEventType.StillImage)
                {
                    return(false);
                }
                if (dest.EventType == TEventType.Rundown && (source.EventType == TEventType.StillImage || destEvent?.SubEventsCount > 0))
                {
                    return(false);
                }
                if (dest.EventType == TEventType.Container && source.EventType != TEventType.Rundown)
                {
                    return(false);
                }
            }
            if (location == TPasteLocation.After || location == TPasteLocation.Before)
            {
                if (!(source.EventType == TEventType.Rundown ||
                      source.EventType == TEventType.Movie ||
                      source.EventType == TEventType.Live)
                    ||
                    !(dest.EventType == TEventType.Rundown ||
                      dest.EventType == TEventType.Movie ||
                      dest.EventType == TEventType.Live)
                    )
                {
                    return(false);
                }
            }
            if (operation == ClipboardOperation.Cut && destEvent.IsContainedIn(sourceEvent))
            {
                return(false);
            }
            return(true);
        }
Example #8
0
        static IEvent _paste(IEventProperties source, IEvent dest, TPasteLocation location, ClipboardOperation operation)
        {
            if (operation == ClipboardOperation.Cut)
            {
                var sourceEvent = source as IEvent;
                if (sourceEvent != null)
                {
                    if (sourceEvent.Engine == dest.Engine)
                    {
                        sourceEvent.Remove();
                        switch (location)
                        {
                        case TPasteLocation.After:
                            dest.InsertAfter(sourceEvent);
                            break;

                        case TPasteLocation.Before:
                            dest.InsertBefore(sourceEvent);
                            break;

                        case TPasteLocation.Under:
                            dest.InsertUnder(sourceEvent, false);
                            break;
                        }
                        return(sourceEvent);
                    }
                    else
                    {
                        //TODO: paste from another engine
                        throw new NotImplementedException("Event engines are different");
                    }
                }
                else
                {
                    throw new InvalidOperationException($"Cannot paste from type: {source?.GetType().Name}");
                }
            }
            else //(operation == ClipboardOperation.Copy)
            {
                EventProxy sourceProxy = source as EventProxy;
                if (sourceProxy != null)
                {
                    var mediaFiles     = (dest.Engine.MediaManager.MediaDirectoryPRI ?? dest.Engine.MediaManager.MediaDirectorySEC)?.GetFiles();
                    var animationFiles = (dest.Engine.MediaManager.AnimationDirectoryPRI ?? dest.Engine.MediaManager.AnimationDirectorySEC)?.GetFiles();
                    switch (location)
                    {
                    case TPasteLocation.After:
                        return(sourceProxy.InsertAfter(dest, mediaFiles, animationFiles));

                    case TPasteLocation.Before:
                        return(sourceProxy.InsertBefore(dest, mediaFiles, animationFiles));

                    case TPasteLocation.Under:
                        var newEvent = sourceProxy.InsertUnder(dest, false, mediaFiles, animationFiles);
                        if (dest.EventType == TEventType.Container)
                        {
                            newEvent.ScheduledTime = DateTime.UtcNow;
                        }
                        return(newEvent);
                    }
                    throw new InvalidOperationException("Invalid paste location");
                }
                else
                {
                    throw new InvalidOperationException($"Cannot paste from type: {source?.GetType().Name}");
                }
            }
        }