Beispiel #1
0
        public Region( StatLog statLog,  CacheManager cacheManager)
            : base(0, 0, 0, 0)
        {
            // Store the statLog
            _statLog = statLog;

            // Store the cache manager
            // TODO: What happens if the cachemanger changes during the lifecycle of this region?
            _cacheManager = cacheManager;

            //default options
            options.Width = 1024;
            options.Height = 768;
            options.Left = 0;
            options.Top = 0;
            options.Uri = null;

            this.Size = new Size(options.Width, options.Height);

            this.Location = new Point(options.Left, options.Top);



              this.Background = new SolidColorBrush(Colors.Red);

            if (Settings.Default.DoubleBuffering)
            {
                //   SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                //      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            }

            // Create a new BlackList for us to use
            blackList = new BlackList();
        }
Beispiel #2
0
        public Region(StatLog statLog, CacheManager cacheManager)
            : base(0, 0, 0, 0)
        {
            // Store the statLog
            _statLog = statLog;

            // Store the cache manager
            // TODO: What happens if the cachemanger changes during the lifecycle of this region?
            _cacheManager = cacheManager;

            //default options
            options.Width  = 1024;
            options.Height = 768;
            options.Left   = 0;
            options.Top    = 0;
            options.Uri    = null;

            this.Size = new Size(options.Width, options.Height);

            this.Location = new Point(options.Left, options.Top);



            this.Background = new SolidColorBrush(Colors.Red);

            if (Settings.Default.DoubleBuffering)
            {
                //   SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                //      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            }

            // Create a new BlackList for us to use
            blackList = new BlackList();
        }
Beispiel #3
0
 public Region(StatLog statLog, CacheManager cacheManager) : base(0, 0, 0, 0)
 {
     this.currentSequence = -1;
     this._statLog = statLog;
     this._cacheManager = cacheManager;
     this.options.Width = 0x400;
     this.options.Height = 0x300;
     this.options.Left = 0;
     this.options.Top = 0;
     this.options.Uri = null;
     this.Size = new System.Windows.Size((double) this.options.Width, (double) this.options.Height);
     this.Location = new Point((double) this.options.Left, (double) this.options.Top);
     base.Background = new SolidColorBrush(Colors.Transparent);
     bool doubleBuffering = Settings.Default.DoubleBuffering;
     this.blackList = new BlackList();
 }
Beispiel #4
0
        public Region(StatLog statLog, CacheManager cacheManager) : base(0, 0, 0, 0)
        {
            this.currentSequence = -1;
            this._statLog        = statLog;
            this._cacheManager   = cacheManager;
            this.options.Width   = 0x400;
            this.options.Height  = 0x300;
            this.options.Left    = 0;
            this.options.Top     = 0;
            this.options.Uri     = null;
            this.Size            = new System.Windows.Size((double)this.options.Width, (double)this.options.Height);
            this.Location        = new Point((double)this.options.Left, (double)this.options.Top);
            base.Background      = new SolidColorBrush(Colors.Transparent);
            bool doubleBuffering = Settings.Default.DoubleBuffering;

            this.blackList = new BlackList();
        }
Beispiel #5
0
        /// <summary>
        /// Compares the xml file list with the files currently in the library
        /// Downloads any missing files
        /// For file types of Layout will fire a LayoutChanged event, giving the filename of the layout changed
        /// </summary>
        public void CompareAndCollect()
        {

            var fileForComparison = new List<RequiredFileModel>((IEnumerable<RequiredFileModel>)_requiredFiles.Files);
            //Inspect each file we have here
            foreach (var file in fileForComparison)
            {

                RequiredFileModel fileList = new RequiredFileModel();

                string path = file.Path;
                if (file.FileType == "layout")
                {
                    // Layout

                    // Does this file exist?
                    if (File.Exists(Settings.Default.LibraryPath + @"\" + path))
                    {
                        // Calculate a MD5 for the current file
                        String md5 = _cacheManager.GetMD5(path);

                        System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5));

                        // Now we have the md5, compare it to the md5 in the xml
                        if (file.MD5 != md5)
                        {
                            // They are different
                            _cacheManager.Remove(path);

                            //TODO: This might be bad! Delete the old layout as it is wrong
                            try
                            {
                                File.Delete(Settings.Default.LibraryPath + @"\" + path);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message));
                            }

                            // Get the file and save it
                            fileList.ChunkOffset = 0;
                            fileList.ChunkSize = 0;
                            fileList.Complete = false;
                            fileList.Downloading = false;
                            fileList.Path = path;
                            fileList.FileType = "layout";
                            fileList.MD5 = file.MD5;
                            fileList.Retrys = 0;

                            _files.Add(fileList);
                        }
                        else
                        {
                            // The MD5 of the current file and the MD5 in RequiredFiles are the same.
                            // Therefore make sure this MD5 is in the CacheManager
                            _cacheManager.Add(path, md5);

                            _requiredFiles.MarkComplete(path, md5);
                        }
                    }
                    else
                    {
                        // No - get the file and save it (no chunks)
                        fileList.ChunkOffset = 0;
                        fileList.ChunkSize = 0;
                        fileList.Complete = false;
                        fileList.Downloading = false;
                        fileList.Path = path;
                        fileList.FileType = "layout";
                        fileList.MD5 = file.MD5;
                        fileList.Retrys = 0;

                        _files.Add(fileList);
                    }
                }
                else if (file.FileType == "media")
                {
                    // Media

                    // Does this media exist?
                 
                    if (File.Exists(Settings.Default.LibraryPath + @"\" + path))
                    {
                        String md5 = _cacheManager.GetMD5(path);

                        System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5));

                        // MD5 the file to make sure it is the same.
                        if (md5 != file.MD5)
                        {
                            // File changed
                            _cacheManager.Remove(path);

                            // Delete the old media as it is wrong
                            try
                            {
                                File.Delete(Settings.Default.LibraryPath + @"\" + path);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message));
                            }

                            // Add to queue
                            fileList.ChunkOffset = 0;
                            fileList.ChunkSize = DefaultChunkSize;
                            fileList.Complete = false;
                            fileList.Downloading = false;
                            fileList.Path = path;
                            fileList.FileType = "media";
                            fileList.Size = file.Size;
                            fileList.MD5 = file.MD5;
                            fileList.Retrys = 0;

                            _files.Add(fileList);
                        }
                        else
                        {
                            // The MD5 of the current file and the MD5 in RequiredFiles are the same.
                            // Therefore make sure this MD5 is in the CacheManager
                            _cacheManager.Add(path, md5);

                            //string[] filePart = path.Split('.');
                            _requiredFiles.MarkComplete(path, md5);
                        }
                    }
                    else
                    {
                        // No - Get it (async call - with chunks... through another class?)
                        fileList.ChunkOffset = 0;
                        fileList.ChunkSize = DefaultChunkSize;
                        fileList.Complete = false;
                        fileList.Downloading = false;
                        fileList.Path = path;
                        fileList.FileType = "media";
                        fileList.Size = file.Size;
                        fileList.MD5 = file.MD5;
                        fileList.Retrys = 0;

                        _files.Add(fileList);
                    }
                }
                else if (file.FileType == "blacklist")
                {
                    // Expect <file type="blacklist"><file id="" /></file>
                    var items = (List<string>)file.Other;

                    BlackList blackList = new BlackList();

                    try
                    {
                        blackList.Truncate();
                    }
                    catch { }

                    if (items.Count > 0)
                    {
                        blackList.Add(items);

                        blackList.Dispose();
                        blackList = null;
                    }

                    items = null;
                }
                else
                {
                    //Ignore node
                }
            }

            Debug.WriteLine(String.Format("There are {0} files to get", _files.Count.ToString()));

            // Output a list of the files we need to get
            string debugMessage = "";

            foreach (RequiredFileModel fileToGet in _files)
                debugMessage += string.Format("File: {0}, Type: {1}, MD5: {2}. ", fileToGet.Path, fileToGet.FileType, fileToGet.MD5);

            Debug.WriteLine(debugMessage);

            // Report the files files back to XMDS
            _requiredFiles.ReportInventory();

            // Write Required Files
            _requiredFiles.WriteRequiredFiles();

            // Is there anything to get?
            if (_files.Count == 0)
            {
                CollectionComplete();
                return;
            }

            // Start with the first file
            _currentFile = 0;

            // Preload the first filelist
            _currentFileList = _files[_currentFile];

            // Get the first file
            GetFile();
        }
Beispiel #6
0
        /// <summary>
        /// Compares the xml file list with the files currently in the library
        /// Downloads any missing files
        /// For file types of Layout will fire a LayoutChanged event, giving the filename of the layout changed
        /// </summary>
        public void CompareAndCollect()
        {
            var fileForComparison = new List <RequiredFileModel>((IEnumerable <RequiredFileModel>)_requiredFiles.Files);

            //Inspect each file we have here
            foreach (var file in fileForComparison)
            {
                RequiredFileModel fileList = new RequiredFileModel();

                string path = file.Path;
                if (file.FileType == "layout")
                {
                    // Layout

                    // Does this file exist?
                    if (File.Exists(Settings.Default.LibraryPath + @"\" + path))
                    {
                        // Calculate a MD5 for the current file
                        String md5 = _cacheManager.GetMD5(path);

                        System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5));

                        // Now we have the md5, compare it to the md5 in the xml
                        if (file.MD5 != md5)
                        {
                            // They are different
                            _cacheManager.Remove(path);

                            //TODO: This might be bad! Delete the old layout as it is wrong
                            try
                            {
                                File.Delete(Settings.Default.LibraryPath + @"\" + path);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message));
                            }

                            // Get the file and save it
                            fileList.ChunkOffset = 0;
                            fileList.ChunkSize   = 0;
                            fileList.Complete    = false;
                            fileList.Downloading = false;
                            fileList.Path        = path;
                            fileList.FileType    = "layout";
                            fileList.MD5         = file.MD5;
                            fileList.Retrys      = 0;

                            _files.Add(fileList);
                        }
                        else
                        {
                            // The MD5 of the current file and the MD5 in RequiredFiles are the same.
                            // Therefore make sure this MD5 is in the CacheManager
                            _cacheManager.Add(path, md5);

                            _requiredFiles.MarkComplete(path, md5);
                        }
                    }
                    else
                    {
                        // No - get the file and save it (no chunks)
                        fileList.ChunkOffset = 0;
                        fileList.ChunkSize   = 0;
                        fileList.Complete    = false;
                        fileList.Downloading = false;
                        fileList.Path        = path;
                        fileList.FileType    = "layout";
                        fileList.MD5         = file.MD5;
                        fileList.Retrys      = 0;

                        _files.Add(fileList);
                    }
                }
                else if (file.FileType == "media")
                {
                    // Media

                    // Does this media exist?

                    if (File.Exists(Settings.Default.LibraryPath + @"\" + path))
                    {
                        String md5 = _cacheManager.GetMD5(path);

                        System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5));

                        // MD5 the file to make sure it is the same.
                        if (md5 != file.MD5)
                        {
                            // File changed
                            _cacheManager.Remove(path);

                            // Delete the old media as it is wrong
                            try
                            {
                                File.Delete(Settings.Default.LibraryPath + @"\" + path);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message));
                            }

                            // Add to queue
                            fileList.ChunkOffset = 0;
                            fileList.ChunkSize   = DefaultChunkSize;
                            fileList.Complete    = false;
                            fileList.Downloading = false;
                            fileList.Path        = path;
                            fileList.FileType    = "media";
                            fileList.Size        = file.Size;
                            fileList.MD5         = file.MD5;
                            fileList.Retrys      = 0;

                            _files.Add(fileList);
                        }
                        else
                        {
                            // The MD5 of the current file and the MD5 in RequiredFiles are the same.
                            // Therefore make sure this MD5 is in the CacheManager
                            _cacheManager.Add(path, md5);

                            //string[] filePart = path.Split('.');
                            _requiredFiles.MarkComplete(path, md5);
                        }
                    }
                    else
                    {
                        // No - Get it (async call - with chunks... through another class?)
                        fileList.ChunkOffset = 0;
                        fileList.ChunkSize   = DefaultChunkSize;
                        fileList.Complete    = false;
                        fileList.Downloading = false;
                        fileList.Path        = path;
                        fileList.FileType    = "media";
                        fileList.Size        = file.Size;
                        fileList.MD5         = file.MD5;
                        fileList.Retrys      = 0;

                        _files.Add(fileList);
                    }
                }
                else if (file.FileType == "blacklist")
                {
                    // Expect <file type="blacklist"><file id="" /></file>
                    var items = (List <string>)file.Other;

                    BlackList blackList = new BlackList();

                    try
                    {
                        blackList.Truncate();
                    }
                    catch { }

                    if (items.Count > 0)
                    {
                        blackList.Add(items);

                        blackList.Dispose();
                        blackList = null;
                    }

                    items = null;
                }
                else
                {
                    //Ignore node
                }
            }

            Debug.WriteLine(String.Format("There are {0} files to get", _files.Count.ToString()));

            // Output a list of the files we need to get
            string debugMessage = "";

            foreach (RequiredFileModel fileToGet in _files)
            {
                debugMessage += string.Format("File: {0}, Type: {1}, MD5: {2}. ", fileToGet.Path, fileToGet.FileType, fileToGet.MD5);
            }

            Debug.WriteLine(debugMessage);

            // Report the files files back to XMDS
            _requiredFiles.ReportInventory();

            // Write Required Files
            _requiredFiles.WriteRequiredFiles();

            // Is there anything to get?
            if (_files.Count == 0)
            {
                CollectionComplete();
                return;
            }

            // Start with the first file
            _currentFile = 0;

            // Preload the first filelist
            _currentFileList = _files[_currentFile];

            // Get the first file
            GetFile();
        }