그대가 서 있는 곳에서,
그대가 가진 것으로,
그대가 할 수 있는
최선의 일을 하라.
-루즈벨트
class AnalysisEngine { public enum Step { WEB, IN, CAFE, BLOG } const string NAVER_OPENAPI_KEY = "InputYourNaverAPIKey"; const string NAVER_OPENAPI_URL = "http://openapi.naver.com/search?"; const int NAVER_SEARCH_COUNT = 100; string keyword; string url; string blog; string cafe; public AnalysisEngine(string keyword, string url, string blog, string cafe) { this.keyword = keyword; this.url = url; this.blog = blog; this.cafe = cafe; } public void Analysis() { AnalysisResult result = new AnalysisResult(); result.webRank = AnalysisProccess(Step.WEB, url); result.blogRank = AnalysisProccess(Step.BLOG, blog); result.cafeRank = AnalysisProccess(Step.CAFE, cafe); Console.WriteLine("0 = 100위안에 없음."); Console.WriteLine("네이버 웹문서 분석 결과 : " + result.webRank); Console.WriteLine("네이버 블로그 분석 결과 : " + result.blogRank); Console.WriteLine("네이버 카페 분석 결과 : " + result.cafeRank); Console.ReadLine(); } int AnalysisProccess(Step step, string target) { string html = AnalysisTools.GetHTML(CreateURL(step)); XmlDocument doc = new XmlDocument(); doc.LoadXml(html); int rank = 0; foreach (XmlNode node in doc.SelectNodes("rss/channel/item/link")) { string realURL = GetRealURL(node.InnerText); if (realURL.Length > target.Length) realURL = realURL.Substring(0, target.Length); Console.WriteLine(realURL); ++rank; if (target == realURL) { return rank; } } return 0; } string CreateURL(Step step) { string target = ""; switch (step) { case Step.WEB: target = "webkr"; break; case Step.IN: target = "in"; break; case Step.CAFE: target = "cafearticle"; break; case Step.BLOG: target = "blog"; break; default: break; } return string.Format("{0}key={1}&query={2}&display={4}&start=1&target={3}", NAVER_OPENAPI_URL, NAVER_OPENAPI_KEY, keyword, target, NAVER_SEARCH_COUNT); } /* Naver API를 활용하여 url주소를 획득 할 시 실주소가 아닌 API 로 맵핑된 가상주소를 제공 해주기 때문에 직접 리다이렉트 주소를 획득하여 반영 하기위한 함수. */ string GetRealURL(string url) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.AllowAutoRedirect = false; webRequest.Timeout = 10000; webRequest.Method = "HEAD"; HttpWebResponse webResponse; string uriString = string.Empty; using (webResponse = (HttpWebResponse)webRequest.GetResponse()) { if ((int)webResponse.StatusCode >= 300 && (int)webResponse.StatusCode <= 399) { uriString = webResponse.Headers["Location"]; webResponse.Close(); } } return uriString; } }
class AnalysisResult { public int webRank; public int cafeRank; public int blogRank; }
class AnalysisTools { public static string GetHTML(string url) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream receiveStream = response.GetResponseStream(); StreamReader readStream = null; if (response.CharacterSet == null) { readStream = new StreamReader(receiveStream); } else { readStream = new StreamReader(receiveStream, Encoding.UTF8); } string data = readStream.ReadToEnd(); response.Close(); readStream.Close(); return data; } return string.Empty; } }
class Program { static string keyword = ""; //키워드 static string homepage = ""; //홈페이지 주소 static string blog = ""; //블로그 주소 static string cafe = ""; //카페 주소 static void Main(string[] args) { AnalysisEngine engine = new AnalysisEngine( keyword , homepage, blog, cafe); engine.Analysis(); } }
IEnumerator moveCoroutine(float duration, Vector3 end) { WaitEndOfFrame wait = new WaitEndOfFrame(); Vector3 start = transform.position; float elapsed = 0.0f; while(elapsed < duration){ elapsed += Time.deltatime; transform.position = Vector3.Lerp(start,end elapsed / duration); yield return wait; } transform.position = end; } IEnumerator colorCoroutine(float duration, Color start, Color end) { WaitEndOfFrame wait += new WaitEndOfFrame(); float elapsed = 0.0f; while(elapsed < duration){ elapsed = Time.deltaTime; renderer.material.color = Color.Lerp(start,end elapsed / duration); yield return wait; } renderer.material.color = end; }
class MainFrame { public enum State { Game, Lobby } FiniteStateMachine<MainFrame, State> FSM; LobbyState stateLobby = new LobbyState(); GameState stateGame = new GameState(); void Awake() { FSM = new FiniteStateMachine<MainFrame, State>(this); FSM.AddState(stateLobby); FSM.AddState(stateGame); FSM.ChangeState(stateLobby); // 시작시 stateLobby State } }LobbyState.cs
class LobbyState : FiniteState<MainFrame, MainFrame.State> { public override void SetEntity(MainFrame entity) { base.SetEntity(entity); } public override void Enter() { base.Enter(); //게임 입장시 이벤트 구현부 } public override void Excute() { base.Excute(); //게임 실행시 이벤트 구현부 } public override void Exit() { base.Exit(); //게임 퇴장시 이벤트 구현부 } public override MainFrame.State _StateID { get { return MainFrame.State.Game; } } }GameState.cs
class GameState : FiniteState<MainFrame, MainFrame.State> { public override void SetEntity(MainFrame entity) { base.SetEntity(entity); } public override void Enter() { base.Enter(); //게임 입장시 이벤트 구현부 } public override void Excute() { base.Excute(); //게임 실행시 이벤트 구현부 } public override void Exit() { base.Exit(); //게임 퇴장시 이벤트 구현부 } public override MainFrame.State _StateID { get { return MainFrame.State.Game; } } }
interface IState<T> { void Enter(); void Excute(); void Exit(); T _StateID { get; } }
class FiniteState<T, U> : IState<U> { protected T entity; public virtual void SetEntity(T entity) { this.entity = entity; } public virtual void Enter() { Console.WriteLine(typeof(T).ToString() + "Enter"); } public virtual void Excute() { Console.WriteLine(typeof(T).ToString() + "Excute"); } public virtual void Exit() { Console.WriteLine(typeof(T).ToString() + "Exite"); } public virtual U _StateID { get { throw new ArgumentException("Exception"); } } }
class FiniteStateMachine<T, U> { private T entity; // State의 주체가 되는 class private Dictionary<U, FiniteState<T, U>> stateDic; // 전체 State private FiniteState<T, U> currentState; // 현재 상태 private FiniteState<T, U> previousState; // 이전 상태 /// <summary> /// 생성자 /// </summary> /// <param name="entity">주체 class</param> public FiniteStateMachine(T entity) { this.entity = entity; stateDic = new Dictionary<U, FiniteState<T, U>>(); } public void ExcuteState() { if (currentState != null) currentState.Excute(); } public void ChangeState(FiniteState<T, U> nextState) { if (currentState == nextState) return; if(currentState != null) { currentState.Exit(); previousState = currentState; } currentState = nextState; currentState.Enter(); } public void ChangeState(U stateID) { try { FiniteState<T, U> state = stateDic[stateID]; ChangeState(state); } catch(KeyNotFoundException) { // exception 처리 } } //이전 state로 상태 되돌리기 public void RevertState() { if (previousState != null) ChangeState(previousState); } public void AddState(FiniteState<T, U> state) { if (state == null) return; state.SetEntity(entity); stateDic.Add(state._StateID, state); } public void RemoveState(FiniteState<T, U> state) { stateDic.Remove(state._StateID); } }
Project Properties 창을 선택한뒤. |
Include Directories 에 C:\Boost\include 폴더를 포함시킨다. |
1.회원가입후 로그인시 볼수있는 AWS서비스 화면 EC2를 활용하여 서버구현을 진행할것이므로 EC2를 선택한다. |
2. 그후 인스턴스를 추가해야되기때문에 좌측에 인스턴스 클릭. |
3. 현재 실행중인 인스턴스들을 보여주는 창이나오는데 상단의 Launch Instance를 선택 |
4. OS 선택. Amazon Linux를 선택하여 진행.(다른운영체제를 선택하셔도 무방합니다.) |
5. Instance type을 선택하는 부분인데 free tier용 타입(t2.micro) 선택 후 Next |
6. 이후 서버관련 셋팅(과금과 관련된 부분은 안건드시는게 좋습니다.^^;) 딱히 따로 셋팅이 필요없으신분은 디폴트로 놔두시고 Launch 하셔도 무방합니다. |
class HtmlLoader { public enum State { Working, End } string mURL; HtmlDocument mDocument; State mState; Action mCallback; Encoding mEncoding; public HtmlLoader(string url, Encoding enc , Action callback) { this.mURL = url; this.mState = State.End; this.mCallback = callback; this.mEncoding = enc; } //새로운 스레드를 생성하여 실행. public void LoadWithThread() { if (mState == State.Working) return; Thread thraed = new Thread(new ThreadStart(LoadHtml)); thraed.Start(); } //호출한 스레드상에서 바로 실행. public void Load() { if (mState == State.Working) return; LoadHtml(); } void LoadHtml() { mState = State.Working; mDocument = new HtmlDocument(); HtmlWeb website = new HtmlWeb(); StreamReader reader = new StreamReader(WebRequest.Create(mURL).GetResponse().GetResponseStream(), mEncoding); mDocument.Load(reader); mCallback(); mState = State.End; } public HtmlDocument _Document { get { return mDocument; } } }
string url = textBox1.Text; loader = new HtmlLoader(url, Encoding.GetEncoding("euc-kr"), new Action(() => System.IO.File.WriteAllText("web.txt", loader._Document.DocumentNode.InnerText) )); loader.LoadWithThread();