/// <summary>
        /// Unity下载资源
        /// </summary>
        /// <param name="remoteUrl"></param>
        /// <param name="localPath"></param>
        /// <param name="type"></param>
        /// <param name="result"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        IEnumerator UnityWebStartDownload(string remoteUrl, string localPath, DownloadFileType type, Action <string, string, bool, string> result, Action <string, string, ulong, float, float> progress)
        {
            UnityWebRequest request = UnityWebRequest.Get(remoteUrl);

            request.downloadHandler = new CustomDownloadHandlerFile(localPath, _bytes);
            asyncOperation          = request.SendWebRequest();

            long lastTicks = DateTime.Now.Ticks;

            while (!request.isDone)
            {
                float seconds = (DateTime.Now.Ticks - lastTicks) / 10000000.0f;
                progress.Invoke(remoteUrl, localPath, request.downloadedBytes, request.downloadProgress, seconds);
                yield return(null);
            }

            if (request.responseCode == 200L)
            {
                result.Invoke(remoteUrl, localPath, true, "File Download success and save to " + localPath);
            }
            else
            {
                result.Invoke(remoteUrl, localPath, false, request.error);
            }

            //if (request.isNetworkError || request.isHttpError)
            //    result.Invoke(remoteUrl, localPath, false, "NetworkError: " + request.isNetworkError + " \t HttpError: " + request.isHttpError);
            //else
            //    result.Invoke(remoteUrl, localPath, true, "File Download success and save to " + localPath);
        }
 public DownloadCampaignsByCampaignIdsResponse TryDownloadCampaignsByCampaignIds(
     ApiAuthentication auth,
     CampaignScope[] campaigns,
     long accountId,
     long?customerId,
     DataScope dataScope,
     BulkDownloadEntity entities,
     CompressionType compressionType   = CompressionType.Zip,
     DownloadFileType downloadFileType = DownloadFileType.Tsv,
     string formatVersion       = "4.0",
     DateTime?lastSyncTimeInUTC = null,
     DateTime?start             = null,
     DateTime?end = null)
 {
     return(MethodHelper.TryGet(DownloadCampaignsByCampaignIds, this,
                                auth,
                                campaigns,
                                accountId,
                                customerId,
                                dataScope,
                                entities,
                                compressionType,
                                downloadFileType,
                                formatVersion,
                                lastSyncTimeInUTC,
                                start,
                                end));
 }
Ejemplo n.º 3
0
        public ActionResult Download(DownloadFileType FileType)
        {
            if (FileType == DownloadFileType.CSV)
            {
                StringBuilder sb    = new StringBuilder();
                List <Role>   Roles = Web.Admin.Logic.Collections.Roles.Get();

                sb.Append("Name,Settings,Color,BackgroundColor Created, Modified\r\n");
                foreach (Role Role in Roles)
                {
                    sb.Append(String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"\r\n", Role.Name, Role.Settings, Role.BackColor, Role.ForeColor, Role.Created.ToString("dd.MM.yyyy HH:mm:ss"), Role.Modified.ToString("dd.MM.yyyy HH:mm:ss")));
                }

                ControllerContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=roles-" + DateTime.Now.ToString("dd.MM.yyyy") + ".csv");
                ControllerContext.HttpContext.Response.ContentType = "text/csv";
                ControllerContext.HttpContext.Response.BinaryWrite(System.Text.ASCIIEncoding.UTF8.GetBytes(sb.ToString()));
                ControllerContext.HttpContext.Response.Flush();

                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleDounloaded, Roles.Count));
            }
            else if (FileType == DownloadFileType.XLS)
            {
            }

            return(new EmptyResult());
        }
Ejemplo n.º 4
0
        public string GetStrollerImageFile(int id, DownloadFileType fileType)
        {
            IStrollerRetriever ret;

            switch (fileType)
            {
            default:
                return(null);

            case DownloadFileType.Zip:
                ret = new StrollerRetrieverZip();
                break;

            case DownloadFileType.Json:
                ret = new StrollerRetrieverJson();
                break;
            }

            var image = GetImage(id);

            if (image == null)
            {
                return(null);
            }

            var strollerImage = new StrollerFileInfo
            {
                CreatedAt = image.CreatedAt,
                Id        = image.Id.ToString(),
                Name      = image.Name,
                Thumbnail = image.Thumbnail
            };

            var chunks       = new List <StrollerChunkItem>();
            var chunkManager = new ChunkManager(DbOptions);

            try
            {
                foreach (var imageChunk in image.Chunks)
                {
                    var chunkRecord = chunkManager.GetChunk(imageChunk.Id);
                    if (!string.IsNullOrEmpty(chunkRecord?.Data))
                    {
                        chunks.Add(new StrollerChunkItem
                        {
                            Index = chunkRecord.Index,
                            Data  = chunkRecord.Data
                        });
                    }
                }
            }
            catch (Exception e)
            {
                throw new ApiException(e.Message, HttpStatusCode.InternalServerError);
            }

            strollerImage.Chunks = chunks;

            return(ret.GetFile(strollerImage));
        }
 public void OutputDownloadFileType(DownloadFileType valueSet)
 {
     OutputStatusMessage(string.Format("Values in {0}", valueSet.GetType()));
     foreach (var value in Enum.GetValues(typeof(DownloadFileType)))
     {
         OutputStatusMessage(value.ToString());
     }
 }
Ejemplo n.º 6
0
 public override void Reset()
 {
     Id                 = 0;
     fileUrl            = "";
     filePath           = "";
     fileType           = DownloadFileType.None;
     onScriptDownloaded = null;
     isSaved            = false;
 }
Ejemplo n.º 7
0
        public RenewableRequest(string key, string parameter = null, int order = 0, StorageClass store = StorageClass.None, DownloadFileType type = DownloadFileType.None)
        {
            this.key = key;

            this.parameter = parameter;

            this.order = order;

            this.store = store;

            this.type = type;
        }
Ejemplo n.º 8
0
    public void Download(string url, string targetPath, DownloadFileType fileType,
                         OnScriptDownloadFinishedEvent downloadedEvent = null, bool isSaved = false)
    {
        var file = PoolManager.GetInstance().Get <DownloadFileRequest>("DownloadFileRequest");

        file.Id                 = System.DateTime.Now.Millisecond;
        file.fileUrl            = url;
        file.filePath           = targetPath;
        file.fileType           = fileType;
        file.onScriptDownloaded = downloadedEvent;
        file.isSaved            = isSaved;
        _downloadFileList.Add(file);

        StartDownloadFile();
    }
Ejemplo n.º 9
0
    public void Download(string url, string targetPath, DownloadFileType fileType,
                         OnScriptDownloadFinishedEvent downloadedEvent = null, bool isSaved = false)
    {
        var file = new DownloadFileRequest();

        file.Id                 = DateTime.Now.Millisecond;
        file.fileUrl            = url;
        file.filePath           = targetPath;
        file.fileType           = fileType;
        file.onScriptDownloaded = downloadedEvent;
        file.isSaved            = isSaved;
        _downloadFileList.Add(file);

        StartDownloadFile();
    }
Ejemplo n.º 10
0
        public CsvTextFormatter(DownloadFileType fileType)
        {
            switch (fileType)
            {
            case DownloadFileType.Csv:
                separatorValue = CommaSeparator;
                break;

            case DownloadFileType.Tsv:
                separatorValue = TabSeparator;
                break;

            default:
                throw new InvalidOperationException();
            }

            this.headers = GetContentsForRow(CsvHeaders.Headers, false);
        }
Ejemplo n.º 11
0
        public CsvTextFormatter(DownloadFileType fileType)
        {
            switch (fileType)
            {
                case DownloadFileType.Csv:
                    separatorValue = CommaSeparator;
                    break;

                case DownloadFileType.Tsv:
                    separatorValue = TabSeparator;
                    break;

                default:
                    throw new InvalidOperationException();
            }

            this.headers = GetContentsForRow(CsvHeaders.Headers, false);
        }
Ejemplo n.º 12
0
            public Task(RenewableRequest request, string url, string path)
            {
                this._key = request.key;

                this._parameter = request.parameter;

                this._url = url;

                this._path = path;

                this._type = request.type;

                this._store = request.store;

                this.order = request.order;

                this.local = File.Exists(path);
            }
Ejemplo n.º 13
0
        private UnityWebRequest Request(DownloadFileType fileType, string url)
        {
            switch (fileType)
            {
            case DownloadFileType.Image:
                return(UnityWebRequestTexture.GetTexture(url));

            case DownloadFileType.Audio:
#if UNITY_EDITOR && UNITY_STANDALONE
                return(UnityWebRequest.Get(url));
#else
                return(UnityWebRequestMultimedia.GetAudioClip(url, DetectAudioType(url)));
#endif
            case DownloadFileType.Bundle:
                return(UnityWebRequestAssetBundle.GetAssetBundle(url));

            default:
                return(UnityWebRequest.Get(url));
            }
        }
Ejemplo n.º 14
0
        private Object DownloadHandler(DownloadFileType fileType, UnityWebRequest request)
        {
            switch (fileType)
            {
            case DownloadFileType.Image:
                return(DownloadHandlerTexture.GetContent(request));

            case DownloadFileType.Audio:
#if UNITY_EDITOR && UNITY_STANDALONE
                return(null);
#else
                return(DownloadHandlerAudioClip.GetContent(request));
#endif
            case DownloadFileType.Bundle:
                return(DownloadHandlerAssetBundle.GetContent(request));

            default:
                return(null);
            }
        }
        public async Task <DownloadCampaignsByCampaignIdsResponse> DownloadCampaignsByCampaignIdsAsync(
            ApiAuthentication auth,
            CampaignScope[] campaigns,
            long accountId,
            long?customerId,
            DataScope dataScope,
            BulkDownloadEntity entities,
            CompressionType compressionType   = CompressionType.Zip,
            DownloadFileType downloadFileType = DownloadFileType.Tsv,
            string formatVersion       = "4.0",
            DateTime?lastSyncTimeInUTC = null,
            DateTime?start             = null,
            DateTime?end = null)
        {
            var request = new DownloadCampaignsByCampaignIdsRequest
            {
                CustomerId                = string.Format("{0}", customerId),
                CustomerAccountId         = string.Format("{0}", accountId),
                Campaigns                 = campaigns,
                CompressionType           = compressionType,
                DataScope                 = dataScope,
                DownloadFileType          = downloadFileType,
                Entities                  = entities,
                FormatVersion             = formatVersion,
                LastSyncTimeInUTC         = lastSyncTimeInUTC,
                PerformanceStatsDateRange = BuildDateRange(start, end)
            };

            try
            {
                SetAuthHelper.SetAuth(auth, request);

                return(await Check().DownloadCampaignsByCampaignIdsAsync(request));
            }
            catch (Exception ex)
            {
                Log(new LogEventArgs(ServiceType.Bulk, "DownloadCampaignsByCampaignIdsAsync", ex.Message, new { Request = request }, ex));
            }

            return(null);
        }
Ejemplo n.º 16
0
 public BulkObjectWriter(Stream stream, DownloadFileType fileFormat)
     : this(new StreamWriter(stream, Encoding.UTF8), new BulkObjectFactory(), new CsvTextFormatter(fileFormat))
 {
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of this class with the specified file path.
        /// </summary>
        /// <param name="filePath">The path of the bulk file to write.</param>
        /// <param name="fileFormat">The bulk file format.</param>
        public BulkFileWriter(string filePath, DownloadFileType fileFormat)
            : this(new BulkObjectWriter(filePath, fileFormat))
        {

        }
Ejemplo n.º 18
0
 public BulkObjectWriter(string fileName, DownloadFileType fileFormat)
     : this(new StreamWriter(fileName, false, Encoding.UTF8), new BulkObjectFactory(), new CsvTextFormatter(fileFormat))
 {
     
 }
Ejemplo n.º 19
0
 public BulkStreamReader(Stream stream, DownloadFileType fileType)
 {
     _bulkObjectReader = new BulkObjectReader(stream, GetDelimiter(fileType));
 }
Ejemplo n.º 20
0
 private static char GetDelimiter(DownloadFileType fileType)
 {
     return(fileType == DownloadFileType.Csv ? ',' : '\t');
 }
Ejemplo n.º 21
0
 public BulkStreamReader(Stream stream, DownloadFileType fileType) : base(new BulkObjectReader(stream, fileType == DownloadFileType.Csv ? ',' : '\t'))
 {
 }
 public BulkStreamReader(string fileName, DownloadFileType fileType)
 {
     _bulkObjectReader = new BulkObjectReader(fileName, fileType == DownloadFileType.Csv ? ',' : '\t');
 }
        public ActionResult Download(DownloadFileType FileType)
        {
            if (FileType == DownloadFileType.CSV)
            {
                StringBuilder sb = new StringBuilder();
                List<Role> Roles = Web.Admin.Logic.Collections.Roles.Get();

                sb.Append("Name,Settings,Color,BackgroundColor Created, Modified\r\n");
                foreach (Role Role in Roles)
                    sb.Append(String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"\r\n", Role.Name, Role.Settings, Role.BackColor, Role.ForeColor, Role.Created.ToString("dd.MM.yyyy HH:mm:ss"), Role.Modified.ToString("dd.MM.yyyy HH:mm:ss")));

                ControllerContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=roles-" + DateTime.Now.ToString("dd.MM.yyyy") + ".csv");
                ControllerContext.HttpContext.Response.ContentType = "text/csv";
                ControllerContext.HttpContext.Response.BinaryWrite(System.Text.ASCIIEncoding.UTF8.GetBytes(sb.ToString()));
                ControllerContext.HttpContext.Response.Flush();

                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleDounloaded, Roles.Count));
            }
            else if (FileType == DownloadFileType.XLS)
            {

            }

            return new EmptyResult();
        }
        public ActionResult Download(DownloadFileType FileType)
        {
            if (FileType == DownloadFileType.CSV)
            {
                StringBuilder sb = new StringBuilder();
                List<Member> Members = Web.Admin.Logic.Collections.Members.Get();

                sb.Append("Name, Roles, Email, Password, AvatarID, AvatarImage, LastLogin, Created, Token, GeneratedBy, TokenCreated, TokenModified\r\n");
                foreach (Member Member in Members)
                {
                    MemberToken Token = MemberTokens.GetByMember(Member.MemberID);
                    string Format = "\"{0}\",\"{1}\",\"{2}\",{3},{4},{5},{6},{7},{8},{9},{10},{11}\r\n";

                    if (Token.MemberID > 0)
                    {
                        sb.Append(String.Format(Format,
                         AppSession.DemoMode ? "**** demo ****" : Member.Name,
                         Member.RolesToString,
                         AppSession.DemoMode ? "**** demo ****" : Member.Email,
                         AppSession.DemoMode ? "**** demo ****" : Member.Password,
                         (Member.Avatar != null && Member.Avatar.Length > 0 ? Member.Avatar : ""),
                         (Member.Avatar != null && Member.Avatar.Length > 0 ? GetAvatarBase64FromByteArray(Member.Avatar) : ""),
                         Member.LastLogin.ToString("dd.MM.yyyy HH:mm:ss"),
                         Member.Created.ToString("dd.MM.yyyy HH:mm:ss"),
                         Token.Token,
                         Token.GeneratedBy,
                         Token.Created.ToString("dd.MM.yyyy HH:mm:ss"),
                         Token.Modified.ToString("dd.MM.yyyy HH:mm:ss")
                         ));
                    }
                    else
                    {
                        sb.Append(String.Format(Format,
                            AppSession.DemoMode ? "**** demo ****" : Member.Name,
                            Member.RolesToString,
                            AppSession.DemoMode ? "**** demo ****" : Member.Email,
                            AppSession.DemoMode ? "**** demo ****" : Member.Password,
                            (Member.Avatar != null && Member.Avatar.Length > 0 ? Member.Avatar : ""),
                            (Member.Avatar != null && Member.Avatar.Length > 0 ? GetAvatarBase64FromByteArray(Member.Avatar) : ""),
                            Member.LastLogin.ToString("dd.MM.yyyy HH:mm:ss"),
                            Member.Created.ToString("dd.MM.yyyy HH:mm:ss"),
                            "","","",""
                            ));
                    }
                }

                ControllerContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=members-" + DateTime.Now.ToString("dd.MM.yyyy") + ".csv");
                ControllerContext.HttpContext.Response.ContentType = "text/csv";
                ControllerContext.HttpContext.Response.BinaryWrite(System.Text.ASCIIEncoding.UTF8.GetBytes(sb.ToString()));
                ControllerContext.HttpContext.Response.Flush();

                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.MemberDounloaded, Members.Count));

            }else if (FileType == DownloadFileType.XLS)
            {

            }

            return new EmptyResult();
        }
 public UnityWebRequestAsyncOperation StartDownLoad(string remoteUrl, string localPath, DownloadFileType type, Action <string, string, bool, string> result, Action <string, string, ulong, float, float> progress)
 {
     //StartCoroutine();//暂时考虑不使用协程
     StartCoroutine(UnityWebStartDownload(remoteUrl, localPath, type, result, progress));
     return(asyncOperation);
 }
Ejemplo n.º 26
0
        public ActionResult DownloadFilePlan(int id, DownloadFileType type)
        {
            var list = db.ListOfQuestionsRepository.GetById(id);
            byte[] array = null;
            string fileName = null;
            if (type == DownloadFileType.FilePlan)
            {
                array = list.PlanFileBytes;
                fileName = list.PlanFileName;
            }
            if (type == DownloadFileType.FuelMain) {
                array = list.FuelMainFile;
                fileName = list.FuelMainFileName;
            }
            if (type == DownloadFileType.FuelBacking) {
                array = list.FuelBackingFile;
                fileName = list.FuelBackingFileName;
            }
            if (type == DownloadFileType.FuelCrash) {
                array = list.FuelCrashFile;
                fileName = list.FuelCrashFileName;
            }

            return File(array, "image/jpg", fileName);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of this class with the specified file path.
 /// </summary>
 /// <param name="filePath">The path of the bulk file to write.</param>
 /// <param name="fileFormat">The bulk file format.</param>
 public BulkFileWriter(string filePath, DownloadFileType fileFormat)
     : this(new BulkObjectWriter(filePath, fileFormat))
 {
 }
 public void StartDownLoad(string remoteUrl, string localPath, DownloadFileType type, Action <string, string, bool, string> result, Action <string, string, ulong, float, float> progress)
 {
     StartCoroutine(BPDownloadResources(remoteUrl, localPath, result, progress));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of this class with the specified stream.
 /// </summary>
 /// <param name="stream">The stream to write.</param>
 /// <param name="fileFormat">The bulk file format.</param>
 public BulkFileWriter(Stream stream, DownloadFileType fileFormat)
     : this(new BulkObjectWriter(stream, fileFormat))
 {
 }
Ejemplo n.º 30
0
 public DownloadType(DownloadFileType t, string remote, string pc_dest)
 {
     type           = t;
     file2Download  = remote;
     PC_Destination = pc_dest;
 }
 public BulkFileReader CreateBulkFileReader(string bulkFilePath, ResultFileType bulkFileType, DownloadFileType bulkFileFormat)
 {
     return(new BulkFileReader(bulkFilePath, bulkFileType, bulkFileFormat));
 }
 public BulkFileReader CreateBulkFileReader(string bulkFilePath, ResultFileType bulkFileType, DownloadFileType bulkFileFormat)
 {
     return new BulkFileReader(bulkFilePath, bulkFileType, bulkFileFormat);
 }