>>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; >>} >>