コード例 #1
0
        private bool SaveSiteContents(string domain, SiteContents siteContents, bool overwrite)
        {
            if (!SiteInfo.IsValidDomain(domain))
            {
                return(false);
            }

            var container = GetContentsBlobContainer();
            var blob      = container.GetBlockBlobReference(domain + _siteFileExt);

            if (!overwrite && blob.Exists())
            {
                return(false);
            }

            try
            {
                blob.UploadText(siteContents.SerializeToJson());
            }
            catch
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private SiteContents LoadSiteContents(string domain)
        {
            if (!SiteInfo.IsValidDomain(domain))
            {
                return(null);
            }

            var container = GetContentsBlobContainer();
            var blob      = container.GetBlockBlobReference(domain + _siteFileExt);

            if (!blob.Exists())
            {
                return(null);
            }

            try
            {
                string st = blob.DownloadText();
                return(SiteContents.DeserializeFromJson(st));
            }
            catch
            {
                return(null);
            }
        }
コード例 #3
0
        private bool SaveSiteContentsToFile(string domain, SiteContents siteContents, bool overwrite)
        {
            if (!SiteInfo.IsValidDomain(domain))
            {
                return(false);
            }

            string fileName = GetFullSiteContentsFileName(domain);

            if (!overwrite && File.Exists(fileName))
            {
                return(false);
            }

            int retryCount = 3;

            do
            {
                try
                {
                    using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write(siteContents.SerializeToJson());
                        }
                    }

                    return(true);
                }
                catch (IOException)
                {
                    retryCount--;

                    if (retryCount == 0)
                    {
                        return(false);
                    }

                    Thread.Sleep(2);
                }
                catch
                {
                    return(false);
                }
            }while (retryCount > 0);

            return(true);
        }
コード例 #4
0
        private SiteContents LoadSiteContentsFromFile(string domain)
        {
            if (!SiteInfo.IsValidDomain(domain))
            {
                return(null);
            }

            string fileName = GetFullSiteContentsFileName(domain);

            if (!File.Exists(fileName))
            {
                return(null);
            }

            int retryCount = 3;

            do
            {
                try
                {
                    using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            string st = reader.ReadToEnd();
                            return(SiteContents.DeserializeFromJson(st));
                        }
                    }
                }
                catch (IOException)
                {
                    retryCount--;

                    if (retryCount == 0)
                    {
                        return(null);
                    }

                    Thread.Sleep(2);
                }
                catch
                {
                    return(null);
                }
            }while (retryCount > 0);

            return(null);
        }
コード例 #5
0
    protected void Save_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            Boolean _status = true;

            foreach (RepeaterItem I in rpt_Share.Items)
            {
                Label _lbl = (Label)I.FindControl("lbl_ContentId");
                if (_lbl != null)
                {
                    SiteContents _cont = new SiteContents(this.ConnectionString);
                    _cont.LitePopulate(_lbl.Text, true);
                    _cont.Description = ((TextBox)I.FindControl("txt_Desc")).Text;
                    _cont.Title = ((TextBox)I.FindControl("txt_Title")).Text;
                    _cont.Sort = Convert.ToInt32(((TextBox)I.FindControl("txt_Sort")).Text);
                    _cont.PageId = Convert.ToInt32(ConfigurationManager.AppSettings["Share"]);

                    if (!_cont.Save(true, null))
                    {
                        lbl_Error.Text = "An unexpected error has occurred. Please try again.";
                        lbl_Error.Visible = true;
                        _status = false;
                        break;
                    }
                }
            }
            if (_status)
            {
                Pages _page = new Pages(this.ConnectionString);
                _page.LitePopulate(ConfigurationManager.AppSettings["Share"], true);
                Bind(_page);
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "alert('Record has been updated successfully.');", true);
            }
        }
    }
コード例 #6
0
ファイル: History.aspx.cs プロジェクト: noximus/TopOfTheRock
    protected void Save_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            Boolean _status = true;

            foreach (RepeaterItem I in rpt_History.Items)
            {
                Label _lbl = (Label)I.FindControl("lbl_ContentId");
                if (_lbl != null)
                {
                    SiteContents _cont = new SiteContents(this.ConnectionString);
                    _cont.LitePopulate(_lbl.Text, true);
                    _cont.Description = ((TextBox)I.FindControl("txt_Desc")).Text;
                    _cont.Title = ((TextBox)I.FindControl("txt_Title")).Text;
                    _cont.Sort = Convert.ToInt32(((TextBox)I.FindControl("txt_Sort")).Text);
                    _cont.PageId = Convert.ToInt32(ConfigurationManager.AppSettings["History"]);

                    String _imgFile = "";
                    FileUpload _fu = (FileUpload)I.FindControl("fu_Image");
                    SiteContentImages _siteImg = null;
                    if (_fu.HasFile)
                    {
                        _imgFile = _fu.FileName.Split('.')[1];

                        if (_cont.Images.Count == 0)
                        {
                            _siteImg = new SiteContentImages(this.ConnectionString);
                            _cont.Images.Add(_siteImg);
                            _siteImg.ContentId = Convert.ToInt32(_cont.ID);
                        }
                        else
                        {
                            _siteImg = (SiteContentImages)_cont.Images[0];
                        }

                        _siteImg.Sort = Convert.ToInt32(((TextBox)I.FindControl("txt_Sort")).Text);
                        _siteImg.ImgType = _imgFile;
                    }

                    if (!_cont.Save(true, null))
                    {
                        lbl_Error.Text = "An unexpected error has occurred. Please try again.";
                        lbl_Error.Visible = true;
                        _status = false;
                        break;
                    }
                    else
                    {
                        if (_fu.HasFile)
                        {
                            String _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["HistoryImagesPath"], _siteImg.ID.ToString(), _imgFile));
                            _fu.SaveAs(_path);
                        }
                    }
                }
            }
            if (_status)
            {
                Pages _page = new Pages(this.ConnectionString);
                _page.LitePopulate(ConfigurationManager.AppSettings["History"], true);
                Bind(_page);
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "alert('Record has been updated successfully.');", true);
            }
        }
    }