} // getExtension /// <summary> /// Get Image /// </summary> /// <returns>image or null</returns> public MImage GetImage() { if (GetAD_Image_ID() != 0) { return(MImage.Get(GetCtx(), GetAD_Image_ID())); } return(null); } // getImage
} // /// <summary> /// Get Window Icon /// </summary> /// <returns></returns> public System.Drawing.Image GetImage() { if (_vo.AD_Image_ID == 0) { return(null); } // Model.MImage mImage = MImage.Get((Context)_vo.GetCtx(), _vo.AD_Image_ID); return(mImage.GetImage()); } // getImage
} // getImage /// <summary> /// Get Data as byte array /// </summary> /// <returns>data or null</returns> public byte[] GetData() { MImage image = GetImage(); if (image != null) { byte[] data = image.GetData(); if (data == null || data.Length == 0) { log.Config("No Image Data"); } } // Attachment MAttachment att = GetAttachment(); if (att == null || att.GetEntryCount() == 0) { log.Config("No Attachment"); return(null); } if (att.GetEntryCount() > 1) { log.Warning(GetName() + " - more then one attachment - " + att.GetEntryCount()); } // MAttachmentEntry entry = att.GetEntry(0); if (entry == null) { log.Config("No Attachment Entry"); return(null); } byte[] buffer = entry.GetData(); if (buffer == null || buffer.Length == 0) { log.Config("No Attachment Entry Data"); return(null); } return(buffer); } // getData
public static MImage Get(Ctx ctx, int AD_Image_ID) { if (AD_Image_ID == 0) { return(new MImage(ctx, AD_Image_ID, null)); } // int key = AD_Image_ID; MImage retValue = s_cache[key]; if (retValue != null) { return(retValue); } retValue = new MImage(ctx, AD_Image_ID, null); if (retValue.Get_ID() != 0) { s_cache[key] = retValue; } return(retValue); }
/// <summary> /// (Re-)Deploy all media /// </summary> /// <returns>true if deployed</returns> public bool Deploy() { MMedia[] media = MMedia.GetMediaToDeploy(GetCtx(), this.Get_ID(), Get_TrxName()); // Check whether the host is our example localhost, we will not deploy locally, but this is no error if (this.GetIP_Address().Equals("127.0.0.1") || this.GetName().Equals("localhost")) { log.Warning("You have not defined your own server, we will not really deploy to localhost!"); return(true); } //FTPClient ftp = new FTPClient(); System.Net.FtpWebRequest ftp; try { //ftp.connect (getIP_Address()); ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(GetIP_Address()); ftp.Credentials = new System.Net.NetworkCredential(GetUserName(), GetPassword()); if (ftp.Credentials != null) { //if (ftp.login (getUserName(), getPassword())) log.Info("Connected to " + GetIP_Address() + " as " + GetUserName()); } else { log.Warning("Could NOT connect to " + GetIP_Address() + " as " + GetUserName()); return(false); } } catch (Exception e) { log.Log(Level.WARNING, "Could NOT connect to " + GetIP_Address() + " as " + GetUserName(), e); return(false); } bool success = true; String cmd = null; // List the files in the directory try { cmd = "cwd"; //ftp.changeWorkingDirectory (getFolder()); ftp.Method = GetFolder(); // cmd = "list"; ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectory; System.IO.StreamReader sr = new System.IO.StreamReader(ftp.GetResponse().GetResponseStream()); List <String> listnames = new List <string>(); String str = sr.ReadLine(); while (str != null) { listnames.Add(str); str = sr.ReadLine(); } String[] fileNames = listnames.ToArray(); log.Log(Level.FINE, "Number of files in " + GetFolder() + ": " + fileNames.Length); /* * FTPFile[] files = ftp.listFiles(); * log.config("Number of files in " + getFolder() + ": " + files.length); * for (int i = 0; i < files.length; i++) * log.fine(files[i].getTimestamp() + " \t" + files[i].getName());*/ // cmd = "bin"; //ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.UseBinary = true; for (int i = 0; i < media.Length; i++) { MMediaDeploy thisDeployment = MMediaDeploy.GetByMedia(GetCtx(), media[i].Get_ID(), this.Get_ID(), false, Get_TrxName()); if (!media[i].IsSummary() && media[i].GetMediaType() != null) { log.Log(Level.INFO, " Deploying Media Item: " + media[i].ToString()); MImage thisImage = media[i].GetImage(); // Open the file and output streams byte[] buffer = thisImage.GetData(); //ByteArrayInputStream is = new ByteArrayInputStream(buffer); //System.IO.BufferedStream iss=new System.IO.BufferedStream(buffer); String fileName = media[i].Get_ID() + media[i].GetExtension(); cmd = "put " + fileName; //ftp.storeFile(fileName, is); System.IO.FileStream streamObj = System.IO.File.OpenRead(fileName); streamObj.Read(buffer, 0, buffer.Length); streamObj.Close(); streamObj = null; ftp.GetRequestStream().Write(buffer, 0, buffer.Length); thisDeployment.SetIsDeployed(true); thisDeployment.Save(); } } } catch (Exception e) { log.Log(Level.WARNING, cmd, e); success = false; } // Logout from the FTP Server and disconnect try { cmd = "logout"; //ftp.logout(); ftp.UsePassive = false; log.Log(Level.FINE, " FTP logged out"); cmd = "disconnect"; //ftp.disconnect(); ftp.KeepAlive = false; } catch (Exception e) { log.Log(Level.WARNING, cmd, e); } ftp = null; return(success); } // deploy