Exemplo n.º 1
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();
             }
         }
     }
 }
Exemplo n.º 2
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
Exemplo n.º 3
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