Storing a single read/writeable value for a web service

I’m writing a web service for some physical visualizations of data we are collecting and showing as part of a project we are running locally http://tenisonroad.com/ Some of the visualizations will be screen based and some will be physical (e.g. page 25 of this presentation from Resonate 2014). One thing my web service will do is signal to the visualizations when to change dataset. To do that I have a single integer, DemoDataSetsDwellTime. I started off in SQL thinking to add this value amoung my existing table declarations, e.g.

CREATE TABLE ActiveDemoDwells 
(secondsDwell INT NOT NULL)

But this seems wrong – why make a table that is only ever going to store one single number, one single record.

So then I thought of using application settings in the Web.config file

[Route("api/getdemodwelltime/")]
[AcceptVerbs("GET", "POST")]
public int GetDemoDwellTime()
{
    return Int32.Parse(ConfigurationManager.AppSettings["DemoDataSetsDwellTimes"]);
}

with corresponding entry

<appSettings>
  <add key="DemoDataSetsDwellTimes" value="20"/>
</appSettings>

But I have realised (from this answer) that the settings file should not really be used for writeable data, it is more suited / intended for read-only settings.

So finally I thought about using a simple flat file, i.e. something like this

[Route("api/getdemodwelltime/")]
[AcceptVerbs("GET", "POST")]
public int GetDemoDwellTime()
{
    var lines = File.ReadAllLines("settings.txt");
    var dwellTimeLine = lines.TakeWhile(line => line.StartsWith("dwellTime=")).FirstOrDefault();
    int result;
    return (dwellTimeLine != null && Int32.TryParse(dwellTimeLine.Remove(0, "dwellTime=".Length), out result)) ? result : -1;
}

But that may get in a mess in the (unlikely) event that get and set methods are called simultaneously (I think, I’m not sure how web servers manage local file system access).

So, which of these is the ‘correct’ approach, or is there another solution that I have overlooked?

  1. Store the single readable and writeable value in its own table in a database,
  2. Store it as an application setting in the Web.config file, or
  3. Store it in a flat file.

  1. Other. How about a static variable? Singletons don’t play well in the web environment, but that may work to your advantage. See also Asp.net session variable.

Another thought – you’re right about a one column / one record table, but if you already have the infrastructure set up to read & write tables, then the additional “cost” for this one would be pretty small. It would be easy to maintain since it’s using the same logic that everything else uses.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Storing a single read/writeable value for a web service

I’m writing a web service for some physical visualizations of data we are collecting and showing as part of a project we are running locally http://tenisonroad.com/ Some of the visualizations will be screen based and some will be physical (e.g. page 25 of this presentation from Resonate 2014). One thing my web service will do is signal to the visualizations when to change dataset. To do that I have a single integer, DemoDataSetsDwellTime. I started off in SQL thinking to add this value amoung my existing table declarations, e.g.

CREATE TABLE ActiveDemoDwells 
(secondsDwell INT NOT NULL)

But this seems wrong – why make a table that is only ever going to store one single number, one single record.

So then I thought of using application settings in the Web.config file

[Route("api/getdemodwelltime/")]
[AcceptVerbs("GET", "POST")]
public int GetDemoDwellTime()
{
    return Int32.Parse(ConfigurationManager.AppSettings["DemoDataSetsDwellTimes"]);
}

with corresponding entry

<appSettings>
  <add key="DemoDataSetsDwellTimes" value="20"/>
</appSettings>

But I have realised (from this answer) that the settings file should not really be used for writeable data, it is more suited / intended for read-only settings.

So finally I thought about using a simple flat file, i.e. something like this

[Route("api/getdemodwelltime/")]
[AcceptVerbs("GET", "POST")]
public int GetDemoDwellTime()
{
    var lines = File.ReadAllLines("settings.txt");
    var dwellTimeLine = lines.TakeWhile(line => line.StartsWith("dwellTime=")).FirstOrDefault();
    int result;
    return (dwellTimeLine != null && Int32.TryParse(dwellTimeLine.Remove(0, "dwellTime=".Length), out result)) ? result : -1;
}

But that may get in a mess in the (unlikely) event that get and set methods are called simultaneously (I think, I’m not sure how web servers manage local file system access).

So, which of these is the ‘correct’ approach, or is there another solution that I have overlooked?

  1. Store the single readable and writeable value in its own table in a database,
  2. Store it as an application setting in the Web.config file, or
  3. Store it in a flat file.

  1. Other. How about a static variable? Singletons don’t play well in the web environment, but that may work to your advantage. See also Asp.net session variable.

Another thought – you’re right about a one column / one record table, but if you already have the infrastructure set up to read & write tables, then the additional “cost” for this one would be pretty small. It would be easy to maintain since it’s using the same logic that everything else uses.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật