简体   繁体   English

在MVC和Windows应用程序之间交换数据

[英]Exchanging data between MVC- and Windows Application

I have a solution that has a MVC-project and a windows console application. 我有一个具有MVC项目和Windows控制台应用程序的解决方案。 Both projects share the same Backend-Project, that loads and saves data. 两个项目共享同一个后端项目,该后端项目可以加载和保存数据。

I need to exchange the data from these two projects. 我需要交换来自这两个项目的数据。 Therefore I decided to use Isolated scope: 因此,我决定使用隔离范围:

    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);
    }
  }
}

Now Inside the mvc-project I save the Data using "SaveInstallationFile()". 现在,在mvc项目中,我使用“ SaveInstallationFile()”保存数据。 I can access that file from within that mvc-project. 我可以从该mvc项目中访问该文件。

But when I try to access the data using the other (console-)project, the File does not exist. 但是,当我尝试使用另一个(控制台)项目访问数据时,该文件不存在。

How can I exchange data between these two? 如何在这两者之间交换数据? (There is a big chance that both run under different user credentials, so GetUserStore...() IMHO would not work. (两者都有很大的机会在不同的用户凭据下运行,因此GetUserStore ...()恕我直言将无法正常工作。

Both, the MVC-Application AND the Console-Application run on the Same Server. MVC应用程序和控制台应用程序都在同一服务器上运行。

If you really need to use isolated storage API you can use GetMachineStoreForAssembly (if this code is shared in the same assembly for both projects). 如果确实需要使用隔离的存储API,则可以使用GetMachineStoreForAssembly (如果两个项目在同一程序GetMachineStoreForAssembly共享此代码)。 Currently you use different storages for different applications. 当前,您将不同的存储用于不同的应用程序。 But to be honest, I would prefer to use database or custom configurable shared disk path as it looks more flexible solution. 但老实说,我宁愿使用数据库或自定义可配置共享磁盘路径,因为它看起来更灵活。

GetMachineStoreForAssembly is less restrictive version of GetMachineStoreForDomain (both of them require code to be in the same assembly but GetMachineStoreForDomain requires it to be also in the same application). GetMachineStoreForAssembly是较少限制的版本GetMachineStoreForDomain (两者需要代码,以在相同的组件,但GetMachineStoreForDomain要求它也以相同的应用程序)。 You can check MSDN documentation: 您可以检查MSDN文档:

  • First method ( GetMachineStoreForAssembly ) is equivalent of GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine, null, null) 第一种方法( GetMachineStoreForAssembly )等效于GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine, null, null)
  • Second method is equivalent of GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.Machine, null, null); 第二种方法等效于GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.Machine, null, null); (so, it includes one additional flag that's why it's more restrictive) (因此,它包含一个额外的标志,这就是它更具限制性的原因)

And also both of them check calling assembly. 并且他们两个都检查调用程序集。 Not root executing assembly. 不是root执行程序集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM