コード例 #1
0
        public JObject SaveToDB(IDBService dbProxy, string fileName, string baseFolder, string collection, string updateFilter = null, string fileBase64Data = null)
        {
            string destination = string.Format("{0}\\{1}{2}", ApplicationConfig.AppTempFolderPath, CommonUtility.RandomString(5), fileName);

            if (!string.IsNullOrEmpty(Save(fileName, destination, fileBase64Data)))
            {
                FileInfo fi             = new FileInfo(destination);
                var      contentType    = GetContentType(fi);
                var      fileUploadData = JObjectHelper.GetJObjectDbDataFromFile(fi, contentType, ApplicationConfig.AppTempFolderPath, "ZNxtAppUpload", baseFolder);
                File.Delete(destination);
                if (string.IsNullOrEmpty(updateFilter))
                {
                    _logger.Debug(string.Format("SaveToDB Writing new file  Name {0} ", fileName));

                    dbProxy.Write(collection, fileUploadData);
                    return(dbProxy.FirstOrDefault(collection, CommonConst.CommonField.DISPLAY_ID, fileUploadData[CommonConst.CommonField.DISPLAY_ID].ToString()));
                }
                else
                {
                    _logger.Debug(string.Format("SaveToDB updating file  Name {0} ", fileName));
                    fileUploadData.Remove(CommonConst.CommonField.DISPLAY_ID);
                    dbProxy.Write(collection, fileUploadData, updateFilter, true, MergeArrayHandling.Replace);
                    return(dbProxy.Get(collection, updateFilter, new List <string>()
                    {
                        CommonConst.CommonField.DISPLAY_ID, CommonConst.CommonField.FILE_PATH
                    }).First as JObject);
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: ModuleInstaller.cs プロジェクト: kc85/ZNxt.Net.Core
        private void InstallCollections(ModuleInstallRequest request)
        {
            const string collection       = "collections";
            var          collectionFilter = @"{name: /^content\/" + collection + "/, " + CommonConst.CommonField.MODULE_NAME + ": '" + request.Name + "', " + CommonConst.CommonField.VERSION + ": '" + request.Version + "'}";

            foreach (var item in _dbService.Get(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, new RawQuery(collectionFilter)))
            {
                var fileSourceId   = item[CommonConst.CommonField.DISPLAY_ID].ToString();
                var fileName       = item[CommonConst.CommonField.NAME].ToString();
                var fileSize       = int.Parse(item[CommonConst.CommonField.FILE_SIZE].ToString());
                var contentType    = Mime.GetMimeType(fileName);
                var fileData       = JObjectHelper.GetJObjectDbDataFromFile(fileName, contentType, "content/wwwroot", request.Name, fileSize);
                var id             = fileData[CommonConst.CommonField.DISPLAY_ID].ToString();
                var collectionName = new FileInfo(fileName).Name.Replace(CommonConst.CONFIG_FILE_EXTENSION, "");
                var parent         = new FileInfo(fileName).Directory.Name;
                _logger.Debug($"InstallCollection File : {fileName}, Collection {collectionName}, Parent: { parent}");

                foreach (JObject joData in JObjectHelper.GetJArrayFromString(CommonUtility.GetStringFromBase64(_keyValueStorage.Get <string>(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, fileSourceId))))
                {
                    try
                    {
                        joData[CommonConst.CommonField.DISPLAY_ID]             = CommonUtility.GetNewID();
                        joData[CommonConst.CommonField.CREATED_DATA_DATE_TIME] = DateTime.Now;
                        joData[CommonConst.CommonField.MODULE_NAME]            = request.Name;
                        joData[CommonConst.CommonField.VERSION]     = request.Version;
                        joData[CommonConst.CommonField.ÌS_OVERRIDE] = false;
                        joData[CommonConst.CommonField.OVERRIDE_BY] = CommonConst.CommonValue.NONE;
                        var url = GetUIAppUrl(parent);
                        if (string.IsNullOrEmpty(url))
                        {
                            WriteToDB(joData, request.Name, collectionName, CommonConst.CommonField.DATA_KEY);
                        }
                        else
                        {
                            _logger.Debug($"Callling remote /ui/installcollection Flile : {fileName}, Collection {collectionName}, Parent: { parent}, url {url}");
                            joData[CommonConst.CommonValue.COLLECTION] = collectionName;
                            _apiGateway.CallAsync(CommonConst.ActionMethods.POST, "/ui/installcollection", "", joData, null, url).GetAwaiter().GetResult();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"Error InstallCollections collection:{joData}", ex);
                    }
                }
            }
        }
コード例 #3
0
ファイル: ModuleInstaller.cs プロジェクト: kc85/ZNxt.Net.Core
        private void InstallWWWRoot(ModuleInstallRequest request)
        {
            var wwwrootFilter = @"{name: /^content\/wwwroot/, " + CommonConst.CommonField.MODULE_NAME + ": '" + request.Name + "', " + CommonConst.CommonField.VERSION + ": '" + request.Version + "'}";

            _dbService.OverrideData(new JObject()
            {
                [CommonConst.CommonField.MODULE_NAME] = request.Name
            }, request.Name, CommonConst.CommonField.MODULE_NAME, CommonConst.Collection.STATIC_CONTECT);

            foreach (var item in _dbService.Get(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, new RawQuery(wwwrootFilter)))
            {
                var fileName = string.Empty;
                try
                {
                    var fileSourceId = item[CommonConst.CommonField.DISPLAY_ID].ToString();
                    fileName = item[CommonConst.CommonField.NAME].ToString();
                    var fileSize    = int.Parse(item[CommonConst.CommonField.FILE_SIZE].ToString());
                    var contentType = Mime.GetMimeType(fileName);
                    var fileData    = JObjectHelper.GetJObjectDbDataFromFile(fileName, contentType, "content/wwwroot", request.Name, fileSize);
                    fileData[CommonConst.CommonField.VERSION] = request.Version;
                    var id = fileData[CommonConst.CommonField.DISPLAY_ID].ToString();

                    var appUIFolder = GetAppFromUIFolder(fileData[CommonConst.CommonField.FILE_PATH].ToString());
                    if (!string.IsNullOrEmpty(appUIFolder))
                    {
                        fileData[CommonConst.CommonField.FILE_PATH] = fileData[CommonConst.CommonField.FILE_PATH].ToString().Replace($"/{appUIFolder}", "");
                    }
                    var appUIFolderUrl = GetUIAppUrl(appUIFolder);
                    if (string.IsNullOrEmpty(appUIFolderUrl))
                    {
                        WriteToDB(fileData, request.Name, CommonConst.Collection.STATIC_CONTECT, CommonConst.CommonField.FILE_PATH);
                        _keyValueStorage.Put <string>(CommonConst.Collection.STATIC_CONTECT, id, _keyValueStorage.Get <string>(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, fileSourceId), null, request.Name);
                    }
                    else
                    {
                        fileData[CommonConst.CommonField.DATA] = _keyValueStorage.Get <string>(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, fileSourceId);
                        _apiGateway.CallAsync(CommonConst.ActionMethods.POST, "/ui/installpage", "", fileData, null, appUIFolderUrl).GetAwaiter().GetResult();
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error($"Error InstallWWWRoot file:{fileName}", ex);
                }
            }
        }
コード例 #4
0
ファイル: ModuleInstaller.cs プロジェクト: kc85/znxtapp.core
        private void InstallDlls(string moduleDir, string moduleName)
        {
            var dllPath = string.Format("{0}\\lib\\net452\\", moduleDir);

            if (Directory.Exists(dllPath))
            {
                DirectoryInfo di    = new DirectoryInfo(dllPath);
                FileInfo[]    files = di.GetFiles("*.dll");
                CleanDBCollection(moduleName, CommonConst.Collection.DLLS);
                foreach (var item in files)
                {
                    FileInfo fi          = new FileInfo(item.FullName);
                    var      contentType = _httpProxy.GetContentType(fi.FullName);
                    var      joData      = JObjectHelper.GetJObjectDbDataFromFile(fi, contentType, string.Format("{0}", di.FullName), moduleName);
                    WriteToDB(joData, moduleName, CommonConst.Collection.DLLS, CommonConst.CommonField.FILE_PATH);
                }
            }
        }
コード例 #5
0
ファイル: ModuleInstaller.cs プロジェクト: kc85/znxtapp.core
        private void InstallWWWRoot(string path, string moduleName)
        {
            var wwwrootPath = string.Format("{0}\\Content\\{1}", path, CommonConst.MODULE_INSTALL_WWWROOT_FOLDER);

            if (Directory.Exists(wwwrootPath))
            {
                DirectoryInfo di    = new DirectoryInfo(wwwrootPath);
                FileInfo[]    files = di.GetFiles("*.*", SearchOption.AllDirectories);

                CleanDBCollection(moduleName, CommonConst.Collection.STATIC_CONTECT);

                foreach (var item in files)
                {
                    FileInfo fi          = new FileInfo(item.FullName);
                    var      contentType = _httpProxy.GetContentType(fi);
                    var      joData      = JObjectHelper.GetJObjectDbDataFromFile(fi, contentType, di.FullName, moduleName);
                    WriteToDB(joData, moduleName, CommonConst.Collection.STATIC_CONTECT, CommonConst.CommonField.FILE_PATH);
                }
            }
        }
コード例 #6
0
ファイル: ModuleInstaller.cs プロジェクト: kc85/ZNxt.Net.Core
        private void InstallDlls(ModuleInstallRequest request)
        {
            var dllFilter = @"{name: /^lib\/netstandard2.0/, " + CommonConst.CommonField.MODULE_NAME + ": '" + request.Name + "', " + CommonConst.CommonField.VERSION + ": '" + request.Version + "'}";

            foreach (var item in _dbService.Get(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, new RawQuery(dllFilter)))
            {
                var fileSourceId = item[CommonConst.CommonField.DISPLAY_ID].ToString();
                var fileName     = item[CommonConst.CommonField.NAME].ToString();
                var fileSize     = int.Parse(item[CommonConst.CommonField.FILE_SIZE].ToString());
                var contentType  = Mime.GetMimeType(fileName);
                var fileData     = JObjectHelper.GetJObjectDbDataFromFile(fileName, contentType, "lib/netstandard2.0/", request.Name, fileSize);
                fileData[CommonConst.CommonField.VERSION] = request.Version;
                var id       = fileData[CommonConst.CommonField.DISPLAY_ID].ToString();
                var data     = _keyValueStorage.Get <string>(CommonConst.Collection.MODULE_FILE_UPLOAD_CACHE, fileSourceId);
                var assembly = Assembly.Load(Convert.FromBase64String(data));
                fileData[CommonConst.CommonField.NAME] = assembly.FullName;
                WriteToDB(fileData, request.Name, CommonConst.Collection.DLLS, CommonConst.CommonField.FILE_PATH);
                InstallRoutes(request, assembly);
                _keyValueStorage.Put <string>(CommonConst.Collection.DLLS, id, data);
            }
        }