Example #1
0
        internal string DrawHtml(string uniqueID, WebGridHtmlWriter writer, Grid grid, RowCell cell)
        {
            string theValueToShow = Value(cell);

            HtmlEditor e = new HtmlEditor
            {
                ID        = uniqueID,
                ImagePath = Grid.ImagePath,
                UserBRonCarriageReturn = true,
                Width  = (WidthEditableColumn != Unit.Empty ? WidthEditableColumn : 500),
                Height = (HeightEditableColumn != Unit.Empty ? HeightEditableColumn : 400),
                Text   = theValueToShow
            };

            e.ImagePath = GridConfig.Get("WGEditorImagePath", grid.ImagePath);
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            System.Web.UI.HtmlTextWriter mywriter = new System.Web.UI.HtmlTextWriter(sw);
            e.RenderControl(mywriter);
            mywriter.Flush();
            mywriter.Close();

            return(sb.ToString());
        }
Example #2
0
 private bool ShouldSerializeConnectionString()
 {
     if (string.IsNullOrEmpty(ConnectionString) == false &&
         (string.IsNullOrEmpty(GridConfig.Get("WGConnectionString", null as string)) ||
          ConnectionString.Equals(GridConfig.Get("WGConnectionString", null as string)) == false))
     {
         return(true);
     }
     return(Equals(m_ShouldSerializeConnectionString, true) ? true : false);
 }
Example #3
0
        /// <summary>
        /// This method is for sending out html emails asynchronously, the
        /// e-mail addresses are added into a thread-pool by the program and processed.
        /// Useful if your application need to send mass e-mails.
        /// IMPORTANT: "Async" Property for your web page has to be turned on to use this Method.
        /// </summary>
        /// <param name="message">E-mail message you want to send</param>
        /// <param name="smtpserver">smtp server for this e-mail</param>
        /// <remarks>This asynchronous method are logged at Windows EventLog (Application category) if any error. </remarks>
        public void SendEmail(MailMessage message, string smtpserver)
        {
            if (string.IsNullOrEmpty(smtpserver))
            {
                smtpserver = GridConfig.Get("WGSMTPSERVER", (string)null);
            }

            SendMailMessageDelegate dc = SendMailMessage;

            Asynchronous.FireAndForget(dc, message, smtpserver);
        }
Example #4
0
        /// <summary>
        /// Finds the valid connection string for your data source.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="grid">The grid object</param>
        /// <returns>The connection string</returns>
        public static string FindConnectionString(string connectionString, Grid grid)
        {
            DataBaseConnectionType connection_type = ConnectionType.FindConnectionType(connectionString);

            if (string.IsNullOrEmpty(connectionString) == false &&
                connectionString.IndexOf("|DataDirectory|", StringComparison.OrdinalIgnoreCase) > -1)
            {
                if (!Grid.GotHttpContext)
                {
                    if (grid == null || grid.Site == null)
                    {
                        return(connectionString);
                    }
                    IWebApplication webApp = (IWebApplication)grid.Site.GetService(typeof(IWebApplication));
                    if (webApp != null)
                    {
                        string directory = webApp.RootProjectItem.PhysicalPath;

                        if (directory == null)
                        {
                            throw new ApplicationException("No Physical path found for |DataDirectory|");
                        }
                        if (Directory.Exists(Path.Combine(directory, "App_data")))
                        {
                            directory = Path.Combine(directory, "App_data");
                        }
                        AppDomain.CurrentDomain.SetData("DataDirectory", directory);
                    }
                }
            } // We already got valid connection string
            if (connection_type != DataBaseConnectionType.Unknown)
            {
                return(connectionString);
            }
            // Load default connection string from AppSettings
            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = "WGConnectionString";
            }
            if (GridConfig.Get(connectionString, null as string) == null)
            {
                //If not try to load it from ConnectionStrings
                if (ConfigurationManager.ConnectionStrings != null && ConfigurationManager.ConnectionStrings[connectionString] != null)
                {
                    return(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString);
                }
                return(null);
            }
            connectionString = GridConfig.Get(connectionString, null as string);
            return(connectionString);
        }
Example #5
0
        /// <summary>
        /// Finds the valid connection string for your data source.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>The connection string</returns>
        public static string FindConnectionString(string connectionString)
        {
            DataBaseConnectionType connection_type = ConnectionType.FindConnectionType(connectionString);

            if (connection_type != DataBaseConnectionType.Unknown) // Already valid connection string?
            {
                return(connectionString);
            }

            // NO ConnectionString provided...
            connectionString = string.IsNullOrEmpty(connectionString) ? GridConfig.Get("WGConnectionString", null as string) : GridConfig.Get(connectionString, connectionString);

            return(connectionString);
        }
Example #6
0
        /// <summary>
        /// Method to access WebGrid Sms Service and sending out sms asynchronously (threadpool), to access this service you must provide
        /// a customerId and password. For further information please read documentation at
        /// <see cref="WebGrid.Util.Sms"/>.
        /// This method support also Web.Config to access customerId and password information for WebGrid Sms
        /// the web.config keys are "WGSMSCUSTOMERID" and "WGSMSPASSWORD".
        /// </summary>
        /// <param name="sender">Sender address, must be alfanumeric string with no more then 11 characters and no special characters.</param>
        /// <param name="receiver">The receivers cellphone number, can be Separated by ";" and all numbers must be written with international number. See documentation for further information.</param>
        /// <param name="message">The message you want to send. All messages with more then 160 characters will be split.</param>
        /// <param name="eventhandler">The event handler</param>
        /// <param name="userToken">The user token for this message</param>
        /// <remarks>
        /// Using the receiver parameter you must include country number, area number, and local number. Example could be "4712345678", where
        /// "47" is the norwegian country code and 12345678 is area and local number.
        /// </remarks>
        public void SendSms(string sender, string receiver, string message, UploadDataCompletedEventHandler eventhandler,
                            object userToken)
        {
            if (string.IsNullOrEmpty(customerId))
            {
                customerId = GridConfig.Get("WGSMSCUSTOMERID", "0");
            }
            if (string.IsNullOrEmpty(password))
            {
                password = GridConfig.Get("WGSMSPASSWORD", null as string);
            }

            if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(customerId))
            {
                throw (new ApplicationException(
                           "customerID or password is missing for WebGrid.Util.Sms (Could not find web.config keys WGSMSCUSTOMERID and WGSMSPASSWORD"));
            }

            internalSendSms(sender, receiver, message, eventhandler, userToken);
        }
Example #7
0
        /// <summary>
        /// Sends the email.
        /// </summary>
        /// <param name="emailAddresses">A string array of email addresses to send.</param>
        /// <param name="senderEmailAddress">The sender's email address</param>
        /// <param name="grid">The grid.</param>
        /// <returns>Number of email's sent</returns>
        /// <remarks>This asynchronous method are logged at Windows EventLog (Application category) if any error. </remarks>
        public static int SendEmail(string[] emailAddresses, string senderEmailAddress, Grid grid)
        {
            StringBuilder sb = new StringBuilder(string.Empty);

            sb.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");

            // Render header for rows if more then 1 row.
            if (grid.Rows.Count > 1)
            {
                sb.Append("<tr>");
                foreach (Column column in grid.Columns)
                {
                    if (column.Visibility == Visibility.Both || column.Visibility == Visibility.Grid)
                    {
                        sb.AppendFormat("<td>{0}</td>", column.Title);
                    }
                }
                sb.Append("</tr>");
            }
            Mail      wgmail      = new Mail();
            ArrayList attachments = new ArrayList();

            // Render column foreach row if one row, else render all columns in one row.
            foreach (Row gridrow in grid.Rows)
            {
                if (gridrow == null)
                {
                    continue;
                }
                if (grid.Rows.Count > 1)
                {
                    sb.Append("<tr>");
                }
                foreach (Column column in gridrow.Columns)
                {
                    if (column.Visibility == Visibility.None || column.ColumnType == ColumnType.Chart ||
                        column.ColumnType == ColumnType.SystemColumn)
                    {
                        continue;
                    }

                    if (column.ColumnType == ColumnType.File && grid.Rows.Count == 1)
                    {
                        File attachcolumn = (File)column;

                        Attachment attachfile =
                            new Attachment(attachcolumn.AbsoluteDirectoryFileName(gridrow[column.ColumnId]).Replace("NULL", grid.InternalId),
                                           "UUEncode");

                        attachments.Add(attachfile);
                        continue;
                    }
                    object value = gridrow[column.ColumnId].Value;
                    if (column.ColumnType == ColumnType.ColumnTemplate)
                    {
                        if (grid.DisplayView == DisplayView.Detail && ((ColumnTemplate)column).DetailViewTemplate != null)
                        {
                            value = ((ColumnTemplate)column).RenderTemplate(gridrow[column.ColumnId]);
                        }
                        else if (grid.DisplayView == DisplayView.Grid && ((ColumnTemplate)column).GridViewTemplate != null)
                        {
                            value = ((ColumnTemplate)column).RenderTemplate(gridrow[column.ColumnId]);
                        }
                    }
                    switch (column.ColumnType)
                    {
                    case ColumnType.Foreignkey:
                    {
                        RowCollection row = ((Foreignkey)column).Table.Rows;

                        for (int i = 0; i < row.Count; i++)
                        {
                            if (row[i][column.ColumnId].Value == null ||
                                row[i].PrimaryKeyUpdateValues != row[i][column.ColumnId].Value.ToString())
                            {
                                continue;
                            }
                            value =
                                Foreignkey.BuildDisplayText(i,
                                                            ((Foreignkey)column).ValueColumn,
                                                            ((Foreignkey)column).Table);
                            break;
                        }
                    }
                    break;

                    case ColumnType.ManyToMany:
                    {
                        value = string.Empty;
                        ManyToManyCollection items = ((ManyToMany)column).LoadItems(gridrow[column.ColumnId]);

                        for (int i = 0; i < items.Count; i++)
                        {
                            if (items[i].Checked)
                            {
                                if (value == null)
                                {
                                    value = items[i].DisplayText;
                                }
                                else
                                {
                                    value += string.Format(" , {0}", items[i].DisplayText);
                                }
                            }
                        }
                    }
                    break;
                    }
                    if ((column.Visibility == Visibility.Both || column.Visibility == Visibility.Grid) &&
                        grid.Rows.Count > 1)
                    {
                        sb.AppendFormat("<td>{0}</td>", value);
                    }
                    else if ((column.Visibility == Visibility.Both || column.Visibility == Visibility.Detail) &&
                             grid.Rows.Count == 1)
                    {
                        if (!column.HideDetailTitle)
                        {
                            sb.AppendFormat("<tr><td><b>{0}</b></td></tr><tr><td>{1}</td></tr>", column.Title, value);
                        }
                        else
                        {
                            sb.AppendFormat("<tr><td></td></tr><tr><td>{0}</td></tr>", value);
                        }
                    }
                }

                sb.Append("</tr>");
            }
            sb.Append("</table>");

            string smtpserver = GridConfig.Get("WGSMTPSERVER", (string)null);

            if (grid.MailForm.SmtpServer != null)
            {
                smtpserver = grid.MailForm.SmtpServer;
            }
            string body       = sb.ToString();
            int    sentemails = 0;

            foreach (string emailaddress in emailAddresses)
            {
                if (!ValidEmail(emailaddress))
                {
                    continue;
                }
                sentemails++;
                MailMessage message = new MailMessage(new MailAddress(emailaddress), new MailAddress(emailaddress));

                for (int i = 0; i < attachments.Count; i++)
                {
                    message.Attachments.Add((Attachment)attachments[i]);
                }

                message.IsBodyHtml = true;

                message.From = string.IsNullOrEmpty(senderEmailAddress) == false
                                   ? new MailAddress(senderEmailAddress)
                                   : new MailAddress(emailaddress);
                message.Subject = grid.MailForm.Subject ?? grid.Title;
                message.Body    = HttpUtility.HtmlDecode(body);
                wgmail.SendEmail(message, smtpserver);
            }
            return(sentemails);
        }
Example #8
0
 private bool ShouldSerializeEnableCallBack()
 {
     return(EnableCallBack != GridConfig.Get("WGEnableCallBack", true));
 }
Example #9
0
        private void LoadLanguage()
        {
            if (Language == SystemLanguage.Undefined)
            {
                Language = (SystemLanguage)Enum.Parse(typeof(SystemLanguage),
                                                      GridConfig.Get("WGLanguage", SystemLanguage.English.ToString()),
                                                      true);
            }

            string cacheobjectSystemMessages = string.Format("{0}_{1}_{2}_SystemMessages_{3}", ClientID, Trace.ClientID, DataSourceId, Language);

            if (m_GridSystemMessages != null)
            {
                return;
            }
            if (DesignMode == false && HttpRuntime.Cache != null && Equals(CacheGridStructure, true) &&
                HttpRuntime.Cache.Get(cacheobjectSystemMessages) != null)
            {
                m_GridSystemMessages = HttpRuntime.Cache.Get(cacheobjectSystemMessages) as SystemMessages;

                if (Debug)
                {
                    m_DebugString.AppendFormat("<b>Cache</b> - Loading system messages from cache object: {0}<br/>",
                                               cacheobjectSystemMessages);
                }
                return;
            }

            if (Trace.IsTracing)
            {
                Trace.Trace("{0} : Started LoadLanguage()", ID);
            }
            // What language should we load?

            string systemmessagefile = SystemMessageDataFile;

            try
            {
                if (systemmessagefile != null &&
                    systemmessagefile.StartsWith("http://", StringComparison.OrdinalIgnoreCase) == false)
                {
                    if (Equals(DesignMode, true) && Site != null)
                    {
                        systemmessagefile = GridConfig.LoadSystemLanguages(systemmessagefile, Site);
                    }
                    else
                    {
                        systemmessagefile = GridConfig.LoadSystemLanguages(systemmessagefile);
                    }
                }
                if (systemmessagefile != null && System.IO.File.Exists(systemmessagefile) == false)
                {
                    throw new GridException(
                              string.Format("The system message file '{0}' does not exists.", systemmessagefile));
                }
                if (string.IsNullOrEmpty(systemmessagefile))
                // Load from resources if not available.
                {
                    m_GridSystemMessages = new SystemMessages();
                    Assembly a = Assembly.GetExecutingAssembly(); //Assembly.Load(GetType().Assembly.GetName().Name);

                    Stream str = a.GetManifestResourceStream("WebGrid.Resources.WebGridMessages.xml");
                    if (str == null)
                    {
                        throw new GridException("WebGrid messages is not found in resources.");
                    }
                    XmlTextReader tr  = new XmlTextReader(str);
                    XmlDocument   xml = new XmlDocument();
                    xml.Load(tr);
                    XPathNavigator nav = xml.CreateNavigator();

                    if (nav == null)
                    {
                        throw new GridException("Unable to get a XpathNavigator for WebGrid Messages (in resources).");
                    }
                    XPathNodeIterator it = nav.Select(string.Format(@"//{0}/*", Language));

                    while (it.MoveNext())
                    {
                        if (string.IsNullOrEmpty(it.Current.Name) || string.IsNullOrEmpty(it.Current.Value))
                        {
                            continue;
                        }
                        m_GridSystemMessages.SetSystemMessage(it.Current.Name, it.Current.Value, null);
                    }
                }
                else
                {
                    m_GridSystemMessages = new SystemMessages(Language, systemmessagefile, this);
                }
            }
            catch (Exception ee)
            {
                throw new GridException(
                          string.Format("Error loading WebGrid system message file '{0}'.", systemmessagefile), ee);
            }

            if (HttpRuntime.Cache != null && Equals(CacheGridStructure, true))
            {
                HttpRuntime.Cache[cacheobjectSystemMessages] = m_GridSystemMessages;
            }
            if (Trace.IsTracing)
            {
                Trace.Trace(string.Format("{0} : Stopped LoadLanguage()", ID));
            }
        }