用iSpring+MSMQ+觸發器 達成自動PPT轉SWF

用iSpring+MSMQ+觸發器 達成自動PPT轉SWF – dyco- 點部落

功能:

使用者上傳PPT檔後做SWF轉檔,我們要考量到的因素有下列:

1.程式專檔不直接在asp.net的程序做,因為這樣會讓User會誤以為網頁死當

2.不透過資料庫

  1.原本一開始是打算要用觸發器(Trigger)來做,後來放棄…..因為要開啟xp_cmdshell 實在太危險了

  2.後來又想到第二個方式,先把要轉檔的資料訊息寫到DB,在寫一支WebService每分鐘讀這個DB做轉檔,後來放棄,因為我不太愛每分鐘去讀DB這個動作…..

3.不能與原本的專案有任何的關聯,將來的其它專案也能一併使用

安裝:

1.iSpring下載網址 下載    (下載後安裝) 30天試用

2.安裝訊息佇列(MSMQ)

.Net下的MSMQ的同步異步調用-.Net編程教程

.Net下的MSMQ的同步異步調用-.Net編程教程

以下為引用的內容:
1using System;
2using System.Messaging;
3using System.Threading;

5
6namespace LoveStatusService
7{
8 /**//// <summary>
9 /// Summary description for Msmq.
10 /// </summary>
11 public class Msmq
12 {
13 public Msmq()
14 {
15 //
16 // TODO: Add constructor logic here
17 //
18 }
19
20
21 private MessageQueue _messageQueue=null;
22 //最大并發線程數
23 private static int MAX_WORKER_THREADS=Convert.ToInt32( System.Configuration.ConfigurationSettings.AppSettings[“MAX_WORKER_THREADS"].ToString());
24 //Msmq路徑
25 private static string MsmqPath=System.Configuration.ConfigurationSettings.AppSettings[“LoveStatusMQPath"];
26 //等待句柄
27 private WaitHandle[] waitHandleArray = new WaitHandle[MAX_WORKER_THREADS];
28 //任務類型
29 //1. Send Email 2. Send Message 3. Send Email and Message
30 private string TaskType=System.Configuration.ConfigurationSettings.AppSettings[“TaskType"];
31 public MessageQueue MessQueue
32 {
33 get
34 {
35
36 if (_messageQueue==null)
37 {
38 if(MessageQueue.Exists(MsmqPath))
39 {
40 _messageQueue = new MessageQueue(MsmqPath);
41 }
42 else
43 {
44 _messageQueue = MessageQueue.Create(MsmqPath);
45 }
46 }
47
48
49 return _messageQueue;
50 }
51 }
52
53
54 Private Method#region Private Method
55
56 private void mq_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
57 {
58 MessageQueue mqq = (MessageQueue)sender;
59 System.Messaging.Message m = mqq.EndReceive(e.AsyncResult);
60 //m.Formatter = new System.Messaging.XmlMessageFormatter(new string[]{“System.String,mscorlib"});
61 m.Formatter =new System.Messaging.XmlMessageFormatter(new Type[] {typeof(UserObject)}) ;
62 //log.Info(“Receive UserID: " (string)m.Body) ;
63 UserObject obj=(UserObject)m.Body ;
64 long curUserId=obj.curUserID ;
65 long oppUserId=obj.oppUserID;
66 string curUserName=obj.curUserName;
67 string oppUserName=obj.oppUserName;
68 string curEmail=obj.curEmail ;
69 string oppEmail=obj.oppEmail;
70 string subject =obj.subject ;
71 string body=obj.body ;
72 //AppLog.log.Info(“curUserId:" curUserId) ;
73 //AppLog.log.Info(“oppUserId:" oppUserId) ;
74 AppLog.log.Info(“==type=" TaskType) ;
75 switch(TaskType)
76 {
77 //Email
78 case “1″:
79 EmailForMQ.SendEmailForLoveStatus(curEmail,oppEmail,curUserName,oppUserName,subject) ;
80 AppLog.log.Info(“==Send to==" oppEmail) ;
81 break;
82 //Message
83 case “2″:
84 MessageForMQ.SendMessage(curUserId,oppUserId,subject,body) ;
85 AppLog.log.Info(“==Send Msg to==" oppUserId) ;
86 break;
87 //Email and Message
88 case “3″:
89 EmailForMQ.SendEmailForLoveStatus(curEmail,oppEmail,curUserName,oppUserName,subject) ;
90 AppLog.log.Info(“==Send to==" oppEmail) ;
91 MessageForMQ.SendMessage(curUserId,oppUserId,subject,body) ;
92 AppLog.log.Info(“==Send Msg to==" oppUserId) ;
93 break;
94 default:
95 break;
96
97 }
98 mqq.BeginReceive() ;
99
100 }
101
102 #endregion
103
104 Public Method#region Public Method
105
106 //一個將對象發送到隊列的方法,這里發送的是對象
107 public void SendUserIDToMQ(object arr)
108 {
109 MessQueue.Send(arr) ;
110 Console.WriteLine(“Ok") ;
111 Console.Read() ;
112 }
113
114 //同步接受隊列內容的方法
115 public void ReceiveFromMQ()
116 {
117 Message ms=new Message() ;
118
119 //ms=MessQueue.Peek();
120 try
121 {
122 ms=MessQueue.Receive(new TimeSpan(0,0,5));
123 if(ms!=null)
124 {
125 ms.Formatter = new XmlMessageFormatter ( new Type [] { typeof (string) } );
126 AppLog.log.Info((string)ms.Body) ;
127 }
128 }
129 catch(Exception ex)
130 {
131
132 }
133
134
135 }
136
137 //開始監聽工作線程
138 public void startListen()
139 {
140 AppLog.log.Info(“–Thread–" MAX_WORKER_THREADS) ;
141 MessQueue.ReceiveCompleted =new ReceiveCompletedEventHandler(mq_ReceiveCompleted);
142
143 //異步方式,并發
144
145 for(int i=0; i<MAX_WORKER_THREADS; i )
146 {
147 // Begin asynchronous operations.
148 waitHandleArray[i] = MessQueue.BeginReceive().AsyncWaitHandle;
149 }
150
151 AppLog.log.Info(“——Start Listen——–“) ;
152
153 return;
154
155 }
156
157
158 //停止監聽工作線程
159 public void stopListen()
160 {
161
162 for(int i=0;i<waitHandleArray.Length;i )
163 {
164
165 try
166 {
167 waitHandleArray[i].Close();
168 }
169 catch
170 {
171 AppLog.log.Info(“—waitHandleArray[i].Close() Error!—–“) ;
172 }
173
174 }
175
176 try
177 {
178 // Specify to wait for all operations to return.
179 WaitHandle.WaitAll(waitHandleArray,1000,false);
180 }
181 catch
182 {
183 AppLog.log.Info(“—WaitHandle.WaitAll Error!—–“) ;
184 }
185 AppLog.log.Info(“——Stop Listen——–“) ;
186
187 }
188
189 #endregion
190
191
192
193
194 }
195}
196

 

UserObject的代碼

 

以下為引用的內容:
1using System;
2
3namespace Goody9807
4{
5 /**//// <summary>
6 /// 用與在MQ上傳輸數據的對象
7 /// </summary>
8 public class UserObject
9 {
10 public UserObject()
11 {
12 //
13 // TODO: Add constructor logic here
14 //
15 }
16
17 private long _curUserID;
18 public long curUserID
19 {
20 get
21 {
22 return _curUserID;
23 }
24 set
25 {
26 _curUserID=value;
27 }
28 }
29
30 private string _curUserName="";
31 public string curUserName
32 {
33 get
34 {
35 return _curUserName;
36 }
37 set
38 {
39 _curUserName=value;
40 }
41 }
42
43 private string _curEmail="";
44 public string curEmail
45 {
46 get
47 {
48 return _curEmail;
49 }
50 set
51 {
52 _curEmail=value;
53 }
54 }
55
56
57 private long _oppUserID;
58 public long oppUserID
59 {
60 get
61 {
62 return _oppUserID;
63 }
64 set
65 {
66 _oppUserID=value;
67 }
68 }
69
70 private string _oppUserName="";
71 public string oppUserName
72 {
73 get
74 {
75 return _oppUserName;
76 }
77 set
78 {
79 _oppUserName=value;
80 }
81 }
82
83 private string _oppEmail="";
84 public string oppEmail
85 {
86 get
87 {
88 return _oppEmail;
89 }
90 set
91 {
92 _oppEmail=value;
93 }
94 }
95
96 private string _subject ="";
97 public string subject
98 {
99 get
100 {
101 return _subject;
102 }
103 set
104 {
105 _subject=value;
106 }
107 }
108
109 private string _body="";
110 public string body
111 {
112 get
113 {
114 return _body;
115 }
116 set
117 {
118 _body=value;
119 }
120 }
121 }
122}
123

Using compc, the component compiler

Adobe Flex 4 * Using compc, the component compiler

You use the component compiler to generate a SWC file from component source files and other asset files such as images and style sheets.

To use the component compiler with Flex SDK, you use the compc command-line utility. In Flash Builder, you use the compc component compiler by building a new Flex Library Project. Some of the Flex SDK command-line options have equivalents in the Flash Builder environment. You use the tabs in the Flex Library Build Path dialog box to add classes, libraries, and other resources to the SWC file.

Building an SWC library using the Flex 3 SDK

Building an SWC library using the Flex 3 SDK | Dirty Motherfucking Blog

So the other day i was trying to build the AsWing library with the Flex SDK. Sadly, i failed miserably. I didn’t even know where to start. How do you feed all the files into the compiler? What command line switches to use? So after reading basically every piece of documentation that Adobe has to offer, i finally pieced it together.

And now i can proudly say, that wasn’t so hard after all, was it?
Alright, enough with the prologue. If you’re interested in the topic of build an SWC with the SDK you most likely know that you have to feed all the libraries classes into it using a manifest file. But in the case of AsWing, there are like a million files to add (give or take). So i wrote myself a handy script real quick:

How to: Publish a Project That Has a Specific Locale

HOW TO:發行具有指定地區的專案

How to: Publish a Project That Has a Specific Locale

To create the publishing macro

  1. To open the Macro Explorer, on the Tools menu, point to Macros, and then click Macro Explorer.

  2. Create a new macro module. In the Macro Explorer, select MyMacros. On the Tools menu, point to Macros, and then click New Macro Module. Name the module PublishSpecificCulture.

  3. In the Macro Explorer, expand the MyMacros node, and then open the PublishAllProjects module by double-clicking it (or, from the Tools menu, point to Macros, and then click Macros IDE).

  4. In the Macros IDE, add the following code to the module, after the Import statements:

    Module PublishSpecificCulture
        Sub PublishProjectFirstProjectWithEnLocale()
            ' Note: You should publish projects by using the IDE at least once
            ' before you use this macro. Items such as the certficate and the 
            ' security zone must be set.
            Dim localeString As String = "en"
    
            ' Get first project.
            Dim proj As Project = DTE.Solution.Projects.Item(1)
            Dim publishProperties As Object = proj.Properties.Item("Publish").Value
    
            ' GenerateManifests and SignManifests must always be set to
            ' True for publishing to work. 
            proj.Properties.Item("GenerateManifests").Value = True
            proj.Properties.Item("SignManifests").Value = True
    
            'Set the publish language.
            'This will set the deployment language and pick up all 
            ' en resource dlls:
            Dim originalTargetCulture As String = _
                publishProperties.Item("TargetCulture").Value
            publishProperties.Item("TargetCulture").Value = localeString
    
            'Append 'en' to end of publish, install, and update URLs if needed:
            Dim originalPublishUrl As String = _
                publishProperties.Item("PublishUrl").Value
            Dim originalInstallUrl As String = _
                publishProperties.Item("InstallUrl").Value
            Dim originalUpdateUrl As String = _
                publishProperties.Item("UpdateUrl").Value
            publishProperties.Item("PublishUrl").Value = _
                AppendStringToUrl(localeString, New Uri(originalPublishUrl))
            If originalInstallUrl <> String.Empty Then
                publishProperties.Item("InstallUrl").Value = _
                    AppendStringToUrl(localeString, New Uri(originalInstallUrl))
            End If
            If originalUpdateUrl <> String.Empty Then
                publishProperties.Item("UpdateUrl").Value = _
                    AppendStringToUrl(localeString, New Uri(originalUpdateUrl))
            End If
            proj.Save()
    
            Dim slnbld2 As SolutionBuild2 = _
                CType(DTE.Solution.SolutionBuild, SolutionBuild2)
            slnbld2.Clean(True)
    
            slnbld2.BuildProject( _
            proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, _
            proj.UniqueName, True)
    
            ' Only publish if build is successful.
            If slnbld2.LastBuildInfo <> 0 Then
                MsgBox("Build failed for " & proj.UniqueName)
            Else
                slnbld2.PublishProject( _
                proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, _
                proj.UniqueName, True)
                If slnbld2.LastPublishInfo = 0 Then
                    MsgBox("Publish succeeded for " & proj.UniqueName _
                    & vbCrLf & "." _
                    & " Publish Language was '" & localeString & "'.")
                Else
                    MsgBox("Publish failed for " & proj.UniqueName)
                End If
            End If
    
            ' Return URLs and target culture to their previous state.
            publishProperties.Item("PublishUrl").Value = originalPublishUrl
            publishProperties.Item("InstallUrl").Value = originalInstallUrl
            publishProperties.Item("UpdateUrl").Value = originalUpdateUrl
            publishProperties.Item("TargetCulture").Value = originalTargetCulture
            proj.Save()
        End Sub
    
        Private Function AppendStringToUrl(ByVal str As String, _
        ByVal baseUri As Uri) As String
            Dim returnValue As String = baseUri.OriginalString
            If baseUri.IsFile OrElse baseUri.IsUnc Then
                returnValue = IO.Path.Combine(baseUri.OriginalString, str)
            Else
                If Not baseUri.ToString.EndsWith("/") Then
                    returnValue = baseUri.OriginalString & "/" & str
                Else
                    returnValue = baseUri.OriginalString & str
                End If
            End If
            Return returnValue
        End Function
    End Module
    
  5. Close the Macros IDE. The focus will return to Visual Studio.

如何成為一位傑出的工程師

如何成為一位傑出的工程師 – 藏經閣

如何成為一位傑出的工程師
How to be a Star Engineer
Robert E. Kelley, Carnegie Mellon University
(Robert E. Kelley, “How to be a star engineer," IEEE Spectrum, pp. 51-58, Oct. 1999.)
翻譯:馬仕毅

在1985年,我被問了一些問題,從那時起,我就開始找尋真正的答案。提出問題的是貝爾實驗室(那是仍然是AT&T的一部分,現在屬於 Lucent Technologies Inc.)。貝爾實驗室由全世界最好的大學中聘用了最優秀,最聰明的畢業生,然而, 最後只有少數的人真正發揮他們的潛力而成為卓越的工程師。大部分的新進人員發展成可以穩定地完成任務的執行者,生產力並沒有特別突出,無法幫助貝爾實驗室 在提昇AT&T的市場競爭力方面,做出顯著的貢獻。

Synergy:在多台電腦之間共享滑鼠鍵盤

Synergy:在多台電腦之間共享滑鼠鍵盤 – 藏經閣

有時候在工作場合上需要多台電腦工作。我常常遇到的問題是在不同的滑鼠鍵旁間游走,感覺滿不方便的。我後來就發現Synergy這套軟體,可以讓你用同一個鍵旁滑鼠就可以在多台電腦上工作。如下圖所示:我平常會在右邊的電腦工作,但是有時候會用左邊的電腦看文件。以下文章假設使用右邊電腦的滑鼠鍵盤控制2台電腦。

layout

1. 下載並安裝synergy:http://sourceforge.net/projects/synergy2/files/ 

2. 右邊電腦設定如下

2.1 點選AutoStart,讓電腦可以自動開機執行此程式