Esempio n. 1
0
        /// <summary>
        /// Get Media AD_ MPrintForm
        /// </summary>
        /// <param name="project">project</param>
        /// <returns>list of server</returns>
        public static MMedia[] GetMedia(MWebProject project)
        {
            List <MMedia> list = new List <MMedia>();

            SqlParameter[] param = new SqlParameter[1];
            IDataReader    idr   = null;
            String         sql   = "SELECT * FROM CM_Media WHERE CM_WebProject_ID=@param ORDER BY CM_Media_ID";

            try
            {
                //pstmt = DataBase.prepareStatement (sql, project.get_TrxName());
                //pstmt.setInt (1, project.getCM_WebProject_ID());
                param[0] = new SqlParameter("@param", project.GetCM_WebProject_ID());
                idr      = DataBase.DB.ExecuteReader(sql, param, project.Get_TrxName());
                while (idr.Read())
                {
                    list.Add(new MMedia(project.GetCtx(), idr, project.Get_TrxName()));
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            MMedia[] retValue = new MMedia[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }       //	getMedia
Esempio n. 2
0
        }       //	getMedia

        /// <summary>
        /// /**
        /// </summary>
        /// get container by name
        /// <param name="ctx">context</param>
        /// <param name="Name">name</param>
        /// <param name="CM_WebProject_Id">id</param>
        /// <param name="trxName">trx</param>
        /// <returns>container or null if nt found</returns>
        public static MMedia GetByName(Ctx ctx, String Name, int CM_WebProject_Id, Trx trxName)
        {
            MMedia thisMedia = null;
            String sql       = "SELECT * FROM CM_Media WHERE (LOWER(Name) LIKE @param1) AND CM_WebProject_ID=@param2";

            SqlParameter[] param = new SqlParameter[2];
            IDataReader    idr   = null;

            try
            {
                //pstmt = DataBase.prepareStatement(sql, trxName);
                //pstmt.setString (1,Name.toLowerCase ());
                //pstmt.setInt(2, CM_WebProject_Id);
                param[0] = new SqlParameter("@param1", Name.ToLower());
                param[1] = new SqlParameter("@param2", CM_WebProject_Id);
                idr      = DataBase.DB.ExecuteReader(sql, param, trxName);
                if (idr.Read())
                {
                    thisMedia = (new MMedia(ctx, idr, trxName));
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }

            return(thisMedia);
        }
Esempio n. 3
0
 /// <summary>
 /// Deployment Parent Constructor
 /// </summary>
 /// <param name="server">server</param>
 /// <param name="media">media</param>
 public MMediaDeploy(MMediaServer server, MMedia media)
     : this(server.GetCtx(), 0, server.Get_TrxName())
 {
     SetCM_Media_Server_ID(server.GetCM_Media_Server_ID());
     SetCM_Media_ID(media.GetCM_Media_ID());
     SetClientOrg(server);
     //
     SetIsDeployed(true);
     SetLastSynchronized(DateTime.Now); // new Timestamp(System.currentTimeMillis()));
 }                                      //	MMediaDeploy
Esempio n. 4
0
 /// <summary>
 /// reDeployAll set all media items to redeploy
 /// </summary>
 public void ReDeployAll()
 {
     MMedia[] media = MMedia.GetMedia(GetWebProject());
     if (media != null && media.Length > 0)
     {
         for (int i = 0; i < media.Length; i++)
         {
             MMediaDeploy thisDeploy = MMediaDeploy.GetByMedia(GetCtx(), media[i].Get_ID(), Get_ID(), true, null);
             if (thisDeploy.IsDeployed())
             {
                 log.Log(Level.FINE, "Reset Deployed Flag on MediaItem" + media[i].Get_ID());
                 thisDeploy.SetIsDeployed(false);
                 thisDeploy.Save();
             }
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// /**
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="CM_Media_Server_ID">server id</param>
        /// <param name="trxName">id</param>
        /// <returns>server list of media items to deploy</returns>
        public static MMedia[] GetMediaToDeploy(Ctx ctx, int CM_Media_Server_ID, Trx trxName)
        {
            List <MMedia> list = new List <MMedia>();

            SqlParameter[] param = new SqlParameter[1];
            IDataReader    idr   = null;
            String         sql   = "SELECT CMM.* FROM CM_Media CMM, CM_MediaDeploy CMMD WHERE " +
                                   "CMM.CM_Media_ID = CMMD.CM_Media_ID AND " +
                                   "CMMD.CM_Media_Server_ID = @param AND " +
                                   "CMMD.IsDeployed='N' " +
                                   "ORDER BY CMM.CM_Media_ID";

            try
            {
                //pstmt = DataBase.prepareStatement (sql, trxName);
                //pstmt.setInt (1, CM_Media_Server_ID);
                param[0] = new SqlParameter("@param", CM_Media_Server_ID);
                idr      = DataBase.DB.ExecuteReader(sql, param, trxName);
                while (idr.Read())
                {
                    list.Add(new MMedia(ctx, idr, trxName));
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }

            MMedia[] retValue = new MMedia[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }       //	getMedia
Esempio n. 6
0
        }       //	deploy

        /// <summary>
        /// (Re-)Deploy all media
        /// </summary>
        /// <param name="t_media">true if deployed</param>
        /// <returns></returns>
        public bool DeleteMediaItem(MMedia t_media)
        {
            // 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.login (getUserName(), getPassword()))
                if (ftp.Credentials != null)
                {
                    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();
                //
                if (!t_media.IsSummary())
                {
                    log.Log(Level.INFO, " Deleting Media Item:" + t_media.Get_ID() + t_media.GetExtension());
                    //ftp.dele (t_media.Get_ID() + t_media.GetExtension());
                    ftp = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(t_media.Get_ID() + t_media.GetExtension());
                    // ftp.Method = t_media.Get_ID() + t_media.GetExtension();
                    ftp.Method = System.Net.WebRequestMethods.Ftp.DeleteFile;
                }
            }
            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;
                cmd            = "disconnect";
                //ftp.disconnect();
                ftp.KeepAlive = false;
            }
            catch (Exception e)
            {
                log.Log(Level.WARNING, cmd, e);
            }
            ftp = null;
            return(success);
        }       //	deploy
Esempio n. 7
0
        /// <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
Esempio n. 8
0
 /**
  *  process any token to a StringBuffer, the different types need to handle the results different.
  *	@param source
  *	@param CM_WebProject_ID
  *	@return converted StringBuffer
  */
 public StringBuilder ProcessToken(StringBuilder source, int CM_WebProject_ID, String MediaPath)
 {
     if (GetTokenType().Equals(X_CM_WikiToken.TOKENTYPE_Style))
     {
         Matcher matcher = GetPattern().matcher(source.ToString());
         source = new StringBuilder(matcher.replaceAll(GetMacro()));
     }
     else if (GetTokenType().Equals(X_CM_WikiToken.TOKENTYPE_SQLCommand))
     {
     }
     else if (GetTokenType().Equals(X_CM_WikiToken.TOKENTYPE_ExternalLink))
     {
         Matcher matcher = GetPattern().matcher(source.ToString());
         source = new StringBuilder(matcher.replaceAll(GetMacro()));
     }
     else if (GetTokenType().Equals(X_CM_WikiToken.TOKENTYPE_InternalLink))
     {
         Matcher matcher = GetPattern().matcher(source.ToString());
         while (matcher.find())
         {
             if (matcher.group(1).Equals("Media:"))
             {
                 String Name          = matcher.group(2);
                 MMedia thisMedia     = MMedia.GetByName(GetCtx(), Name, CM_WebProject_ID, null);
                 String replaceString = "";
                 if (thisMedia != null)
                 {
                     if (matcher.groupCount() > 2)
                     {
                         replaceString = "<img src=\"" + MediaPath + thisMedia.GetFileName() + "\" alt=\"" + matcher.group(3) + "\"/>";
                     }
                 }
                 source  = new StringBuilder(matcher.replaceFirst(replaceString));
                 matcher = GetPattern().matcher(source.ToString());
             }
             else
             {
                 String     link          = matcher.group(1);
                 MContainer thisContainer = MContainer.GetByName(GetCtx(), link, CM_WebProject_ID, null);
                 if (thisContainer == null)
                 {
                     thisContainer = MContainer.GetByTitle(GetCtx(), link, CM_WebProject_ID, null);
                 }
                 String replaceURL = "/index.html";
                 if (thisContainer != null)
                 {
                     if (matcher.groupCount() > 1)
                     {
                         replaceURL = "<a href=\"" + thisContainer.GetRelativeURL() + "\">" + matcher.group(2) + "</a>";
                     }
                     else
                     {
                         replaceURL = "<a href=\"" + thisContainer.GetRelativeURL() + "\">" + matcher.group(1) + "</a>";
                     }
                 }
                 source  = new StringBuilder(matcher.replaceFirst(replaceURL));
                 matcher = GetPattern().matcher(source.ToString());
             }
         }
     }
     return(source);
 }