Example #1
0
        private void DoChanged(GCAction action)
        {
            //Does it still exist?
            if (!FileOrDirectoryExists(action.Path))
            {
                return;                                      // can happen when creating a new folder that immediately gets a different name
            }
            if (ThisIsFromMe(action))
            {
                return;
            }


            // We should already have this file in DB if not then it could be a new folder thats being renamed (it fires a change event as well)
            Object o = FindDiskItem(action);

            if (o == null)
            {
                return;
            }

            if (o is DiskItem)
            {
                DiskItem item = (DiskItem)o;

                // anything changed? (it may be a parent folder)
                if (item.Folder)
                {
                    return;
                }
            }

            // we don't do anything for workspaces
        }
 /// <summary>
 /// Show play list dialog to make some action
 /// </summary>
 /// <param name="item">Disk item - audio or video file</param>
 /// <param name="action">What to do - 0 is Add, 1 Remove</param>
 public PlaylistDialog(DiskItem item, int action = 0)
 {
     _diskItem = item;
     InitializeComponent();
     if (action == 0)
     {
         Title             = $"Add '{_diskItem.DisplayName}' to playlist";
         PrimaryButtonText = "Add";
         PlayLists         = DataProvider.Instance.GetPlaylists(true)
                             .Where(l => l.DiskItems.FirstOrDefault(i => i.Equals(_diskItem)) == null)
                             .ToList();
     }
     else if (action == 1)
     {
         PrimaryButtonText = "Remove";
         PlayLists         = DataProvider.Instance.GetPlaylists(true)
                             .Where(l => l.DiskItems.FirstOrDefault(i => i.Equals(_diskItem)) != null)
                             .ToList();
         if (PlayLists.Count == 0)
         {
             Title = Title = $"'{_diskItem.DisplayName}' does not belong to any of playlists";
         }
         else
         {
             Title = $"Remove '{_diskItem.DisplayName}' from playlist";
         }
     }
 }
Example #3
0
		public static string Run(Window parent, DiskItem item)
		{
			var dialog = new RenameDialog(item) { Owner = parent };
			if (!dialog.ShowDialog())
				return null;
			return dialog.FullName;
		}
Example #4
0
        private void UpdateDiskItem(DiskItem i)
        {
            DiskItem original = db.Find <DiskItem>(i.Id);

            DeleteDiskItem(original);
            NewFileAdded(i);
        }
Example #5
0
        public async Task <bool> DeleteItem(DiskItem diskItem, Action <DiskItem> action = null)
        {
            if (diskItem == null)
            {
                return(false);
            }

            var dialog = new ContentDialog()
            {
                Title             = "Delete disk item?",
                Content           = $"Are you sure you want to delete '{diskItem.DisplayName}'?",
                CloseButtonText   = "No",
                PrimaryButtonText = "Delete"
            };
            var dialogResult = await dialog.ShowAsync();

            if (dialogResult != ContentDialogResult.Primary)
            {
                return(false);
            }

            var result = await Client.Delete(diskItem.Path);

            if (result != null && result.IsError())
            {
                return(false);
            }

            if (action != null)
            {
                await Task.Factory.StartNew(() => action(diskItem), CancellationToken.None, TaskCreationOptions.None, Client.Sync);
            }

            return(true);
        }
Example #6
0
        private void doDelete(GCAction action)
        {
            // find DiskItem
            var rs = from d in db.Table <DiskItem>()
                     where d.Path.Equals(action.Path)
                     select d;

            if (rs.Count() == 0)
            {
                Console.Error.Write("No matching Diskitem when deleting ?", action.Path);
                return;
            }
            DiskItem item = rs.FirstOrDefault();

            var request = newReq("/rest/sync/delete");

            SetUpRequest(request);
            request.AddParameter("docId", action.DiskItemId);
            request.AddParameter("folder", item.Folder);

            var response = client.Execute <DeleteFileMeta>(request);

            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                DeleteFileMeta meta = response.Data;
                if (meta.success)
                {
                    // what do if anything?
                }
            }
        }
Example #7
0
 public DiskItemViewModel(Disk disk, DiskItem diskItem)
 {
     DiskItem    = diskItem;
     Name        = Path.GetFileName(DiskItem.FullPath);
     IsDirectory = DiskItem.Kind == DiskItemKind.Directory;
     SetSizeAndUnits();
     TotalPercent = 100.0f * diskItem.SizeBytes / disk.TotalSizeBytes;
 }
Example #8
0
		public static ItemTestResult[] ExecuteTests(DiskItem[] items, ITest[] tests)
		{
			var results = new List<ItemTestResult>(items.Length);

			ExecuteTests(items, tests, results.Add);

			return results.ToArray();
		}
Example #9
0
		public static void ExecuteTests(DiskItem[] items, ITest[] tests, Action<ItemTestResult> resultCallback)
		{
			foreach (var item in items)
			{
				var result = new ItemTestResult(item, new TestResultCollection(tests.Select(x => x.Execute(item, items)).ToList()));

				resultCallback(result);
			}
		}
Example #10
0
        public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
        {
            if (contextItem.Item.Versions.Count > 0)
            {
                return(new TestResult(this, true));
            }

            return(new TestResult(this, false, "This item had no versions in any language. This can be valid, but is highly unusual."));
        }
Example #11
0
        public async Task AddToPlayListAsync(PlayList playList, DiskItem diskItem)
        {
            var item = new ItemList()
            {
                ItemID = diskItem.ID, PlayListID = playList.ID
            };
            await _localContext.ItemsInPlaylist.AddAsync(item);

            await Save();
        }
Example #12
0
        public async Task RemoveFromPlayListAsync(PlayList playList, DiskItem diskItem)
        {
            var item = await _localContext.ItemsInPlaylist.FirstOrDefaultAsync(i => i.ItemID == diskItem.ID && i.PlayListID == playList.ID);

            if (item != null)
            {
                _localContext.ItemsInPlaylist.Remove(item);
                await Save();
            }
        }
Example #13
0
		RenameDialog(DiskItem item)
		{
			InitializeComponent();

			label.Content = $"Please enter new name for {item.Name}:";
			this.item = item;
			ItemName = item.Name;

			name.Focus();
			name.CaretIndex = item.NameWoExtension.Length;
			name.Select(0, name.CaretIndex);
		}
Example #14
0
		public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
		{
			var duplicates = allItems.Where(x =>
				x.Item.DatabaseName.Equals(contextItem.Item.DatabaseName, StringComparison.Ordinal) &&
				x.Item.ID.Equals(contextItem.Item.ID, StringComparison.Ordinal) &&
				x.FullPath != contextItem.FullPath)
					.ToArray();

			if (duplicates.Length == 0) return new TestResult(this, true);

			return new TestResult(this, false, contextItem.Item.ID + " was present in other files: " + string.Join(",", duplicates.Select(x => x.FullPath)));
		}
Example #15
0
        public async Task <DiskItem> CreateItemAsync(DiskItem diskItem)
        {
            if (diskItem.ID != 0)
            {
                return(diskItem);
            }

            var result = await _localContext.Items.AddAsync(diskItem);

            await Save();

            return(result.Entity);
        }
Example #16
0
        public async Task <DiskItem> UpdateItemAsync(DiskItem diskItem)
        {
            if (diskItem.ID == 0)
            {
                return(null);
            }

            var result = _localContext.Items.Update(diskItem);

            await Save();

            return(result.Entity);
        }
Example #17
0
        private void DownLoadFile(DiskItem f)
        {
            var path     = GetRootPath(f);
            var fullpath = Path.Combine(path, f.FileName);

            // conflict?
            if (File.Exists(fullpath))
            {
                bool conflict = true;
                int  count    = 1;
                while (conflict)
                {
                    string name = Path.GetFileNameWithoutExtension(f.FileName);
                    name = name + "(" + count + ")" + Path.GetExtension(f.FileName);
                    if (File.Exists(Path.Combine(path, name)))
                    {
                        count++;
                    }
                    else
                    {
                        fullpath   = Path.Combine(path, name);
                        conflict   = false;
                        f.FileName = name;
                    }
                }
            }

            // f.Path = fullpath;
            f.Path = f.FileName;

            db.Update(f);

            using (var client = new WebClient())
            {
                string url = server + "rest/sync/get?key=" + key + "&apiId=" + apiId + "&docId=" + f.Id;
                try {
                    client.DownloadFile(url, fullpath);
                    var length = new System.IO.FileInfo(fullpath).Length;
                    f.Size             = length;
                    f.Updated          = DateTime.Now;
                    f.UpdatedOnDiskUTC = File.GetLastWriteTimeUtc(fullpath);
                    f.CreatedOnDiskUTC = File.GetCreationTimeUtc(fullpath);
                    db.Update(f);
                }
                catch (WebException e)
                {
                    Console.Error.Write("Problem connecting to Glasscubes");
                    Console.Error.Write(e);
                }
            }
        }
Example #18
0
        private void DeleteDiskItem(DiskItem i)
        {
            db.Delete(i);
            var path = Path.Combine(GetRootPath(i), i.FileName);

            if (File.Exists(path) && !i.Folder)
            {
                File.Delete(path);
            }
            if (Directory.Exists(path) && i.Folder)
            {
                Directory.Delete(path, true);
            }
        }
Example #19
0
        private string GetRootPath(DiskItem f, string path)
        {
            if (f.FolderId > 0)
            {
                DiskItem parent = db.Find <DiskItem>(f.FolderId);
                return(GetRootPath(parent, Path.Combine(parent.Path, path)));
            }

            Workspace w = db.Find <Workspace>(f.WorkspaceId);

            path = Path.Combine(rootDir, w.Name, path);

            return(path);
        }
Example #20
0
        public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
        {
            var duplicates = allItems.Where(x =>
                                            x.Item.DatabaseName.Equals(contextItem.Item.DatabaseName, StringComparison.Ordinal) &&
                                            x.Item.ID.Equals(contextItem.Item.ID, StringComparison.Ordinal) &&
                                            x.FullPath != contextItem.FullPath)
                             .ToArray();

            if (duplicates.Length == 0)
            {
                return(new TestResult(this, true));
            }

            return(new TestResult(this, false, contextItem.Item.ID + " was present in other files: " + string.Join(",", duplicates.Select(x => x.FullPath))));
        }
Example #21
0
        public async Task <bool> PlayPlaylistAsync(PlayList playlist)
        {
            if (playlist == null)
            {
                return(false);
            }

            _currentPlayList = playlist;
            if (_currentPlayList.DiskItems.Count == 0)
            {
                return(false);
            }

            _currentlyPlaying = _currentPlayList.DiskItems.FirstOrDefault();
            return(await PlayDiskItemAsync(_currentlyPlaying));
        }
Example #22
0
        // We need to check if this GCAction event has occured from a user or from the DownloadMinitor (me) i.e. event arising from files being downloaded/deleted/rename etc on Glasscubes
        private bool ThisIsFromMe(GCAction action)
        {
            Object o = FindDiskItem(action);

            if (o == null)
            {
                return(false);
            }

            if (o is DiskItem)
            {
                DiskItem di = (DiskItem)o;
                // Test to see if its the same file/folder or a different version
                FileInfo fi = new FileInfo(action.Path);
                if (di.Folder)
                {
                    // fuzzy timecheck
                    TimeSpan span = fi.LastAccessTimeUtc - di.UpdatedOnDiskUTC;
                    if (span.TotalMilliseconds < FUZZY_TIMESTAMP_DIFF_MS)
                    {
                        return(true);
                    }
                }
                else
                {
                    var length = fi.Length;
                    if (di.Size == length)
                    {
                        // fuzzy timecheck
                        TimeSpan span = fi.LastAccessTimeUtc - di.UpdatedOnDiskUTC;
                        if (span.Milliseconds < FUZZY_TIMESTAMP_DIFF_MS)
                        {
                            return(true);
                        }
                    }
                }
            }


            if (o is Workspace)
            {
                return(true);
            }

            return(false);
        }
Example #23
0
		public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
		{
			var parent = Path.GetDirectoryName(contextItem.FullPath) + PathUtils.Extension;

			if (File.Exists(parent))
			{
				var parentItem = allItems.First(x => x.FullPath.Equals(parent, StringComparison.Ordinal));

				bool result = parentItem.Item.ID.Equals(contextItem.Item.ParentID, StringComparison.Ordinal);

				if(result) return new TestResult(this, true);
				
				return new TestResult(this, false, string.Format("Parent ID: {0} did not match actual serialized parent ID {1}", contextItem.Item.ParentID, parentItem.Item.ID));
			}

			return new TestResult(this, true);
		}
Example #24
0
        private void createChildFolders(DiskItem item, string path)
        {
            var folders = db.Query <DiskItem>("select * from DiskItem where FolderId = ? and Folder = ?", item.Id, true);

            foreach (var f in folders)
            {
                string newPath = Path.Combine(path, f.FileName);
                System.IO.Directory.CreateDirectory(newPath);
                //f.Path = newPath;
                f.Path             = f.FileName;
                f.Updated          = DateTime.Now;
                f.UpdatedOnDiskUTC = Directory.GetLastWriteTimeUtc(newPath);
                f.CreatedOnDiskUTC = Directory.GetCreationTimeUtc(newPath);
                db.Update(f);

                createChildFolders(f, newPath);
            }
        }
Example #25
0
		public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
		{
			if(!ID.IsID(contextItem.Item.ID))
				return new TestResult(this, false, (contextItem.Item.ID ?? "null") + " is not a valid item ID.");

			if(ID.Parse(contextItem.Item.ID) == ID.Null)
				return new TestResult(this, false, "Item ID was the null ID.");

			if (!ID.IsID(contextItem.Item.ParentID))
				return new TestResult(this, false, (contextItem.Item.ParentID ?? "null") + " is not a valid parent ID.");

			if (ID.Parse(contextItem.Item.ParentID) == ID.Null && contextItem.Item.ID != ItemIDs.RootID.ToString())
				return new TestResult(this, false, "Parent ID was the null ID.");

			if (!ID.IsID(contextItem.Item.TemplateID))
				return new TestResult(this, false, (contextItem.Item.TemplateID ?? "null") + " is not a valid template ID.");

			if (ID.Parse(contextItem.Item.TemplateID) == ID.Null)
				return new TestResult(this, false, "Template ID was the null ID.");

			if (!ID.IsID(contextItem.Item.MasterID))
				return new TestResult(this, false, (contextItem.Item.MasterID ?? "null") + " is not a valid master ID.");

			if(string.IsNullOrWhiteSpace(contextItem.Item.TemplateName))
				return new TestResult(this, false, "Template name was null or empty.");

			if (string.IsNullOrWhiteSpace(contextItem.Item.ItemPath))
				return new TestResult(this, false, "Path was null or empty.");

			if (string.IsNullOrWhiteSpace(contextItem.Item.DatabaseName))
				return new TestResult(this, false, "Database was null or empty.");

			if (string.IsNullOrWhiteSpace(contextItem.Item.Name))
				return new TestResult(this, false, "Item name was null or empty.");

			if (contextItem.Item.SharedFields.Count == 0)
			{
				if (contextItem.Item.Versions.Count == 0 || contextItem.Item.Versions[0].Fields.Count == 0)
					return new TestResult(this, false, "Item had no shared fields and no versioned fields. While this can be valid, it is highly unusual.");
			}

			return new TestResult(this, true);
		}
Example #26
0
        public async Task <bool> DownloadItem(DiskItem diskItem)
        {
            if (diskItem == null)
            {
                return(false);
            }

            var picker = new FolderPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };

            if (diskItem.DisplayName.Contains("."))
            {
                picker.FileTypeFilter.Add($".{diskItem.DisplayName.Split('.').LastOrDefault()}");
            }
            else
            {
                FileTypes.Extensions.Keys.ToList().ForEach(e => picker.FileTypeFilter.Add(e));
            }

            var folder = await picker.PickSingleFolderAsync();

            if (folder != null)
            {
                if (!diskItem.IsFolder)
                {
                    var downloadUrl = await Client.GetDownloadURL(diskItem.Path);

                    if (downloadUrl.IsError())
                    {
                        return(false);
                    }

                    var result = await Client.DownLoadFileAsync(downloadUrl, folder, diskItem.DisplayName, new CancellationTokenSource().Token);

                    return(!result.IsError());
                }
            }
            return(false);
        }
Example #27
0
        private void NewFileAdded(DiskItem i)
        {
            i.Updated = DateTime.Now;
            if (i.Folder)
            {
                string newPath = Path.Combine(GetRootPath(i), i.FileName);
                System.IO.Directory.CreateDirectory(newPath);
                // i.Path = newPath;
                i.Path             = i.FileName;
                i.CreatedOnDiskUTC = Directory.GetCreationTimeUtc(newPath);
                i.UpdatedOnDiskUTC = Directory.GetLastAccessTimeUtc(newPath);

                db.Insert(i);
            }
            else
            {
                db.Insert(i);
                DownLoadFile(i);
            }
        }
Example #28
0
        public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
        {
            var parent = Path.GetDirectoryName(contextItem.FullPath) + PathUtils.Extension;

            if (File.Exists(parent))
            {
                var parentItem = allItems.First(x => x.FullPath.Equals(parent, StringComparison.Ordinal));

                bool result = parentItem.Item.ID.Equals(contextItem.Item.ParentID, StringComparison.Ordinal);

                if (result)
                {
                    return(new TestResult(this, true));
                }

                return(new TestResult(this, false, string.Format("Parent ID: {0} did not match actual serialized parent ID {1}", contextItem.Item.ParentID, parentItem.Item.ID)));
            }

            return(new TestResult(this, true));
        }
Example #29
0
        public async Task <bool> PlayDiskItemAsync(DiskItem diskItem)
        {
            if (diskItem == null || !diskItem.MimeType.StartsWith("audio") && !diskItem.MimeType.StartsWith("video"))
            {
                return(false);
            }

            var url = await DiskService.Client.GetDownloadURL(diskItem.Path);

            if (url.IsError())
            {
                return(false);
            }

            var nameParts = diskItem.DisplayName.Split('.');

            _currentlyPlaying = diskItem;
            PlayByURL(new Uri(url.URL), string.Join(" ", nameParts.Take(nameParts.Length - 1)), _currentlyPlaying.MimeType.StartsWith("audio"));
            return(true);
        }
Example #30
0
 private async void _mediaPlayer_MediaEnded(MediaPlayer sender, object args)
 {
     if (_currentlyPlaying == null && sender.PlaybackSession.CanPause)
     {
         sender.Pause();
         return;
     }
     if (_currentPlayList != null && _currentPlayList.DiskItems.Count > 0 && _currentPlayList.DiskItems.Contains(_currentlyPlaying))
     {
         var current = _currentPlayList.DiskItems.IndexOf(_currentlyPlaying);
         if (current < 0)
         {
             sender.Pause();
             return;
         }
         _currentlyPlaying = current < _currentPlayList.DiskItems.Count - 1 ?
                             _currentPlayList.DiskItems.Skip(current + 1).Take(1).FirstOrDefault() :
                             _currentPlayList.DiskItems.FirstOrDefault();
         await PlayDiskItemAsync(_currentlyPlaying);
     }
 }
Example #31
0
		public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
		{
			// translate the full physical path into an item path
			var mappedPath = PathUtils.MakeItemPath(contextItem.FullPath, _rootPath);

			// if more than one item is in the same path with the same name, it will map something like "name_FDA63242325453" (guid)
			// we want to strip the disambiguating GUID from the name, if it exists
			var split = mappedPath.Split('_');
			if (ShortID.IsShortID(split.Last()))
				mappedPath = string.Join("_", split.Take(split.Length - 1));

			if (_databaseName != null)
			{
				string dbPrefix = "/" + _databaseName;

				if (mappedPath.StartsWith(dbPrefix, StringComparison.OrdinalIgnoreCase))
					mappedPath = mappedPath.Substring(dbPrefix.Length);
			}

			// MakeItemPath seems to return paths in the format "//sitecore/foo" sometimes, let's normalize that
			mappedPath = "/" + mappedPath.TrimStart('/');

			// if we have a database name (e.g. we are pointing at a raw serialized root such as "serialization\master" instead of "serialization"), prepend to the mapped path
			if (_databaseName != null)
			{
				mappedPath = "/" + _databaseName + mappedPath;
			}

			// compute the item reference path for the context item SyncItem
			string syncItemReferencePath = new ItemReference(contextItem.Item.DatabaseName, contextItem.Item.ItemPath).ToString();

			// ensure the ref path is prepended with /
			syncItemReferencePath = "/" + syncItemReferencePath.TrimStart('/');

			bool passed = mappedPath.Equals(syncItemReferencePath, StringComparison.OrdinalIgnoreCase);

			if (passed) return new TestResult(this, true);

			return new TestResult(this, false, string.Format("Physical: {0} != Serialized: {1}", mappedPath, syncItemReferencePath));
		}
Example #32
0
        private bool DoesThisNeedUpdating(DiskItem i)
        {
            DiskItem di = db.Find <DiskItem>(i.Id);

            if (di == null)
            {
                return(true);
            }

            switch (i.Action)
            {
            case "ADD":
                return(false);

            case "DELETE":
                return(true);

            case "UPDATED":
                if (di.Updated != i.Updated ||
                    di.FileName != i.FileName ||
                    di.Version != i.Version ||
                    di.Size != i.Size)
                {
                    return(true);
                }
                return(false);

            case "RENAME":
                if (di.FileName != i.FileName)
                {
                    return(true);
                }
                return(false);
            }


            return(true);
        }
Example #33
0
        private void DiskItemRenamed(DiskItem i)
        {
            try
            {
                DiskItem orig        = db.Find <DiskItem>(i.Id);
                string   root        = GetRootPath(orig);
                string   newFullPath = Path.Combine(root, i.FileName);
                if (i.Folder)
                {
                    Directory.Move(Path.Combine(root, orig.FileName), newFullPath);
                }
                else
                {
                    File.Move(Path.Combine(root, orig.FileName), newFullPath);
                }
                //i.Path = Path.Combine(root, i.FileName).ToString();
                i.Path = i.FileName;

                DateTime now = DateTime.Now;
                i.Updated = now;

                if (i.Folder)
                {
                    Directory.SetLastWriteTime(newFullPath, now);
                    i.UpdatedOnDiskUTC = Directory.GetLastWriteTimeUtc(newFullPath);
                }
                else
                {
                    File.SetLastWriteTime(newFullPath, now);
                    i.UpdatedOnDiskUTC = File.GetLastWriteTimeUtc(newFullPath);
                }
                db.Update(i);
            }
            catch (SQLiteException e)
            {
                //TODO
            }
        }
Example #34
0
        public static SizableToolBar CreateToolBar(DiskItem item)
        {
            var bar = new SizableToolBar();
            //bar.DataContext = item;
            Binding itemsBinding = new Binding()
            {
                Source = item,
                Path   = new PropertyPath("SubItems"),
                Mode   = BindingMode.OneWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };

            BindingOperations.SetBinding(bar, ToolBar.ItemsSourceProperty, itemsBinding);
            return(bar);

            /*var list = new ListView()
             * {
             *  ItemsSource = item.SubItems
             * };
             * list.SelectionChanged += ToolbarListView_SelectionChanged;
             * bar.Items.Add(list);*/
            /*bar.Tag = item.ItemPath;
             *
             * bool containsThis = false;
             * foreach (DiskItem d in Config.FolderToolBars)
             * {
             *  if (d.ItemPath.ToLowerInvariant() == item.ItemPath.ToLowerInvariant())
             *      containsThis = true;
             * }
             * if (!containsThis)
             * {
             *  Config.FolderToolBars.Add(item);
             *  return bar;
             * }
             * else
             *  return null;*/
        }
Example #35
0
		public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
		{
			if (contextItem.Item.Versions.Count > 0) return new TestResult(this, true);

			return new TestResult(this, false, "This item had no versions in any language. This can be valid, but is highly unusual.");
		}
Example #36
0
        private Object FindParentDiskItem(GCAction action)
        {
            string[] directories = action.Path.Split(Path.DirectorySeparatorChar);

            string    path                = "";
            Workspace workspace           = null;
            DiskItem  parent              = null;
            bool      matchRoot           = true;
            bool      matchWorkspace      = false;
            bool      matchFoldersOrFiles = false;
            int       index               = 1;

            foreach (string p in directories)
            {
                if (path == "")
                {
                    path = p + "\\";
                }
                else
                {
                    path = Path.Combine(path, p);
                }

                if (matchRoot && path == rootDir)
                {
                    matchRoot      = false;
                    matchWorkspace = true;
                }
                else
                if (matchWorkspace)
                {
                    var wrs = from w in db.Table <Workspace>()
                              where w.Path.Equals(p)
                              select w;
                    if (wrs.Count() != 0)
                    {
                        workspace = wrs.FirstOrDefault <Workspace>();
                    }
                    // TODO no workspace?
                    matchWorkspace      = false;
                    matchFoldersOrFiles = true;
                }
                else
                if (matchFoldersOrFiles)
                {
                    if (parent == null)
                    {
                        IEnumerable <DiskItem> d = db.Query <DiskItem>("select * from DiskItem where Path = ? and WorkspaceId = ?", p, workspace.Id);
                        DiskItem it = d.FirstOrDefault <DiskItem>();
                        if (it != null && index + 1 == directories.Length)
                        {
                            parent = it;
                        }
                    }
                    else
                    {
                        IEnumerable <DiskItem> d = db.Query <DiskItem>("select * from DiskItem where Path = ? and WorkspaceId = ? and FolderId = ? ", p, workspace.Id, parent.Id);
                        DiskItem item            = d.FirstOrDefault <DiskItem>();
                        if (item != null && index + 1 == directories.Length)
                        {
                            parent = item;
                        }
                    }
                }
                index++;
            }

            if (parent != null)
            {
                return(parent);
            }
            if (workspace != null)
            {
                return(workspace);
            }


            return(null);
        }
Example #37
0
        private void DoRenamed(GCAction action)
        {
            //Does it still exist?
            if (!FileOrDirectoryExists(action.Path))
            {
                return;
            }


            if (ThisIsFromMe(action))
            {
                return;
            }

            Object o = FindDiskItem(action);

            // We should already have this file in DB unless its a new folder thats just got renamed
            if (!Directory.Exists(action.Path) && o == null)
            {
                return;
            }

            if (o == null)
            {
                // new folder
                DoNew(action);
                return;
            }

            //        @GET
            // @Path("/rename")
            // @Produces(MediaType.APPLICATION_JSON)
            // @Transactional
            //public FileMetaUpdate rename(
            //        @QueryParam("apiId") String apiId,
            //        @QueryParam("key") String key,
            //        @QueryParam("docId") Long docId,
            //        @QueryParam("filename") String fileName,
            //        @QueryParam("folder") Boolean isFolder) {

            if (o is DiskItem)
            {
                DiskItem item    = (DiskItem)o;
                var      request = newReq("/rest/sync/rename");

                SetUpRequest(request);
                request.AddParameter("docId", item.Id);
                request.AddParameter("folder", item.Folder);
                request.AddParameter("filename", Path.GetFileName(action.Path));

                var response = client.Execute <NewFileMeta>(request);
                if (response.ResponseStatus == ResponseStatus.Completed)
                {
                    NewFileMeta meta = response.Data;
                    if (meta.success)
                    {
                        // what do if anything?
                        return;
                    }
                }
                Console.Error.Write("Could not rename file ? ", action.Path);
            }

            // we do nothing if workspace
            Console.Error.Write("Workspace NOT being renamed ? ", action.Path);
        }
Example #38
0
		public ItemTestResult(DiskItem item, TestResultCollection results)
		{
			Item = item;
			Results = results;
		}
Example #39
0
 public ItemTestResult(DiskItem item, TestResultCollection results)
 {
     Item    = item;
     Results = results;
 }