コード例 #1
0
        public static void ScanAssemblyForHandlers(Assembly assembly)
        {
            try
            {
                //Locate JSONObjects and JSONRequestImplementations in the assembly.
                var objects = assembly.GetTypes()
                              .Where(t => t.GetInterfaces()
                                     .Any(i => i.Equals(typeof(JSONObject))))
                              .Where(t => !JSONObjects.Contains(t)).AsEnumerable();

                var handlers = assembly.GetTypes()
                               .Where(t => t.GetInterfaces()
                                      .Any(i => i.Equals(typeof(IJSONRequestImplementationCore))) && t.IsAbstract == false && t.IsInterface == false)
                               .Where(t => !JSONObjects.Contains(t)).AsEnumerable();

                //Add the JSONObjects and JSONRequestImplementations to their respective caches.
                JSONObjects.AddRange(objects);
                JSONRequestImplementations.AddRange(handlers);

                //Map each handler to it's json formatted name ([TypeName].json)
                foreach (var handler in handlers)
                {
                    string hName = handler.Name;
                    if (hName.Contains("`"))
                    {
                        hName = hName.Substring(0, hName.IndexOf("`"));
                    }
                    MapRequestToType(string.Format("{0}.json", hName), handler);
                }
            }

            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                throw ex;
            }
        }
コード例 #2
0
ファイル: API.cs プロジェクト: nuieee/win-rt-feup
 internal static void handleError(JSONObjects.ErrorResponse error)
 {
     Debug.Assert(error.erro != null, "API.handleError invocado sem antes ser verificado se continha erro != null.");
     switch (error.erro)
     {
         case "Autorização":
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                 MessageBox.Show("You don't have access to this information.");
             });
             break;
         case "Autenticação":
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                 MessageBox.Show("Previous session expired. Please login again.");
             });
             break;
         default:
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                 MessageBox.Show(error.erro_msg);
             });
             break;
     }
 }
コード例 #3
0
 /// <summary>
 /// Converts the given string to byte array of websocket protocol
 /// </summary>
 public void Send(Socket SendSocket,string SendData)
 {
     JSONObjects JS = new JSONObjects{ClientVersion = Application.ProductName,HandShake = true,}
     SendSocket.Send(Encoding.ASCII.GetBytes(SendData));
 }