当前位置: 首页>>代码示例>>C#>>正文


C# CommandArgs.As方法代码示例

本文整理汇总了C#中CommandArgs.As方法的典型用法代码示例。如果您正苦于以下问题:C# CommandArgs.As方法的具体用法?C# CommandArgs.As怎么用?C# CommandArgs.As使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandArgs的用法示例。


在下文中一共展示了CommandArgs.As方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<renameArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );

			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			if( vol == null )
				return new Response.ErrorResponse( "invalid target" );
			// rename this object and change first if this is directory or a file
			var dirToChange = vol.GetDirectoryByHash( pa.target );
			if( dirToChange == null )
			{
				var fileToChange = vol.GetFileByHash( pa.target );
				if( fileToChange == null )
					return new Response.ErrorResponse( "target not found" );

				var newFile = vol.RenameFile( fileToChange, pa.name );
				if( newFile == null )
					return new Response.ErrorResponse( "errRename" );
				return new Response.RenameResponse( pa.target, newFile );
			}
			else
			{
				var newDir = vol.RenameDirectory( dirToChange, pa.name );
				if( newDir == null )
					return new Response.ErrorResponse( "errRename" );
				return new Response.RenameResponse( pa.target, newDir );
			}
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:32,代码来源:RenameCommand.cs

示例2: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<parentsArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );

			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			// try to get directory for our target
			var cwd = ( vol != null ? vol.GetDirectoryByHash( pa.target ) : null );
			// if we still haven't got volume service, then something is wrong
			if( cwd == null || cwd.IsReadable.IsFalse() )
				return new Response.ErrorResponse( "target dir not found or access denied" );

			HashSet<Model.DirectoryModel> tree = new HashSet<Model.DirectoryModel>();
			tree.Add( cwd );
			var rootDir = vol.GetRootDirectory();
			// now get parent untill we reach root
			while( cwd != null && cwd.Hash != rootDir.Hash )
			{
				if( cwd.ParentHash == null )
					break;
				var parentDir = vol.GetDirectoryByHash( cwd.ParentHash );
				if( parentDir == null )
					return new Response.ErrorResponse( "error getting parent dir: not found or access denied" );
				tree.Add( parentDir );
				var subDirs = vol.GetSubdirectoriesFlat( parentDir, 0 );
				foreach( var sd in subDirs )
					tree.Add( sd );
				cwd = parentDir;
			}
			return new Response.TreeResponse( tree.ToArray() );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:34,代码来源:ParentsCommand.cs

示例3: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var ra = args.As<rmArgs>();

			if( ra.targets == null || ra.targets.Length == 0 )
				return new Response.ErrorResponse( "target(s) not specified" );

			IList<string> removeHashes = new List<string>();
			foreach( var toRemove in ra.targets )
			{
				var vol = _volumeManager.GetByHash( toRemove );
				if( vol == null )
					continue;

				var dirToRemove = vol.GetDirectoryByHash( toRemove );
				if( dirToRemove == null )
				{
					var fileToRemove = vol.GetFileByHash( toRemove );
					if( fileToRemove == null )
						continue;

					if( vol.DeleteFile( fileToRemove ) )
						removeHashes.Add( toRemove );
				}
				else
				{
					if( vol.DeleteDirectory( dirToRemove ) )
						removeHashes.Add( toRemove );
				}
			}

			return new Response.RmResponse( removeHashes.ToArray() );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:33,代码来源:RmCommand.cs

示例4: Execute

        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As<pasteArgs>();

            if (pa.targets == null || pa.targets.Length == 0)
                return new Response.ErrorResponse("source file(s) not specified");
            if (string.IsNullOrWhiteSpace(pa.dst))
                return new Response.ErrorResponse("destination directory not specified");

            var dstVol = _volumeManager.GetByHash(pa.dst);
            if (dstVol == null)
                return new Response.ErrorResponse("invalid target");
            //这是一个丑陋的兼容,这个是一个我做的烂补丁
            bool toAbsolutePath = dstVol is LocalFileSystemVolume;

            string dstPath = dstVol.DecodeHashToPath(pa.dst, toAbsolutePath);

            bool cut = pa.cut.IsTrue();
            IList<Model.ObjectModel> changedElements = new List<Model.ObjectModel>();
            IList<string> removedElements = new List<string>();
            // now copy each element
            foreach (string elemHash in pa.targets)
            {
                var vol = _volumeManager.GetByHash(elemHash);
                if (vol == null || dstVol != vol)
                    continue;
                // check if this is directory or a file
                var dirToCopy = vol.GetDirectoryByHash(elemHash);
                if (dirToCopy == null)
                {
                    var fileToCopy = vol.GetFileByHash(elemHash);
                    if (fileToCopy == null)
                        continue;

                    var copied = vol.CopyFile(fileToCopy, dstPath, cut);
                    if (copied != null)
                    {
                        changedElements.Add(copied);
                        if (cut) // if we are cutting element, then it was removed (or at least should be)
                            removedElements.Add(elemHash);
                    }
                }
                else
                {
                    var copied = vol.CopyDirectory(dirToCopy, dstPath, cut);
                    if (copied != null)
                    {
                        changedElements.Add(copied);
                        if (cut) // if we are cutting element, then it was removed (or at least should be)
                            removedElements.Add(elemHash);
                    }
                }
            }

            return new Response.PasteResponse(changedElements.ToArray(), removedElements.ToArray());
        }
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:56,代码来源:PasteCommand.cs

示例5: Execute

        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As<resizeArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
                return new Response.ErrorResponse("target not specified");

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);
            if (vol == null)
                return new Response.ErrorResponse("invalid target");

            var fileToModify = vol.GetFileByHash(pa.target);
            if (fileToModify == null)
                return new Response.ErrorResponse("invalid target");

            // check if we can generate thumbnail for this file
            if (!_imageEditorService.CanGenerateThumbnail(fileToModify.Name))
                return new Response.ErrorResponse("unsupported extension");

            //这是一个丑陋的兼容,这个是一个我做的烂补丁
            bool toAbsolutePath = vol is LocalFileSystemVolume;

            // check what operation we want to perform
            string sourceFilePath = vol.DecodeHashToPath(pa.target, toAbsolutePath);
            switch (pa.mode)
            {
                case imageEditMode.crop:
                    if (!_imageEditorService.CropImage(
                        sourceFilePath,
                        new System.Drawing.Point(pa.x ?? 0, pa.y ?? 0),
                        new System.Drawing.Size(pa.width, pa.height)))
                        return new Response.ErrorResponse("other error");
                    break;
                case imageEditMode.resize:
                    if (!_imageEditorService.ResizeImage(
                        sourceFilePath,
                        new System.Drawing.Size(pa.width, pa.height)))
                        return new Response.ErrorResponse("other error");
                    break;
                case imageEditMode.rotate:
                    if (!_imageEditorService.RotateImage(sourceFilePath, pa.degree ?? 0))
                        return new Response.ErrorResponse("other error");
                    break;
            }


            // hmm since we need to recreate the thumbnail, then we need to delete existing
            vol.DeleteThumbnailFor(fileToModify);
            // and set that thumbnail is supported
            fileToModify.Thumbnail = Model.FileModel.ThumbnailIsSupported;

            return new Response.ResizeResponse(new Model.FileModel[] { fileToModify });
        }
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:54,代码来源:ResizeCommand.cs

示例6: Execute

        public Response.IResponse Execute( CommandArgs args )
        {
            var oa = args.As<openArgs>();

            if( string.IsNullOrWhiteSpace( oa.target ) && oa.init.IsFalse() )
                return new Response.ErrorResponse( "target not specified" );

            // get volume for our target
            var vol = _volumeManager.GetByHash( oa.target );
            // try to get directory for our target
            var cwd = ( vol != null ? vol.GetDirectoryByHash( oa.target ) : null );

            if( (cwd == null || cwd.IsReadable.IsFalse() ) && oa.init.IsTrue() )
            {
                // get default volume
                vol = _volumeManager.DefaultVolume;
                if( vol != null )
                    cwd = vol.GetRootDirectory();
            }

            // if we still haven't got volume service, then something is wrong
            if( cwd == null || cwd.IsReadable.IsFalse() )
                return new Response.ErrorResponse( "target dir not found or access denied" );

            var subItems = new List<Model.ObjectModel>();

            // get sub directories
            if( oa.tree.IsTrue() )
                subItems.AddRange( vol.GetSubdirectoriesFlat( cwd ) );
            else
                subItems.AddRange( vol.GetSubdirectoriesFlat( cwd, 0 ) );

            // get files in our CWD
            subItems.AddRange( vol.GetFiles( cwd ) );

            if( oa.init.IsTrue() )
            {
                return new Response.InitDirectoryResponse( _config.ApiVersion,
                    new string[0], //TODO
                    _config.UploadMaxSize,
                    cwd,
                    subItems.ToArray(),
                    new Model.OptionsModel( vol.GetPathToRoot( cwd ), _config.BaseUrl, _config.BaseThumbsUrl ) );
            }
            else
            {
                return new Response.DirectoryResponse( cwd,
                    subItems.ToArray(),
                    new Model.OptionsModel( vol.GetPathToRoot( cwd ), _config.BaseUrl, _config.BaseThumbsUrl ) );
            }
        }
开发者ID:khushbug-optimus,项目名称:Hackathon,代码行数:51,代码来源:OpenCommand.cs

示例7: Execute

        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As<FileArgs>();

            if (string.IsNullOrWhiteSpace(pa.target))
                return new Response.ErrorResponse("target not specified");

            // get volume for our target
            var vol = _volumeManager.GetByHash(pa.target);
            if (vol == null)
                return new Response.ErrorResponse("invalid target");
            // ensure that the file is valid
            //var fileToGet = vol.GetFileByHash(pa.target);
            //if (fileToGet == null)
            //    return new Response.ErrorResponse("invalid target");

            Size size = vol.GetSize(pa.target);
            return new Response.DimResponse(size.Width, size.Height);
        }
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:19,代码来源:DimCommand.cs

示例8: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<treeArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );

			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			// try to get directory for our target
			var cwd = ( vol != null ? vol.GetDirectoryByHash( pa.target ) : null );
			// if we still haven't got volume service, then something is wrong
			if( cwd == null || cwd.IsReadable.IsFalse() )
				return new Response.ErrorResponse( "target dir not found or access denied" );

			var tree = vol.GetSubdirectoriesFlat( cwd, 0 );
			
			return new Response.TreeResponse( tree.ToArray() );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:19,代码来源:TreeCommand.cs

示例9: Execute

        public Response.IResponse Execute( CommandArgs args )
        {
            var pa = args.As<fileArgs>();

            if( string.IsNullOrWhiteSpace( pa.target ) )
                return new Response.ErrorResponse( "target not specified" );

            // get volume for our target
            var vol = _volumeManager.GetByHash( pa.target );
            if( vol == null )
                return new Response.ErrorResponse( "invalid target" );
            // ensure that the file is valid
            var fileToGet = vol.GetFileByHash( pa.target );
            if( fileToGet == null )
                return new Response.ErrorResponse( "invalid target" );
            // now get path
            string filePath = vol.DecodeHashToPath( pa.target );
            return new Response.BinaryFileResponse( filePath );
        }
开发者ID:khushbug-optimus,项目名称:Hackathon,代码行数:19,代码来源:FileCommand.cs

示例10: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<uploadArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );
			
			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			if( vol == null )
				return new Response.ErrorResponse( "invalid target" );

			if( args.Files == null || args.Files.Count == 0 )
				return new Response.ErrorResponse( "no files" );
				//return new Response.UploadResponse( new Model.FileModel[ 0 ] );
				
			var savedFiles = vol.SaveFiles( pa.target, args.Files );
			return new Response.UploadResponse( savedFiles );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:19,代码来源:UploadCommand.cs

示例11: Execute

        public Response.IResponse Execute(CommandArgs args)
        {
            var pa = args.As<tmbArgs>();

            if (pa.targets == null || pa.targets.Length == 0)
                return new Response.ErrorResponse("target(s) not specified");

            string thumbsDestPath = _config.LocalFSThumbsDirectoryPath; //TODO: this directory CAN'T be set in CONFIG!
            if (string.IsNullOrWhiteSpace(thumbsDestPath))
                return new Response.ErrorResponse("thumbs target directory not specified in config");

            Dictionary<string, string> images = new Dictionary<string, string>();
            foreach (var fileHash in pa.targets)
            {
                // get volume for our target
                var vol = _volumeManager.GetByHash(fileHash);
                if (vol == null)
                    return new Response.ErrorResponse("invalid target");
                var fileToProcess = vol.GetFileByHash(fileHash);
                if (fileToProcess == null)
                    return new Response.ErrorResponse("invalid target");

                // check if we can generate thumbnail
                if (!_imageEditorService.CanGenerateThumbnail(fileToProcess.Name))
                    continue;



                //这是一个丑陋的兼容,这个是一个我做的烂补丁
                bool toAbsolutePath = vol is LocalFileSystemVolume;

                string generatedFileName = _imageEditorService.CreateThumbnail(vol.DecodeHashToPath(fileHash, toAbsolutePath), thumbsDestPath, fileHash,
                    _config.ThumbsSize, false);
                if (generatedFileName != null)
                {
                    images.Add(fileHash, generatedFileName);
                }
            }

            return new Response.TmbResponse(images);
        }
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:41,代码来源:TmbCommand.cs

示例12: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<mkdirArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );

			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			// try to get directory for our target
			var cwd = ( vol != null ? vol.GetDirectoryByHash( pa.target ) : null );
			// if we still haven't got volume service, then something is wrong
			if( cwd == null || cwd.IsReadable.IsFalse() )
				return new Response.ErrorResponse( "target dir not found or access denied" );

			var created = vol.CreateDirectory( cwd, pa.name );
			if( created == null )
				return new Response.ErrorResponse( "errMkdir" );

			return new Response.MkdirResponse( created );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:21,代码来源:MkdirCommand.cs

示例13: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<getArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );

			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			if( vol == null )
				return new Response.ErrorResponse( "invalid target" );

			var fileToGet = vol.GetFileByHash( pa.target );
			if( fileToGet == null )
				return new Response.ErrorResponse( "invalid target" );

			var content = vol.GetTextFileContent( fileToGet );
			if( content == null )
				return new Response.ErrorResponse( "error getting file content" );
			return new Response.GetResponse( content );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:21,代码来源:GetCommand.cs

示例14: Execute

		public Response.IResponse Execute( CommandArgs args )
		{
			var pa = args.As<putArgs>();

			if( string.IsNullOrWhiteSpace( pa.target ) )
				return new Response.ErrorResponse( "target not specified" );

			// get volume for our target
			var vol = _volumeManager.GetByHash( pa.target );
			if( vol == null )
				return new Response.ErrorResponse( "invalid target" );

			var fileToModify = vol.GetFileByHash( pa.target );
			if( fileToModify == null )
				return new Response.ErrorResponse( "invalid target" );

			Model.FileModel modifiedFile = vol.SetTextFileContent( fileToModify, pa.content );
			if( modifiedFile == null )
				return new Response.ErrorResponse( "error setting file content" );
			return new Response.PutResponse( new Model.FileModel[]{ modifiedFile } );
		}
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:21,代码来源:PutCommand.cs


注:本文中的CommandArgs.As方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。