コード例 #1
0
        public static string downloadFile(iControl.Interfaces interfaces, string remote_file)
        {
            long   chunk_size    = 64 * 1024;
            long   file_offset   = 0;
            bool   bContinue     = true;
            string file_contents = "";

            System.IO.StringWriter sw = new System.IO.StringWriter();
            if (interfaces.initialized)
            {
                iControl.SystemConfigSyncFileTransferContext ftc = new iControl.SystemConfigSyncFileTransferContext();
                while (bContinue)
                {
                    ftc            = interfaces.SystemConfigSync.download_file(remote_file, chunk_size, ref file_offset);
                    file_contents += System.Text.ASCIIEncoding.ASCII.GetString(ftc.file_data);

                    if ((ftc.chain_type == iControl.CommonFileChainType.FILE_LAST) ||
                        (ftc.chain_type == iControl.CommonFileChainType.FILE_FIRST_AND_LAST))
                    {
                        bContinue = false;
                    }
                }
            }
            return(file_contents);
        }
コード例 #2
0
        protected override void ProcessRecord()
        {
            if (isInitialized())
            {
                try
                {
                    iControl.SystemConfigSyncFileTransferContext ctx = new iControl.SystemConfigSyncFileTransferContext();
                    bool bContinue = true;
                    ctx.chain_type = iControl.CommonFileChainType.FILE_FIRST;
                    long chunk_size  = _chunk_size;
                    long total_bytes = 0;

                    FileStream   fs = new FileStream(_file, FileMode.Open);
                    BinaryReader r  = new BinaryReader(fs);

                    while (bContinue)
                    {
                        ctx.file_data = r.ReadBytes(Convert.ToInt32(chunk_size));
                        if (ctx.file_data.Length != chunk_size)
                        {
                            // At the end.  Check to see if it is the first request also.
                            if (0 == total_bytes)
                            {
                                ctx.chain_type = iControl.CommonFileChainType.FILE_FIRST_AND_LAST;
                            }
                            else
                            {
                                ctx.chain_type = iControl.CommonFileChainType.FILE_LAST;
                            }
                            bContinue = false;
                        }
                        total_bytes += ctx.file_data.Length;

                        // Upload bytes.
                        GetiControl().SystemConfigSync.upload_configuration(_name, ctx);

                        // Move to middle
                        ctx.chain_type = iControl.CommonFileChainType.FILE_MIDDLE;

                        WriteVerbose("Uploaded " + total_bytes + " bytes");
                    }

                    r.Close();

                    WriteObject(true);
                }
                catch (Exception ex)
                {
                    handleException(ex);
                }
            }
            else
            {
                handleNotInitialized();
            }
        }
コード例 #3
0
        public static bool uploadFile(iControl.Interfaces interfaces, string remote_file_path, string file_contents)
        {
            bool bUploaded  = false;
            bool bContinue  = true;
            long chunk_size = 64 * 1024;

            iControl.SystemConfigSyncFileTransferContext ftc = new iControl.SystemConfigSyncFileTransferContext();
            ftc.chain_type = iControl.CommonFileChainType.FILE_FIRST;
            long total_bytes = 0;

            System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
            string chunk        = null;
            long   chunk_length = 0;
            long   file_length  = file_contents.Length;

            if (interfaces.initialized)
            {
                while (bContinue)
                {
                    chunk_length = chunk_size;
                    if (chunk_length > file_length - total_bytes)
                    {
                        chunk_length = file_length - total_bytes;
                    }
                    chunk = file_contents.Substring((int)total_bytes, (int)chunk_length);
                    if (chunk.Length != chunk_size)
                    {
                        if (0 == total_bytes)
                        {
                            ftc.chain_type = iControl.CommonFileChainType.FILE_FIRST_AND_LAST;
                        }
                        else
                        {
                            ftc.chain_type = iControl.CommonFileChainType.FILE_LAST;
                        }
                        bContinue = false;
                    }
                    ftc.file_data = encoding.GetBytes(chunk);
                    total_bytes  += chunk.Length;

                    // Upload bytes
                    interfaces.SystemConfigSync.upload_file(remote_file_path, ftc);
                    ftc.chain_type = iControl.CommonFileChainType.FILE_MIDDLE;
                }
            }
            bUploaded = (total_bytes > 0);

            return(bUploaded);
        }
コード例 #4
0
        public static bool uploadFile(iControl.Interfaces interfaces, string remote_file_path, string file_contents)
        {
            bool bUploaded = false;
            bool bContinue = true;
            long chunk_size = 64 * 1024;
            iControl.SystemConfigSyncFileTransferContext ftc = new iControl.SystemConfigSyncFileTransferContext();
            ftc.chain_type = iControl.CommonFileChainType.FILE_FIRST;
            long total_bytes = 0;
            System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
            string chunk = null;
            long chunk_length = 0;
            long file_length = file_contents.Length;

            if (interfaces.initialized)
            {
                while (bContinue)
                {
                    chunk_length = chunk_size;
                    if ( chunk_length > file_length-total_bytes )
                    {
                        chunk_length = file_length - total_bytes;
                    }
                    chunk = file_contents.Substring((int)total_bytes, (int)chunk_length);
                    if (chunk.Length != chunk_size)
                    {
                        if (0 == total_bytes)
                        {
                            ftc.chain_type = iControl.CommonFileChainType.FILE_FIRST_AND_LAST;
                        }
                        else
                        {
                            ftc.chain_type = iControl.CommonFileChainType.FILE_LAST;
                        }
                        bContinue = false;
                    }
                    ftc.file_data = encoding.GetBytes(chunk);
                    total_bytes += chunk.Length;

                    // Upload bytes
                    interfaces.SystemConfigSync.upload_file(remote_file_path, ftc);
                    ftc.chain_type = iControl.CommonFileChainType.FILE_MIDDLE;
                }
            }
            bUploaded = (total_bytes > 0);

            return bUploaded;
        }
コード例 #5
0
        private bool isEof(iControl.SystemConfigSyncFileTransferContext ctx)
        {
            bool bEof = true;

            if (null != ctx)
            {
                if ((ctx.chain_type == iControl.CommonFileChainType.FILE_LAST) ||
                    (ctx.chain_type == iControl.CommonFileChainType.FILE_FIRST_AND_LAST))
                {
                    bEof = true;
                }
                else
                {
                    bEof = false;
                }
            }
            return(bEof);
        }
コード例 #6
0
        public static string downloadFile(iControl.Interfaces interfaces, string remote_file)
        {
            long chunk_size = 64 * 1024;
            long file_offset = 0;
            bool bContinue = true;
            string file_contents = "";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            if (interfaces.initialized)
            {
                iControl.SystemConfigSyncFileTransferContext ftc = new iControl.SystemConfigSyncFileTransferContext();
                while (bContinue)
                {
                    ftc = interfaces.SystemConfigSync.download_file(remote_file, chunk_size, ref file_offset);
                    file_contents += System.Text.ASCIIEncoding.ASCII.GetString(ftc.file_data);

                    if ((ftc.chain_type == iControl.CommonFileChainType.FILE_LAST) ||
                         (ftc.chain_type == iControl.CommonFileChainType.FILE_FIRST_AND_LAST))
                    {
                        bContinue = false;
                    }
                }
            }
            return file_contents;
        }