Type: Note
Intro
這只是一篇學習筆記若看倌們對這個標題有興趣
可參考最下面的 Reference~
根據官方文章說法, GAE 不支援使用JAX-WS, 因此要自己用 wsgen, wsimport 來實作 Web Service.
步驟
1. 建立 Web Application Project
2. 建立 WebMethod (Web Service API)
3. 使用 wsgen 產生所需檔案
4. 產生可執行的實例
using (var wdDoc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open("HelloOpenXML.docx", true)){ //因為是Template, 所以不會為null var doc = wdDoc.MainDocumentPart.Document; //尋找所有別名(alias) var alias = doc.Descendants<DocumentFormat.OpenXml.Wordprocessing.SdtAlias>(); foreach (var loop in alias){ switch (loop.Val.Value){ case "user_name"://若是 user_name //取得文字物件 var text = loop.Parent.Parent .Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>() .FirstOrDefault(); //取代原文字 text.Text = "Your Name"; break; } } }
static object RunCode(string code){ var provider = Microsoft.CSharp.CSharpCodeProvider.CreateProvider("C#"); /*---Compiler Parameters---*/ var compilerParams = new System.CodeDom.Compiler.CompilerParameters(); compilerParams.ReferencedAssemblies.Add("System.dll"); compilerParams.GenerateExecutable = false; compilerParams.GenerateInMemory = false; /*---Code---*/ System.Text.StringBuilder fileCode = new StringBuilder(); fileCode.Append("using System; \n") .Append("public class TestDynCode{") .Append("public object Run(){") .Append(code) .Append("}") .Append("}"); /*---Compile---*/ var compilerResult = provider.CompileAssemblyFromSource(compilerParams, fileCode.ToString()); if (compilerResult.Errors.HasErrors){ System.Text.StringBuilder error = new StringBuilder(); foreach (System.CodeDom.Compiler.CompilerError err in compilerResult.Errors) { error.AppendFormat("{0}\n", err.ErrorText); } throw new Exception("Error Compiling Expression: " + error.ToString()); } /*---Run---*/ System.Reflection.Assembly assembly = compilerResult.CompiledAssembly; var obj = assembly.CreateInstance("TestDynCode"); return obj.GetType().GetMethod("Run").Invoke(obj, null); }
static void Main(string[] args){ Console.WriteLine(GetTotalPrice(10, 9)); Console.WriteLine(GetTotalPrice(10, 4)); Console.ReadKey(); } static object GetTotalPrice(decimal price, int count){ string inputRule = "return [數量] > 5 ? [價格] * [數量] * 0.9 : [價格] * [數量];";//賣方Input //實際要Run的Code string realInputRule = inputRule .Replace("[數量]", count.ToString()) .Replace("[價格]", price.ToString()); return RunCode(realInputRule); }
var buffer = new StringBuilder(); using (var write = System.Xml.XmlWriter.Create(buffer)){ write.WriteStartElement("Transaction"); write.WriteAttributeString("Action", "AskData"); write.WriteEndElement(); }
var buffer = new StringBuilder(); var setting = new System.Xml.XmlWriterSettings(); setting.Indent = true; setting.Encoding = new System.Text.UTF8Encoding(); using (var write = System.Xml.XmlWriter.Create(buffer, setting)){ write.WriteStartElement("Transaction"); write.WriteAttributeString("Action", "AskData"); write.WriteEndElement(); }
var buffer = new System.IO.MemoryStream();
var buffer = new System.IO.MemoryStream(); var setting = new System.Xml.XmlWriterSettings(); setting.Indent = true; setting.Encoding = new System.Text.UTF8Encoding(false);//取消前置識別字元 using (var write = System.Xml.XmlWriter.Create(buffer, setting)){ write.WriteStartElement("Transaction"); write.WriteAttributeString("Action", "AskData"); write.WriteEndElement(); }
private void btnReceive_Click(object sender, EventArgs e){ var mqPath = @".\Private$\MqTest"; if (!System.Messaging.MessageQueue.Exists(mqPath)) { System.Messaging.MessageQueue.Create(mqPath); } var msgQueue = new System.Messaging.MessageQueue(mqPath); msgQueue.ReceiveCompleted += new System.Messaging.ReceiveCompletedEventHandler(msgQueue_ReceiveCompleted); msgQueue.BeginReceive(); } void msgQueue_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e){ var msgQueue = sender as System.Messaging.MessageQueue; var msg = msgQueue.EndReceive(e.AsyncResult);//suspend and get message msg.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) }); LogRecorder.Log(msg.Label + "\n" + msg.Body);//Display msgQueue.BeginReceive();//Repeat Listen }
private void btnSend_Click(object sender, EventArgs e){ var mqPath = @"FormatName:Direct=TCP:192.168.1.30\Private$\MqTest"; //var mqPath = @".\Private$\MqTest";//if local test var msgQueue = new System.Messaging.MessageQueue(mqPath); msgQueue.Send("Message Content", "Message Label"); }就醬!!
System.Messaging.MessageQueue.Create(mqPath, true);手動建立的話, 請至
private void btnTranSend_Click(object sender, EventArgs e){ var mqPath = @".\Private$\MqTranTest"; var msgQueue = new System.Messaging.MessageQueue(mqPath); var mqTran = new System.Messaging.MessageQueueTransaction(); mqTran.Begin(); msgQueue.Send("non-transaction body", "non-transaction label");//沒有transaction的不會被同意 msgQueue.Send("transaction body", "transaction label", mqTran); mqTran.Commit(); //可做一次性交易, 自動beginl, commit msgQueue.Send("single transaction body", "single transaction label", System.Messaging.MessageQueueTransactionType.Single); }
- url: /common/menu.html
static_files: common/menu.html
upload: common/menu.html
- url: /css
static_dir: css
- url: /product
script: script/product.py
- url: /(common/.*\.(html|png))
static_files: \1
upload: (common/.*\.(html|png))
#Rewrite Path
- url: /(.*\.(html|png))
static_files: common/\1
upload: common/(.*\.(html|png))
<asp:GridView ID="gvList" runat="server" OnRowEditing="gvList_RowEditing"> <Columns><asp:TemplateField> <ItemTemplate> <asp:Button ID="btnEdit" runat="server" CommandName="Edit" /> </ItemTemplate> </asp:TemplateField></Columns> </asp:GridView>這是咱們的Code
protected void Page_Load(object sender, EventArgs e){ //if (IsPostBack) { return; }//*3 var item = new[]{ new { id = "i001", name="John"}, new { id = "i002", name="Merry"}, new { id = "i003", name="Ellin"} }; gvList.DataSource = item; gvList.DataBind();//*1 } protected void gvList_RowEditing(object sender, GridViewEditEventArgs e){ gvList.EditIndex = e.NewEditIndex; gvList.DataBind();//*2 Response.Write(e.NewEditIndex); } protected void Page_PreRender(object sender, EventArgs e){ //this.DataBind();//*4 }剛開始, 習慣上
public static void ClickSendValidConfirmDisabled(System.Web.UI.Page page, System.Web.UI.WebControls.WebControl ctrl, string confirmText){ string clientScript = ctrl.ClientID + ".disabled='disabled';" + page.ClientScript.GetPostBackEventReference(ctrl, null) + ";"; bool needValid = false; string validationGroup = null; if (ctrl is System.Web.UI.WebControls.IButtonControl){ System.Web.UI.WebControls.IButtonControl ibtnCtrl = ctrl as System.Web.UI.WebControls.IButtonControl; needValid = ibtnCtrl.CausesValidation; validationGroup = ibtnCtrl.ValidationGroup; } clientScript = "if(confirm('" + confirmText + "')){" + clientScript + "}"; if (needValid){ clientScript = "if(Page_ClientValidate('" + validationGroup + "')){" + clientScript + "}"; } ctrl.Attributes["onclick"] = clientScript + "return false;"; }
---取得連線資訊---------------------
Use master
Select * From sysprocesses
---Foreach table------------------
Use []
--請注意唷, 下面指令會刪除All table
Exec sp_MSforeachtable @command1 = "DROP TABLE ?"
---Limit---------------------------
select * from (select row_number() over (order by ac_id) as row_num,* from account)
t where row_num between 1 and 30
public class MyTest extends EventDispatcher
{
public static const Event_UnknownComplete:String="MyTest.Event_UnknownComplete";
public function doEvent_UnknownComplete():void{
this.dispatchEvent(new Event(Event_UnknownComplete));
}
public function start():void{
setTimeout(doEvent_UnknownComplete,2000);
}
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var test : MyTest = new MyTest();
test.addEventListener(MyTest.Event_UnknownComplete, test_Event_UnknownComplete, false);
test.addEventListener(MyTest.Event_UnknownComplete, function(event:Event):void{
Alert.show("Event_UnknownComplete be dispatched 2");
});
test.start();
}
protected function test_Event_UnknownComplete(event:Event):void{
Alert.show("Event_UnknownComplete be dispatched 1");
}
<% System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Rows.Add("01", "John"); dt.Rows.Add("02", "Mary"); GridView1.DataSource = dt; GridView1.DataBind(); %> <asp:GridView ID="GridView1" runat="server"><Columns> <asp:TemplateField><ItemTemplate> <asp:HyperLink ID="hlEdit" runat="server" NavigateUrl='<%#"javascript:alert('"+Eval("id")+"');" %>'> Edit</asp:HyperLink> </ItemTemplate></asp:TemplateField> </Columns></asp:GridView>
<configuration> <system.web> <identity impersonate="true" userName="adminUser" password="adminUserPassword" />
Response.AddHeader("content-disposition", "attachment;filename=MyExcel.xls");