Ejemplo n.º 1
0
        /// <summary>
        /// Gets a new instance of the application storage.
        /// </summary>
        public static bool GetStorage(string directory, string storageCode, StorageContext storageContext,
                                      out StorageLogic storageLogic, out string message)
        {
            string fileName = Path.Combine(directory, storageCode + ".dll");
            string typeName = string.Format("Scada.Storages.{0}.{0}Logic", storageCode);

            try
            {
                if (File.Exists(fileName))
                {
                    Assembly assembly = Assembly.LoadFrom(fileName);
                    Type     type     = assembly.GetType(typeName, true);
                    storageLogic = (StorageLogic)Activator.CreateInstance(type, storageContext);

                    message = string.Format(Locale.IsRussian ?
                                            "Хранилище {0} {1} загружено из файла {2}" :
                                            "Storage {0} {1} loaded from file {2}",
                                            storageCode, assembly.GetName().Version, fileName);
                    return(true);
                }
                else
                {
                    storageLogic = null;
                    message      = string.Format(Locale.IsRussian ?
                                                 "Невозможно создать логику хранилища {0}. Файл {1} не найден" :
                                                 "Unable to create storage logic {0}. File {1} not found", storageCode, fileName);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                storageLogic = null;
                message      = string.Format(Locale.IsRussian ?
                                             "Ошибка при создании логики хранилища {0} типа {1} из файла {2}: {3}" :
                                             "Error creating storage logic {0} of type {1} from file {2}: {3}",
                                             storageCode, typeName, fileName, ex.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public StorageWrapper(StorageContext storageContext, InstanceConfig instanceConfig)
 {
     this.storageContext = storageContext ?? throw new ArgumentNullException(nameof(storageContext));
     this.instanceConfig = instanceConfig ?? throw new ArgumentNullException(nameof(instanceConfig));
     storageLogic        = null;
 }