Exemplo n.º 1
0
        public static RootInfo ParseJson(string jsonString)
        {
            Hyena.Json.Deserializer deserializer =
                new Hyena.Json.Deserializer(jsonString);
            object obj = deserializer.Deserialize();

            Hyena.Json.JsonObject jsonObj =
                obj as Hyena.Json.JsonObject;
            if (jsonObj == null)
            {
                throw new ArgumentException("jsonString does not contain a valid RootInfo representation");
            }

            // TODO: Checks
            RootInfo root = new RootInfo();

            root.ApiVersion = (string)jsonObj ["api-version"];

            object val;

            if (jsonObj.TryGetValue("user-ref", out val))
            {
                Hyena.Json.JsonObject userRefJsonObj = (Hyena.Json.JsonObject)val;

                root.User =
                    ResourceReference.ParseJson(userRefJsonObj);
            }

            root.AuthorizeUrl    = (string)jsonObj ["oauth_authorize_url"];
            root.AccessTokenUrl  = (string)jsonObj ["oauth_access_token_url"];
            root.RequestTokenUrl = (string)jsonObj ["oauth_request_token_url"];

            return(root);
        }
Exemplo n.º 2
0
        public static NoteInfo ParseJson(string jsonString)
        {
            Hyena.Json.Deserializer deserializer =
                new Hyena.Json.Deserializer(jsonString);
            object obj = deserializer.Deserialize();

            Hyena.Json.JsonObject jsonObj =
                obj as Hyena.Json.JsonObject;
            return(ParseJson(jsonObj));
        }
Exemplo n.º 3
0
        public static UserInfo ParseJson(string jsonString)
        {
            Hyena.Json.Deserializer deserializer =
                new Hyena.Json.Deserializer(jsonString);
            object obj = deserializer.Deserialize();

            Hyena.Json.JsonObject jsonObj =
                obj as Hyena.Json.JsonObject;
            if (jsonObj == null)
            {
                throw new ArgumentException("jsonString does not contain a valid UserInfo representation");
            }

            // TODO: Checks
            UserInfo user = new UserInfo();

            user.UserName  = (string)jsonObj ["user-name"];
            user.FirstName = (string)jsonObj ["first-name"];
            user.LastName  = (string)jsonObj ["last-name"];

            object val;

            if (jsonObj.TryGetValue("latest-sync-revision", out val))
            {
                user.LatestSyncRevision = (int)val;
            }
            else
            {
                user.LatestSyncRevision = -1;
            }

            if (jsonObj.TryGetValue("current-sync-guid", out val))
            {
                user.CurrentSyncGuid = (string)val;
            }

            Hyena.Json.JsonObject notesRefJsonObj =
                (Hyena.Json.JsonObject)jsonObj ["notes-ref"];
            user.Notes =
                ResourceReference.ParseJson(notesRefJsonObj);

            if (jsonObj.TryGetValue("friends-ref", out val))
            {
                user.Notes =
                    ResourceReference.ParseJson((Hyena.Json.JsonObject)val);
            }

            return(user);
        }
Exemplo n.º 4
0
        public static ResourceReference ParseJson(Hyena.Json.JsonObject jsonObj)
        {
            if (jsonObj == null)
            {
                throw new ArgumentNullException("jsonObj");
            }

            // TODO: Casting checks?
            ResourceReference resourceRef = new ResourceReference();
            object            uri;

            if (jsonObj.TryGetValue("api-ref", out uri))
            {
                resourceRef.ApiRef = (string)uri;
            }
            if (jsonObj.TryGetValue("href", out uri))
            {
                resourceRef.Href = (string)uri;
            }

            return(resourceRef);
        }
Exemplo n.º 5
0
        private string CreateNoteChangesJsonString(IList <NoteInfo> noteUpdates, int?expectedNewRevision)
        {
            Hyena.Json.JsonObject noteChangesObj =
                new Hyena.Json.JsonObject();
            Hyena.Json.JsonArray noteChangesArray =
                new Hyena.Json.JsonArray();
            foreach (NoteInfo note in noteUpdates)
            {
                noteChangesArray.Add(note.ToUpdateObject());
            }
            noteChangesObj [NoteChangesElementName] = noteChangesArray;
            if (expectedNewRevision != null)
            {
                noteChangesObj [LatestSyncRevisionElementName] = expectedNewRevision;
            }

            // TODO: Handle errors
            Hyena.Json.Serializer serializer =
                new Hyena.Json.Serializer(noteChangesObj);
            // TODO: Log this for debugging?
            return(serializer.Serialize());
        }
Exemplo n.º 6
0
        private IList <NoteInfo> ParseJsonNotes(string jsonString, out int?latestSyncRevision)
        {
            Hyena.Json.Deserializer deserializer =
                new Hyena.Json.Deserializer(jsonString);
            object obj = deserializer.Deserialize();

            Hyena.Json.JsonObject jsonObj =
                obj as Hyena.Json.JsonObject;
            Hyena.Json.JsonArray noteArray =
                (Hyena.Json.JsonArray)jsonObj [NotesElementName];

            object val;

            if (jsonObj.TryGetValue(LatestSyncRevisionElementName, out val))
            {
                latestSyncRevision = (int)val;
            }
            else
            {
                latestSyncRevision = null;
            }

            return(ParseJsonNoteArray(noteArray));
        }
Exemplo n.º 7
0
        public static NoteInfo ParseJson(Hyena.Json.JsonObject jsonObj)
        {
            if (jsonObj == null)
            {
                throw new ArgumentException("jsonObj does not contain a valid NoteInfo representation");
            }

            // TODO: Checks
            NoteInfo note = new NoteInfo();

            note.Guid = (string)jsonObj ["guid"];

            // TODO: Decide how much is required
            object val;

            if (jsonObj.TryGetValue(TitleElementName, out val))
            {
                note.Title = (string)val;
            }
            if (jsonObj.TryGetValue(NoteContentElementName, out val))
            {
                note.NoteContent = (string)val;
            }
            if (jsonObj.TryGetValue(NoteContentVersionElementName, out val))
            {
                note.NoteContentVersion = (double)val;
            }

            if (jsonObj.TryGetValue(LastChangeDateElementName, out val))
            {
                note.LastChangeDate = DateTime.Parse((string)val);
            }
            if (jsonObj.TryGetValue(LastMetadataChangeDateElementName, out val))
            {
                note.LastMetadataChangeDate = DateTime.Parse((string)val);
            }
            if (jsonObj.TryGetValue(CreateDateElementName, out val))
            {
                note.CreateDate = DateTime.Parse((string)val);
            }

            if (jsonObj.TryGetValue(LastSyncRevisionElementName, out val))
            {
                note.LastSyncRevision = (int)val;
            }
            if (jsonObj.TryGetValue(OpenOnStartupElementName, out val))
            {
                note.OpenOnStartup = (bool)val;
            }
            if (jsonObj.TryGetValue(PinnedElementName, out val))
            {
                note.Pinned = (bool)val;
            }

            if (jsonObj.TryGetValue(TagsElementName, out val))
            {
                Hyena.Json.JsonArray tagsJsonArray =
                    (Hyena.Json.JsonArray)val;
                note.Tags = new List <string> (tagsJsonArray.Count);
                foreach (string tag in tagsJsonArray)
                {
                    note.Tags.Add(tag);
                }
            }

            if (jsonObj.TryGetValue(ResourceReferenceElementName, out val))
            {
                note.ResourceReference =
                    ResourceReference.ParseJson((Hyena.Json.JsonObject)val);
            }

            return(note);
        }
Exemplo n.º 8
0
        public Hyena.Json.JsonObject ToUpdateObject()
        {
            Hyena.Json.JsonObject noteUpdateObj =
                new Hyena.Json.JsonObject();

            if (string.IsNullOrEmpty(Guid))
            {
                throw new InvalidOperationException("Cannot create a valid JSON representation without a Guid");
            }

            noteUpdateObj [GuidElementName] = Guid;

            if (!string.IsNullOrEmpty(Command))
            {
                noteUpdateObj [CommandElementName] = Command;
                return(noteUpdateObj);
            }

            if (Title != null)
            {
                noteUpdateObj [TitleElementName] = Title;
            }
            if (NoteContent != null)
            {
                noteUpdateObj [NoteContentElementName] = NoteContent;
            }
            if (NoteContentVersion.HasValue)
            {
                noteUpdateObj [NoteContentVersionElementName] = NoteContentVersion.Value;
            }

            if (LastChangeDate.HasValue)
            {
                noteUpdateObj [LastChangeDateElementName] =
                    LastChangeDate.Value.ToString(NoteArchiver.DATE_TIME_FORMAT);
            }
            if (LastMetadataChangeDate.HasValue)
            {
                noteUpdateObj [LastMetadataChangeDateElementName] =
                    LastMetadataChangeDate.Value.ToString(NoteArchiver.DATE_TIME_FORMAT);
            }
            if (CreateDate.HasValue)
            {
                noteUpdateObj [CreateDateElementName] =
                    CreateDate.Value.ToString(NoteArchiver.DATE_TIME_FORMAT);
            }

            // TODO: Figure out what we do on client side for this
//			if (LastSyncRevision.HasValue)
//				noteUpdateObj [LastSyncRevisionElementName] = LastSyncRevision;
            if (OpenOnStartup.HasValue)
            {
                noteUpdateObj [OpenOnStartupElementName] = OpenOnStartup.Value;
            }
            if (Pinned.HasValue)
            {
                noteUpdateObj [PinnedElementName] = Pinned.Value;
            }

            if (Tags != null)
            {
                Hyena.Json.JsonArray tagArray =
                    new Hyena.Json.JsonArray();
                foreach (string tag in Tags)
                {
                    tagArray.Add(tag);
                }
                noteUpdateObj [TagsElementName] = tagArray;
            }

            return(noteUpdateObj);
        }
Exemplo n.º 9
0
		private string CreateNoteChangesJsonString (IList<NoteInfo> noteUpdates, int? expectedNewRevision)
		{
			Hyena.Json.JsonObject noteChangesObj =
				new Hyena.Json.JsonObject ();
			Hyena.Json.JsonArray noteChangesArray =
				new Hyena.Json.JsonArray ();
			foreach (NoteInfo note in noteUpdates)
				noteChangesArray.Add (note.ToUpdateObject ());
			noteChangesObj [NoteChangesElementName] = noteChangesArray;
			if (expectedNewRevision != null)
				noteChangesObj [LatestSyncRevisionElementName] = expectedNewRevision;

			// TODO: Handle errors
			Hyena.Json.Serializer serializer =
				new Hyena.Json.Serializer (noteChangesObj);
			// TODO: Log this for debugging?
			return serializer.Serialize ();
		}
Exemplo n.º 10
0
        public static NoteInfo ParseJson(Hyena.Json.JsonObject jsonObj)
        {
            if (jsonObj == null)
            {
                throw new ArgumentException("jsonObj does not contain a valid NoteInfo representation");
            }

            // TODO: Checks
            NoteInfo note = new NoteInfo();

            note.Guid = (string)jsonObj ["guid"];

            // TODO: Decide how much is required
            object val = 0;
            string key = "<unknown>";

            try {
                key = TitleElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.Title = (string)val;
                }
                key = NoteContentElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.NoteContent = (string)val;
                }
                key = NoteContentVersionElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.NoteContentVersion = (double)val;
                }

                key = LastChangeDateElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.LastChangeDate = DateTime.Parse((string)val);
                }
                key = LastMetadataChangeDateElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.LastMetadataChangeDate = DateTime.Parse((string)val);
                }
                key = CreateDateElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.CreateDate = DateTime.Parse((string)val);
                }

                key = LastSyncRevisionElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.LastSyncRevision = (int)val;
                }
                key = OpenOnStartupElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.OpenOnStartup = (bool)val;
                }
                key = PinnedElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.Pinned = (bool)val;
                }

                key = TagsElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    Hyena.Json.JsonArray tagsJsonArray =
                        (Hyena.Json.JsonArray)val;
                    note.Tags = new List <string> (tagsJsonArray.Count);
                    foreach (string tag in tagsJsonArray)
                    {
                        note.Tags.Add(tag);
                    }
                }

                key = ResourceReferenceElementName;
                if (jsonObj.TryGetValue(key, out val))
                {
                    note.ResourceReference =
                        ResourceReference.ParseJson((Hyena.Json.JsonObject)val);
                }
            } catch (InvalidCastException e) {
                Logger.Error("Note '{0}': Key '{1}', value  '{2}' failed to parse due to invalid type", note.Guid, key, val);
                throw e;
            }

            return(note);
        }
Exemplo n.º 11
0
        public Actions(HomeSource source)
            : base("InternetArchive")
        {
            Add (
                new ActionEntry ("IaResultPopup", null, null, null, null, (o, a) => {
                    ShowContextMenu ("/IaResultPopup");
                }),
                new ActionEntry ("ViewItemDetails", null, Catalog.GetString ("View Item Details"), null, null, (o, a) => {
                    var item = source.SearchSource.FocusedItem;
                    if (item != null && item.Id != null) {
                        string id = item.Id;
                        var src = new DetailsSource (id, item.Title, item.MediaType);
                        source.AddChildSource (src);
                        Banshee.ServiceStack.ServiceManager.SourceManager.SetActiveSource (src);
                    }
                }),
                new ActionEntry ("OpenItemWebsite", Stock.JumpTo, Catalog.GetString ("Open Webpage"), null, null, (o, a) => {
                    string uri = null;
                    var src = ActiveSource as DetailsSource;
                    if (src != null) {
                        uri = src.Item.Details.WebpageUrl;
                    } else {
                        var item = source.SearchSource.FocusedItem;
                        if (item != null) {
                            uri = item.WebpageUrl;
                        }
                    }

                    if (uri != null) {
                        Banshee.Web.Browser.Open (uri);
                    }
                })
            );

            AddImportant (
                new ActionEntry ("VisitInternetArchive", Stock.JumpTo, Catalog.GetString ("Visit Archive.org"), null, null, (o, a) => {
                    Banshee.Web.Browser.Open ("http://archive.org");
                }),
                new ActionEntry ("SubscribeToIASearch", Stock.Add,
                    Catalog.GetString ("Subscribe"), null,
                    Catalog.GetString ("Subscribe to this search as a podcast"), (o, a) => {
                        var desc = source.SearchSource.SearchDescription;
                        var podcast = new Hyena.Json.JsonObject ();
                        podcast["uri"] = source.SearchSource.Search.RssUrl;
                        podcast["name"] = String.Format (Catalog.GetString ("Internet Archive: {0}"), desc.Name ?? desc.Query);
                        Log.DebugFormat ("InternetArchive: subscribing to search: {0} ({1})", podcast["name"], podcast["uri"]);

                        ServiceManager.Get<DBusCommandService> ().PushArgument ("podcast", podcast.ToString ());
                    }
                )
            );

            AddUiFromFile ("GlobalUI.xml");

            Register ();
        }
Exemplo n.º 12
0
        public Actions(HomeSource source) : base("InternetArchive")
        {
            Add(
                new ActionEntry("IaResultPopup", null, null, null, null, (o, a) => {
                ShowContextMenu("/IaResultPopup");
            }),
                new ActionEntry("ViewItemDetails", null, Catalog.GetString("View Item Details"), null, null, (o, a) => {
                var item = source.SearchSource.FocusedItem;
                if (item != null && item.Id != null)
                {
                    string id = item.Id;
                    var src   = new DetailsSource(id, item.Title, item.MediaType);
                    source.AddChildSource(src);
                    Banshee.ServiceStack.ServiceManager.SourceManager.SetActiveSource(src);
                }
            }),
                new ActionEntry("OpenItemWebsite", Stock.JumpTo, Catalog.GetString("Open Webpage"), null, null, (o, a) => {
                string uri = null;
                var src    = ActiveSource as DetailsSource;
                if (src != null)
                {
                    uri = src.Item.Details.WebpageUrl;
                }
                else
                {
                    var item = source.SearchSource.FocusedItem;
                    if (item != null)
                    {
                        uri = item.WebpageUrl;
                    }
                }

                if (uri != null)
                {
                    Banshee.Web.Browser.Open(uri);
                }
            })
                );

            AddImportant(
                new ActionEntry("VisitInternetArchive", Stock.JumpTo, Catalog.GetString("Visit Archive.org"), null, null, (o, a) => {
                Banshee.Web.Browser.Open("http://archive.org");
            }),
                new ActionEntry("SubscribeToIASearch", Stock.Add,
                                Catalog.GetString("Subscribe"), null,
                                Catalog.GetString("Subscribe to this search as a podcast"), (o, a) => {
                var desc        = source.SearchSource.SearchDescription;
                var podcast     = new Hyena.Json.JsonObject();
                podcast["uri"]  = source.SearchSource.Search.RssUrl;
                podcast["name"] = String.Format(Catalog.GetString("Internet Archive: {0}"), desc.Name ?? desc.Query);
                Log.DebugFormat("InternetArchive: subscribing to search: {0} ({1})", podcast["name"], podcast["uri"]);

                ServiceManager.Get <DBusCommandService> ().PushArgument("podcast", podcast.ToString());
            }
                                )
                );

            AddUiFromFile("GlobalUI.xml");

            Register();
        }
Exemplo n.º 13
0
		public Hyena.Json.JsonObject ToUpdateObject ()
		{
			Hyena.Json.JsonObject noteUpdateObj =
				new Hyena.Json.JsonObject ();

			if (string.IsNullOrEmpty (Guid))
				throw new InvalidOperationException ("Cannot create a valid JSON representation without a Guid");
			
			noteUpdateObj [GuidElementName] = Guid;
			
			if (!string.IsNullOrEmpty (Command)) {
				noteUpdateObj [CommandElementName] = Command;
				return noteUpdateObj;
			}

			if (Title != null)
				noteUpdateObj [TitleElementName] = Title;
			if (NoteContent != null)
				noteUpdateObj [NoteContentElementName] = NoteContent;
			if (NoteContentVersion.HasValue)
				noteUpdateObj [NoteContentVersionElementName] = NoteContentVersion.Value;

			if (LastChangeDate.HasValue)
				noteUpdateObj [LastChangeDateElementName] =
					LastChangeDate.Value.ToString (NoteArchiver.DATE_TIME_FORMAT);
			if (LastMetadataChangeDate.HasValue)
				noteUpdateObj [LastMetadataChangeDateElementName] =
					LastMetadataChangeDate.Value.ToString (NoteArchiver.DATE_TIME_FORMAT);
			if (CreateDate.HasValue)
				noteUpdateObj [CreateDateElementName] =
					CreateDate.Value.ToString (NoteArchiver.DATE_TIME_FORMAT);

			// TODO: Figure out what we do on client side for this
//			if (LastSyncRevision.HasValue)
//				noteUpdateObj [LastSyncRevisionElementName] = LastSyncRevision;
			if (OpenOnStartup.HasValue)
				noteUpdateObj [OpenOnStartupElementName] = OpenOnStartup.Value;
			if (Pinned.HasValue)
				noteUpdateObj [PinnedElementName] = Pinned.Value;

			if (Tags != null) {
				Hyena.Json.JsonArray tagArray =
					new Hyena.Json.JsonArray ();
				foreach (string tag in Tags)
					tagArray.Add (tag);
				noteUpdateObj [TagsElementName] = tagArray;
			}

			return noteUpdateObj;
		}