Upload ProgressChanged event fires for the last uploaded file only

8 posts, 0 answers
  1. Qusai
    Qusai avatar
    4 posts
    Member since:
    Sep 2007

    Posted 20 Dec 2010 Link to this post

    Hi,

     

     

    I am working on a Silverlight application to upload documents to a SharePoint site with a custom upload handler in the backend. My issue is: I can’t capture the upload progress for all uploaded files. The “ProgressChanged” event fires for the last uploaded file only. Can yopu please review the code below and let me know if I am missing anything?


    I am using Silverlight 4 with Telerik Controls for Silverlight version 2010.2.812.1040


    Following is a snippet of the Silverlight code

     


    <
    RadInput:RadUpload
                Style="{StaticResource UploadStyle}"
                x:Name="Upload"
                Visibility="Collapsed"
                Filter="Documents (*.doc;*.xls;*.ppt;*.pdf)|*.doc;*.xls;*.ppt;*.pdf;*.docx;*.xlsx;*.pptx|All Files(*.*)|*.*"
                FilterIndex="0"
                IsAutomaticUpload="True"
                OverwriteExistingFiles="True"            
                TargetFolder=""
                IsAppendFilesEnabled="True"
                FileUploadStarting="Upload_FileUploadStarting"
                FileUploaded="Upload_FileUploaded"
                ProgressChanged="Upload_ProgressChanged"
                UploadStarted="Upload_Started"            
                BufferSize="1024000"                    
                MaxFileSize="51000000" MaxUploadSize="1010000000" FileUploadFailed="Upload_FileUploadFailed" IsMultiselect="False"
                 />


    void Upload_ProgressChanged(object sender, EventArgs e)
            {
                Action<string, int> d =
                    (name, percent) =>
                    {
                        //do something
                    };
      
                var radUpload = sender as RadUpload;
                if (radUpload != null)
                {
                    if (Dispatcher.CheckAccess())
                    {
                        d(radUpload.CurrentSession.CurrentFile.Name,
                          Convert.ToInt32(radUpload.CurrentSession.CurrentFileProgress));
                    }
                    else
                    {
                        Dispatcher.BeginInvoke(d, radUpload.CurrentSession.CurrentFile.Name,
                                               Convert.ToInt32(radUpload.CurrentSession.CurrentFileProgress));
                    }
                }
            }

    Also here is the code for the upload handler

     

    public class UploadHandler
            : RadUploadHandler
        {
            private const string paramNameSessonId = "sessionId";
            private const string paramNameFilePath = "filePath";
            private const string paramNameSessonType = "sessionType";
      
            private string fileServerUrl = string.Empty;
      
            public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLengtgh, out int savedBytes)
            {
                if (!base.SaveChunkData(filePath, position, buffer, contentLengtgh, out savedBytes))
                {
                    return false;
                }
                  
      
                if(IsFinalFileRequest())
                {
                    try
                    {
                        using (FileStream stream = File.OpenRead(filePath))
                        {
                            byte[] fullBuffer = new byte[stream.Length];
                            stream.Read(fullBuffer, 0, (int)stream.Length);
                            var name = GetFileName();
                            Core.Facade.DocLibraryFacade.AppendToFile(
                                name, 
                                Request.Form[paramNameSessonId],
                                Request.Form[paramNameSessonType],
                                fullBuffer, 0, out fileServerUrl);
                        }
                    }
                    catch (Exception exception)
                    {
                        savedBytes = 0;
                        this.AddReturnParam(RadUploadConstants.ParamNameMessage,
                                            string.Format("Cannot save the document reason why {0}",  exception));
                        return false;
                    }
                }
      
                return true;
            }
      
            public override string GetFilePath(string fileName)
            {
                return base.GetFilePath(fileName) + Request.Form[paramNameSessonId];
            }
      
            public override string TargetFolder
            {
                get
                {
                    return BoozConfig.Current.UploadHandler.TempFolderRelativePath;
                }
                set
                {
                }
            }
      
            public override string TargetPhysicalFolder
            {
                get
                {
                    return BoozConfig.Current.UploadHandler.TempFolderPhysicalPath;
                }
                set
                {
                }
            }
      
            public override Dictionary<string, object> GetAssociatedData()
            {
                return new Dictionary<string, object> {{paramNameFilePath, fileServerUrl}};
            }
        }

     

     

    Thanks

     

    Qusai

  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 21 Dec 2010 Link to this post

    Hi Qusai,

    We had a similar issue, which disappeared with the Q3 release. When uploading relatively large files and some small ones amongst them, sometimes not all of the events were raised. However, this seems to be resolved in the latest release. Is it an option for you to test this with Q3 and confirm whether this issue is still reproducible or not?

    Kind regards,
    Alex Fidanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Qusai
    Qusai avatar
    4 posts
    Member since:
    Sep 2007

    Posted 21 Dec 2010 Link to this post

    Hi Alex,

    I actually tried to upgrade to Q3 release before I posted this issue, the problem with that is in Q3 release all RadNavigation functionality, which I am using heavily in my application, have become obsolete so Performing the upgrade requires a lot of refactoring time. unfortunately my client didn't approve this time.

    If fixing the bug isn’t part of your task list anymore, can you please point me to a example where I can find a sample of upgrading RadNavigation?

     

    Thanks

     
    Qusai
  5. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 27 Dec 2010 Link to this post

    Hi Qusai,

     You can read this blog post in order to get more information on how to use the Silverlight navigation framework with transitions.
    Also note that you can use the Latest Internal Build, where you won't get any compile-time errors from using our Navigation. (You will see only warnings that the classes are marked as obsolete, instead of Error). 
    If you still have issues, please let us know.

    Greetings,
    Miro Miroslavov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  6. Qusai
    Qusai avatar
    4 posts
    Member since:
    Sep 2007

    Posted 06 Jan 2011 Link to this post

    Hi Miro,

    Thanks for the help! Just like you said the internal build doesn’t throw compile-time errors for the RadNavigation controls however when running the application I am getting an “object is not set to an instance of an object”  exception. The exception is thrown by the following statement:

     

    var frame = new MainPage();
    NavigationService service = NavigationService.GetNavigationService();
    service.Nafigate(frame); //Exception gets thrown here

    following is the stack for the exception:
    Telerik.Windows.Controls.NavigationService.PerformTransition(IFrame nextFrame)
       at Telerik.Windows.Controls.NavigationService.Navigate(IFrame frame, Boolean addToHistory)
       at Telerik.Windows.Controls.NavigationService.Navigate(IFrame frame)
       at PS.Booz.Intranet.SL.DocumentUpload.Wizard.Wizard_Loaded(Object sender, RoutedEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32

    My guess is the instantiation of the NavigationService object is missing something. Is it possible to test this scenario on your end?  
    Also any other guidance is much appreciated!
    Thanks a lot!
    Qusai

  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 11 Jan 2011 Link to this post

    Hi Qusai,

    I am unable to reproduce your issue in my environment. Could first try to use dispatcher  like so:
    Dispatcher.BeginInvoke(() => 
                     {                   
                             NavigationService service = NavigationService.GetNavigationService();
                     });
    If this doesn`t solve the issue, we would highly appreciate if you send us a runnable sample so that we can investigate in depth and provide you with a better suited solution.

    All the best,
    Petar Mladenov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  8. Qusai
    Qusai avatar
    4 posts
    Member since:
    Sep 2007

    Posted 14 Jan 2011 Link to this post

    Hi,

    First thanks a lot for your help, I really appreciate it!

    In regard to the exception I was getting after I upgraded to the new binary, the null reference was caused by the  NavigationService. NavigationService being null. I created a custom Transition object and assigned to the NavigationService object and my issue was fixed.

    No back to my original issue which is: “The “ProgressChanged” event fires for the last uploaded file only.” I am still having the same issue even with the new binary. Following is a dump for the RadUpload event:

     

    -/----FileUploaded
    -Uploaded File:101 Change Diagnostic - Copy (2).ppt | True
    -----FileUploaded
    -/----ProgressChanged
    -UploadedFilesCount:2
    -UploadedBytes:537088
    -TotalFileSize:537088
    -TotalFilesCount:1
    -Current FileProgress:100
    -Current File:101 Change Diagnostic - Copy (2).ppt
    -Current Progress:1
    -----ProgressChanged
    -/----FileUploaded
    -Uploaded File:101 Change Diagnostic - Copy.ppt | True
    -----FileUploaded
    -/----ProgressChanged
    -UploadedFilesCount:1
    -UploadedBytes:1074176
    -TotalFileSize:1074176
    -TotalFilesCount:2
    -Current FileProgress:100
    -Current File:101 Change Diagnostic - Copy (2).ppt
    -Current Progress:1
    -----ProgressChanged
    -/----ProgressChanged
    -UploadedFilesCount:1
    -UploadedBytes:486177
    -TotalFileSize:1074176
    -TotalFilesCount:2
    -Current FileProgress:90.5209202216397
    -Current File:101 Change Diagnostic - Copy (2).ppt
    -Current Progress:0.452604601108198
    -----ProgressChanged
    -/----FileUploaded
    -Uploaded File:101 Change Diagnostic.ppt | True
    -----FileUploaded
    -/----ProgressChanged
    -UploadedFilesCount:0
    -UploadedBytes:1023265
    -TotalFileSize:1611264
    -TotalFilesCount:3
    -Current FileProgress:90.5209202216397
    -Current File:101 Change Diagnostic - Copy (2).ppt
    -Current Progress:0.635069734072132
    -----ProgressChanged
    -/----FileUploadStarting
    -Uploading File:101 Change Diagnostic - Copy (2).ppt | 101 Change Diagnostic - Copy (2).ppt
    -----FileUploadStarting
    -/----FileUploadStarting
    -Uploading File:101 Change Diagnostic - Copy.ppt | 101 Change Diagnostic - Copy.ppt
    -----FileUploadStarting
    -/----FileUploadStarting
    -Uploading File:101 Change Diagnostic.ppt | 101 Change Diagnostic.ppt
    -----FileUploadStarting
    -/----FilesSelected
    -FirstFile Name: 101 Change Diagnostic.ppt
    -FileCount: 3
    -----FilesSelected

    To speed up the process I downloaded the source code for your Silverlight controls and compiled with my application. I managed to fix my issue by adding to the following code to the following classes respectively:

    [ScriptableType]
        public class UploadProgressChangedEventArgs : EventArgs
        {
      
            /// <summary>
            /// Initializes a new instance of the <see cref="FilesSelectedEventArgs"/> class.
            /// </summary>
            /// <param name="selectedFiles">The selected files.</param>
            public UploadProgressChangedEventArgs(string file, Single compelted)
            {
                this.File = file;
                this.Compelted = compelted;
            }
      
            /// <summary>
            /// Gets the selected files.
            /// </summary>
            /// <value>The selected files.</value>
            [ScriptableMember]
            public string File
            {
                get; set;
            }
      
      
            [ScriptableMember]
            public Single Compelted
            {
                get; set;
            }
        }

    public partial class RadUpload : ItemsControl 
        
    ...... 
    private void OnProgressChanged(FileUploader uploader) 
            
                if (this.ProgressChanged != null
                
                    string fileName = null
                    double fileProgress = 0d; 
                    if (uploader != null
                    
                        fileName = uploader.OriginalFileName; 
                        if (uploader.HasServerError) 
                        
                            fileProgress = 0; 
                        
                        else if (uploader.FileSize != 0 && uploader.FileSize >= uploader.StreamPosition) 
                        
                            fileProgress = uploader.StreamPosition / (double)uploader.FileSize * 100; 
                        
                    
                    else if (this.CurrentSession.CurrentFile != null
                    
                        fileProgress = this.CurrentSession.CurrentFileProgress; 
                        fileName = this.CurrentSession.CurrentFile.Name; 
                    
        
                    this.ProgressChanged(this, new UploadProgressChangedEventArgs(fileName, (float)fileProgress)); 
                
                this.UpdateProgressArea(uploader); 
            
    .... 
    }

    Now my problem is I lost the RadMaskedTextBox. It’s just not showing in the application, although it shows in design mode (in visual studio). I am suspecting that the source code is missing something. Can you please check? I am using RadControls for Silverlight Version: 2010.2 812

    Thanks again for the help!

    Qusai

     

     

  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Jan 2011 Link to this post

    Hello Qusai,

    Please inspect carefully how you have changed the original source code and how you have precompiled the dlls. This is a very had-to-reproduce issue and we cannot tell for sure what is the reason.

    Greetings,
    Petar Mladenov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top
DevCraft banner