Example #1
0
        public static StackHashCabCollection GetCabInfoApi(ref Login login, Event theEvent)
        {
            CabCollection cabs = theEvent.GetCabs(ref login);

            StackHashCabCollection apiStackHashCabs = new StackHashCabCollection();

            foreach (Cab cab in cabs)
            {
                StackHashCab stackHashCab = ObjectConversion.ConvertCab(cab);
                apiStackHashCabs.Add(stackHashCab);
            }
            return(apiStackHashCabs);
        }
Example #2
0
        private void UpdateCabs(DateTime lastPullDate, IErrorIndex errorIndex,
                                StackHashProduct stackHashProduct, Event dpEvent, StackHashFile stackHashFile, StackHashEvent stackHashEvent)
        {
            // Get the cabs for the event.
            CabCollection cabs = dpEvent.GetCabs(ref m_Login);

            // Work out how many cabs should be downloaded.
//            int cabsDownloaded = errorIndex.GetCabCount(stackHashProduct, stackHashFile, stackHashEvent);
//            int maxCabsToDownload = m_ProductsToSynchronize.GetMaxCabs(stackHashProduct.Id);

            // Loop through the cab collection
            foreach (Cab cab in cabs)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                // Disabled till beta 5.
//                if (cabsDownloaded >= maxCabsToDownload)
//                    break;

                StackHashCab stackHashCab = ObjectConversion.ConvertCab(cab);

                m_SyncProgress.EventId = stackHashEvent.Id;

                String cabFileName = errorIndex.GetCabFileName(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab);

                // Add the cab if not already in the database.
                if (!errorIndex.CabExists(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab) ||
                    !File.Exists(cabFileName))
                {
                    if (cab.DateModifiedLocal <= lastPullDate)
                    {
                        // This shouldn't happen so log it.
                        DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Cab date older than last pull date but didn't exist in database - adding anyway: " + cab.ID.ToString(CultureInfo.InvariantCulture));
                    }

                    // Save the cab to a folder.
                    string cabFolder = errorIndex.GetCabFolder(stackHashProduct, stackHashFile,
                                                               stackHashEvent, stackHashCab);

                    if (!Directory.Exists(cabFolder))
                    {
                        Directory.CreateDirectory(cabFolder);
                    }


                    int retryCount = 0;

                    do
                    {
                        cab.SaveCab(cabFolder, false, ref m_Login);

                        retryCount++;

                        if (File.Exists(cabFileName))
                        {
                            FileInfo fileInfo = new FileInfo(cabFileName);

                            if (fileInfo.Length != cab.SizeInBytes)
                            {
                                // File was only partially downloaded so delete it and retry.
                                File.Delete(cabFileName);
                            }
                            else
                            {
                                // All appears ok so add the cab to the database.
                                errorIndex.AddCab(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab, false);

                                // Done.
                                break;
                            }
                        }
                    } while (retryCount < s_TotalCabDownloadRetries);
                }
            }
        }