When move file in ngCordova or Cordova, it will need 2 plugins.

  1. cordova plugin add org.apache.cordova.file
  2. cordova plugin add org.apache.cordova.file-transfer

basic usage.

1
2
3
4
5
6
7
$cordovaFile.downloadFile(source, filepath, true, {}).then(function(result) {
// Success!
}, function(err) {
// Error
}, function(progress) {
// constant progress updates
});

it’s same as

1
2
3
4
5
6
7
8
9
10
var fileTransfer = new FileTransfer();
var uri = encodeURI(source);
fileTransfer.download(uri,filePath,
function (entry) {
// success
},
function (error) {
// error
},
trustAllHosts, options);

if you want to use it with $cordovaCamera.getPicture(), you will need to resolve FILE_URI first, and use it as source.

1
2
3
4
5
6
7
8
9
function getImageFileName(image) {
window.resolveLocalFileSystemURL(image,
function(entry) {
var uri = entry.toURL();
entry.file(function(file) {
var fileName = file.name;
});
});
}

API Document#File Entry

another problem is filepath. basePath can find it by below code. and filepath need a filename at the end.

1
2
3
4
5
6
$cordovaFile.createDir(directory, false).then(function(entry) {
// Success!
alert(entry.toURL());
}, function(err) {
// An error occured. Show a message to the user
});

今天在將資料庫搬到Azure的環境上面,然後遇到了一個選擇的困擾. 原本SQL Azure的規格有兩種. Web和Business 新的規格有三種Basic, Standard, Premium. 相關的規格說明請參閱http://azure.microsoft.com/zh-tw/pricing/details/sql-database/

所以我就先試試看Basic方案,結果:速度一個慢, 但是比Web規格便宜 (真的不建議使用,用這個不如用S0) Web的速度只有Premium 2可以跟的上, 價錢就是一個不可思議

那S0呢? 我嘗試後的結果是在可以接受的範圍內。但是價錢比Web貴了一點. 之後的規格,基本上就是價錢決定效能。

那我又想說如果自己用VM架設sql server呢…哈, 更貴. Orz. 直接放棄不考慮

最後只好還是繼續用要被淘汰的Web規格。然後抱著希望說等明年Web規格退休後,Azure可以提供更優價錢可以接受的選項。

angular在寫ng-repeat的時後, 因為想要利用 filter的功能將過濾後的資料集拿到不同區塊使用, 把function 寫到ng-repeat裡面。 像是

1
ng-repeat="item in processData((items | filter: someCondition))"

這一個粗心的錯誤會讓angular產生Error: error:infdig,Infinite $digest Loop的錯誤訊息

這個訊息的產生原因是當ng-repeat每跑一次, 會觸發processData fuction => 因為值改變,所以又會觸發$digest. 然後當$digest的次數太多之後,就會發生錯誤訊息, 執行效率也會變得非常的不好。

所以回到angularjs的頁面裡找到這個https://docs.angularjs.org/error/$rootScope/infdig

下面的說明就有提到這個現象.

Since getUsers() returns a new array, Angular determines that the model is different on each $digest cycle, resulting in the error. The solution is to return the same array object if the elements have not changed:

解決的方式就是不要在ng-repeat裡面寫function. 但如果要達到相同的效果, 可以先將過濾後的結果存到一個變數中, 然後在去操作那個變數就不會產生這個錯誤了

1
ng-repeat="item in (someVar = items | filter: someCondition)"

文章參考: http://www.hanselman.com/blog/IntroducingGulpGruntBowerAndNpmSupportForVisualStudio.aspx

需要條件 VS2013 update 3 installed

Visual Studio Extension

  1. [TRX - Task Runner Explorer](TRX - Task Runner Explorer)
  2. NPM/NBower Package Intellisense : Search for online NPM and Bower packages directly with Intellisense
  3. Grunt Launcher

操作方式: 請參考 http://www.hanselman.com/blog/IntroducingGulpGruntBowerAndNpmSupportForVisualStudio.aspx

好處:

不用再開一個command window 來跑grunt or gulp command, 所有的動作可以在VS裡面完成了 VS2013對於前端網頁的開發支援程度愈來越好了

1
2
ODataHttpRequestMessageExtensions.GetNextPageLink 和 
ODataHttpRequestMessageExtensions.GetInlineCount 都過時了..

要改用

1
2
Request.ODataProperties().NextLink,
Request.ODataProperties().TotalCount

ODataProperties 需要使用 System.Web.Http.OData.ExtensionsSystem.Web.OData.Extensions 命名空間

asp.net mvc webapi 2 提供了 IHttpActionResult 這個界面

這個界面的效果基本上是跟HttpResponseMessage是一樣的 但是在回傳值的表示有些微的不一樣,以下是整理表

IHttpActionResult HttpResponseMessage Request.CreateResponse(HttpStatusCode)
Ok() HttpStatusCode.OK
InternalServerError() HttpStatusCode.InternalServerError
NotFound() HttpStatusCode.NotFound

more on http://msdn.microsoft.com/zh-tw/library/system.web.http.apicontroller_methods(v=vs.118).aspx

這樣子寫起來就乾淨很多了

javascript基本操作html5的 local storage方法 image_thumb.png

1
2
3
4
5
// set item val
window.localstorage.setItem(key,value);
window.localstorage.getItem(key);
window.localstorage.removeItem(key);
window.localstorage.clear();

如果要把array object存入到localstorage裡面,需要把object轉換成文字.所以可透過json的方法來處理

1
2
JSON.stringify(object);
JSON.parse(value);

ref:

http://www.w3schools.com/html/html5_webstorage.asp

http://blog.roodo.com/rocksaying/archives/15967715.html

處理狀況

當要同一時間新增大量資料時,如果單純用EF的新增方式,速度會讓人吐血。 所以需要透過BulkInsert的方式處理,但是又不想自己另外寫ado的方式處理,所以就要透過extenstion的方式, 讓EF的功能加強一下

##安裝 EntityFramework.BulkInsert-ef6

Nuget

##參考文件

http://efbulkinsert.codeplex.com/

##(用法)Demo Code

1
2
3
4
5
6
7
8
using(context db = new context()){
// 原本會用
// db.tables.AddRange(entities);
// 改用
db.BulkInsert(entities);

db.SaveChanges();
}

##執行結果 非常快速

Ref: http://www.dotnet-tricks.com/Tutorial/entityframework/2VOa140214-Entity-Framework-6-Code-First-Migrations-with-Multiple-Data-Contexts.html

如何動態產生Database

如果利用Code first的方式,搭配DbMigration即可完成工作

  • DBContext.cs
1
2
3
4
5
6
7
8
9
10
11
public class DemoContext : DbContext
{
public DemoContext() { }
public DemoContext(string ConnectionString)
: base(ConnectionString)
{
Database.SetInitializer(new CustomInitializer());
Database.Initialize(true);
}
public DbSet<Blog> Blogs { get; set; }
}
  • CustomInitializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
using System.Linq;

internal sealed class Configuration : DbMigrationsConfiguration<DemoContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
MigrationsDirectory = @"Migration";
}


protected override void Seed(DemoContext context)
{
}
}

class CustomInitializer : IDatabaseInitializer<DemoContext>
{
public void InitializeDatabase(DemoContext context)
{
if (!context.Database.Exists() || !context.Database.CompatibleWithModel(false))
{
var configuration = new Configuration();
configuration.TargetDatabase = new DbConnectionInfo(context.Database.Connection.ConnectionString, "System.Data.SqlClient");
var migrator = new DbMigrator(configuration);
migrator.Update();
}
}
}
  • client端
1
2
using (var db = new AtaBookContext(connection1)){}
using (var db = new AtaBookContext(connection2)){}

connection1和connection2分別指到不同的資料庫,EF就會根據連線字串的設定產生相對應的資料庫

0%