Ejemplo n.º 1
0
		void UpdatePath (PathData pathData)
		{
			var newRoot = GetFilenameFromFd (pathData.Fd);
			if (!newRoot.StartsWith (fullPathNoLastSlash)) { // moved outside of our watched path (so stop observing it)
				RemoveTree (pathData);
				return;
			}
				
			var toRename = new List<PathData> ();
			var oldRoot = pathData.Path;

			toRename.Add (pathData);
															
			if (pathData.IsDirectory) { // anything under the directory must have their paths updated
				var prefix = oldRoot + Path.DirectorySeparatorChar;
				foreach (var path in pathsDict.Keys)
					if (path.StartsWith (prefix))
						toRename.Add (pathsDict [path]);
			}
		
			foreach (var renaming in toRename) {
				var oldPath = renaming.Path;
				var newPath = newRoot + oldPath.Substring (oldRoot.Length);

				renaming.Path = newPath;
				pathsDict.Remove (oldPath);

				// destination may exist in our records from a Created event, take care of it
				if (pathsDict.ContainsKey (newPath)) {
					var conflict = pathsDict [newPath];
					if (GetFilenameFromFd (renaming.Fd) == GetFilenameFromFd (conflict.Fd))
						Remove (conflict);
					else
						UpdatePath (conflict);
				}
					
				pathsDict.Add (newPath, renaming);
			}
			
			PostEvent (FileAction.RenamedNewName, oldRoot, newRoot);
		}
Ejemplo n.º 2
0
		void Remove (PathData pathData)
		{
			fdsDict.Remove (pathData.Fd);
			pathsDict.Remove (pathData.Path);
			close (pathData.Fd);
			PostEvent (FileAction.Removed, pathData.Path);
		}
Ejemplo n.º 3
0
		void RemoveTree (PathData pathData)
		{
			var toRemove = new List<PathData> ();

			toRemove.Add (pathData);

			if (pathData.IsDirectory) {
				var prefix = pathData.Path + Path.DirectorySeparatorChar;
				foreach (var path in pathsDict.Keys)
					if (path.StartsWith (prefix)) {
						toRemove.Add (pathsDict [path]);
					}
			}
			toRemove.ForEach (Remove);
		}
Ejemplo n.º 4
0
		PathData Add (string path, bool postEvents, ref List<int> fds)
		{
			PathData pathData;
			pathsDict.TryGetValue (path, out pathData);

			if (pathData != null)
				return pathData;

			if (fdsDict.Count >= maxFds)
				throw new IOException ("kqueue() FileSystemWatcher has reached the maximum number of files to watch."); 

			var fd = open (path, O_EVTONLY, 0);

			if (fd == -1) {
				fsw.DispatchErrorEvents (new ErrorEventArgs (new IOException (String.Format (
					"open() error while attempting to process path '{0}', error code = '{1}'", path, Marshal.GetLastWin32Error ()))));
				return null;
			}

			try {
				fds.Add (fd);

				var attrs = File.GetAttributes (path);

				pathData = new PathData {
					Path = path,
					Fd = fd,
					IsDirectory = (attrs & FileAttributes.Directory) == FileAttributes.Directory
				};
				
				pathsDict.Add (path, pathData);
				fdsDict.Add (fd, pathData);

				if (postEvents)
					PostEvent (FileAction.Added, path);

				return pathData;
			} catch (Exception e) {
				close (fd);
				fsw.DispatchErrorEvents (new ErrorEventArgs (e));
				return null;
			}

		}
Ejemplo n.º 5
0
		void Rename (PathData pathData, string newRoot)
		{
			var toRename = new List<PathData> ();
			var oldRoot = pathData.Path;

			toRename.Add (pathData);
															
			if (pathData.IsDirectory) {
				var prefix = oldRoot + Path.DirectorySeparatorChar;
				foreach (var path in pathsDict.Keys)
					if (path.StartsWith (prefix))
						toRename.Add (pathsDict [path]);
			}

			toRename.ForEach ((pd) => { 
				var oldPath = pd.Path;
				var newPath = newRoot + oldPath.Substring (oldRoot.Length);
				pd.Path = newPath;
				pathsDict.Remove (oldPath);
				pathsDict.Add (newPath, pd);
			});

			PostEvent (FileAction.RenamedNewName, oldRoot, newRoot);
		}
Ejemplo n.º 6
0
 async void ReadWheelsData()
 {
     string data;
     var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"GEODATA.txt");
     var stream = await file.OpenStreamForReadAsync();
     var rdr = new StreamReader(stream);
     data = await rdr.ReadToEndAsync();
     var lines = data.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
     var index = 0;
     foreach (string line in lines)
     {
         var info = line.Split(new char[] { ':' });
         int indx = int.Parse(info[0].Substring(1, info[0].Length - 2));
         string[] pdata = info[1].Split(new char[] { ',' });
         BazelyChuck bc = new BazelyChuck(index++, pdata);
         _BazelyPatterns.Add(bc);
     }
     _lastWheelsPattern = _WheelsPatterns[0];
 }
Ejemplo n.º 7
0
        public void SetupPattern(PatternType ptyp, PathData d, double inc)
        {
            if (d == null)
            {
                RestoreLastPathdata(ptyp);
            }
            else
            {
                CurrentPathData = d;
            }

            if (inc > 0)
                Increment = inc;
            SetupEngine(ptyp);
        }
Ejemplo n.º 8
0
        public void CreateData()
        {
            BazeleyPatterns = new ObservableCollection<BazelyChuck>();
            _lastBazleyPattern = null;
            RossPatterns = new ObservableCollection<RossData>();
            _currentPath = new ShapeCollection();
            _lastRossPattern = null;
            WheelsPatterns = new ObservableCollection<WheelsData>();
            _lastWheelsPattern = null;
            BarrelPatterns = new ObservableCollection<Barrel>();
            _lastBarrelPattern = null;
            LatticePatterns = new ObservableCollection<LatticeData>();
            _lastLatticePattern = null;
            BraidPatterns = new ObservableCollection<BraidData>();
            _lastBraidPattern = null;

            CreateBazelyData();
            CreateRossData();
            CreateWheelsData();
            CreateBarrelData();
            CreateLatticeData();
            CreateBraidData();
            NeedsInitialising = false;
        }