예제 #1
0
        void StartDrag(string commanderId, string[] filesToDrag)
        {
            var effect = Dispatcher.WindowElement.DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag),
                                                             DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link);

            EventSession.DragFinished(commanderId, effect == DragDropEffects.Move);
        }
예제 #2
0
        void OnDrop(int x, int y, DragDropKind dragDropKind, [MarshalAs(UnmanagedType.LPWStr)] string filesString)
        {
            EventSession.DragLeave();
            var pathes = filesString.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
            var items  = (from n in pathes
                          where Directory.Exists(n)
                          let i = new DirectoryInfo(n)
                                  select new
            {
                parent = i.Parent.FullName,
                item = Item.CreateDirectoryItem(i.Name, i.LastWriteTime, false)
            }).Concat(
                (from n in pathes
                 where File.Exists(n)
                 let i = new FileInfo(n)
                         select new
            {
                parent = i.DirectoryName,
                item = Item.CreateFileItem(i.Name, i.FullName, i.Extension, i.LastWriteTime, i.Length, false)
            })).ToArray();

            if (items.Length == 0)
            {
                return;
            }

            if (items.Any(n => string.Compare(n.parent, items[0].parent, true) != 0))
            {
                MessageBox.Show("Fehler");
                return;
            }

            EventSession.Drop(x, y, dragDropKind, items[0].parent, items.Select(n => n.item).ToArray());
        }
예제 #3
0
        void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var updateItems = services.Where(n =>
            {
                var status = n.Status;
                n.Refresh();
                return(status != n.Status);
            }).Select(n => Item.CreateServiceItem(n));

            EventSession.UpdateServiceState(id, updateItems.ToArray());
        }
예제 #4
0
        void Rename(IService service)
        {
            var result = OperationCheckResult.ServiceNotSupported;
            var item   = service.GetInput <NewName>();

            switch (item.directory)
            {
            case "Dienste":
            case "drives":
                result = OperationCheckResult.Incompatible;
                break;

            case "Favoriten":
                if (!item.makeCopy)
                {
                    result = OperationCheckResult.CopyToFavorites;
                }
                else
                {
                    result = OperationCheckResult.AlreadyExists;
                }
                break;

            default:
                var newItem = Path.Combine(item.directory, item.newName);
                if (File.Exists(newItem) || Directory.Exists(newItem))
                {
                    result = OperationCheckResult.AlreadyExists;
                }
                else
                {
                    var fo = new FileOperation(item.directory, item.makeCopy ? Api.FileFuncFlags.FO_COPY : Api.FileFuncFlags.FO_RENAME);
                    OperationRunner.Operate(() =>
                    {
                        fo.Rename(item.oldName, item.newName);
                    }, () =>
                    {
                        foreach (var id in item.idsToRefresh)
                        {
                            EventSession.Refresh(id);
                        }
                    });

                    result = OperationCheckResult.OK;
                }
                break;
            }
            service.SendResult(result);
        }
예제 #5
0
 public static void UpdateServiceState(string id, Item[] serviceItem)
 {
     try
     {
         if (!sessions.TryGetValue(id, out var session))
         {
             session      = new EventSession();
             sessions[id] = session;
         }
         session.SendUpdateServiceState(id, serviceItem);
     }
     catch (Exception e)
     {
         var test = e;
     }
 }
예제 #6
0
 public static void UpdateItems(string directory, string id, int requestNumber, Item[] items)
 {
     try
     {
         if (!sessions.TryGetValue(id, out var session))
         {
             session      = new EventSession();
             sessions[id] = session;
         }
         Interlocked.Exchange(ref session.requestNumber, requestNumber);
         ThreadPool.QueueUserWorkItem(n => session.UpdateItem(directory, id, items, requestNumber));
     }
     catch (Exception e)
     {
         var test = e;
     }
 }
예제 #7
0
 void RunOperation(IService service)
 {
     try
     {
         var operate = service.GetInput <Operate>();
         currentOperation.Operate(operate.ignoreConflicts, () =>
         {
             foreach (var id in operate.idsToRefresh)
             {
                 EventSession.Refresh(id);
             }
         });
         currentOperation = null;
     }
     catch (Exception)
     {
     }
     finally
     {
         service.SendResult(new object());
     }
 }
예제 #8
0
 void OnDragLeave()
 {
     EventSession.DragLeave();
 }
예제 #9
0
 bool OnDragOver(int x, int y)
 {
     EventSession.DragOver(x, y);
     return(true);
 }
예제 #10
0
        void GetItems(IService service)
        {
            ItemResult itemResult = null;

            try
            {
                var input = service.GetInput <GetItems>();

                if (serviceStates.TryRemove(input.Id, out var ssp))
                {
                    ssp.Dispose();
                }

                IEnumerable <Item> dirIoItems;
                switch (input.Directory)
                {
                case "drives":
                    var items = System.IO.DriveInfo.GetDrives()
                                .Where(n => n.IsReady)
                                .OrderBy(n => n.Name).Select(n => Item.CreateDriveItem(n.Name, n.VolumeLabel, n.TotalSize,
                                                                                       n.DriveType == DriveType.Network ? "images/networkdrive.png" : "images/drive.png"))
                                .Concat(new[]
                    {
                        Item.CreateDriveItem("Registry", null, 0, "images/registry.png"),
                        Item.CreateDriveItem("Dienste", null, 0, "images/service.png"),
                        Item.CreateDriveItem("History", null, 0, "images/history.png"),
                        Item.CreateDriveItem("Favoriten", null, 0, "images/favorite.png")
                    }).ToArray();
                    itemResult = new ItemResult("drives", items);
                    break;

                case "Dienste":
                    try
                    {
                        var services = ServiceController.GetServices();
                        dirIoItems = services.OrderBy(n => n.DisplayName).Select(n => Item.CreateServiceItem(n));
                        items      = Enumerable.Repeat <Item>(Item.CreateParentItem("drives"), 1).Concat(dirIoItems).ToArray();
                        itemResult = new ItemResult("Dienste", items);
                        serviceStates[input.Id] = new ServiceStateProcessor(services, input.Id);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case "Registry":
                    itemResult = new ItemResult("Registry", new Item[]
                    {
                        Item.CreateParentItem("drives"),
                        Item.CreateDriveItem("HKEY_CLASSES_ROOT", null, 0, "images/registry.png"),
                        Item.CreateDriveItem("HKEY_CURRENT_USER", null, 0, "images/registry.png"),
                        Item.CreateDriveItem("HKEY_LOCAL_MACHINE", null, 0, "images/registry.png"),
                    }.ToArray());
                    break;

                default:
                    if (input.Directory.StartsWith("HKEY_"))
                    {
                        var regType = Registry.Type.ClassesRoot;
                        if (input.Directory.StartsWith("HKEY_CLASSES_ROOT"))
                        {
                            regType = Registry.Type.ClassesRoot;
                        }
                        else if (input.Directory.StartsWith("HKEY_CURRENT_USER"))
                        {
                            regType = Registry.Type.CurrentUser;
                        }
                        else if (input.Directory.StartsWith("HKEY_LOCAL_MACHINE"))
                        {
                            regType = Registry.Type.LocalMachine;
                        }
                        items      = Registry.Current.GetItems(regType, input.Directory);
                        itemResult = new ItemResult(input.Directory, items);
                        break;
                    }
                    var di = new DirectoryInfo(input.Directory);

                    var directories = from n in di.SafeGetDirectories()
                                      let isHidden = FileAttributes.IsHidden(n.Attributes)
                                                     where showHidden ? true : !isHidden
                                                     select Item.CreateDirectoryItem(n.Name, n.LastWriteTime, isHidden);

                    var files = from n in di.SafeGetFiles()
                                let isHidden = FileAttributes.IsHidden(n.Attributes)
                                               where showHidden ? true : !isHidden
                                               select Item.CreateFileItem(n.Name, n.FullName, n.Extension, n.LastWriteTime, n.Length, isHidden);

                    dirIoItems = directories;
                    string parent = null;
                    if (di.Parent != null)
                    {
                        parent = di.Parent.FullName;
                    }
                    else
                    {
                        parent = "drives";
                    }
                    items      = Enumerable.Repeat <Item>(Item.CreateParentItem(parent), 1).Concat(dirIoItems).Concat(files).ToArray();
                    itemResult = new ItemResult(di.FullName, items);
                    EventSession.UpdateItems(input.Directory, input.Id, input.RequestNumber, items);
                    break;
                }
            }
            catch (UnauthorizedAccessException)
            {
                // TODO:
                // httpSession.SendError("Tut nich", "Tut nich", 500, "UnauthorizedAccessException");
            }
            catch (Exception)
            {
            }
            if (itemResult == null)
            {
                itemResult = new ItemResult();
            }
            service.SendResult(itemResult);
        }
예제 #11
0
 public void Initialize(IWebSocketSender sender, string token)
 {
     EventSession.GetEvents(sender);
 }