Ejemplo n.º 1
0
		public ENNoteRef UploadNote(ENNote note, ENNotebook notebook)
		{

			return UploadNote(note, UploadPolicy.Create, notebook, null);

		}
Ejemplo n.º 2
0
		public ENNoteRef UploadNote(ENNote note, ENSession.UploadPolicy policy, ENNotebook notebook, ENNoteRef noteToReplace)
		{

			if (note == null)
			{
				ENSDKLogger.ENSDKLogError("Must specify note");
				throw new ENInvalidDataException();
			}

			if (policy == UploadPolicy.Replace && noteToReplace == null || policy == UploadPolicy.ReplaceOrCreate && noteToReplace == null)
			{
				ENSDKLogger.ENSDKLogError("Must specify existing ID when requesting a replacement policy");
				throw new ENInvalidDataException();
			}

			if (policy == UploadPolicy.Create && noteToReplace != null)
			{
				ENSDKLogger.ENSDKLogError("Can't use create policy when specifying an existing note ref. Ignoring.");
				noteToReplace = null;
			}

			if (notebook != null && !notebook.AllowsWriting)
			{
				var errorMessage = "A specified notebook must not be readonly";
				ENSDKLogger.ENSDKLogError(errorMessage);
				throw new ArgumentException(errorMessage);
			}

			if (!IsAuthenticated)
			{
				throw new ENAuthExpiredException();
			}

			// Run size validation on any resources included with the note. This is done at upload time because
			// the sizes are a function of the user's service level, which can change.
			if (!note.ValidateForLimits())
			{
				ENSDKLogger.ENSDKLogError("Note failed limits validation. Cannot upload.");
				throw new ENLimitReachedException();
			}

			ENSessionUploadContext context = new ENSessionUploadContext();
			if (noteToReplace != null)
			{
				context.Note = note.EDAMNoteToReplaceServiceNoteGUID(noteToReplace.Guid);
			}
			else
			{
				context.Note = note.EDAMNote();
			}
			context.RefToReplace = noteToReplace;
			context.Notebook = notebook;
			context.Policy = policy;

			context = UploadNote_DetermineDestination(context);
			return context.NoteRef;
		}
Ejemplo n.º 3
0
		private ENSessionListNotebooksContext ListNotebooks_ProcessBusinessNotebooks(ENSessionListNotebooksContext context)
		{
			// Postprocess our notebook sets for business notebooks. For every linked notebook in the personal
			// account, check for a corresponding business shared notebook (by shareKey). If we find it, also
			// grab its corresponding notebook object from the business notebook list.
			List<LinkedNotebook> linkedPersonalNotebooksCopy = new List<LinkedNotebook>(context.LinkedPersonalNotebooks);
			foreach (LinkedNotebook linkedNotebook in linkedPersonalNotebooksCopy)
			{
				SharedNotebook sharedNotebook = null;
				context.SharedBusinessNotebooks.TryGetValue(linkedNotebook.ShareKey, out sharedNotebook);
				if (sharedNotebook != null)
				{
					// This linked notebook corresponds to a business notebook.
					Notebook businessNotebook = context.BusinessNotebooks[sharedNotebook.NotebookGuid];
					ENNotebook result = new ENNotebook(businessNotebook, sharedNotebook, linkedNotebook);

					context.ResultNotebooks.Add(result);
					context.LinkedPersonalNotebooks.Remove(linkedNotebook);

				}
			}

			// Any remaining linked notebooks are personal shared notebooks. No shared notebooks?
			// Then go directly to results preparation.
			if (context.LinkedPersonalNotebooks.Count == 0)
			{
				context = ListNotebooks_PrepareResults(context);
			}
			else
			{
				context = ListNotebooks_FetchSharedNotebooks(context);
			}

			return context;
		}
Ejemplo n.º 4
0
		private ENSessionListNotebooksContext ListNotebooks_ProcessSharedNotebooks(ENSessionListNotebooksContext context)
		{
			// Process the results
			foreach (LinkedNotebook linkedNotebook in context.LinkedPersonalNotebooks)
			{
				object sharedNotebook = context.SharedNotebooks[linkedNotebook.Guid];
				ENNotebook result = null;
				if (sharedNotebook.GetType() == typeof(SharedNotebook))
				{
					// Shared notebook with individuals
					result = new ENNotebook((SharedNotebook)sharedNotebook, linkedNotebook);
				}
				else
				{
					// Public notebook
					result = new ENNotebook((Notebook)sharedNotebook, linkedNotebook);
				}
				context.ResultNotebooks.Add(result);
			}

			context = ListNotebooks_PrepareResults(context);
			return context;
		}
Ejemplo n.º 5
0
		private ENSessionListNotebooksContext ListNotebooks_ListNotebooks(ENSessionListNotebooksContext context)
		{
			List<Notebook> notebooks = PrimaryNoteStore.ListNotebooks();
			if (notebooks.Count > 0)
			{
				// Populate the result list with personal notebooks.
				foreach (Notebook book in notebooks)
				{
					ENNotebook result = new ENNotebook(book);
					context.ResultNotebooks.Add(result);
				}
				// Now get any shared notebook records for the personal account.
				context = ListNotebooks_ListSharedNotebooks(context);
			}
			else
			{
				// This must be a single notebook auth token, so try getting linked notebooks.
				context = ListNotebooks_ListLinkedNotebooks(context);
			}

			return context;
		}
Ejemplo n.º 6
0
		internal object NoteStoreForNotebook(ENNotebook notebook)
		{
			if (notebook.IsBusinessNotebook)
			{
				return BusinessNoteStore;
			}
			else if (notebook.IsLinked)
			{
				return NoteStoreForLinkedNotebook(notebook.LinkedNotebook);
			}
			else
			{
				return PrimaryNoteStore;
			}
		}
Ejemplo n.º 7
0
		public ENCollection FindNotes(string noteSearchString, ENNotebook notebook, SearchScope scope, SortOrder order, int maxResults)
		{
			List<ENSessionFindNotesResult> results = ENSession.SharedSession.FindNotes(ENNoteSearch.NoteSearch(noteSearchString), notebook, scope, order, maxResults);

			ENCollection comResults = new ENCollection();
            foreach (ENSessionFindNotesResult result in results)
            {
                object tempvar = result;
                comResults.Add(ref tempvar);
            }
            //foreach (var result in results)
            //{
            //    var tempVar = result;
            //    comResults.Add(ref tempVar);
            //}
            ////foreach (var result in results)
            ////{
            ////    object null_object = null;
            ////    object null_object2 = null;
            ////    object null_object3 = null;
            ////    object temp_object = result;
            ////    comResults.Add(ref temp_object, ref null_object, ref null_object2, ref null_object3);
            ////}
			return comResults;
		}
Ejemplo n.º 8
0
		public List<ENSessionFindNotesResult> FindNotes(ENNoteSearch noteSearch, ENNotebook notebook, SearchScope scope, SortOrder order, int maxResults)
		{
			if (!IsAuthenticated)
			{
				throw new ENAuthExpiredException();
			}

			// App notebook scope is internally just an "all" search, because we don't a priori know where the app
			// notebook is. There's some room for a fast path in this flow if we have a saved linked record to a
			// linked app notebook, but that case is likely rare enough to prevent complexifying this code for.
			if (scope.HasFlag(SearchScope.AppNotebook))
			{
				scope = SearchScope.All;
			}

			// Validate the scope and sort arguments.
			if (notebook != null && scope != SearchScope.None)
			{
				ENSDKLogger.ENSDKLogError("No search scope necessary if notebook provided.");
				scope = SearchScope.None;
			}
			else if (notebook == null && scope == SearchScope.None)
			{
				ENSDKLogger.ENSDKLogError("Search scope or notebook must be specified. Defaulting to personal scope.");
				scope = SearchScope.DefaultScope;
			}

			bool requiresLocalMerge = false;
			if (scope != SearchScope.None)
			{
				// Check for multiple scopes. Because linked scope can subsume multiple linked notebooks, that *always* triggers
				// the multiple scopes. If not, then both personal and business must be set together.
				if ((scope.HasFlag(SearchScope.Personal) && scope.HasFlag(SearchScope.Business)) || scope.HasFlag(SearchScope.PersonalLinked))
				{
					// If we're asked for multiple scopes, relevance is not longer supportable (since we
					// don't know how to combine relevance on the client), so default to updated date,
					// which is probably the closest proxy to relevance.
					if (order.HasFlag(SortOrder.Relevance))
					{
						ENSDKLogger.ENSDKLogError("Cannot sort by relevance across multiple search scopes. Using update date.");
						order = (EvernoteSDK.ENSession.SortOrder)EN_FLAG_CLEAR(order, SortOrder.Relevance);
						order = (EvernoteSDK.ENSession.SortOrder)EN_FLAG_SET(order, SortOrder.RecentlyUpdated);
					}
					requiresLocalMerge = true;
				}
			}

			NotesMetadataResultSpec resultSpec = new NotesMetadataResultSpec();
			resultSpec.IncludeNotebookGuid = true;
			resultSpec.IncludeTitle = true;
			resultSpec.IncludeCreated = true;
			resultSpec.IncludeUpdated = true;
			resultSpec.IncludeUpdateSequenceNum = true;

			NoteFilter noteFilter = new NoteFilter();
			noteFilter.Words = noteSearch.SearchString;

			if (order.HasFlag(SortOrder.Title))
			{
				noteFilter.Order = (System.Int32)NoteSortOrder.TITLE;
			}
			else if (order.HasFlag(SortOrder.RecentlyCreated))
			{
				noteFilter.Order = (System.Int32)NoteSortOrder.CREATED;
			}
			else if (order.HasFlag(SortOrder.RecentlyUpdated))
			{
				noteFilter.Order = (System.Int32)NoteSortOrder.UPDATED;
			}
			else if (order.HasFlag(SortOrder.Relevance))
			{
				noteFilter.Order = (System.Int32)NoteSortOrder.RELEVANCE;
			}

			// "Normal" sort is ascending for titles, and descending for dates and relevance.
			bool sortAscending = order.HasFlag(SortOrder.Title) ? true : false;
			if (order.HasFlag(SortOrder.Reverse))
			{
				sortAscending = !sortAscending;
			}
			noteFilter.Ascending = sortAscending;

			if (notebook != null)
			{
				noteFilter.NotebookGuid = notebook.Guid;
			}

			// Set up context
			ENSessionFindNotesContext context = new ENSessionFindNotesContext();
			context.scopeNotebook = notebook;
			context.scope = scope;
			context.order = order;
			context.noteFilter = noteFilter;
			context.resultSpec = resultSpec;
			context.maxResults = maxResults;
			context.findMetadataResults = new List<NoteMetadata>();
			context.requiresLocalMerge = requiresLocalMerge;
			context.sortAscending = sortAscending;

			// If we have a scope notebook, we already know what notebook the results will appear in.
			// If we don't have a scope notebook, then we need to query for all the notebooks to determine
			// where to search.
			if (context.scopeNotebook == null)
			{
				context = FindNotes_ListNotebooks(context);
				return context.results;
			}

			context = FindNotes_FindInPersonalScope(context);
			return context.results;
		}
		public ENCollection FindNotesForCOM(ENNoteSearch noteSearch,  ENNotebook notebook, SearchScope scope, SortOrder order, int maxResults)
		{
            System.Windows.Forms.MessageBox.Show("Finding...", "Debug", System.Windows.Forms.MessageBoxButtons.OK);
            
            List<ENSessionFindNotesResult> results = ENSession.SharedSession.FindNotes(noteSearch, notebook, scope, order, maxResults);

            System.Windows.Forms.MessageBox.Show(results.Count.ToString(),"Debug",System.Windows.Forms.MessageBoxButtons.OK);

			ENCollection comResults = new ENCollection();
            foreach (ENSessionFindNotesResult result in results)
            {
                object tempvar = result;
                comResults.Add(ref tempvar);
            }
			return comResults;
		}