簡體   English   中英

在MVC和Windows應用程序之間交換數據

[英]Exchanging data between MVC- and Windows Application

我有一個具有MVC項目和Windows控制台應用程序的解決方案。 兩個項目共享同一個后端項目,該后端項目可以加載和保存數據。

我需要交換來自這兩個項目的數據。 因此,我決定使用隔離范圍:

    private string LoadInstallationFile()
{
  IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForDomain();
  if (!isoStore.FileExists(ClientSettingsFile)) return null;
  /* do stuff */
}


private void SaveInstallationFile() {
  IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForDomain(); 
  using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(ClientSettingsFile, FileMode.CreateNew, isoStore))
  {
    using (StreamWriter writer = new StreamWriter(isoStream))
    {
      writer.WriteLine(data);
    }
  }
}

現在,在mvc項目中,我使用“ SaveInstallationFile()”保存數據。 我可以從該mvc項目中訪問該文件。

但是,當我嘗試使用另一個(控制台)項目訪問數據時,該文件不存在。

如何在這兩者之間交換數據? (兩者都有很大的機會在不同的用戶憑據下運行,因此GetUserStore ...()恕我直言將無法正常工作。

MVC應用程序和控制台應用程序都在同一服務器上運行。

如果確實需要使用隔離的存儲API,則可以使用GetMachineStoreForAssembly (如果兩個項目在同一程序GetMachineStoreForAssembly共享此代碼)。 當前,您將不同的存儲用於不同的應用程序。 但老實說,我寧願使用數據庫或自定義可配置共享磁盤路徑,因為它看起來更靈活。

GetMachineStoreForAssembly是較少限制的版本GetMachineStoreForDomain (兩者需要代碼,以在相同的組件,但GetMachineStoreForDomain要求它也以相同的應用程序)。 您可以檢查MSDN文檔:

  • 第一種方法( GetMachineStoreForAssembly )等效於GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine, null, null)
  • 第二種方法等效於GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.Machine, null, null); (因此,它包含一個額外的標志,這就是它更具限制性的原因)

並且他們兩個都檢查調用程序集。 不是root執行程序集。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM