public ActionResult UpdateForm(UploadObject objUpload)
 {
     return(Json(new ResponseInfo
     {
         ResponseMessage = $"FileUrl: {objUpload.FileUrl}<br/> ImageUrl: {objUpload.ImageUrl}"
     }));
 }
 private void HttpCallback(int objectId, string message)
 {
     if (objectId >= 0)
     {
         if (message.Contains("SUCCESS"))
         {
             loader.Data[objectId].RaiseSuccess();
         }
         else
         {
             loader.Data[objectId].RaiseFailed();
         }
         PrintTXB(message);
     }
     else if (objectId == -2)
     {
         //wird aufgerufen, wenn der Uploadthread seine Arbeit abgeschlossen hat
         UploadObject upload = loader.Data[objectId];
         PrintTXB("Erfolgreiche Uploads: " + upload.SuccessfullUploads.ToString() + " / Gescheiterte Uploads: " +
                  upload.FailedUploads.ToString());
         PrintTXB(message);
     }
     else
     {
         PrintTXB(message);
     }
 }
Exemple #3
0
        public async Task <Result <UploadObject> > ContinueUploadProgressAsync(string username, int id, string ipAddress, int failureCount)
        {
            var result = new UploadObject(Constants.NoValueDatetime, Constants.NoValueString, Constants.NoValueInt, Constants.NoValueString,
                                          Constants.NoValueInt, Constants.NoValueString, Constants.NoValueDouble, Constants.NoValueString,
                                          Constants.NoValueString, Constants.NoValueInt, Constants.NoValueInt, Constants.NoValueBool,
                                          Constants.NoValueString);

            // Escape condition for recursive call if exception is thrown.
            if (failureCount >= Constants.OperationRetry)
            {
                return(SystemUtilityService.CreateResult(Constants.UploadRetrievalFailedMessage, result, true));
            }

            try
            {
                result = await _uploadService.ContinueUploadProgressAsync(id).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                // Log exception.
                await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                               Constants.ContinueDraftOperation, username, ipAddress, ex.ToString()).ConfigureAwait(false);

                // Recursively retry the operation until the maximum amount of retries is reached.
                await ContinueUploadProgressAsync(username, id, ipAddress, ++failureCount).ConfigureAwait(false);
            }


            // Log the fact that the operation was successful.
            await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                           Constants.ContinueDraftOperation, username, ipAddress).ConfigureAwait(false);

            return(SystemUtilityService.CreateResult(Constants.UploadRetrievalSuccessMessage, result, false));
        }
Exemple #4
0
            private async Task <UploadResponse> ImportObject(UploadObject obj)
            {
                var uploadClient = new Client(new SwiftAuthManager(credentials))
                                   .SetRetryCount(2)
                                   .SetLogger(new SwiftConsoleLog());

                UploadResponse result = null;

                using (var stream = File.OpenRead(obj.Path))
                {
                    var response = await uploadClient.PutLargeObject(obj.Container, obj.Object, stream, null, null, Convert.ToInt64(ByteSize.FromMegabytes(10).Bytes));

                    if (response.IsSuccess)
                    {
                        result = new UploadResponse
                        {
                            IsSuccess = true
                        };
                    }
                    else
                    {
                        result = new UploadResponse
                        {
                            IsSuccess = false,
                            Message   = response.Reason
                        };
                    }
                }

                return(result);
            }
 public void Awake()
 {
     if (File.Exists(Application.streamingAssetsPath + "/printer.txt"))
     {
         printerName = File.ReadAllText(Application.streamingAssetsPath + "/printer.txt");
     }
     uo = new UploadObject();
     PanelInit();
 }
Exemple #6
0
        public override void Event_AddUploadedFileInfoIntoDb(IHasUploads entity, UploadObject uploadObj)
        {
            if (uploadObj.NumberOfFilesInFileList > 0)
            {
                foreach (var file in uploadObj.FileList)
                {
                    file.MetaData.Created.SetToTodaysDate(UserId, UserName);

                    file.MenuPath1   = entity as MenuPath1;
                    file.MenuPath1Id = entity.Id;

                    //add the owner of the file here....
                    entity.MiscFiles.Add(file);
                    UploadedFileBiz.Create(CreateControllerCreateEditParameter(file as ICommonWithId));
                }
            }
        }
Exemple #7
0
        private async Task <B2File> UploadLargeFile(UploadObject uploadObject, string b2Path, string contentType)
        {
            B2File file;
            ConcurrentDictionary <int, string> Sha1List = new ConcurrentDictionary <int, string>();
            List <UploadParts> uploadParts = GetUploadPartList(new FileStream(uploadObject.FileObject.FilePath, FileMode.Open,
                                                                              FileAccess.Read, FileShare.ReadWrite));

            B2File largeFile = await Client.LargeFiles.StartLargeFile(b2Path, contentType);

            await uploadParts.ForEachAsync(4, async uploadPart =>
            {
                try
                {
                    // Log.Information("Uploading | TID {0}, Count {1}",
                    //     Thread.CurrentThread.ManagedThreadId, uploadPart.PartNumber);
                    byte[] currentBytes = new byte[uploadPart.CurrentBytes];

                    FileStream currentStream = new FileStream(uploadObject.FileObject.FilePath,
                                                              FileMode.Open,
                                                              FileAccess.Read, FileShare.ReadWrite);
                    currentStream.Seek(uploadPart.LastBytes, SeekOrigin.Begin);
                    currentStream.Read(currentBytes, 0, currentBytes.Length);

                    B2UploadPartUrl uploadPartUrl =
                        await Client.LargeFiles.GetUploadPartUrl(largeFile.FileId);
                    await Client.LargeFiles.UploadPart(currentBytes, uploadPart.PartNumber,
                                                       uploadPartUrl);

                    Sha1List.TryAdd(uploadPart.PartNumber, Utils.BytesToSha1Hash(currentBytes));
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            });

            string[] sortedSha1List = new string[Sha1List.Count];
            for (int i = 0; i < Sha1List.Count; i++)
            {
                sortedSha1List[i] = Sha1List[i + 1];
            }

            file = await Client.LargeFiles.FinishLargeFile(largeFile.FileId, sortedSha1List);

            return(file);
        }
Exemple #8
0
        public async Task <IDataObject> ReadByIdAsync(int id)
        {
            // Check if the id exists in the table, and throw an argument exception if it doesn't.
            if (!await CheckUploadsExistenceAsync(new List <int>()
            {
                id
            }).ConfigureAwait(false))
            {
                throw new ArgumentException(Constants.UploadReadDNE);
            }

            // Object to return -- UploadObject
            UploadObject result;

            using (var connection = new MySqlConnection(_SQLConnection))
            {
                connection.Open();

                // Construct the sql string to get the record where the id column equals the id parameter.
                var sqlString = $"SELECT * FROM {Constants.UploadDAOTableName} WHERE {Constants.UploadDAOUploadIdColumn} = @ID;";

                using (var command = new MySqlCommand(sqlString, connection))
                    using (var dataTable = new DataTable())
                    {
                        // Add the value to the id parameter, execute the reader asynchronously, load the reader into
                        // the data table, and get the first row (the result).
                        command.Parameters.AddWithValue("@ID", id);
                        var reader = await command.ExecuteReaderAsync().ConfigureAwait(false);

                        dataTable.Load(reader);
                        DataRow row = dataTable.Rows[0];

                        // Construct the UserObject by casting the values of the columns to their proper data types.
                        result = new UploadObject((DateTime)row[Constants.UploadDAOPostTimeDateColumn], (string)row[Constants.UploadDAOUploaderColumn],
                                                  (int)row[Constants.UploadDAOStoreIdColumn], (string)row[Constants.UploadDAODescriptionColumn],
                                                  Int32.Parse((string)row[Constants.UploadDAORatingColumn]), (string)row[Constants.UploadDAOPhotoColumn],
                                                  (double)row[Constants.UploadDAOPriceColumn], (string)row[Constants.UploadDAOPriceUnitColumn],
                                                  (string)row[Constants.UploadDAOIngredientNameColumn], (int)row[Constants.UploadDAOUpvoteColumn],
                                                  (int)row[Constants.UploadDAODownvoteColumn], (((int)row[Constants.UploadDAOInProgressColumn] == Constants.InProgressStatus) ? true : false),
                                                  (string)row[Constants.UploadDAOCategoryColumn]);
                    }
            }

            return(result);
        }
        /// <summary>
        /// Übernimmt die Verarbeitung der Rückgabewerte der asynchron ausgeführten HTTP-Abfragen.
        /// Es werden keine Fortschrittsmeldungen für den Benutzer verarbeitet.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="response"></param>
        private void HttpUICallback(short method, string response, int objectId)
        {
            switch (method)
            {
            case 1:
                //GetDBVersion
                PrintTXB("Serverabfrage abgeschlossen!");
                tb_serverversion.Text = response;
                break;

            case 0:
                PrintTXB("Upload abgeschlossen!");
                UploadObject upload = loader.Data[objectId];
                PrintTXB("Erfolgreiche Uploads: " + upload.SuccessfullUploads.ToString() + " / Gescheiterte Uploads: " +
                         upload.FailedUploads.ToString());
                break;
            }
        }
Exemple #10
0
        private async Task <B2File> UploadSmallFile(UploadObject uploadObject, string b2Path, string contentType)
        {
            B2File     file;
            FileStream fileStream = new FileStream(uploadObject.FileObject.FilePath, FileMode.Open,
                                                   FileAccess.Read, FileShare.ReadWrite);
            UploadStream uploadStream = new UploadStream(fileStream);

            // uploadStream.OnProgressUpdate += UploadStreamOnProgressUpdate;

            uploadStream.Seek(0, SeekOrigin.Begin);
            file = await Client.Files.Upload(uploadStream,
                                             b2Path,
                                             await Client.Files.GetUploadUrl(),
                                             contentType, true, dontSHA : true);

            uploadStream.Close();
            fileStream.Close();
            return(file);
        }
Exemple #11
0
        internal void UpLoadFile(string fullFileName, string uploadedName, string dirName)
        {
            string fileName = uploadedName + new FileInfo(fullFileName).Extension;
            string uri      = string.Format("ftp://{0}:{1}/{2}/{3}", _ip, _port, dirName, fileName);

            _request = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(uri));
            //request.Credentials = new System.Net.NetworkCredential(sftpUsername, sftpPassword);
            _request.KeepAlive = false;
            _request.UseBinary = true;
            _request.Method    = System.Net.WebRequestMethods.Ftp.UploadFile;
            _request.UseBinary = true;
            System.IO.FileStream fs = new System.IO.FileStream(fullFileName, System.IO.FileMode.Open);
            _request.ContentLength = fs.Length;
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            System.IO.Stream stream = _request.GetRequestStream();
            UploadObject     uo     = new UploadObject {
                stream = stream, fs = fs
            };

            stream.BeginWrite(buffer, 0, buffer.Length, UploadCallBack, uo);
        }
Exemple #12
0
            private async Task<UploadResponse> ImportObject(UploadObject obj)
            {
                var uploadClient = new Client(new SwiftAuthManager(credentials))
                        .SetRetryCount(2)
                        .SetLogger(new SwiftConsoleLog());

                UploadResponse result = null;

                using (var stream = File.OpenRead(obj.Path))
                {
                    var response = await uploadClient.PutLargeObject(obj.Container, obj.Object, stream, null, null, Convert.ToInt64(ByteSize.FromMegabytes(10).Bytes));

                    if (response.IsSuccess)
                    {
                        result = new UploadResponse
                        {
                            IsSuccess = true
                        };
                    }
                    else
                    {
                        result = new UploadResponse
                        {
                            IsSuccess = false,
                            Message = response.Reason
                        };
                    }
                }

                return result;
            }
Exemple #13
0
    private void OnGUI()
    {
        if (!m_WINDOW)
        {
            Init();
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical();
        m_Place           = EditorGUILayout.TextField("Place", m_Place);
        m_Version         = EditorGUILayout.FloatField("Asset Version", m_Version, GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.8f));
        m_AssetbundleFile = EditorGUILayout.ObjectField("Upload File", m_AssetbundleFile, typeof(object), false, GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.8f));
        m_FileType        = (FILETYPE)EditorGUILayout.EnumPopup("File Type", m_FileType, GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.8f));

        m_Descript = EditorGUILayout.TextField("Descript", m_Descript, EditorStyles.textArea, GUILayout.Height(30));

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField("Thumbnail", GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.25f));
        m_ThumbnailFile = EditorGUILayout.ObjectField("", m_ThumbnailFile, typeof(Texture), false, GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.15f)) as Texture;
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Upload"))
        {
            if (m_ThumbnailFile == null || m_AssetbundleFile == null || m_Place == null)
            {
                Debug.LogError("File is empty");
                return;
            }
            string m_Filetypename = "";
            switch (m_FileType)
            {
            case FILETYPE.ASSETBUNDLE:
                m_Filetypename = ".assetbundle";
                break;

            case FILETYPE.IMAGE360:
                m_Filetypename = ".png";
                break;

            case FILETYPE.VIDEO360:
                m_Filetypename = ".mp4";
                break;
            }
            UploadObject.UploadFile(AssetDatabase.GetAssetPath(m_AssetbundleFile), m_Buckname, m_AssetbundleFile.name + m_Filetypename);
            UploadObject.UploadFile(AssetDatabase.GetAssetPath(m_ThumbnailFile), m_Buckname, m_ThumbnailFile.name + ".png");
            string tmp_Myurl = string.Format(m_Gateway + "?place={0}&type={1}&descript={2}&version={3}&assetName={4}&thumbnailName={5}",
                                             m_Place, m_FileType.ToString(), m_Descript, m_Version, m_AssetbundleFile.name + m_Filetypename, m_ThumbnailFile.name + ".png");
            Debug.Log(tmp_Myurl);
            MyThread tmp_Mythrea = new MyThread(tmp_Myurl);
            Thread   tmp_thread  = new Thread(new ThreadStart(tmp_Mythrea.CreateGetHttpResponse));
            tmp_thread.Start();
        }

        if (GUILayout.Button("Clean"))
        {
            m_Descript        = null;
            m_ThumbnailFile   = null;
            m_AssetbundleFile = null;
            m_Version         = 1;
            m_Place           = null;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginVertical("WindowBackground");
        m_ShowInfo = EditorGUILayout.Foldout(m_ShowInfo, "Upload info");
        if (m_ShowInfo)
        {
            GUILayout.Label(string.Format("AB Name:{0}", m_AssetbundleFile == null ? "Empty" : m_AssetbundleFile.name));
            GUILayout.Label(string.Format("Thumbnail Name:{0}", m_ThumbnailFile == null ? "Empty" : m_ThumbnailFile.name));
        }
        EditorGUILayout.EndVertical();
        m_WINDOW.Repaint();
    }