Beispiel #1
0
		internal bool PreviewTabSelected(ScenarioNode node)
		{
			if (templateEditor.InnerHtml == null)
			{
				previewBrowser.DocumentText = "";
				return true;
			}
			var topicNumber = "";
			var title = "";

			var tableCounter = 1;

#warning Review this: eval sessions now lock the vault for reading

#if VAULT_EVAL_1
            using (_evalSession1 = new Esath.Eval.Ver1.EvalSession(Scenario.Vault))
            {
#endif

#if VAULT_EVAL_2
			using (var repo = RepositoryEditor.Repository())
			using (_evalSession2 = new Esath.Eval.Ver2.EvalSession(Scenario.Vault, repo, null))
			{
#endif

#if VAULT_EVAL_3
            using (_evalSession3 = new Esath.Eval.Ver3.EvalSession(Scenario.VaultCompiler))
            {
#endif

				var preview = Regex.Replace(templateEditor.InnerHtml, StartUp.VFIELD_PATTERN, vpathEvaluator, RegexOptions.Compiled);
				if (node.Title != "")
				{
					title = node.Title;
					switch (node.NodeType)
					{
						case ScenarioNodeType.Topic:
							topicNumber = "1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "1", topicNumber);
							break;
						case ScenarioNodeType.Subtopic2:
							topicNumber = "1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "2", topicNumber);
							break;
						case ScenarioNodeType.Subtopic3:
							topicNumber = "1.1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "3", topicNumber);
							break;
						case ScenarioNodeType.Subtopic4:
							topicNumber = "1.1.1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "4", topicNumber);
							break;
						case ScenarioNodeType.Subtopic5:
							topicNumber = "1.1.1.1.1";
							title = string.Format("<h{1}>{2} {0}</h{1}>", title, "5", topicNumber);
							break;
						default:
							break;
					}
					topicNumber += "."; // for tables only
				}

				preview = Regex.Replace(preview, @"<table\s", match => string.Format(@"<div style='text-align:right'>Таблица {1}{0}</div><table ", tableCounter++, topicNumber), RegexOptions.Compiled | RegexOptions.IgnoreCase);
				if (title != "") preview = title + preview;
				previewBrowser.DocumentText = preview;

#if VAULT_EVAL_1
            }
#endif

#if VAULT_EVAL_2
			}
#endif

#if VAULT_EVAL_3
            }
#endif

			return true;
		}
Beispiel #2
0
		private void buttonGenerate_Click(object sender, EventArgs e)
		{
			if (Scenario == null) return;
			if (CheckedIds == null) return;

			buttonGenerate.Visible = false;
			buttonExport.Visible = false;


			var levelage = new Levelage();
			var mainBuffer = new StringBuilder(300*1024);
			var appendinxBuffer = new StringBuilder(200*1024);

			var cwd = new CancellableWorkerDialog
			          	{
			          		Information = "Производится генерация документа, представляющего собой типовой отчет об оценке недвижимости. \n\nВ генерируемый документ попадут только выбранные ветви дерева сценария. Продолжительность данной процедуры зависит от количества выбранных ветвей дерева сценария.",
			          	};

			cwd.Worker = x =>
				{
					x.UpdateProgress(0, "Обработка выбранных узлов сценария");

					var nodes = from node in Scenario.Vault.GetBranchesRecursive()
					            let sn = new ScenarioNode(node)
					            where CheckedIds.Contains(node.Id) && !string.IsNullOrEmpty(sn.Template)
					            orderby sn.SortingWeight
					            select new {branch = sn, sn.Name};

					var total = 0;
					if ((total = nodes.Count()) == 0) return;
					var marker = 0;

					//#warning Review this: eval sessions now lock the vault for reading
					using (var repo = RepositoryEditor.Repository())
					using (_evalSession2 = new Esath.Eval.Ver2.EvalSession(Scenario.Vault, repo, CheckedIds))
					{
						foreach (var n in nodes)
						{
							x.UpdateProgress(++marker*99/total, n.Name);
							if (x.CancelPending) return;

							var source = Regex.Replace(n.branch.Template ?? "", @"<SPAN[^>]+vpath\s*=\s*""([^""]+)""[^>]*>[^<]+</SPAN>", vpathEvaluator, RegexOptions.Compiled);
							//var source = Regex.Replace(n.branch.Template ?? "", StartUp.VFIELD_PATTERN, vpathEvaluator, RegexOptions.Compiled);

							var title = "";

							if (n.branch.Title != "")
							{
								title = n.branch.Title;
								switch (n.branch.NodeType)
								{
									case ScenarioNodeType.Topic:
										levelage.Enter(1);
										title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "1", levelage);
										break;
									case ScenarioNodeType.Subtopic2:
										levelage.Enter(2);
										title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "2", levelage);
										break;
									case ScenarioNodeType.Subtopic3:
										levelage.Enter(3);
										title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "3", levelage);
										break;
									case ScenarioNodeType.Subtopic4:
										levelage.Enter(4);
										title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "4", levelage);
										break;
									case ScenarioNodeType.Subtopic5:
										levelage.Enter(5);
										title = string.Format("<hr><h{1}>{2} {0}</h{1}>", title, "5", levelage);
										break;
									default:
										break;
								}
							}

							source = Regex.Replace(source, @"<table\s", match => string.Format(@"<div style='text-align:right'>Таблица {0}</div><table ", levelage.AddTable()), RegexOptions.Compiled | RegexOptions.IgnoreCase);
							if (title != "") source = title + source;

							if (n.branch.IsAppendix)
								appendinxBuffer.Append(source);
							else
								mainBuffer.Append(source);
						}

						x.UpdateProgress(100, "Почти все готово");

						var main = mainBuffer.ToString().Replace("<hr>", "$$$newline$$$");
						main = main.Replace("<HR>", "$$$newline$$$");
						if (main.StartsWith("$$$newline$$$")) main = main.Substring(13);

						var appendix = appendinxBuffer.ToString().Replace("<hr>", "$$$newline$$$");
						appendix = appendix.Replace("<HR>", "$$$newline$$$");
						if (appendix.StartsWith("$$$newline$$$")) appendix = appendix.Substring(13);

						MainSource = "<html><head>" + Styles + "</head><body>" + main + "</body></html>";
						AppendixSource = "<html><head>" + Styles + "</head><body>" + appendix + "</body></html>";
					}
				};

			if (cwd.ShowDialog(this) != DialogResult.OK)
			{
				buttonGenerate.Visible = true;
				buttonExport.Visible = false;
				return;
			}

			webBrowser.DocumentText = "<html><head>" + Styles + "</head><body>" + mainBuffer + appendinxBuffer + "</body></html>";
			Application.DoEvents();

			buttonGenerate.Visible = false;
			buttonExport.Visible = true;
		}