public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, Action<LibraryProvider> setCurrentLibraryProvider, LibraryProvider parentLibraryProvider, string visibleName)
			: base(parentLibraryProvider, setCurrentLibraryProvider)
		{
			this.Name = visibleName;

			if (baseLibraryCollection == null)
			{
				baseLibraryCollection = GetRootLibraryCollection().Result;
			}

			this.baseLibraryCollection = baseLibraryCollection;
			LoadLibraryItems();

			sqliteDatabaseWatcher.Path = Path.GetDirectoryName(ApplicationDataStorage.Instance.DatastorePath);

			sqliteDatabaseWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
				   | NotifyFilters.FileName | NotifyFilters.DirectoryName;
			sqliteDatabaseWatcher.Changed += DatabaseFileChange;
			sqliteDatabaseWatcher.Created += DatabaseFileChange;
			sqliteDatabaseWatcher.Deleted += DatabaseFileChange;
			sqliteDatabaseWatcher.Renamed += DatabaseFileChange;

			// Begin watching.
			sqliteDatabaseWatcher.EnableRaisingEvents = true;
		}
		public LibraryRowItemCollection(PrintItemCollection collection, LibraryDataView libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget)
			: base(libraryDataView, thumbnailWidget)
		{
			this.parentProvider = parentProvider;
			this.printItemCollection = collection;
			CreateGuiElements();
		}
		public LibraryProviderQueue(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider)
			: base(parentLibraryProvider)
		{
			this.baseLibraryCollection = baseLibraryCollection;

			QueueData.Instance.ItemAdded.RegisterEvent((sender, e) => OnDataReloaded(null), ref unregisterEvent);
		}
		public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider)
			: base(parentLibraryProvider)
		{
			if (baseLibraryCollection == null)
			{
				baseLibraryCollection = GetRootLibraryCollection2(this);
			}

			this.baseLibraryCollection = baseLibraryCollection;
			LoadLibraryItems();
		}
		public LibraryRowItemCollection(PrintItemCollection collection, LibraryProvider currentProvider, int collectionIndex, LibraryDataView libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget)
			: base(libraryDataView, thumbnailWidget)
		{
			this.currentProvider = currentProvider;
			this.CollectionIndex = collectionIndex;
			this.parentProvider = parentProvider;
			this.printItemCollection = collection;
			this.ItemName = printItemCollection.Name;

			CreateGuiElements();
		}
		public LibrarySelectorRowItem(PrintItemCollection collection, int collectionIndex, LibrarySelectorWidget libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget)
		{
			this.thumbnailWidget = thumbnailWidget;
			this.libraryDataView = libraryDataView;

			this.CollectionIndex = collectionIndex;
			this.parentProvider = parentProvider;
			this.printItemCollection = collection;
			this.ItemName = printItemCollection.Name;

			CreateGuiElements();
		}
		public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider, string visibleName)
			: base(parentLibraryProvider)
		{
			this.visibleName = visibleName;

			if (baseLibraryCollection == null)
			{
				baseLibraryCollection = GetRootLibraryCollection2(this);
			}

			this.baseLibraryCollection = baseLibraryCollection;
			LoadLibraryItems();
		}
		public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, Action<LibraryProvider> setCurrentLibraryProvider, LibraryProvider parentLibraryProvider, string visibleName)
			: base(parentLibraryProvider)
		{
			this.setCurrentLibraryProvider = setCurrentLibraryProvider;
			this.Name = visibleName;

			if (baseLibraryCollection == null)
			{
				baseLibraryCollection = GetRootLibraryCollection().Result;
			}

			this.baseLibraryCollection = baseLibraryCollection;
			LoadLibraryItems();
		}
		public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, Action<LibraryProvider> setCurrentLibraryProvider, LibraryProvider parentLibraryProvider, string visibleName)
			: base(parentLibraryProvider, setCurrentLibraryProvider)
		{
			this.Name = visibleName;

			if (baseLibraryCollection == null)
			{
				baseLibraryCollection = GetRootLibraryCollection().Result;
			}

			this.baseLibraryCollection = baseLibraryCollection;
			LoadLibraryItems();

			ItemAdded.RegisterEvent(DatabaseFileChange, ref unregisterEvents);
		}
Пример #10
0
        //Run initial checks and operations on sqlite datastore
        public void Initialize()
        {
            ValidateSchema();

            // Construct the root library collection if missing
            var rootLibraryCollection = Datastore.Instance.dbSQLite.Table <PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

            if (rootLibraryCollection == null)
            {
                rootLibraryCollection      = new PrintItemCollection();
                rootLibraryCollection.Name = "_library";
                rootLibraryCollection.Commit();
            }

            StartSession();
        }
		public LibraryProviderSQLite(PrintItemCollection callerSuppliedCollection, Action<LibraryProvider> setCurrentLibraryProvider, LibraryProvider parentLibraryProvider, string visibleName)
			: base(parentLibraryProvider, setCurrentLibraryProvider)
		{
			this.Name = visibleName;

			// Lock ensures that SQLite providers initialized near the same time from different threads (which has been observed during debug)
			// will run in a serial fashion and only one instance will construct and assign to .baseLibraryCollection
			lock (initializingLock) 
			{
				// Use null coalescing operator to assign either the caller supplied collection or if null, the root library collection
				this.baseLibraryCollection = callerSuppliedCollection ?? GetRootLibraryCollection();
			}

			LoadLibraryItems();

			ItemAdded.RegisterEvent(DatabaseFileChange, ref unregisterEvents);
		}
		public LibraryRowItemCollection(PrintItemCollection collection, LibraryProvider currentProvider, int collectionIndex, LibraryDataView libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget, string openButtonText)
			: base(libraryDataView, thumbnailWidget)
		{
			this.openButtonText = openButtonText;
			this.currentProvider = currentProvider;
			this.CollectionIndex = collectionIndex;
			this.parentProvider = parentProvider;
			this.printItemCollection = collection;
			this.ItemName = printItemCollection.Name;

			this.Name = this.ItemName + " Row Item Collection";

			if (collection.Key == LibraryRowItem.LoadingPlaceholderToken)
			{
				this.EnableSlideInActions = false;
				this.IsViewHelperItem = true;
			}

			CreateGuiElements();
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			LibraryProvider provider = libraryProviders.Values.Where(p => p.ProviderKey == collection.Key).FirstOrDefault();
			if (provider != null)
			{
				return provider;
			}

			foreach (ILibraryCreator libraryCreator in libraryCreators)
			{
				if (collection.Key == libraryCreator.ProviderKey)
				{
					return libraryCreator.CreateLibraryProvider(this, SetCurrentLibraryProvider);
				}
			}

			throw new NotImplementedException();
		}
Пример #14
0
		private void AddAllItems()
		{
			topToBottomItemList.RemoveAllChildren();

			var provider = this.CurrentLibraryProvider;

			if (provider != null && provider.ProviderKey != "ProviderSelectorKey")
			{
				PrintItemCollection parent = new PrintItemCollection("..", provider.ProviderKey);
				LibraryRowItem queueItem = new LibraryRowItemCollection(parent, provider, -1, this, provider.ParentLibraryProvider, GetThumbnailWidget(provider.ParentLibraryProvider, parent, LibraryProvider.UpFolderImage));
				AddListItemToTopToBottom(queueItem);
			}

			for (int i = 0; i < provider.CollectionCount; i++)
			{
				PrintItemCollection item = provider.GetCollectionItem(i);
				LibraryRowItem queueItem = new LibraryRowItemCollection(item, provider, i, this, null, GetThumbnailWidget(null, item, provider.GetCollectionFolderImage(i)));
				AddListItemToTopToBottom(queueItem);
			}

			for (int i = 0; i < provider.ItemCount; i++)
			{
				GuiWidget thumbnailWidget = provider.GetItemThumbnail(i);
				LibraryRowItem queueItem = new LibraryRowItemPart(provider, i, this, thumbnailWidget);

				AddListItemToTopToBottom(queueItem);
			}
		}
Пример #15
0
		protected GuiWidget GetThumbnailWidget(LibraryProvider parentProvider, PrintItemCollection printItemCollection, ImageBuffer imageBuffer)
		{
			Vector2 expectedSize = new Vector2((int)(50 * TextWidget.GlobalPointSizeScaleRatio), (int)(50 * TextWidget.GlobalPointSizeScaleRatio));
			if (imageBuffer.Width != expectedSize.x)
			{
				ImageBuffer scaledImageBuffer = new ImageBuffer((int)expectedSize.x, (int)expectedSize.y, 32, new BlenderBGRA());
				scaledImageBuffer.NewGraphics2D().Render(imageBuffer, 0, 0, scaledImageBuffer.Width, scaledImageBuffer.Height);
				imageBuffer = scaledImageBuffer;
			}

			ImageWidget folderThumbnail = new ImageWidget(imageBuffer);
			folderThumbnail.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;

			Button clickThumbnail = new Button(0, 0, folderThumbnail);
			clickThumbnail.Cursor = Cursors.Hand;

			clickThumbnail.Click += (sender, e) =>
			{
				if (parentProvider == null)
				{
					this.CurrentLibraryProvider = this.CurrentLibraryProvider.GetProviderForCollection(printItemCollection);
				}
				else
				{
					this.CurrentLibraryProvider = parentProvider;
				}
			};

			return clickThumbnail;
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			foreach (ILibraryCreator libraryCreator in libraryCreators)
			{
				if (collection.Key == libraryCreator.ProviderKey)
				{
					return libraryCreator.CreateLibraryProvider(this, SetCurrentLibraryProvider);
				}
			}

			throw new NotImplementedException();
		}
		private async Task<PrintItemCollection> GetRootLibraryCollection()
		{
			// Attempt to initialize the library from the Datastore if null
			PrintItemCollection rootLibraryCollection = Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

			// If the _library collection is still missing, create and populate it with default content
			if (rootLibraryCollection == null)
			{
				rootLibraryCollection = new PrintItemCollection();
				rootLibraryCollection.Name = "_library";
				rootLibraryCollection.Commit();

				// In this case we now need to update the baseLibraryCollection instance member as code that executes
				// down this path will attempt to use the property and will exception if its not set
				this.baseLibraryCollection = rootLibraryCollection;

				// Preload library with Oem supplied list of default parts
				await this.EnsureSamplePartsExist(OemSettings.Instance.PreloadedLibraryFiles);
			}

			return rootLibraryCollection;
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			return new LibraryProviderFileSystem(Path.Combine(rootPath, collection.Key), collection.Name, this);
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			return new LibraryProviderQueue(collection, this);
		}
Пример #20
0
		// TODO: make this asnyc
		//public abstract Task<LibraryProvider> GetProviderForCollectionAsync(PrintItemCollection collection);
		public abstract LibraryProvider GetProviderForCollection(PrintItemCollection collection);
		public override void RemoveCollection(PrintItemCollection collectionToRemove)
		{
			collectionToRemove.Delete();
			LoadLibraryItems();
			LibraryProvider.OnDataReloaded(null);
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			return new LibraryProviderHistory(collection, this, SetCurrentLibraryProvider);
		}
		private void AddAllItems(object inData = null)
		{
			// Clear SelectedItems when the list is rebuilt to prevent duplicate entries
			this.SelectedItems.Clear();

			topToBottomItemList.RemoveAllChildren();

			var provider = this.CurrentLibraryProvider;
			if (provider != null)
			{
				if (provider.ProviderKey != LibraryProviderSelector.ProviderKeyName)
				{
					// Create logical "up folder" entry
					PrintItemCollection parent = new PrintItemCollection("..", provider.ProviderKey);
					LibraryRowItem queueItem = new LibraryRowItemCollection(parent, provider, -1, this, provider.ParentLibraryProvider, GetThumbnailWidget(provider.ParentLibraryProvider, parent, LibraryProvider.UpFolderImage), "Back".Localize());
					queueItem.IsViewHelperItem = true;
					AddListItemToTopToBottom(queueItem);
				}

				for (int i = 0; i < provider.CollectionCount; i++)
				{
					PrintItemCollection item = provider.GetCollectionItem(i);
					LibraryRowItem queueItem = new LibraryRowItemCollection(item, provider, i, this, null, GetThumbnailWidget(null, item, provider.GetCollectionFolderImage(i)), "Open".Localize());
					AddListItemToTopToBottom(queueItem);
				}

				for (int i = 0; i < provider.ItemCount; i++)
				{
					GuiWidget thumbnailWidget = provider.GetItemThumbnail(i);
					LibraryRowItem queueItem = new LibraryRowItemPart(provider, i, this, thumbnailWidget);

					AddListItemToTopToBottom(queueItem);
				}
			}

			LastScrollPosition scrollPosition = inData as LastScrollPosition;
			if (scrollPosition != null)
			{
				this.TopLeftOffset = scrollPosition.topLeftScrollPosition;
			}
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			foreach (LibraryProvider libraryProvider in libraryProviders)
			{
				if (collection.Key == libraryProvider.ProviderKey)
				{
					return libraryProvider;
				}
			}

			throw new NotImplementedException();
		}
		public override void AddCollectionToLibrary(string collectionName)
		{
			PrintItemCollection newCollection = new PrintItemCollection(collectionName, "");
			newCollection.ParentCollectionID = baseLibraryCollection.Id;
			newCollection.Commit();
			LoadLibraryItems();
		}
Пример #26
0
		public void AddCollection(PrintItemCollection collection)
		{
			collection.Commit();
		}
		public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
		{
			return new LibraryProviderSQLite(collection, setCurrentLibraryProvider, this, collection.Name);
		}
		static PrintItemCollection GetRootLibraryCollection2(LibraryProviderSQLite rootLibrary)
		{
			// Attempt to initialize the library from the Datastore if null
			PrintItemCollection rootLibraryCollection = Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

			// If the _library collection is still missing, create and populate it with default content
			if (rootLibraryCollection == null)
			{
				rootLibraryCollection = new PrintItemCollection();
				rootLibraryCollection.Name = "_library";
				rootLibraryCollection.Commit();

				// Preload library with Oem supplied list of default parts
				string[] itemsToAdd = SyncCalibrationFilesToDisk(OemSettings.Instance.PreloadedLibraryFiles);
				if (itemsToAdd.Length > 0)
				{
					// Import any files sync'd to disk into the library, then add them to the queue
					rootLibrary.AddFilesToLibrary(itemsToAdd);
				}
			}

			return rootLibraryCollection;
		}
		public override void RemoveCollection(PrintItemCollection collectionToRemove)
		{
			throw new NotImplementedException();
		}
		public LibraryProviderHistory(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider)
			: base(parentLibraryProvider, setCurrentLibraryProvider)
		{
			//PrintHistoryData.Instance.ItemAdded.RegisterEvent((sender, e) => OnDataReloaded(null), ref unregisterEvent);
			this.Name = "Print History";
		}
		public override LibraryProvider GetProviderForItem(PrintItemCollection collection)
		{
			return new LibraryProviderSQLite(collection, this);
		}