private static WebProvider Create()
{
WebProvider provider = null;
CleanTemporaryFiles();
try
{
// Does a binary file exist?
if (Manager.BinaryFilePath != null)
{
// Log API version for diagnosis.
var assembly = Assembly.GetExecutingAssembly().GetName();
EventLog.Info(String.Format(
"Creating data set from '{0}' version '{1}'",
assembly.Name,
assembly.Version));
if (File.Exists(Manager.BinaryFilePath))
{
if (Manager.MemoryMode)
{
EventLog.Info(String.Format(
"Creating memory byte array dataset and provider from binary data file '{0}'.",
Manager.BinaryFilePath));
provider = new WebProvider(StreamFactory.Create(File.ReadAllBytes(Manager.BinaryFilePath)));
}
else
{
provider = new WebProvider(GetTempFileDataSet());
}
EventLog.Info(String.Format(
"Created provider from version '{0}' format '{1}' data published on '{2:u}' in master file '{3}'.",
provider.DataSet.Version,
provider.DataSet.Name,
provider.DataSet.Published,
Manager.BinaryFilePath));
}
else
{
EventLog.Info("Data file at '{0}' could not be found. Either it does not exist or " +
"there is insufficient permission to read it. Check the AppPool has read permissions " +
"and the application is not running in medium trust if the data file is not in the " +
"application directory.", Manager.BinaryFilePath);
}
}
}
catch (Exception ex)
{
// Record the exception in the log file.
EventLog.Fatal(
new MobileException(String.Format(
"Exception processing device data from binary file '{0}'. " +
"Enable debug level logging and try again to help identify cause.",
Manager.BinaryFilePath),
ex));
}
// Does the provider exist and has data been loaded?
if (provider == null || provider.DataSet == null)
{
EventLog.Fatal("No data source available to create provider.");
}
return provider;
}