Exemple #1
0
        /// <summary>
        /// Gets the connection string for the DaoContext with the specified logical name.
        /// The component will first check if any call has been made to SetContextConnectionString
        /// then check the default configuration (app.config or web.config) returning an empty string
        /// if the connection string is not found.
        /// </summary>
        /// <param name="contextName">The logical name returned by the implementation of
        /// DaoObject.ContextName.</param>
        /// <returns>A database connection string to be used for the specified logicalName.</returns>
        public static string GetContextConnectionString(string contextName)
        {
            if (contexts == null)
            {
                contexts = SingletonHelper.GetApplicationProvider <DaoContextStore>(new DaoContextStore());
            }

            if (staticConnectionStrings != null && staticConnectionStrings.ContainsKey(contextName))
            {
                return(staticConnectionStrings[contextName]);
            }

            if (contexts != null &&
                contexts.ContainsKey(contextName))
            {
                return(contexts[contextName].ConnectionString);
            }

            string property = DefaultConfiguration.GetProperty(typeof(DaoContext).Name, contextName);//CascadeConfiguration.GetProperty(logicalName, true, typeof(DaoContext));

            if (property.StartsWith("$"))
            {
                string propertyName = property.Replace("$", "");
                if (propertyName.Equals(contextName))
                {
                    throw new InvalidOperationException("Invalid DaoContext $ reference.  Must not be the same name as the context or Stack overflow will occur");
                }
                property = GetContextConnectionString(propertyName);
            }


            return(property);
        }
Exemple #2
0
        public static void SendDataBoxScriptResponse(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            string clientKey = request.QueryString["ck"];

            BoxResponses responses = SingletonHelper.GetApplicationProvider <BoxResponses>();
            string       script;

            if (!responses.ContainsKey(clientKey))
            {
                script = "// no scripts";
            }
            else
            {
                script = responses[clientKey].Script;
            }

            responses.Remove(clientKey);
            response.Clear();
            response.Write(script);
            response.Flush();
            response.SuppressContent = true;
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            //response.End();
        }
Exemple #3
0
        private static EventManager GetEventManager()
        {
            if (current == null)
            {
                current = SingletonHelper.GetApplicationProvider <EventManager>(new EventManager());
            }

            return(current);
        }
Exemple #4
0
        public static void SendBoxResponse(HttpContext context, string templateName)
        {
            HttpResponse response = context.Response;

            string clientKey = context.Request.QueryString["ck"];

            if (string.IsNullOrEmpty(clientKey))
            {
                throw new JsonInvalidOperationException("No client key was specified");
            }

            BoxResponses boxResponses = SingletonHelper.GetApplicationProvider <BoxResponses>();

            if (IsScriptRequest(context.Request))
            {
                response.Clear();
                response.Write(boxResponses[clientKey].Script);
                boxResponses.Remove(clientKey);
                response.Flush();
                response.SuppressContent = true;
                context.ApplicationInstance.CompleteRequest();
                return;
            }

            string virtualBoxPath = GetVirtualBoxPath(context, templateName);

            try
            {
                if (string.IsNullOrEmpty(virtualBoxPath))
                {
                    throw new JsonInvalidOperationException("The box template file could not be found: [" + templateName + "]");
                }

                // this is the dom id of the requesting "box" div element
                string requesterId = context.Request.QueryString["domid"]; // TODO: enumify magic strings

                BoxResponse boxResponse = GetBoxResponse(context, virtualBoxPath, null, true);

                boxResponses.Add(clientKey, boxResponse);

                response.Clear();
                response.Write(boxResponse.Html);
                response.Flush();
                response.SuppressContent = true;
                context.ApplicationInstance.CompleteRequest();
            }
            catch (Exception ex)
            {
                SendBoxedError(context, ex);
            }

            return;
        }
Exemple #5
0
        private static ILogger GetLogger()
        {
            ILogger logger = SingletonHelper.GetApplicationProvider <ILogger>();

            if (logger != null)
            {
                return(logger);
            }
            else
            {
                InitializeLogManager();

                return(currentLog);
            }
        }
Exemple #6
0
 static DaoContext()
 {
     contexts             = SingletonHelper.GetApplicationProvider <DaoContextStore>(new DaoContextStore());//new Dictionary<string, DaoContext>();
     contextDatabaseTypes = new Dictionary <string, DaoDbType>();
 }
Exemple #7
0
        /// <summary>
        /// This method will send the "ConglomerateScript" for the specified templateName.
        /// </summary>
        /// <remarks>A ConglomerateScript represents all the scripts required by the JsonControls
        /// in an ascx file.   The BoxUserControl class prepares the resulting ascx control for
        /// Json/Box rendering.</remarks>
        /// <param name="context">The HttpContext significant to the current request.</param>
        /// <param name="templateName">The name of an ascx file contained in the
        /// BoxServer.BoxTemplateDirectory or the virutal path to an ascx file.</param>
        /// <returns></returns>
        //public static void SendBoxScriptResponse(HttpContext context, string templateName)
        //{
        //    string virtualBoxPath = GetVirtualBoxPath(context, templateName);
        //    try
        //    {
        //        if (string.IsNullOrEmpty(virtualBoxPath))
        //            throw new InvalidOperationException("The box template could not be found: [" + templateName + "]");

        //        string requesterId = context.Request.QueryString["domid"];

        //        HttpResponse response = context.Response;
        //        //string responseString = BoxServer.GetScriptString(virtualBoxPath, requesterId);
        //        //GetDataBoxResponse(context, virtualBoxPath, null);
        //        response.Clear();
        //        response.Write(responseString);
        //        response.Flush();
        //        response.SuppressContent = true;
        //        context.ApplicationInstance.CompleteRequest();
        //    }
        //    catch (Exception ex)
        //    {
        //        SendBoxedError(context, ex);
        //    }
        //}

        /// <summary>
        /// Applies a template to the Data property of the specified JsonResult object
        /// and sends the result to the client as an html section or "Box".
        /// </summary>
        /// <param name="context">The HttpContext</param>
        /// <param name="jsonResult">The result to be Boxed</param>
        public static void SendDataBoxResponse(HttpContext context, JsonResult jsonResult)
        {
            #region check JsonResult
            HttpResponse response = context.Response;

            // Check the status of the jsonResult
            // if status is error send default error box
            if (jsonResult.Status == JsonResultStatus.Error)
            {
                SendBoxedError(response, jsonResult);
                return;
            }

            if (jsonResult.Data == null)
            {
                SendBoxedError(response, jsonResult);
                return;
            }
            #endregion


            HttpRequest request = context.Request;

            string boxTemplateName = request.QueryString["dbx"];// TODO: create enums to represent all the magic strings used by the different script components
            string clientKey       = request.QueryString["ck"];
            if (string.IsNullOrEmpty(boxTemplateName))
            {
                SendBoxedError(response, jsonResult);
                return;
            }

            object[] objectsToTemplate = new object[] { jsonResult.Data };
            if (jsonResult.Data is Array)
            {
                objectsToTemplate = (object[])jsonResult.Data;
            }

            BoxResponses responses = SingletonHelper.GetApplicationProvider <BoxResponses>();
            string       allHtml   = string.Empty;
            string       allScript = string.Empty;
            try
            {
                foreach (object objectToTemplate in objectsToTemplate)
                {
                    // getting the property variables for each object will allow objects of different types to
                    // be templated in one pass.  This incurs some processing overhead but the flexibility is
                    // worth it.
                    string[] propertyVariables = GetPropertyVariables(objectToTemplate.GetType());
                    string   virtualBoxPath    = GetVirtualDataBoxPath(context, objectToTemplate.GetType(), boxTemplateName);
                    if (string.IsNullOrEmpty(virtualBoxPath))
                    {
                        SendBoxedError(context, ExceptionHelper.CreateException <JsonInvalidOperationException>("Unable to find specified data box template ['{0}.{1}']", objectToTemplate.GetType().Name, boxTemplateName));
                    }

                    BoxResponse dataBoxResponse = GetBoxResponse(context, virtualBoxPath, objectToTemplate, true);
                    string      html            = dataBoxResponse.Html;
                    string      script          = dataBoxResponse.Script;

                    allHtml   += GetVariableReplaceText(html, propertyVariables, objectToTemplate);
                    allScript += GetVariableReplaceText(script, propertyVariables, objectToTemplate);
                }
            }
            catch (Exception ex)
            {
                SendBoxedError(context, ex);
            }

            responses.Add(clientKey, new BoxResponse(allHtml, allScript));

            response.Clear();
            response.Write(allHtml);
            response.Flush();
            response.SuppressContent = true;

            HttpContext.Current.ApplicationInstance.CompleteRequest();
            //response.End();
        }