Ejemplo n.º 1
0
        public override BinaryCommandInfo FindCommandInfo(IAppSession session, byte[] readBuffer, int offset, int length, bool isReusableBuffer, out int left)
        {
            NextCommandReader = this;
            left = 0;
            if (LeftBufferSize + length <= DataLength)
            {
                AddArraySegment(readBuffer, offset, length, isReusableBuffer);

                if (LeftBufferSize < DataLength)
                {
                    return(null);
                }
            }
            else
            {
                AddArraySegment(readBuffer, offset, DataLength - LeftBufferSize, false);
                left = length - (DataLength - LeftBufferSize);
            }
            NextCommandReader = PrevCommandReader;

            var cmdInfo = new BinaryCommandInfo(CommandId.ToString(), BufferSegments.ToArrayData());

            ClearBufferSegments();

            return(cmdInfo);
        }
Ejemplo n.º 2
0
        public override int PerformExecute(CommandExecutionVerb verb, PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            decimal spinnerValue = Convert.ToDecimal(currentValue.PropVariant.Value, CultureInfo.InvariantCulture);

            PerformExecuteWithArgs(verb, new ExecuteEventHandlerArgs(CommandId.ToString(), spinnerValue));
            return(HRESULT.S_OK);
        }
 public int Add(CommandId commandIdentifier, bool separatorBefore, bool separatorAfter)
 {
     MenuDefinitionEntryCommand mde = new MenuDefinitionEntryCommand();
     mde.CommandIdentifier = commandIdentifier.ToString();
     mde.SeparatorBefore = separatorBefore;
     mde.SeparatorAfter = separatorAfter;
     return Add(mde);
 }
Ejemplo n.º 4
0
 void RecentItemsCommand_ExecuteWithArgs(object sender, ExecuteEventHandlerArgs args)
 {
     selectedIndex = args.GetInt(CommandId.ToString());
     if (selectedIndex != INVALID_INDEX && selectedIndex < postInfo.Count)
     {
         WindowCascadeHelper.SetNextOpenedLocation(postEditingSite.FrameWindow.Location);
         postEditingSite.OpenLocalPost(postInfo[selectedIndex]);
     }
 }
        public int Add(CommandId commandIdentifier, bool separatorBefore, bool separatorAfter)
        {
            MenuDefinitionEntryCommand mde = new MenuDefinitionEntryCommand();

            mde.CommandIdentifier = commandIdentifier.ToString();
            mde.SeparatorBefore   = separatorBefore;
            mde.SeparatorAfter    = separatorAfter;
            return(Add(mde));
        }
Ejemplo n.º 6
0
        public override string ToString()
        {
            string ret = "";

            ret += CommandId.ToString();
            ret += "; ";
            ret += DTime;
            ret += "; ";
            return(ret);
        }
Ejemplo n.º 7
0
        void AlignmentCommand_ExecuteWithArgs(object sender, ExecuteEventHandlerArgs args)
        {
            int newSelectedIndex = args.GetInt(CommandId.ToString());

            SetSelectedItem(Items[newSelectedIndex].Cookie);

            if (AlignmentChanged != null)
            {
                AlignmentChanged(this, EventArgs.Empty);
            }
        }
        public override int PerformExecute(CommandExecutionVerb verb, PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            int index = -1;

            if ((uint)currentValue.PropVariant.Value != UI_COLLECTION_INVALIDINDEX)
            {
                index = Convert.ToInt32(currentValue.PropVariant.Value, CultureInfo.InvariantCulture);
            }

            PerformExecuteWithArgs(verb, new ExecuteEventHandlerArgs(CommandId.ToString(), index));
            return(HRESULT.S_OK);
        }
Ejemplo n.º 9
0
        protected XmlCommand(CommandId commandId, bool isSimulated)  // Request
            : this(commandId)
        {
            IsSimulated = isSimulated;

            m_Command = new XElement(Tag.Command);
            m_Doc.Add(m_Command);
            m_Command.Add(new XElement(Tag.Name, commandId.ToString()));
            m_Command.Add(new XElement(Tag.IsSimulated, isSimulated.ToString(CultureInfo.InvariantCulture)));

            m_Request = new XElement(Tag.Request);
            m_Command.Add(m_Request);
        }
Ejemplo n.º 10
0
        public Command Get(CommandId commandIdentifier)
        {
            string str;

            if (!commandIdToString.TryGetValue(commandIdentifier, out str))
            {
                str = commandIdentifier.ToString();
                commandIdToString.Add(commandIdentifier, str);
            }
            CommandInstanceManager commandInstanceManager = (CommandInstanceManager)commandTable[str];
            Command command = (commandInstanceManager == null) ? null : commandInstanceManager.ActiveCommandInstance;

            return(command);
        }
Ejemplo n.º 11
0
        protected override void OnExecute(ExecuteEventHandlerArgs args)
        {
            selectedIndex = args.GetInt(CommandId.ToString());
            if (AllowExecuteOnInvalidIndex || selectedIndex != INVALID_INDEX)
            {
                base.OnExecute(new ExecuteEventHandlerArgs(CommandId.ToString(), selectedIndex));
            }

            if (!AllowSelection)
            {
                Invalidate();
            }

            OnStateChanged(EventArgs.Empty);
        }
Ejemplo n.º 12
0
        private static RoutedUICommand EnsureCommand(CommandId commandId)
        {
            if ((commandId < 0) || ((int)commandId >= CommandsCount))
            {
                return(null);
            }
            lock (InternalCommands.SyncRoot)
            {
                if (InternalCommands[(int)commandId] == null)
                {
                    var newCommand = new RoutedUICommand(
                        GetUIText(commandId), commandId.ToString(), typeof(WindowCommands));

                    InternalCommands[(int)commandId] = newCommand;
                }
            }

            return(InternalCommands[(int)commandId]);
        }
Ejemplo n.º 13
0
        protected XmlCommand(CommandId commandId, Exception ex)
            : this(commandId)
        {
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }

            ExceptionType = ex.GetType().FullName;
            ExceptionText = ex.Message;

            m_Command = new XElement(Tag.Command);
            m_Doc.Add(m_Command);
            m_Command.Add(new XElement(Tag.Name, commandId.ToString()));

            m_Response = new XElement(Tag.Response);
            m_Command.Add(m_Response);

            XElement exceptionElement = new XElement(Tag.Exception);
            m_Response.Add(exceptionElement);
            exceptionElement.Add(new XElement(Tag.Type, ExceptionType));
            exceptionElement.Add(new XElement(Tag.Text, ExceptionText));
        }
Ejemplo n.º 14
0
        public static void CommandHandleLoop(this UsbK USB)
        {
            Array.Clear(CommandBlockBuf, 0, CommandBlockLength);
            USB.ReadPipe(ReadPipeId, CommandBlockBuf, CommandBlockLength, out int readbuf, IntPtr.Zero);
            if (readbuf == 0)
            {
                return;
            }
            if (readbuf != CommandBlockLength)
            {
                Program.Warn.LogL($"Command block read size mismatch (expected: 0x{CommandBlockLength:X}, got 0x{readbuf:X}!)");
                return;
            }
            using (var strm = new MemoryStream(CommandBlockBuf))
            {
                using (var inblock = new BinaryReader(strm))
                {
                    var inmagic = inblock.ReadUInt32();
                    if (inmagic != Command.InputMagic)
                    {
                        Program.Warn.LogL($"Input magic mismatch (expected: 0x{Command.InputMagic:X}, got 0x{inmagic:X}!)");
                        return;
                    }
                    var command = inblock.ReadUInt32();
                    if (!Enum.IsDefined(typeof(CommandId), command))
                    {
                        Program.Warn.LogL($"Invalid command Id (got {command}!)");
                        return;
                    }

                    CommandId cmd = (CommandId)command;
                    Program.Log.LogL("Received command: " + cmd.ToString());

                    var outblockbuf = new byte[CommandBlockLength];
                    var bufs        = new List <byte[]>();

                    using (var wstrm = new MemoryStream(outblockbuf))
                    {
                        using (var outblock = new BinaryWriter(wstrm))
                        {
                            bool out_written = false;

                            void WriteOutBlockBase(uint Result)
                            {
                                if (out_written)
                                {
                                    return;
                                }
                                out_written = true;
                                outblock.Write(Command.OutputMagic);
                                outblock.Write(Result);
                            }

                            switch (cmd)
                            {
                            case CommandId.GetDriveCount:
                            {
                                var drives = DriveInfo.GetDrives().Where(drive => drive.IsReady).ToList();
                                LastDrives = drives;
                                WriteOutBlockBase(Command.ResultSuccess);
                                outblock.Write((uint)drives.Count);
                                break;
                            }

                            case CommandId.GetDriveInfo:
                            {
                                var driveidx = inblock.ReadUInt32();
                                var drives   = LastDrives;
                                if (LastDrives == null)
                                {
                                    drives     = DriveInfo.GetDrives().Where(drive => drive.IsReady).ToList();
                                    LastDrives = drives;
                                }
                                if (driveidx >= drives.Count)
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                else
                                {
                                    var drive = drives[(int)driveidx];
                                    WriteOutBlockBase(Command.ResultSuccess);
                                    string label  = drive.VolumeLabel;
                                    string prefix = drive.Name.Substring(0, 1);
                                    if (string.IsNullOrEmpty(label) || label.IsUnicode())
                                    {
                                        label = prefix;
                                    }
                                    outblock.WriteStringEx(label);
                                    outblock.WriteStringEx(prefix);
                                    outblock.Write((uint)drive.TotalFreeSpace);
                                    outblock.Write((uint)drive.TotalSize);
                                }
                                break;
                            }

                            case CommandId.StatPath:
                            {
                                var   path     = inblock.ReadStringEx().NormalizeAsPath();
                                uint  type     = 0;
                                ulong filesize = 0;
                                if (File.Exists(path))
                                {
                                    type     = 1;
                                    filesize = (ulong)new FileInfo(path).Length;
                                }
                                else if (Directory.Exists(path))
                                {
                                    type = 2;
                                }
                                else
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                    break;
                                }
                                WriteOutBlockBase(Command.ResultSuccess);
                                outblock.Write(type);
                                outblock.Write(filesize);
                                break;
                            }

                            case CommandId.GetFileCount:
                            {
                                var path = inblock.ReadStringEx().NormalizeAsPath();
                                if (Directory.Exists(path))
                                {
                                    if ((LastFilesPath != path) || (LastFiles == null))
                                    {
                                        LastFilesPath = path;
                                        LastFiles     = Directory.GetFiles(path);
                                    }
                                    uint count = (uint)LastFiles.Length;
                                    WriteOutBlockBase(Command.ResultSuccess);
                                    outblock.Write(count);
                                }
                                else
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                break;
                            }

                            case CommandId.GetFile:
                            {
                                var path    = inblock.ReadStringEx().NormalizeAsPath();
                                var fileidx = inblock.ReadUInt32();
                                if (Directory.Exists(path))
                                {
                                    if ((LastFilesPath != path) || (LastFiles == null))
                                    {
                                        LastFilesPath = path;
                                        LastFiles     = Directory.GetFiles(path);
                                    }

                                    if (fileidx >= LastFiles.Length)
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    else
                                    {
                                        var filename = Path.GetFileName(LastFiles[fileidx]);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                        outblock.WriteStringEx(filename);
                                    }
                                }
                                else
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                break;
                            }

                            case CommandId.GetDirectoryCount:
                            {
                                var path = inblock.ReadStringEx().NormalizeAsPath();
                                if (Directory.Exists(path))
                                {
                                    if ((LastDirectoriesPath != path) || (LastDirectories == null))
                                    {
                                        LastDirectoriesPath = path;
                                        LastDirectories     = Directory.GetDirectories(path);
                                    }

                                    uint count = (uint)LastDirectories.Length;
                                    WriteOutBlockBase(Command.ResultSuccess);
                                    outblock.Write(count);
                                }
                                else
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                break;
                            }

                            case CommandId.GetDirectory:
                            {
                                var path   = inblock.ReadStringEx().NormalizeAsPath();
                                var diridx = inblock.ReadUInt32();
                                if (Directory.Exists(path))
                                {
                                    if ((LastDirectoriesPath != path) || (LastDirectories == null))
                                    {
                                        LastDirectoriesPath = path;
                                        LastDirectories     = Directory.GetDirectories(path);
                                    }

                                    if (diridx >= LastDirectories.Length)
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    else
                                    {
                                        var dirname = Path.GetFileName(LastDirectories[diridx]);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                        outblock.WriteStringEx(dirname);
                                    }
                                }
                                else
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                break;
                            }

                            case CommandId.ReadFile:
                            {
                                var path   = inblock.ReadStringEx().NormalizeAsPath();
                                var offset = inblock.ReadUInt64();
                                var size   = inblock.ReadUInt64();
                                try
                                {
                                    if (string.IsNullOrEmpty(LastRFile) || (LastRFile != path))
                                    {
                                        if (LastReadFile != null)
                                        {
                                            LastReadFile.Close();
                                            LastReadFile = null;
                                        }
                                        LastRFile    = path;
                                        LastReadFile = new BinaryReader(new FileStream(LastRFile, FileMode.Open, FileAccess.Read));
                                    }
                                    LastReadFile.BaseStream.Seek((long)offset, SeekOrigin.Begin);
                                    byte[] data   = new byte[size];
                                    var    rbytes = LastReadFile.Read(data, 0, (int)size);
                                    if (rbytes > 0)
                                    {
                                        WriteOutBlockBase(Command.ResultSuccess);
                                        outblock.Write((ulong)rbytes);
                                        bufs.Add(data);
                                    }
                                }
                                catch
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                    break;
                                }
                                break;
                            }

                            case CommandId.WriteFile:
                            {
                                var path = inblock.ReadStringEx().NormalizeAsPath();
                                var size = inblock.ReadUInt64();
                                var data = USB.ReadBuffer(size);
                                try
                                {
                                    if (string.IsNullOrEmpty(LastWFile) || (LastWFile != path))
                                    {
                                        if (LastWriteFile != null)
                                        {
                                            LastWriteFile.Close();
                                            LastWriteFile = null;
                                        }
                                        LastWFile     = path;
                                        LastWriteFile = new FileStream(path, FileMode.Append, FileAccess.Write);
                                    }
                                    LastWriteFile.Write(data, 0, (int)size);
                                    WriteOutBlockBase(Command.ResultSuccess);
                                }
                                catch
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                    break;
                                }
                                break;
                            }

                            case CommandId.Create:
                            {
                                var type = inblock.ReadUInt32();
                                var path = inblock.ReadStringEx().NormalizeAsPath();
                                switch (type)
                                {
                                case 1:
                                {
                                    try
                                    {
                                        File.Create(path);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                    }
                                    catch
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    break;
                                }

                                case 2:
                                {
                                    try
                                    {
                                        Directory.CreateDirectory(path);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                    }
                                    catch
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    break;
                                }

                                default:
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                    break;
                                }
                                }
                                break;
                            }

                            case CommandId.Delete:
                            {
                                var type = inblock.ReadUInt32();
                                var path = inblock.ReadStringEx().NormalizeAsPath();
                                switch (type)
                                {
                                case 1:
                                {
                                    try
                                    {
                                        File.Delete(path);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                    }
                                    catch
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    break;
                                }

                                case 2:
                                {
                                    try
                                    {
                                        Directory.Delete(path, true);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                    }
                                    catch
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    break;
                                }

                                default:
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                    break;
                                }
                                }
                                break;
                            }

                            case CommandId.Rename:
                            {
                                var type    = inblock.ReadUInt32();
                                var path    = inblock.ReadStringEx().NormalizeAsPath();
                                var pathnew = inblock.ReadStringEx().NormalizeAsPath();
                                switch (type)
                                {
                                case 1:
                                {
                                    try
                                    {
                                        Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(path, pathnew);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                    }
                                    catch
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    break;
                                }

                                case 2:
                                {
                                    try
                                    {
                                        Microsoft.VisualBasic.FileIO.FileSystem.RenameDirectory(path, pathnew);
                                        WriteOutBlockBase(Command.ResultSuccess);
                                    }
                                    catch
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                    break;
                                }

                                default:
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                    break;
                                }
                                }
                                break;
                            }

                            case CommandId.GetSpecialPathCount:
                            {
                                WriteOutBlockBase(Command.ResultSuccess);
                                outblock.Write((uint)SpecialPathList.Count);
                                break;
                            }

                            case CommandId.GetSpecialPath:
                            {
                                var spathidx = inblock.ReadUInt32();
                                if (spathidx >= SpecialPathList.Count)
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                else
                                {
                                    var spath = SpecialPathList.ElementAt((int)spathidx);
                                    var path  = Environment.GetFolderPath(spath.Value).NormalizeAsGoldleafPath();
                                    WriteOutBlockBase(Command.ResultSuccess);
                                    outblock.WriteStringEx(spath.Key);
                                    outblock.WriteStringEx(path);
                                }
                                break;
                            }

                            case CommandId.SelectFile:
                            {
                                try
                                {
                                    var openfd = new OpenFileDialog
                                    {
                                        Filter      = "Any file (*.*)|*.*",
                                        Title       = "Select file for Goldleaf",
                                        Multiselect = false
                                    };
                                    if (openfd.ShowDialog() == DialogResult.OK)
                                    {
                                        WriteOutBlockBase(Command.ResultSuccess);
                                        var path = openfd.FileName.NormalizeAsGoldleafPath();
                                        outblock.WriteStringEx(path);
                                    }
                                    else
                                    {
                                        WriteOutBlockBase(Command.ResultInvalidInput);
                                    }
                                }
                                catch
                                {
                                    WriteOutBlockBase(Command.ResultInvalidInput);
                                }
                                break;
                            }
                            }
                        }
                    }

                    USB.WritePipe(WritePipeId, outblockbuf, CommandBlockLength, out int writtenbuf, IntPtr.Zero);

                    if (bufs.Any())
                    {
                        foreach (var buf in bufs)
                        {
                            USB.WriteBuffer(buf);
                        }
                    }

                    if (writtenbuf != CommandBlockLength)
                    {
                        Program.Command.LogL($"Command block write size mismatch (expected: 0x{CommandBlockLength:X}, got 0x{writtenbuf:X}!)");
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public Command Get(CommandId commandIdentifier)
 {
     string str;
     if (!commandIdToString.TryGetValue(commandIdentifier, out str))
     {
         str = commandIdentifier.ToString();
         commandIdToString.Add(commandIdentifier, str);
     }
     CommandInstanceManager commandInstanceManager = (CommandInstanceManager)commandTable[str];
     Command command = (commandInstanceManager == null) ? null : commandInstanceManager.ActiveCommandInstance;
     return command;
 }
Ejemplo n.º 16
0
 public override string ToString() =>
 $"At [{Timestamp:O}], task type [{TypeOfTask.ToString()}] associated " +
 $"with command [{CommandId.ToString()}] started with unique id: [{TaskId.ToString()}]";
Ejemplo n.º 17
0
 private void Queue(CommandId commandId, params object[] args)
 {
     Call(commandId.ToString(), args);
 }
Ejemplo n.º 18
0
 public Command(CommandId commandId)
 {
     UpdateInvalidationState(PropertyKeys.Enabled, InvalidationState.Pending);
     this.Identifier = commandId.ToString();
     this.CommandId = commandId;
     InitializeImageLoaders();
     LoadResources();
 }
Ejemplo n.º 19
0
 public override string ToString()
 {
     return(CommandName + ", " + RibbonClassName + ", " + CommandId.ToString());
 }
Ejemplo n.º 20
0
 public override XElement ToXML()
 {
     return(new XElement("event", new XAttribute("type", "CommandEvent"),
                         new XElement("commandID", CommandId.ToString()),
                         new XElement("dataItemIndex", DataItemIndex)));
 }
Ejemplo n.º 21
0
 private static string GetUIText(CommandId commandId)
 {
     return(commandId.ToString());
 }
Ejemplo n.º 22
0
 private static string GetCommandName(CommandId commandId)
 {
     return(commandId.ToString());
 }