Пример #1
0
        public bool Create(string name, GXProperties properties, ref GxStorageProvider storageProvider, ref GXBaseCollection <SdtMessages_Message> messages)
        {
            storageProvider = null;

            if (string.IsNullOrEmpty(name))
            {
                GXUtil.ErrorToMessages("Unsopported", "Provider cannot be empty", messages);
                return(false);
            }

            try
            {
                if (providerService == null || !string.Equals(providerService.Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    providerService               = new GXService();
                    providerService.Type          = GXServices.STORAGE_SERVICE;
                    providerService.Name          = name;
                    providerService.AllowMultiple = false;
                    providerService.Properties    = new GXProperties();
                }

                preprocess(name, properties);

                GxKeyValuePair prop = properties.GetFirst();
                while (!properties.Eof())
                {
                    providerService.Properties.Set(prop.Key, prop.Value);
                    prop = properties.GetNext();
                }

                string typeFullName = providerService.ClassName;
                logger.Debug("Loading storage provider: " + typeFullName);
#if !NETCORE
                Type type = Type.GetType(typeFullName, true, true);
#else
                Type type = new AssemblyLoader(FileUtil.GetStartupDirectory()).GetType(typeFullName);
#endif
                this.provider = (ExternalProvider)Activator.CreateInstance(type, new object[] { providerService });
            }
            catch (Exception ex)
            {
                logger.Error("Couldn't connect to external storage provider. ", ex);
                StorageMessages(ex, messages);
                return(false);
            }

            storageProvider = this;
            return(true);
        }