| 1 | #region license
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (c) 2008, Kouji Yamaguchi
|
|---|
| 4 | All rights reserved.
|
|---|
| 5 |
|
|---|
| 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|---|
| 7 |
|
|---|
| 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|---|
| 9 |
|
|---|
| 10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|---|
| 11 |
|
|---|
| 12 | * Neither the name of coma2n nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|---|
| 13 |
|
|---|
| 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|---|
| 15 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 16 | IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|---|
| 17 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|---|
| 18 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|---|
| 19 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 20 | */
|
|---|
| 21 | #endregion
|
|---|
| 22 |
|
|---|
| 23 | #region namespaces
|
|---|
| 24 |
|
|---|
| 25 | using System;
|
|---|
| 26 | using System.IO;
|
|---|
| 27 | using System.Web;
|
|---|
| 28 | using System.Web.UI.WebControls;
|
|---|
| 29 | using System.Linq;
|
|---|
| 30 | using System.Text;
|
|---|
| 31 | using System.Diagnostics;
|
|---|
| 32 |
|
|---|
| 33 | using Microsoft.VisualBasic.FileIO;
|
|---|
| 34 |
|
|---|
| 35 | #endregion
|
|---|
| 36 |
|
|---|
| 37 | namespace SilverlightIDE {
|
|---|
| 38 | /// <summary>
|
|---|
| 39 | /// デフォルトのページ
|
|---|
| 40 | /// </summary>
|
|---|
| 41 | public partial class Default : PageBase {
|
|---|
| 42 |
|
|---|
| 43 | #region const
|
|---|
| 44 |
|
|---|
| 45 | private const string CSPROJ_IMG_PATH = "~/Images/csproj.png";
|
|---|
| 46 | private const string CS_IMG_PATH = "~/Images/cs.png";
|
|---|
| 47 | private const string XAML_IMG_PATH = "~/Images/xaml.png";
|
|---|
| 48 |
|
|---|
| 49 | #endregion
|
|---|
| 50 |
|
|---|
| 51 | #region methods
|
|---|
| 52 |
|
|---|
| 53 | /// <summary>
|
|---|
| 54 | /// ソースを初期化します。
|
|---|
| 55 | /// </summary>
|
|---|
| 56 | [DebuggerStepThrough]
|
|---|
| 57 | void InitSource() {
|
|---|
| 58 | SourcePath = "~/Users/" + Session.SessionID;
|
|---|
| 59 |
|
|---|
| 60 | var srcPath = Server.MapPath(SourcePath);
|
|---|
| 61 |
|
|---|
| 62 | if(!Directory.Exists(srcPath)) {
|
|---|
| 63 | Directory.CreateDirectory(srcPath);
|
|---|
| 64 |
|
|---|
| 65 | FileSystem.CopyDirectory(
|
|---|
| 66 | Server.MapPath("~/App_Data/Source"), srcPath
|
|---|
| 67 | );
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | #endregion
|
|---|
| 72 |
|
|---|
| 73 | protected void Page_Load(object sender, EventArgs e) {
|
|---|
| 74 | if(!IsPostBack) {
|
|---|
| 75 | InitSource();
|
|---|
| 76 |
|
|---|
| 77 | var srcPath = Server.MapPath(SourcePath);
|
|---|
| 78 | var csprojFile = Directory.GetFiles(srcPath, "*.csproj").FirstOrDefault();
|
|---|
| 79 |
|
|---|
| 80 | if(csprojFile != null) {
|
|---|
| 81 | // Build.aspxにはプロジェクトファイル名をクエリで渡す。
|
|---|
| 82 | buildButton.NavigateUrl += string.Format(
|
|---|
| 83 | "?proj={0}", HttpUtility.UrlEncode(Path.GetFileName(csprojFile))
|
|---|
| 84 | );
|
|---|
| 85 | var rootNode = new TreeNode(
|
|---|
| 86 | Path.GetFileNameWithoutExtension(csprojFile), Path.GetFileName(csprojFile)) {
|
|---|
| 87 |
|
|---|
| 88 | ImageUrl = CSPROJ_IMG_PATH
|
|---|
| 89 | };
|
|---|
| 90 | foreach(var xamlFile in Directory.GetFiles(srcPath, "*.xaml")) {
|
|---|
| 91 | var node = new TreeNode(Path.GetFileName(xamlFile)) {
|
|---|
| 92 | Expanded = false,
|
|---|
| 93 | ImageUrl = XAML_IMG_PATH
|
|---|
| 94 | };
|
|---|
| 95 | var csFile = xamlFile + ".cs";
|
|---|
| 96 | // 確実に存在してるけどね!
|
|---|
| 97 | if(File.Exists(csFile)) {
|
|---|
| 98 | node.ChildNodes.Add(
|
|---|
| 99 | new TreeNode(Path.GetFileName(csFile)) {
|
|---|
| 100 | ImageUrl = CS_IMG_PATH
|
|---|
| 101 | }
|
|---|
| 102 | );
|
|---|
| 103 | }
|
|---|
| 104 | rootNode.ChildNodes.Add(node);
|
|---|
| 105 | }
|
|---|
| 106 | fileTree.Nodes.Add(rootNode);
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | protected void fileTree_SelectedNodeChanged(object sender, EventArgs e) {
|
|---|
| 112 | var tv = (TreeView)sender;
|
|---|
| 113 | var name = tv.SelectedNode.Value;
|
|---|
| 114 | var filePath = Path.Combine(Server.MapPath(SourcePath), name);
|
|---|
| 115 |
|
|---|
| 116 | using(var sr = new StreamReader(filePath, Encoding.UTF8)) {
|
|---|
| 117 | editText.Text = sr.ReadToEnd();
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /// <summary>
|
|---|
| 122 | /// [保存]
|
|---|
| 123 | /// </summary>
|
|---|
| 124 | /// <param name="sender"></param>
|
|---|
| 125 | /// <param name="e"></param>
|
|---|
| 126 | protected void saveButton_Click(object sender, EventArgs e) {
|
|---|
| 127 | if(fileTree.SelectedNode == null) return;
|
|---|
| 128 |
|
|---|
| 129 | var name = fileTree.SelectedNode.Value;
|
|---|
| 130 | var filePath = Path.Combine(Server.MapPath(SourcePath), name);
|
|---|
| 131 |
|
|---|
| 132 | using(var sw = new StreamWriter(filePath, false, Encoding.UTF8)) {
|
|---|
| 133 | sw.Write(editText.Text);
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /// <summary>
|
|---|
| 138 | /// [追加]
|
|---|
| 139 | /// </summary>
|
|---|
| 140 | /// <param name="sender"></param>
|
|---|
| 141 | /// <param name="e"></param>
|
|---|
| 142 | protected void addFileButton_Click(object sender, EventArgs e) {
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /// <summary>
|
|---|
| 146 | /// [削除]
|
|---|
| 147 | /// </summary>
|
|---|
| 148 | /// <param name="sender"></param>
|
|---|
| 149 | /// <param name="e"></param>
|
|---|
| 150 | protected void remFileButton_Click(object sender, EventArgs e) {
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|