Ejemplo n.º 1
0
        public SimpleResponse LogBlobMetrics(string blobLog, HangoutPostedFile logFile)
        {
            if (!String.IsNullOrEmpty(blobLog))
            {
                WriteMultipleLogsToDb(blobLog);
                return(new SimpleResponse("Success", "false"));
            }
            else if (logFile != null)
            {
                blobLog = "";

                MemoryStream filestream = (MemoryStream)logFile.InputStream;

                byte[] logArray = filestream.ToArray();

                if (logArray != null && logArray.Length > 0)
                {
                    blobLog = Encoding.ASCII.GetString(logArray);

                    WriteMultipleLogsToDb(blobLog);
                }

                return(new SimpleResponse("Success", "false"));
            }


            return(new SimpleResponse("Success", "false"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uploads a file to AmazonS3 then returns back the full Url for that file
        /// </summary>
        /// <returns></returns>
        public SimpleResponse AddFileToAmazon(string fileName, HangoutPostedFile fileToUpload)
        {
            ThreeSharpWrapper amazon = new ThreeSharpWrapper(WebConfig.AmazonAccessKeyId, WebConfig.AmazonSecretAccessKey);

            amazon.AddPublicFileObject(WebConfig.AmazonS3BucketName, fileName, fileToUpload.InputStream);

            return(new SimpleResponse("Success", "true"));
        }
Ejemplo n.º 3
0
        public XmlDocument PayPalCallback(HangoutPostedFile xmlInfoBinary)
        {
            XmlDocument response = new XmlDocument();

            byte[] buffer = new byte[xmlInfoBinary.InputStream.Length];
            xmlInfoBinary.InputStream.Read(buffer, 0, (int)xmlInfoBinary.InputStream.Length);

            UTF8Encoding encoding = new UTF8Encoding();
            String       xmlInfo  = encoding.GetString(buffer);

            PayPalCallBackHandler handler = new PayPalCallBackHandler("PaymentItemsService");

            response = handler.PayPalCallBack(xmlInfo);

            return(response);
        }
Ejemplo n.º 4
0
        public XmlDocument ProcessAdminPaymentItemXml(HangoutPostedFile paymentCommand)
        {
            XmlDocument response = new XmlDocument();

            byte[] buffer = new byte[paymentCommand.InputStream.Length];
            paymentCommand.InputStream.Read(buffer, 0, (int)paymentCommand.InputStream.Length);

            UTF8Encoding encoding             = new UTF8Encoding();
            String       paymentCommandString = encoding.GetString(buffer);

            ServiceCommandSerializer serializer = new ServiceCommandSerializer();
            PaymentCommand           command    = (PaymentCommand)serializer.DeserializeCommandData(paymentCommandString, typeof(PaymentCommand));

            AdminCommandBase parser = new AdminCommandBase("PaymentItemsAdminService");

            response = parser.ProcessRequest(command);

            return(response);
        }
Ejemplo n.º 5
0
        private void ExecuteInAppDomain(Type T, int roomCatalogId, HttpContext context, string verb, MemoryStream GetValueCollectionStream, HttpCookieCollection cookieCollection)
        {
            try
            {
                //Log4NetHandler logger = new Log4NetHandler();
                //logger.SendToLogger("RESTService", "INFO", String.Format("ExecuteInAppDomain roomCatalogId: {0} Verb: {1}", roomCatalogId, verb));

                AppDomain appDomain = appRoomCatalog.GetCatalogAppDomain(roomCatalogId.ToString());
                if (appDomain == null)
                {
                    appDomain = CreateAppDomain(roomCatalogId);
                }

                if (appDomain == null)
                {
                    throw new SystemException(String.Format("CreateAppDomain roomCatalogId: {0} Error: appDomain is null", roomCatalogId));
                }

                //hangoutCookies
                HangoutCookiesCollection oCookies = new HangoutCookiesCollection();
                oCookies.InitCookies(context.Request.Cookies);
                appDomain.SetData("AppCookies", oCookies);

                HangoutPostedFile oFile = new HangoutPostedFile();
                if (context.Request.Files.Count > 0)
                {
                    oFile.InitPostedFile(context.Request.Files[0]);
                }
                appDomain.SetData("PostedFile", oFile);

                AppErrorInformation oErrorInfo = new AppErrorInformation();
                oErrorInfo.RequestType     = context.Request.RequestType;
                oErrorInfo.URL             = context.Request.Url.ToString();
                oErrorInfo.UserHostAddress = context.Request.UserHostAddress;
                oErrorInfo.Timestamp       = context.Timestamp;
                oErrorInfo.MachineName     = Dns.GetHostName().ToString();
                appDomain.SetData("AppErrorInfo", oErrorInfo);

                mServiceLog.Log.Debug("ExecuteInAppDomain (create instance of ) (" + verb + ")");
                AppRestHandler mbrt = (AppRestHandler)appDomain.CreateInstanceAndUnwrap("AppService", "Hangout.Server.WebServices.AppService.AppRestHandler");

                mServiceLog.Log.Debug("ExecuteInAppDomain (process request through specific dll) (" + verb + ")");
                //Specified room catalog of 1 for the data  if we branch db this needs to change to be the roomCatalogId.
                MemoryStream outputStream = mbrt.ProcessRequest(T, verb, 1, GetValueCollectionStream);

                Session.Refresh();
                mServiceLog.Log.Debug("ExecuteInAppDomain (sending response) (" + verb + ")");
                // serialize the response based on the methods return type
                context.Response.OutputStream.Write(outputStream.GetBuffer(), 0, (int)outputStream.Length);

                // System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                // string sTemp = enc.GetString(outputStream.GetBuffer());
            }

            catch (System.Exception ex)
            {
                if (ex.GetType() == typeof(TargetInvocationException))
                {
                    ex = ex.InnerException;
                }

                bool debugMode = (ConfigurationManager.AppSettings["DebugMode"] == "true") ? true : false;

                HangoutException hangoutException = ex as HangoutException;
                if (hangoutException == null)
                {
                    hangoutException = new HangoutException(ex);
                }

                RESTerror e = hangoutException.GetRestError(debugMode);

                // Add additional debug information
                hangoutException.RequestType = context.Request.RequestType;
                hangoutException.RequestUrl  = context.Request.Url.ToString();
                hangoutException.ClientIp    = context.Request.UserHostAddress;
                hangoutException.TimeStamp   = context.Timestamp;
                hangoutException.MachineName = Dns.GetHostName().ToString();
                if (Session.GetCurrentUserId() != null)
                {
                    hangoutException.CurrentUserId = Session.GetCurrentUserId().Id;
                }

                //Log4NetHandler logger = new Log4NetHandler();
                //logger.SendToLogger("RESTService", "ERROR", String.Format("RequestUrl: {0} User: {1}", context.Request.Url.ToString(), hangoutException.CurrentUserId), ex);

                // Handle exception through exception handling application block.
                //ExceptionPolicy.HandleException(hangoutException, "Global Policy");

                //context.Response.StatusCode = 404;
                new XmlSerializer(typeof(RESTerror)).Serialize(context.Response.OutputStream, e);
                return;
            }

            //   finally
            //  {
            //    AppDomain.Unload(appDomain);
            // }
        }
Ejemplo n.º 6
0
        public void DoProcessRequest(HttpContext context, string verb)
        {
            try
            {
                // find the method using the verb name
                // TODO: add argIndex test to make sure it is argIndex static method
                MethodInfo methodInfo = typeof(T).GetMethod(verb);
                if (methodInfo == null)
                {
                    throw new ArgumentException("Service verb could not be found: " + verb);
                }
                // loop though each parameter in the method and look for argIndex corresponding
                // query parameter in the REST request URL.
                string   argString = "";
                string   delimiter = "";
                int      numArgs   = methodInfo.GetParameters().Length;
                object[] args      = new object[numArgs];
                for (int argIndex = 0; argIndex < numArgs; argIndex++)
                {
                    ParameterInfo parameterInfo = methodInfo.GetParameters()[argIndex];

                    if (parameterInfo.ParameterType == typeof(int))
                    {
                        string arg = Util.GetHttpValue(parameterInfo.Name);
                        int    p   = Int32.Parse(arg);
                        args[argIndex] = p;
                        argString     += delimiter + parameterInfo.Name + "=" + Util.GetHttpValue(parameterInfo.Name);
                        delimiter      = "; ";
                    }
                    else if (parameterInfo.ParameterType == typeof(long))
                    {
                        string arg = Util.GetHttpValue(parameterInfo.Name);
                        long   p   = Int64.Parse(arg);
                        args[argIndex] = p;
                        argString     += delimiter + parameterInfo.Name + "=" + Util.GetHttpValue(parameterInfo.Name);
                        delimiter      = "; ";
                    }
                    else if (parameterInfo.ParameterType == typeof(uint))
                    {
                        string arg = Util.GetHttpValue(parameterInfo.Name);
                        uint   p   = UInt32.Parse(arg);
                        args[argIndex] = p;
                        argString     += delimiter + parameterInfo.Name + "=" + Util.GetHttpValue(parameterInfo.Name);
                        delimiter      = "; ";
                    }
                    else if (parameterInfo.ParameterType == typeof(string))
                    {
                        args[argIndex] = Util.GetHttpValue(parameterInfo.Name);
                        argString     += delimiter + parameterInfo.Name + "=" + Util.GetHttpValue(parameterInfo.Name);
                        delimiter      = "; ";
                    }
                    else if (parameterInfo.ParameterType == typeof(HangoutPostedFile))
                    {
                        HangoutPostedFile oFile = new HangoutPostedFile();
                        oFile.InitPostedFile(context.Request.Files[parameterInfo.Name]);
                        args[argIndex] = oFile;
                    }
                    else if (parameterInfo.ParameterType == typeof(Session.UserId))
                    {
                        Session.UserId userId;
                        string         stringUserId = Util.GetHttpValue("userId");
                        if (stringUserId == null)
                        {
                            userId = Session.GetCurrentUserId();
                            if (userId == null)
                            {
                                throw new UserNotLoggedin("No user session active and userId not provided.");
                            }
                        }
                        else
                        {
                            int intUserId = System.Convert.ToInt32(stringUserId);
                            userId = new Session.UserId(intUserId);
                        }
                        args[argIndex] = userId;
                    }
                    //else if (parameterInfo.ParameterType == typeof(RoomCatalog)) {
                    //    args[argIndex] = RestUrl.version;

                    //}
                    else if (parameterInfo.ParameterType == typeof(HangoutCookiesCollection))
                    {
                        HangoutCookiesCollection oCookies = new HangoutCookiesCollection();
                        oCookies.InitCookies(context.Request.Cookies);
                        args[argIndex] = oCookies;
                    }
                    else
                    {
                        throw new ArgumentException("unsupported argument type");
                    }
                }
                if (mDebugMode)
                {
                    mServiceLog.Log.Debug("DoProcessRequest (Invoke Method) (" + methodInfo.ReflectedType.Name + ")(" + verb + ") args: " + argString);
                }
                //Log4NetHandler logger = new Log4NetHandler();
                //logger.SendToLogger("RESTService", "INFO", String.Format("Noun: {0} Verb: {1}", methodInfo.ReflectedType.Name, verb));
                T      instance         = Activator.CreateInstance <T>();
                object reflectionObject = methodInfo.Invoke(instance, args);

                // refresh the session if it has one
                Session.Refresh();

                // serialize the response based on the methods return type
                new XmlSerializer(methodInfo.ReturnType).Serialize(context.Response.OutputStream, reflectionObject);
                Globals.RemoveCurrentRestRequest();
                if (mDebugMode)
                {
                    mServiceLog.Log.Debug("---- Current RestService Requests: " + Globals.GetCurrentRestRequests);
                }
                return;
            }
            catch (System.Exception ex)
            {
                if (ex.GetType() == typeof(TargetInvocationException))
                {
                    ex = ex.InnerException;
                }

                bool debugMode = (ConfigurationManager.AppSettings["DebugMode"] == "true") ? true : false;

                HangoutException hangoutException = ex as HangoutException;
                if (hangoutException == null)
                {
                    hangoutException = new HangoutException(ex);
                }

                RESTerror e = hangoutException.GetRestError(debugMode);

                // Add additional debug information
                hangoutException.RequestType = context.Request.RequestType;
                hangoutException.RequestUrl  = context.Request.Url.ToString();
                hangoutException.ClientIp    = context.Request.UserHostAddress;
                hangoutException.TimeStamp   = context.Timestamp;
                hangoutException.MachineName = Dns.GetHostName().ToString();
                if (Session.GetCurrentUserId() != null)
                {
                    hangoutException.CurrentUserId = Session.GetCurrentUserId().Id;
                }
                if (mDebugMode)
                {
                    mServiceLog.Log.Debug("DoProcessRequest (HangoutException) (" + verb + "): " +
                                          "RequestType: " + hangoutException.RequestType +
                                          "RequestUrl: " + hangoutException.RequestUrl +
                                          "ClientIp: " + hangoutException.ClientIp +
                                          "TimeStamp: " + hangoutException.TimeStamp +
                                          "MachineName: " + hangoutException.MachineName
                                          );
                }
                //Log4NetHandler logger = new Log4NetHandler();
                //logger.SendToLogger("RESTService", "ERROR", String.Format("RequestUrl: {0} User: {1}", context.Request.Url.ToString(), hangoutException.CurrentUserId), ex);

                // Handle exception through exception handling application block.
                // TODO: lucas commented this out... eventually we'll figure out if this needs to be in here
                //ExceptionPolicy.HandleException( hangoutException, "Global Policy" );

                context.Response.StatusCode = 500;
                if (mDebugMode)
                {
                    mServiceLog.Log.Debug("DoProcessRequest (ErrorMessage) (" + verb + "): " + e.ErrorMessage);
                }
                new XmlSerializer(typeof(RESTerror)).Serialize(context.Response.OutputStream, e);
                Globals.RemoveCurrentRestRequest();
                if (mDebugMode)
                {
                    mServiceLog.Log.Debug("---- Current RestService Requests: " + Globals.GetCurrentRestRequests);
                }
                return;
            }
        }