Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
File based Queue processing
Message
De
19/11/2008 12:22:06
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
19/11/2008 12:08:56
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01362837
Message ID:
01362862
Vues:
8
>Good, robust queuing systems are very, very hard to build. Any reason you can't use MSMQ?

Now that I think about this Craig would that mean there is no file representation? It is important to me to keep the records even if the application gets shut down.
Tim

>
>
>>Hi All,
>>
>>I have an application that creates records and saves them to a file based queue for later processing. The files are saved as xml. I have a timer running in another thread that checks this queue directory for files and re-hydrates them back into a record then saves them to the database. After a successful save, they need to be deleted to prevent attempting to save them again. The problem I am having *I think* is they don't always get deleted and then cause a constraint error as they have a primary key. I could deal with this at the error level but I would like to deal with this more proactively.
>>
>>I have considered many ways to do this like populating a list (saveList) with all the filenames in the directory after checking each one against a deleteList first. Then processing the files based on the list. Once saved moving them to the delete list. After completeing the save list, I could process the delete list to delete them. I am not convinced this is the most efficient way to do this so looking for better ideas or proven ways to deal with a file based queue. You can see my basic code below; for simplification I removed the catch code and some of the event firing code, and other stuff that didn't matter.
>>Thanks
>>Tim
>>
>>
>>public void SaveDataFiles()
>>{
>>    string path = AppDesktop.QueueDataPath;
>>    string filter = "Spot_*.xml";
>>    string fileName;
>>    string xmlFile;
>>    bool llSuccess = true;
>>    bool llValid = true;
>>
>>    try
>>    {
>>        // Stop the timer while we work.
>>        if (tmrQChecker != null)
>>            this.SetTimer(tmrQChecker, Timeout.Infinite, this.QCheckInterval, null);
>>
>>        TrackSpotEntity oSpotEntity = null;
>>        while ((fileName = this.PopQueue(path, filter)) != "" && llSuccess)
>>        {
>>            xmlFile = path + @"\" + fileName;
>>
>>            oSpotEntity = null;
>>            oSpotEntity = oSpot.GetEntityFromQueue(xmlFile);
>>
>>            if (oSpotEntity != null && oSpotEntity.HasValues)
>>            {
>>                if (this.CompanyValid == AccessValidation.Valid)
>>                {
>>                    oSpotEntity.CompanyID = this._companyID;
>>                        if (this.TruckValid == AccessValidation.Valid)
>>                        {
>>                            oSpot.Entity.TruckID = this._truckID;
>>
>>                            // Attempt the save
>>                            mmSaveDataResult result = oSpot.SaveEntity(oSpotEntity);
>>
>>                            if (result == mmSaveDataResult.RulesPassed)
>>                            {
>>                                // Must have been a success
>>                                this.DeleteDataFile(xmlFile);
>>                            }
>>                            else
>>                            {
>>                                if (result == mmSaveDataResult.Exception)
>>                                {
>>                                    // Lets deal with this here
>>                                    string exProblem = oSpot.Exception.ToString();
>>                                }
>>                                llSuccess = false;
>>                                // Cancel all the changes to the entity object
>>                                oSpot.CancelEntity(oSpotEntity);
>>                                this.OnDataLoggingError("Data was not saved to Network");
>>                                break;
>>                            }
>>                     }
>>                    else
>>                    {
>>                        // Unable to validate Truck
>>                        if (TruckValid == AccessValidation.NotValid)
>>                        {
>>                            this.OnDataLoggingError("Truck Not Valid");
>>                            // Truck not valid for data transfer
>>                            llValid = false;
>>                        }
>>                    }
>>                }
>>                else
>>                {
>>                    // Unable to validate Company
>>                    if (this.CompanyValid == AccessValidation.NotValid)
>>                    {
>>                         this.OnDataLoggingError("Company Not Valid");
>>                         // Company not valid for data transfer
>>                         llValid = false;
>>                    }
>>                }
>>            }
>>            else
>>            {
>>                // The returned entity is probably null and probably because of 
>>               // a constraint problem.  We need to skip this file now.
>>               this.skipFileList.Add(fileName);
>>            }
>>        } // End of While
>>        this.OnDataLogging("Completed all Network Saves", NetworkAction.CompletedSaveToNetwork);
>>    }
>>    // Catch removed for clarity
>>    finally
>>    {
>>        if (tmrQChecker != null)
>>        {
>>            // Restart Queue Timer if Company and Truck Are Valid.
>>            if (llValid)
>>                this.SetTimer(tmrQChecker, this.QRetryInterval, this.QCheckInterval, null);
>>            else // Otherwise, dispose of the timer.
>>            {
>>                tmrQChecker.Dispose();
>>                tmrQChecker = null;
>>            }
>>        }
>>    }
>>}
>>
>>private string PopQueue(string path, string filter)
>>{
>>    string fileName = "";
>>    try
>>    {
>>        DirectoryInfo directory = new DirectoryInfo(path);
>>        FileInfo[] files = directory.GetFiles(filter);
>>        this.FilesInQueue = files.Length;
>>        if (files.Length > 0)
>>        {
>>            fileName = directory.GetFiles(filter).OrderBy(XmlReadMode => XmlReadMode.LastWriteTime).First().Name;
>>
>>            //TODO: I need to verify it isn't one of the files in the skipFileList					
>>        }
>>    }
>>    catch (DirectoryNotFoundException ex)
>>    {
>>        // Code Removed
>>    }
>>    catch (Exception ex)
>>    {
>>        // code Removed
>>    }
>>
>>    return fileName;
>>}
>>
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform