Beispiel #1
0
		public NetflixDataModel(FileInfo dataDirectory)
		{
			if (dataDirectory == null) 
            {
				throw new ArgumentNullException("dataDirectory is null");
			}
			if (!dataDirectory.Exists || !dataDirectory.IsDirectory()) 
            {
				throw new FileNotFoundException(dataDirectory.toString());
			}

			log.Info("Creating NetflixDataModel for directory: " + dataDirectory);

			log.info("Reading movie data...");
			List<NetflixMovie> movies = ReadMovies(dataDirectory);

			log.info("Reading preference data...");
			List<User> users = ReadUsers(dataDirectory, movies);

			log.Info("Creating delegate DataModel...");
			_delegate = new GenericDataModel(users);
		}
Beispiel #2
0
        /// <summary>
        /// Get last modified time on a single file or recurse if
        /// the file is a directory. 
        /// </summary>
        /// <param name="f">file or directory</param>
        /// <param name="scanInfoMap">map of filenames to last modified times</param>
        void ScanFile(FileInfo f, Dictionary<string, long> scanInfoMap)
        {
            if (IsStopping || IsStopped)
            {
                // stop if no longer running
                return;
            }

            try
            {
                if (!f.Exists)
                    return;

                if (!f.IsDirectory())
                {
                    if ((_filter == null) || ((_filter != null) && _filter.Accept(f.Directory, f.Name)))
                    {
                        string name = f.FullName;
                        long lastModified = f.LastWriteTimeUtc.Ticks;
                        scanInfoMap.Add(name, lastModified);
                    }
                }
                else if (f.IsDirectory() && (_recursive || _scanDirs.Contains(f)))
                {
                    FileInfo[] files = (new DirectoryInfo(f.FullName)).GetFiles();
                    for (int i = 0; i < files.Length; i++)
                    {
                        if (IsStopping || IsStopped)
                        {
                            // stop if no longer running
                            return;
                        }
                        ScanFile(files[i], scanInfoMap);
                    }
                }
            }
            catch (IOException e)
            {
                Log.Warn("Error scanning watched files", e);
            }
        }
Beispiel #3
0
        internal void PrescanTwoTrees()
        {
            var visitor = new AbstractIndexTreeVisitor
                              {
                                  VisitEntryAux = (treeEntry, auxEntry, indexEntry, file) =>
                                                   {
                                                       if (treeEntry is Tree || auxEntry is Tree)
                                                       {
                                                           throw new ArgumentException("Can't pass me a tree!");
                                                       }

                                                       ProcessEntry(treeEntry, auxEntry, indexEntry);
                                                   },

                                  FinishVisitTree = (tree, auxTree, currentDirectory) =>
                                                        {
                                                            if (currentDirectory.Length == 0) return;
                                                            if (auxTree == null) return;

                                                            if (_index.GetEntry(currentDirectory) != null)
                                                            {
                                                                Removed.Add(currentDirectory);
                                                            }
                                                        }
                              };

            new IndexTreeWalker(_index, _head, _merge, _root, visitor).Walk();

            // if there's a conflict, don't list it under
            // to-be-removed, since that messed up our next
            // section
            Removed.RemoveAll(removed => Conflicts.Contains(removed));

            foreach (string path in _updated.Keys)
            {
                if (_index.GetEntry(path) == null)
                {
                    FileSystemInfo file = new FileInfo(Path.Combine(_root.DirectoryName(), path));
                    if (file.IsFile())
                    {
                        Conflicts.Add(path);
                    }
                    else if (file.IsDirectory())
                    {
                        CheckConflictsWithFile(file);
                    }
                }
            }

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
        /// <summary>
        /// Push a single file.
        /// </summary>
        /// <param name="local">the local filepath.</param>
        /// <param name="remote">The remote filepath.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        public SyncResult PushFile( String local, String remote, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            FileInfo f = new FileInfo ( local );
            if ( !f.Exists ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_NO_LOCAL_FILE );
            }

            if ( f.IsDirectory ( ) ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_LOCAL_IS_DIRECTORY );
            }

            monitor.Start ( f.Length );
            SyncResult result = DoPushFile ( local, remote, monitor );
            monitor.Stop ( );

            return result;
        }
        private static bool rename(string src, string dst)
        {
            if (new FileInfo(src).RenameTo(dst))
                return true;

            DirectoryInfo dir = new FileInfo(dst).Directory;
            if ((dir.Exists || !dir.Mkdirs()) && !dir.IsDirectory())
                return false;
            return new FileInfo(src).RenameTo(dst);
        }
        void SetFile()
        {
            lock (_thisLock)
            {
                // Check directory
                FileInfo file = new FileInfo(_filename);
                _filename = file.FullName;
                file = new FileInfo(_filename);
                FileInfo dir = new FileInfo(file.Directory.FullName);
                if (!dir.IsDirectory() || !dir.CanWrite())
                    throw new IOException("Cannot write log directory " + dir);

                DateTime now = DateTime.Now;
                if (_timeZoneInfo != null)
                {
                    now = TimeZoneInfo.ConvertTime(now, _timeZoneInfo);
                }

                // Is this a rollover file?
                string filename = file.Name;
                int i = filename.ToLower().IndexOf(YYYY_MM_DD);
                if (i >= 0)
                {
                    file = new FileInfo(Path.Combine(dir.FullName,
                                  filename.Substring(0, i) +
                                  now.ToString(_fileDateFormat) +
                                  filename.Substring(i + YYYY_MM_DD.Length)));
                }

                if (file.Exists && !file.CanWrite())
                    throw new IOException("Cannot write log file " + file);

                // Do we need to change the output stream?
                if (output == null || !file.Equals(_file))
                {
                    // Yep
                    _file = file;
                    if (!_append && file.Exists)
                    {
                        file.MoveTo(new FileInfo(file.ToString() + "." + now.ToString(_fileBackupFormat)).FullName);
                    }
                    Stream oldOut = output;
                    output = new FileStream(
                        file.FullName, _append
                        ? (FileMode.Append | FileMode.CreateNew)
                        : (FileMode.Truncate | FileMode.CreateNew),
                        FileAccess.Write);
                    if (oldOut != null)
                        oldOut.Close();
                    //if(log.isDebugEnabled())log.debug("Opened "+_file);
                }
            }
        }