示例#1
0
        /// <summary>
        /// Loads the markdown document into the CurrentText
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool Load(string filename = null, SecureString password = null)
        {
            if (string.IsNullOrEmpty(filename))
            {
                filename = Filename;
            }

            if (password == null)
            {
                password = Password;
            }
            else
            {
                Password = password;
            }

            if (!File.Exists(filename))
            {
                FileCrc = null;
                return(false);
            }

            Filename = filename;
            UpdateCrc();
            GetFileEncoding();

            try
            {
                CurrentText = File.ReadAllText(filename, Encoding);

                if (password != null)
                {
                    if (CurrentText.StartsWith(ENCRYPTION_PREFIX))
                    {
                        string encrypted = CurrentText.Substring(ENCRYPTION_PREFIX.Length);
                        CurrentText = Encryption.DecryptString(encrypted, password.GetString());
                        if (string.IsNullOrEmpty(CurrentText))
                        {
                            return(false);
                        }
                    }
                }

                OriginalText      = CurrentText;
                AutoSaveBackups   = mmApp.Configuration.AutoSaveBackups;
                AutoSaveDocuments = mmApp.Configuration.AutoSaveDocuments;
                ProcessScripts    = mmApp.Configuration.MarkdownOptions.AllowRenderScriptTags;
                IsDirty           = false;
            }
            catch
            {
                return(false);
            }

            return(true);
        }
示例#2
0
 /// <summary>
 /// Sets the PreviewWebRootPath from content in the YAML of the document:
 /// webRootPath: c:\temp\post\Topic\
 /// </summary>
 public string GetPreviewWebRootPathFromDocument()
 {
     if (CurrentText.StartsWith("---"))
     {
         var yaml = StringUtils.ExtractString(CurrentText, "---", "---");
         if (!string.IsNullOrEmpty(yaml))
         {
             PreviewWebRootPath = StringUtils.ExtractString(CurrentText, "\npreviewWebRootPath:", "\n", true, false, false);
             if (string.IsNullOrEmpty(PreviewWebRootPath))
             {
                 return(null);
             }
         }
     }
     return(null);
 }