Example #1
0
        /// <summary>
        /// Set last.fm object property values with session from GXmlInner
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="inner"></param>
        /// <param name="session"></param>
        public object SetObjectPropertiesValues(object obj, GXmlInner inner, Session session)
        {
            // This inner has no childs
            var theImagesProperty = new Images();

            Parallel.ForEach(inner.Inners, gXmlInner =>
                   {
                       #region
                       try
                       {
                           if (gXmlInner.HasInners() == false)
                           {
                               gXmlInner.Name = gXmlInner.Name.Replace(":", string.Empty);
                               gXmlInner.Name = gXmlInner.Name.Replace("artist", "artistname");
                               if (gXmlInner.Name.Contains("image"))
                               {
                                   _refTools.SetPropertyValue(theImagesProperty, gXmlInner.GetAttributeValue("size"), gXmlInner.InnerValue);
                                   _refTools.SetPropertyValue(obj, "Images", theImagesProperty);
                               }
                               else
                               {
                                   _refTools.SetPropertyValue(obj, gXmlInner.Name, gXmlInner.InnerValue);
                               }
                           }
                           else
                           {
                               if (!IsList(gXmlInner)) // Is list, but just properties list
                               {
                                   // Replace name
                                   gXmlInner.Name = gXmlInner.Name.Replace(":", string.Empty);
                                   // Get object property 'PropertyInfo'
                                   Type objectPropertyInfo = _refTools.GetPropertyInfoByName(gXmlInner.Name, obj).PropertyType;
                                   // Get object property copy
                                   var tempPropertyObject =
                                       Activator.CreateInstance(objectPropertyInfo.Assembly.FullName,
                                                                objectPropertyInfo.FullName);
                                   // Unwrap object property copy
                                   var propertyObject = tempPropertyObject.Unwrap();
                                   // Add session to obj
                                   SetSessionToObject(session, propertyObject);
                                   // Set values to property copy
                                   propertyObject = SetObjectPropertiesValues(propertyObject, gXmlInner, session);
                                   // Set property copy value to object property
                                   _refTools.SetPropertyValue(obj, gXmlInner.Name, propertyObject);
                               }
                               else // Items list, it's seriusly
                               {
                                   // Parse Items Type Name: Example topalbums - albums
                                   var itemTypeName = gXmlInner.Name.Replace("top", string.Empty);
                                   itemTypeName = itemTypeName.Replace(":", string.Empty);
                                   // Get Item type
                                   Type objectPropertyInfo = _refTools.GetPropertyInfoByName(itemTypeName, obj).PropertyType;
                                   var theItemType = objectPropertyInfo.GetGenericArguments().Single();

                                   // Create temp list for items
                                   var objectsList =
                                           (IList)_refTools.GetPropertyInfoByName(itemTypeName, obj).GetValue(obj, null);

                                   // parallel foreach
                                   Parallel.ForEach(gXmlInner.Inners, xmlInner =>
                                   {
                                       try
                                       {
                                           // create temp item
                                           var tempPropertyObject =
                                           Activator.CreateInstance(theItemType.Assembly.FullName,
                                                                    theItemType.FullName);
                                           object addedPropertyObject = tempPropertyObject.Unwrap();
                                           // Set session to object
                                           SetSessionToObject(session, addedPropertyObject);

                                           addedPropertyObject = SetObjectPropertiesValues(addedPropertyObject, xmlInner, session);
                                           // Add object to list
                                           objectsList.Add(addedPropertyObject);
                                       }
                                       catch { }
                                   });

                                   // after foreach add items = object property(list)
                                   _refTools.SetPropertyValue(obj, gXmlInner.Name, objectsList);
                               }
                           }

                       }
                       catch { }
                       #endregion
                   });
            return obj;
        }
Example #2
0
 /// <summary>
 /// Set session property
 /// </summary>
 /// <param name="session"></param>
 /// <param name="obj"></param>
 private void SetSessionToObject(Session session, object obj)
 {
     if (session != null)
     {
         _refTools.SetPropertyValue(obj, "Session", session);
     }
 }
Example #3
0
 public User(string name, Session session)
 {
     Name = name;
     Session = session;
 }
Example #4
0
        public void GetSession()
        {
            if (string.IsNullOrWhiteSpace(Token)) GetToken();
            if (string.IsNullOrWhiteSpace(ApiSig)) GetApiSig();

            var browser = new System.Windows.Controls.WebBrowser();
            browser.Navigate("http://www.last.fm/api/auth/?api_key="
                + ApiKey + "&token="
                + Token);
            var logWindow = new LogInWindow(browser);
            logWindow.ShowDialog();

            var Params = new RequestParameters { { "token", Token }, { "api_sig", ApiSig },
            { "api_key", ApiKey }};

            object lfmSession = new Session { ApiKey = ApiKey, ApiSec = ApiSec, ApiSig = ApiSig, Token = Token, Name = Name, Key = Key };
            AutomaticGetObject("auth.getsession", Params, ref lfmSession, "session");
            var lastSession = lfmSession as Session;
            if (lastSession != null)
            {
                Key = lastSession.Key;
                Name = lastSession.Name;
            }
        }
Example #5
0
 public void GetToken()
 {
     var Params = new RequestParameters { { "api_key", ApiKey }, { "api_sec", ApiSec } };
     object lfmSession = new Session { ApiKey = ApiKey, ApiSec = ApiSec, ApiSig = ApiSig, Token = Token, Name = Name, Key = Key };
     AutomaticGetObject("auth.getToken", Params, ref lfmSession);
     var lastSession = lfmSession as Session;
     if (lastSession != null) Token = lastSession.Token;
 }
Example #6
0
 /// <summary>
 /// Init an artist
 /// </summary>
 public Artist(string name, Session session)
 {
     Name = name;
     Session = session;
 }