public static bool DeployAssembly(string server, int port, string path, string cacheId, string depAsmPath, LogErrors logError) { List <FileInfo> files = new List <FileInfo>(); // List that will hold the files and subfiles in path string fileName = null; byte[] asmData; string failedNodes = string.Empty; Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = null; try { if (port != -1) { NCache.Port = port; } if (port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (server != null || server != string.Empty) { NCache.ServerName = server; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cacheServer != null) { serverConfig = cacheServer.GetNewConfiguration(cacheId); if (path != null && path != string.Empty) { if (Path.HasExtension(path)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(path); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) { files.Add(f); } } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed."); return(false); } } } if (depAsmPath != null && depAsmPath != string.Empty) { if (Path.HasExtension(depAsmPath)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(depAsmPath); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) { files.Add(f); } } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed."); return(false); } } } foreach (FileInfo f in files) { try { FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read); asmData = new byte[fs.Length]; fs.Read(asmData, 0, asmData.Length); fs.Flush(); fs.Close(); fileName = Path.GetFileName(f.FullName); if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { NCache.ServerName = node.IpAddress.ToString(); try { cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); cacheServer.CopyAssemblies(cacheId, fileName, asmData); } catch (Exception ex) { logError("Failed to Deploy Assembly on " + NCache.ServerName); logError("Error Detail: " + ex.Message); } } } else { cacheServer.CopyAssemblies(cacheId, fileName, asmData); } } catch (Exception e) { string message = string.Format("Could not deploy assembly \"" + fileName + "\". {0}", e.Message); logError("Error : " + message); return(false); } } } } catch (Exception e) { logError("Error : {0}" + e.Message); } finally { NCache.Dispose(); } return(true); }
public static bool DeployAssembly(string server, int port, string path, string cacheId, string depAsmPath,LogErrors logError ) { List<FileInfo> files = new List<FileInfo>(); // List that will hold the files and subfiles in path string fileName=null; byte[] asmData; string failedNodes = string.Empty; Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = null; try { if (port != -1) { NCache.Port = port; } if (port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; if (server != null || server != string.Empty) { NCache.ServerName = server; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cacheServer != null) { serverConfig = cacheServer.GetNewConfiguration(cacheId); if (path != null && path != string.Empty) { if (Path.HasExtension(path)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(path); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) files.Add(f); } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed!!!!"); return false; // We already got an error trying to access dir so dont try to access it again } } } if (depAsmPath != null && depAsmPath != string.Empty) { if (Path.HasExtension(depAsmPath)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(depAsmPath); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) files.Add(f); } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed!!!!"); return false; // We already got an error trying to access dir so dont try to access it again } } } foreach (FileInfo f in files) { try { FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read); asmData = new byte[fs.Length]; fs.Read(asmData, 0, asmData.Length); fs.Flush(); fs.Close(); fileName = Path.GetFileName(f.FullName); if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { NCache.ServerName = node.IpAddress.ToString(); try { cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); cacheServer.CopyAssemblies(cacheId, fileName, asmData); } catch (Exception ex) { logError("Failed to Deploy Assembly on "+NCache.ServerName); logError("Error Detail: "+ex.Message); } } } else cacheServer.CopyAssemblies(cacheId,fileName,asmData); } catch (Exception e) { string message = string.Format("Could not deploy assembly \"" + fileName + "\". {0}", e.Message); logError("Error : " + message); return false; } } } } catch (Exception e) { logError("Error : {0}" + e.Message); } finally { NCache.Dispose(); } return true; }