Exemple #1
0
        /// <summary>
        /// Load the Full Url History
        /// </summary>
        private void LoadHistory()
        {
            this.urlList = DataController.RetrieveUrlList();

            foreach (Container urlContainer in this.urlList)
            {
                urlContainer.ShortenedUrl = Utils.PublicShortUrl(
                    urlContainer.ShortenedUrl, Globals.GetDomainName(this.Request, true));

                // Remove "http://www" or "http://"
                if (urlContainer.ShortenedUrl.StartsWith("http://www"))
                {
                    urlContainer.ShortenedUrl = urlContainer.ShortenedUrl.Replace("http://www.", string.Empty);
                }
                else if (urlContainer.ShortenedUrl.StartsWith("http://"))
                {
                    urlContainer.ShortenedUrl = urlContainer.ShortenedUrl.Replace("http://", string.Empty);
                }

                UserController userController = new UserController();

                try
                {
                    urlContainer.CreatedUser =
                        userController.GetUser(this.PortalId, int.Parse(urlContainer.CreatedUser)).Username;
                }
                catch (Exception)
                {
                    urlContainer.CreatedUser = "******";
                }
            }

            StringBuilder sbHistoryGrd = new StringBuilder();

            sbHistoryGrd.Append("jQuery(document).ready(function(){");

            // Clear Grid Data if PostBack
            sbHistoryGrd.Append("jQuery('#grdUrlHistory').clearGridData();");

            sbHistoryGrd.Append("var grid = jQuery('#grdUrlHistory').jqGrid({");

            sbHistoryGrd.Append("datatype: 'local',");

            sbHistoryGrd.Append("autowidth : true,");
            sbHistoryGrd.Append("height : '100%',");
            sbHistoryGrd.Append("rowNum: 10,");
            sbHistoryGrd.Append("rowList:[10,20,50,100],");
            sbHistoryGrd.Append("sortname: 'CreateDate',");
            sbHistoryGrd.Append("sortorder: 'desc',");
            sbHistoryGrd.Append("viewrecords: true,");

            sbHistoryGrd.Append("pager: jQuery('#pager'),");

            sbHistoryGrd.AppendFormat("colNames:[{0}],", Localization.GetString("Columns.Text", this.LocalResourceFile));

            sbHistoryGrd.Append("colModel:[");
            sbHistoryGrd.Append("{name:'Clicked',index:'Clicked', width:55, sorttype:'int', align:'center'},");
            sbHistoryGrd.Append("{name:'RealUrl', index:'RealUrl', sorttype:'link', width:500, sorttype:'text'},");
            sbHistoryGrd.Append(
                "{name:'ShortenedUrl', index:'ShortenedUrl',sorttype:'link', width:240, sorttype:'text'},");
            sbHistoryGrd.Append("{name:'Created', index:'Created',sorttype:'text', width:125},");
            sbHistoryGrd.Append("{name:'CreatedBy', index:'CreatedBy', align:'center', width:80, sorttype:'float'},");
            sbHistoryGrd.Append("{name:'CreatedUser', index:'CreatedUser', align:'center', width:90, sorttype:'text'},");
            sbHistoryGrd.Append("{name:'CreateDate', index:'CreateDate',sorttype:'int', hidden:true},");
            sbHistoryGrd.Append("],");

            sbHistoryGrd.AppendFormat("caption: '{0}',", Localization.GetString("Caption.Text", this.LocalResourceFile));
            sbHistoryGrd.AppendFormat(
                "emptyrecords: '{0}',", Localization.GetString("NoRecords.Text", this.LocalResourceFile));

            sbHistoryGrd.Append("});");

            // sbHistoryGrd.Append("jQuery('#grdUrlHistory').jqGrid('navGrid','#pager',{edit:false,add:false,del:false, refresh:false});");

            // Delete Helper
            sbHistoryGrd.AppendFormat("jQuery('#{0}').click( function() {{", this.btnDeleteUrl.ClientID);

            sbHistoryGrd.Append("var id; id = jQuery('#grdUrlHistory').jqGrid('getGridParam','selrow');");
            sbHistoryGrd.Append("if (id){");
            sbHistoryGrd.Append("var ret = jQuery('#grdUrlHistory').jqGrid('getRowData',id);");

            sbHistoryGrd.AppendFormat(
                " document.getElementById('{0}').value = ret.ShortenedUrl;", this.inpHide.ClientID);

            sbHistoryGrd.Append("} else { alert('Please select row');}");

            sbHistoryGrd.Append("});");

            // Edit Helper
            sbHistoryGrd.AppendFormat("jQuery('#{0}').click( function() {{", this.btnEditurl.ClientID);

            sbHistoryGrd.Append("var id; id = jQuery('#grdUrlHistory').jqGrid('getGridParam','selrow');");
            sbHistoryGrd.Append("if (id){");
            sbHistoryGrd.Append("var ret = jQuery('#grdUrlHistory').jqGrid('getRowData',id);");

            sbHistoryGrd.AppendFormat(
                " document.getElementById('{0}').value = ret.ShortenedUrl;", this.inpHide.ClientID);

            sbHistoryGrd.Append("} else { alert('Please select row');}");

            sbHistoryGrd.Append("});");

            /////////////
            sbHistoryGrd.Append("var myData = [");

            foreach (Container container in this.urlList)
            {
                TimeSpan ts    = new TimeSpan(container.CreateDate.Ticks);
                long     ticks = ts.Ticks;

                sbHistoryGrd.AppendFormat(
                    "{{Clicked:'{5}', RealUrl:'{0}',ShortenedUrl:'{1}',Created:'{2}',CreatedBy:'{3}',CreatedUser:'******',CreateDate:'{6}'}},",
                    Utils.CleanString(container.RealUrl.Trim()),
                    container.ShortenedUrl,
                    Utils.ReFormatDateTime(container.CreateDate),
                    container.CreatedBy,
                    container.CreatedUser,
                    container.Clicked,
                    ticks);
            }

            sbHistoryGrd.Append("];");
            sbHistoryGrd.Append("for(var i=0;i<=myData.length;i++)");
            sbHistoryGrd.Append("{grid.addRowData(i + 1, myData[i]);}");

            sbHistoryGrd.Append("grid.trigger('reloadGrid',[{page:1}]);");

            sbHistoryGrd.Append("});");

            ScriptManager.RegisterStartupScript(
                this, typeof(Page), Guid.NewGuid().ToString(), sbHistoryGrd.ToString(), true);
        }
        /// <summary>
        /// Load the Full 404 Error Log
        /// </summary>
        private void LoadErrorLog()
        {
            List <ErrorLog> logList;

            try
            {
                logList = DataController.RetrieveErrorList();
            }
            catch (Exception)
            {
                logList = new List <ErrorLog>();
            }

            var historyGridScript = new StringBuilder();

            historyGridScript.Append("jQuery(document).ready(function(){");

            // Clear Grid Data if PostBack
            historyGridScript.Append("jQuery('#grdErrorLog').clearGridData();");

            historyGridScript.Append("var grid = jQuery('#grdErrorLog').jqGrid({");

            historyGridScript.Append("datatype: 'local',");

            historyGridScript.Append("autowidth : true,");
            historyGridScript.Append("height : '100%',");
            historyGridScript.Append("rowNum: 10,");
            historyGridScript.Append("rowList:[10,20,50,100],");
            historyGridScript.Append("sortname: 'ReqTime',");
            historyGridScript.Append("sortorder: 'desc',");
            historyGridScript.Append("viewrecords: true,");

            historyGridScript.Append("pager: jQuery('#pager'),");

            historyGridScript.AppendFormat("colNames:[{0}],", Localization.GetString("Columns.Text", this.LocalResourceFile));

            historyGridScript.Append("colModel:[");
            historyGridScript.Append("{name:'ReqTime',index:'ReqTime', sorttype:'int', align:'center',width:100 },");
            historyGridScript.Append("{name:'RequestUrl', index:'RequestUrl', sorttype:'link', sorttype:'text',width:400},");
            historyGridScript.Append(
                "{name:'UserHostAdress', index:'UserHostAdress',sorttype:'text', sorttype:'text',width:70},");
            historyGridScript.Append("{name:'UserAgent', index:'UserAgent',sorttype:'text',width:130 },");
            historyGridScript.Append("{name:'UrlReferrer', index:'UrlReferrer', align:'center', sorttype:'text',width:200},");
            historyGridScript.Append("{name:'Browser', index:'Browser', align:'center', sorttype:'text',width:70},");
            historyGridScript.Append("{name:'Platform', index:'Platform', align:'center', sorttype:'text',width:55},");
            historyGridScript.Append("],");

            historyGridScript.AppendFormat("caption: '{0}',", Localization.GetString("Caption.Text", this.LocalResourceFile));
            historyGridScript.AppendFormat("emptyrecords: '{0}',", Localization.GetString("NoRecords.Text", this.LocalResourceFile));

            historyGridScript.Append("});");

            historyGridScript.Append("var myData = [");

            foreach (ErrorLog errorLog in logList)
            {
                historyGridScript.AppendFormat(
                    "{{ReqTime:'{0}', RequestUrl:'{1}'\n,UserHostAdress:'{2}',UserAgent:'{3}',UrlReferrer:'{4}',Browser:'{5}',Platform:'{6}'}},",
                    errorLog.ReqTime,
                    Utils.CleanString(errorLog.RequestUrl.Trim()),
                    errorLog.UserHostAddress,
                    errorLog.UserAgent,
                    Utils.CleanString(errorLog.UrlReferrer.Trim()),
                    errorLog.Browser,
                    errorLog.Platform);
            }

            historyGridScript.Append("];");
            historyGridScript.Append("for(var i=0;i<=myData.length;i++)");
            historyGridScript.Append("{grid.addRowData(i + 1, myData[i]);}");

            historyGridScript.Append("grid.trigger('reloadGrid',[{page:1}]);");

            historyGridScript.Append("});");

            ScriptManager.RegisterStartupScript(
                this, typeof(Page), Guid.NewGuid().ToString(), historyGridScript.ToString(), true);
        }
Exemple #3
0
        /// <summary>
        /// The process request.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            string sEncData = !string.IsNullOrEmpty(context.Request["data"])
                                  ? context.Request["data"]
                                  : "http://dnnurlshorty.codeplex.com";

            if (!sEncData.StartsWith(@"http://"))
            {
                sEncData = DataController.RetrieveUrlFromDatabase(sEncData).RealUrl;
            }

            int iScale = !string.IsNullOrEmpty(context.Request["scale"]) ? Convert.ToInt16(context.Request["scale"]) : 3;

            int iVersion = !string.IsNullOrEmpty(context.Request["version"])
                               ? Convert.ToInt16(context.Request["version"])
                               : 7;

            string sErrorCorrect = !string.IsNullOrEmpty(context.Request["errorCorrect"])
                                       ? context.Request["errorCorrect"]
                                       : "M";

            string sEncoding = !string.IsNullOrEmpty(context.Request["encoding"]) ? context.Request["encoding"] : "Byte";

            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder
            {
                QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE, QRCodeScale = iScale, QRCodeVersion = iVersion,
            };

            switch (sEncoding)
            {
            case "Byte":
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                break;

            case "AlphaNumeric":
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
                break;

            case "Numeric":
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
                break;
            }

            switch (sErrorCorrect)
            {
            case "L":
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                break;

            case "M":
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                break;

            case "Q":
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
                break;

            case "H":
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
                break;

            default:
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                break;
            }

            string data  = sEncData;
            Image  image = qrCodeEncoder.Encode(data);

            context.Response.ContentType = "image/jpeg";
            image.Save(context.Response.OutputStream, ImageFormat.Jpeg);

            image.Dispose();
        }
        /// <summary>
        /// Empty Error Log
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void EmptyLog(object sender, EventArgs e)
        {
            DataController.DeleteAllErrorsFromDb();

            this.LoadErrorLog();
        }
Exemple #5
0
        /// <summary>
        /// Generate ShortUrl
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The Event Arguments.
        /// </param>
        protected void GenerateShortUrl(object sender, EventArgs e)
        {
            this.txtRealUrl.Text = this.txtRealUrl.Text.Trim();

            if (string.IsNullOrEmpty(this.txtRealUrl.Text) || !this.txtRealUrl.Text.StartsWith("http"))
            {
                return;
            }

            UserInfo userinfo = UserController.GetCurrentUserInfo();

            string sUserName = userinfo != null?userinfo.UserID.ToString() : "Guest";

            bool   bUseCustom = false;
            string sCustomUrl = null;

            // If Custom Url
            if (this.txtCustomUrl.Visible && !string.IsNullOrEmpty(this.txtCustomUrl.Text))
            {
                sCustomUrl = Utils.CleanCustomUrl(this.txtCustomUrl.Text);

                this.txtCustomUrl.Text = sCustomUrl;

                string sCustomUrlFull = string.Format("http://{0}{1}", this.lblDomainName2.Text, sCustomUrl);

                try
                {
                    bUseCustom = Utils.IsValidCustomUrl(sCustomUrlFull);
                }
                catch (Exception)
                {
                    bUseCustom = false;
                }

                if (!bUseCustom)
                {
                    this.lblDialogInfo.Text = Localization.GetString("lblDialogInfo.Text", this.LocalResourceFile);

                    // Message Error Already taken
                    ScriptManager.RegisterStartupScript(
                        this.Page,
                        this.Page.GetType(),
                        string.Format("DialogOpen{0}", Guid.NewGuid()),
                        "jQuery('#ErrorDialog').dialog('open');",
                        true);
                    return;
                }
            }

            Container oShortUrl = new Container
            {
                RealUrl      = this.txtRealUrl.Text,
                ShortenedUrl = DataController.UniqueShortUrl(),
                CreateDate   = DateTime.Now,
                CreatedBy    = HttpContext.Current.Request.UserHostAddress,
                CreatedUser  = sUserName,
                Clicked      = 0
            };

            // Now Replace Unique Short Url with Custom Url
            if (bUseCustom && !string.IsNullOrEmpty(sCustomUrl))
            {
                oShortUrl.ShortenedUrl = sCustomUrl;
            }

            oShortUrl.ShortenedUrl = DataController.AddUrlToDatabase(oShortUrl, this.sHashReuseMode, bUseCustom);

            // Show QR Code
            this.QrContainer.Visible = true;
            this.imgQrCode.Visible   = true;
            this.imgQrCode.ImageUrl  = string.Format(
                "{0}?data={1}", this.ResolveUrl("QrCode.ashx"), oShortUrl.ShortenedUrl);

            oShortUrl.ShortenedUrl = Utils.PublicShortUrl(
                oShortUrl.ShortenedUrl, Globals.GetDomainName(this.Request, true));

            this.lnkShortUrl.NavigateUrl = oShortUrl.ShortenedUrl;

            // Remove "http://www" or "http://"
            if (oShortUrl.ShortenedUrl.StartsWith("http://www"))
            {
                oShortUrl.ShortenedUrl = oShortUrl.ShortenedUrl.Replace("http://www.", string.Empty);
            }
            else if (oShortUrl.ShortenedUrl.StartsWith("http://"))
            {
                oShortUrl.ShortenedUrl = oShortUrl.ShortenedUrl.Replace("http://", string.Empty);
            }

            // Append Google Analytics URL
            if (this.useAnalyticsUrl)
            {
                oShortUrl.ShortenedUrl = this.GenerateAnalyticsUrl(oShortUrl.ShortenedUrl);
            }

            this.lnkShortUrl.Text = oShortUrl.ShortenedUrl;
            this.txtRealUrl.Text  = oShortUrl.ShortenedUrl;

            this.lblLinkInfo.Visible = true;

            this.btnCopyClip.Visible = true;

            this.LoadUserHistory();

            this.lblDialogInfo.Text =
                string.Format(
                    Localization.GetString("lblDialogInfoCopy.Text", this.LocalResourceFile), this.txtRealUrl.Text);

            var zeroClipBoardScript = new StringBuilder();

            zeroClipBoardScript.AppendFormat(
                "ZeroClipboard.setMoviePath( '{0}' );var clip = new ZeroClipboard.Client(); clip.setText('{1}');clip.glue('{2}');",
                this.ResolveUrl("js/ZeroClipboard.swf"),
                this.txtRealUrl.Text,
                this.btnCopyClip.ClientID);

            zeroClipBoardScript.Append(
                "clip.show();clip.addEventListener( 'mouseDown', function(client) {{jQuery('#ErrorDialog').dialog('open') }});");

            ScriptManager.RegisterStartupScript(
                this.Page,
                this.Page.GetType(),
                string.Format("CopyToClipBoard{0}", Guid.NewGuid()),
                zeroClipBoardScript.ToString(),
                true);
        }