public void Initialize()
        {
            loggerMock        = new Mock <ILogger>();
            nativeMethodsMock = new Mock <INativeMethods>();

            sut = new ClipboardOperation(loggerMock.Object, nativeMethodsMock.Object);
        }
        public async Task <Guid> GenerateAccessToken(Guid operationId)
        {
            ClipboardOperation op = GetOperationFromId(operationId);

            if (op == null)
            {
                ISLogger.Write("GlobalClipboardController: Error generating access token: operation not found");
                return(Guid.Empty);
            }

            Guid id;

            if (op.Host.IsLocalhost)
            {
                id = GenerateLocalAccessTokenForOperation(op);
            }
            else
            {
                try
                {
                    id = await op.Host.RequestFileTokenAsync(op.OperationId);
                }catch (Exception ex)
                {
                    ISLogger.Write("GlobalClipboardController: Failed to get access token for operation: " + ex.Message);
                    return(Guid.Empty);
                }
            }

            op.HostFileAccessTokens.Add(id);
            return(id);
        }
        public void Initialize()
        {
            context           = new ClientContext();
            loggerMock        = new Mock <ILogger>();
            nativeMethodsMock = new Mock <INativeMethods>();

            sut = new ClipboardOperation(context, loggerMock.Object, nativeMethodsMock.Object);
        }
Esempio n. 4
0
 public static void Copy(IEnumerable <EventPanelViewmodelBase> items)
 {
     Clipboard.Clear();
     foreach (var e in items)
     {
         Clipboard.Add(EventProxy.FromEvent(e.Event));
     }
     _operation = ClipboardOperation.Copy;
     _notifyClipboardChanged();
 }
        private void SetClipboardTextOrImage(ClipboardDataBase cbData, ISServerSocket host, Guid operationId)
        {
            if (currentOperation != null && currentOperation.DataType == ClipboardDataType.File)
            {
                previousOperationDictionary.Add(currentOperation.OperationId, currentOperation);
            }

            currentOperation = new ClipboardOperation(operationId, cbData.DataType, cbData, host);
            BroadcastCurrentOperation();
        }
Esempio n. 6
0
 public static void Cut(IEnumerable <EventPanelViewmodelBase> items)
 {
     Clipboard.Clear();
     foreach (var e in items)
     {
         Clipboard.Add(e.Event);
     }
     _operation = ClipboardOperation.Cut;
     _notifyClipboardChanged();
 }
Esempio n. 7
0
 private static IScriptCommand diskClipboardOp(ClipboardOperation op, string entriesVariable = "{Entries}",
                                               string currentDirectoryVariable = "{CurrentDirectory}", string destinationVariable = "{Destination}", IScriptCommand nextCommand = null)
 {
     return(new DiskClipboard()
     {
         Operation = op,
         EntriesKey = entriesVariable,
         CurrentDirectoryEntryKey = currentDirectoryVariable,
         DestinationKey = destinationVariable, NextCommand = (ScriptCommandBase)nextCommand
     });
 }
 public static void Copy(IEnumerable<EventViewmodel> items)
 {
     lock (_clipboard.SyncRoot)
     {
         _clipboard.Clear();
         foreach (EventViewmodel e in items)
             _clipboard.Add(e.Event);
         Operation = ClipboardOperation.Copy;
         _notifyClipboardChanged();
     }
 }
 public static async Task Cut(IEnumerable <EventPanelViewmodelBase> items)
 {
     await Task.Run(() =>
     {
         Clipboard.Clear();
         foreach (var e in items)
         {
             Clipboard.Add(e.Event);
         }
         _operation = ClipboardOperation.Cut;
         _notifyClipboardChanged();
     });
 }
        private Guid GenerateLocalAccessTokenForOperation(ClipboardOperation operation)
        {
            if (operation.DataType != ClipboardDataType.File)
            {
                throw new ArgumentException("DateType must be file");
            }

            ClipboardVirtualFileData file = operation.Data as ClipboardVirtualFileData;

            Guid[]   fIds     = new Guid[file.AllFiles.Count];
            string[] fSources = new string[file.AllFiles.Count];

            for (int i = 0; i < file.AllFiles.Count; i++)
            {
                fIds[i]     = file.AllFiles[i].FileRequestId;
                fSources[i] = file.AllFiles[i].FullPath;
            }

            return(fileController.CreateFileReadTokenForGroup(new FileAccessController.FileAccessInfo(fIds, fSources), 0));
        }
        private async void SetClipboardFiles(ClipboardVirtualFileData cbFiles, ISServerSocket host, Guid operationId)
        {
            if (currentOperation != null && currentOperation.DataType == ClipboardDataType.File)
            {
                previousOperationDictionary.Add(currentOperation.OperationId, currentOperation);
            }

            currentOperation = new ClipboardOperation(operationId, cbFiles.DataType, cbFiles, host);
            if (host == ISServerSocket.Localhost)
            {
                //TODO - We can't use the same access token for clipboard operations, as more than one client can
                //be reading from the stream at the same time which will cause corruption.
                //We need to create a new access token for each client that pastes the files to create multiple stream instances
            }
            else
            {
                //Assign virtual file events, so if localhosts pastes the files then the shell can read data from the host.
                foreach (var file in cbFiles.AllFiles)
                {
                    file.ReadComplete += File_ReadComplete;
                    file.ReadDelegate  = File_RequestDataAsync;
                }

                //Create a token so that localhost can access files

                try
                {
                    currentOperation.LocalhostAccessToken = await currentOperation.Host.RequestFileTokenAsync(operationId);
                }catch (Exception ex)
                {
                    ISLogger.Write("GlobalClipboardController: Failed to get access token for clipboard content: " + ex.Message);
                    return;
                }
            }

            BroadcastCurrentOperation();
        }
Esempio n. 12
0
 public InventoryClipboard(ClipboardOperation operation, InventoryBase item)
 {
     Operation = operation;
     Item = item;
 }
Esempio n. 13
0
File: Clip.cs Progetto: imaun/farcin
 public Clip(string content, ClipboardOperation operation, DateTime when)
 {
     Content   = content;
     Operation = operation;
     When      = when;
 }
Esempio n. 14
0
        private static bool _canPaste(IEventProperties source, IEventProperties dest, PasteLocation 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 == PasteLocation.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 == PasteLocation.After || location == PasteLocation.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);
        }
Esempio n. 15
0
        static IEvent _paste(IEventProperties source, IEvent dest, PasteLocation location, ClipboardOperation operation)
        {
            if (operation == ClipboardOperation.Cut)
            {
                if (source is IEvent sourceEvent)
                {
                    if (sourceEvent.Engine == dest.Engine)
                    {
                        sourceEvent.Remove();
                        switch (location)
                        {
                        case PasteLocation.After:
                            dest.InsertAfter(sourceEvent);
                            break;

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

                        case PasteLocation.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)
            {
                if (source is EventProxy sourceProxy)
                {
                    var mediaFiles     = (dest.Engine.MediaManager.MediaDirectoryPRI ?? dest.Engine.MediaManager.MediaDirectorySEC)?.GetAllFiles();
                    var animationFiles = (dest.Engine.MediaManager.AnimationDirectoryPRI ?? dest.Engine.MediaManager.AnimationDirectorySEC)?.GetAllFiles();
                    switch (location)
                    {
                    case PasteLocation.After:
                        return(sourceProxy.InsertAfter(dest, mediaFiles, animationFiles));

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

                    case PasteLocation.Under:
                        var newEvent = sourceProxy.InsertUnder(dest, false, mediaFiles, animationFiles);
                        if (dest.EventType == TEventType.Container)
                        {
                            newEvent.ScheduledTime = EventExtensions.DefaultScheduledTime;
                        }
                        return(newEvent);
                    }
                    throw new InvalidOperationException("Invalid paste location");
                }
                else
                {
                    throw new InvalidOperationException($"Cannot paste from type: {source?.GetType().Name}");
                }
            }
        }
Esempio n. 16
0
        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");
        }
Esempio n. 17
0
 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;
 }
Esempio n. 18
0
 public InventoryClipboard(ClipboardOperation operation, InventoryBase item)
 {
     Operation = operation;
     Item      = item;
 }