示例#1
0
        protected override bool BeforeDelete()
        {
            // Delete from Deployment Server
            MMediaDeploy[] theseDeployers = MMediaDeploy.GetByMediaAndProject(GetCtx(), Get_IDOld(), _project, false, Get_TrxName());
            if (theseDeployers != null && theseDeployers.Length > 0)
            {
                for (int i = 0; i < theseDeployers.Length; i++)
                {
                    if (!theseDeployers[i].GetServer().DeleteMediaItem(this))
                    {
                        log.Warning("Could not delete file + " + this.ToString() + " from Server: " + theseDeployers[i].GetServer());
                    }
                }
            }
            // Delete From MMediaDeploy
            StringBuilder sb = new StringBuilder("DELETE FROM CM_MediaDeploy ")
                               .Append(" WHERE CM_Media_ID=").Append(Get_IDOld());
            int no = DataBase.DB.ExecuteQuery(sb.ToString(), null, Get_TrxName());

            if (no > 0)
            {
                log.Fine("#" + no + " - CM_MediaDeploy");
            }
            else
            {
                log.Warning("#" + no + " - CM_MediaDeploy");
            }

            return(true);
        }
示例#2
0
        private static VLogger _log = VLogger.GetVLogger(typeof(MMedia).FullName);//.class);

        /// <summary>
        /// getByMediaAndProject Get All deployers by Media ID and WebProject
        /// </summary>
        /// <param name="ctx">Context</param>
        /// <param name="CM_Media_ID">id</param>
        /// <param name="thisProject">web project</param>
        /// <param name="createIfMissing">createIfMissing Whether we create or not</param>
        /// <param name="trxName">trx</param>
        /// <returns> Array of MediaDeploy</returns>
        public static MMediaDeploy[] GetByMediaAndProject(Ctx ctx, int CM_Media_ID, MWebProject thisProject, bool createIfMissing, Trx trxName)
        {
            List <MMediaDeploy> list = new List <MMediaDeploy>();

            MMediaServer[] theseServers = MMediaServer.GetMediaServer(thisProject);
            if (theseServers != null && theseServers.Length > 0)
            {
                for (int i = 0; i < theseServers.Length; i++)
                {
                    list.Add(GetByMedia(ctx, CM_Media_ID, theseServers[i].Get_ID(), createIfMissing, trxName));
                }
            }
            MMediaDeploy[] retValue = new MMediaDeploy[list.Count];// .size ()];
            retValue = list.ToArray();
            return(retValue);
        }
示例#3
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();
             }
         }
     }
 }
示例#4
0
        }       //	beforeSave

        /// <summary>
        /// after save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <param name="success">success</param>
        /// <returns>true if saved</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }
            if (newRecord)
            {
                StringBuilder sb = new StringBuilder("INSERT INTO AD_TreeNodeCMM "
                                                     + "(AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, "
                                                     + "AD_Tree_ID, Node_ID, Parent_ID, SeqNo) "
                                                     + "VALUES (")
                                   .Append(GetAD_Client_ID()).Append(",0, 'Y', SysDate, 0, SysDate, 0,")
                                   .Append(GetAD_Tree_ID()).Append(",").Append(Get_ID())
                                   .Append(", 0, 999)");
                int no = DataBase.DB.ExecuteQuery(sb.ToString(), null, Get_TrxName());
                if (no > 0)
                {
                    log.Fine("#" + no + " - TreeType=CMM");
                }
                else
                {
                    log.Warning("#" + no + " - TreeType=CMM");
                }
                return(no > 0);
            }
            // Construct / Update Deployment Procedure
            MMediaServer[] theseServers = MMediaServer.GetMediaServer(_project);
            if (theseServers != null && theseServers.Length > 0)
            {
                for (int i = 0; i < theseServers.Length; i++)
                {
                    MMediaDeploy thisDeploy = MMediaDeploy.GetByMedia(GetCtx(), Get_ID(), theseServers[i].Get_ID(), true, Get_TrxName());
                    if (thisDeploy.IsDeployed())
                    {
                        thisDeploy.SetIsDeployed(false);
                        thisDeploy.Save();
                    }
                }
            }
            return(success);
        }       //	afterSave
示例#5
0
        /// <summary>
        /// getByMedia returns MMediaDeploy Object corresponding to an MMedia Item
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="CM_Media_ID">id of media item</param>
        /// <param name="CM_Media_Server_ID">id</param>
        /// <param name="createIfMissing"><add missing entery/param>
        /// <param name="trxName">trx</param>
        /// <returns> Object or NULL if not existant</returns>
        public static MMediaDeploy GetByMedia(Ctx ctx, int CM_Media_ID, int CM_Media_Server_ID, bool createIfMissing, Trx trxName)
        {
            MMediaDeploy thisMMediaDeploy = null;
            String       sql = "SELECT * FROM CM_MediaDeploy WHERE CM_Media_ID=@param1 AND CM_Media_Server_ID=@param2";

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

            try
            {
                //pstmt = DataBase.prepareStatement(sql, trxName);
                //pstmt.setInt (1, CM_Media_ID);
                param[0] = new SqlParameter("@param1", CM_Media_ID);
                //pstmt.setInt (2, CM_Media_Server_ID);
                param[1] = new SqlParameter("@param2", CM_Media_Server_ID);
                idr      = DataBase.DB.ExecuteReader(sql, param, trxName);
                if (idr.Read())
                {
                    thisMMediaDeploy = (new MMediaDeploy(ctx, idr, trxName));
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            if (thisMMediaDeploy == null && createIfMissing)
            {
                thisMMediaDeploy = new MMediaDeploy(ctx, 0, trxName);
                thisMMediaDeploy.SetCM_Media_Server_ID(CM_Media_Server_ID);
                thisMMediaDeploy.SetCM_Media_ID(CM_Media_ID);
                thisMMediaDeploy.SetIsDeployed(false);
                thisMMediaDeploy.SetLastSynchronized(null);
                thisMMediaDeploy.Save();
            }
            return(thisMMediaDeploy);
        }
示例#6
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