void Upload(ServiceParamWcf paramWCF)
        {
            try
            {
                Guid guid = paramWCF.param.dataToProcess.Guid;

                //string path = ConfigurationManager.AppSettings["dirBaseClient"].ToString() + guid;
                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\efolding.fcfrp.usp.br\Client\" + guid;
                //string destPath = ConfigurationManager.AppSettings["uploadFolder"].ToString();
                string destPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\efolding.fcfrp.usp.br\Client\_temp\" + guid;

                SIO.FileInfo sourceFile   = new File().FileInfos(path + ".zip");
                SIO.FileInfo destFileName = new File().FileInfos(destPath + ".zip");

                //Valida se arquivo não existe, de uma tentativa de enviado anterior
                if (previousSimulation == false) //!File.Exists(destFileName.FullName) &&
                {
                    //Compress FILE
                    //GICO.WriteLine(guid, rm.GetString("UploadCompression"));
                    GICO.WriteLine(guid, "UploadCompression");
                    Compression.Compress(guid, sourceFile, new ExtendedDirectoryInfo(path), true, string.Empty);

                    if (File.Exists(destFileName.FullName))
                    {
                        File.Delete(destFileName.FullName);
                    }

                    //GICO.WriteLine(guid, rm.GetString("UploadFileMove"));
                    GICO.WriteLine(guid, "UploadFileMove");
                    File.Move(sourceFile.FullName, destFileName.FullName);
                }

                GICO.WriteLine(guid, ExtendedString.Format("Upload file {0}..", destFileName.Name));

                ProxyDocumentManagmentClient.DocumentEcho(destFileName);
                using (System.IO.BinaryReader fs = new System.IO.BinaryReader(System.IO.File.Open(destFileName.FullName, System.IO.FileMode.Open)))
                {
                    int  pos    = 0;
                    bool append = false;
                    int  length = (int)fs.BaseStream.Length;

                    while (pos < length)
                    {
                        byte[] bytes = fs.ReadBytes(1024 * 1024);
                        ProxyDocumentManagmentClient.UploadDocument(destFileName, bytes, append);

                        append = true;
                        pos   += 1024 * 1024;
                    }
                }

                //Extract
                GICO.WriteLine(guid, ExtendedString.Format("Extract file {0}..", destFileName.Name));
                ProxyDocumentManagmentClient.ExtractDocument(destFileName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static ServiceParamWcf GetOneProcessGui(Guid gui)
        {
            for (int tryCon = 0; tryCon < numberTry; tryCon++)
            {
                try
                {
                    OpenChannel();
                    ServiceParamWcf ret = objDistributed.GetOneProcessGui(gui, requestorInfo);
                    CloseChannel();
                    return(ret);
                }
                catch (CommunicationException ex)
                {
                    new CustomLog().CommunicationException(ex);
                    new CustomLog().ProxyException(System.Reflection.MethodBase.GetCurrentMethod().Name, tryCon, true);
                    //CheckStatusChannel();
                    throw;
                }
                catch (Exception ex)
                {
                    new CustomLog().Exception(ex);
                    throw;
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        //        private static void CheckStatusChannel()
        //        {
        //#if DEBUGPROXY
        //            Console.WriteLine(HelperDebug.GetCurrentMethod());
        //#endif
        //            if (objDistributed == null)
        //            {
        //                objDistributed = new ServiceClient();
        //            }

        //            if (objDistributed.State == CommunicationState.Faulted)
        //            {
        //                //new CustomLog().CommunicationException(new CommunicationException("CommunicationState.Faulted"));
        //                OpenChannel();
        //            }
        //            else if (objDistributed.State != CommunicationState.Opened)
        //            {
        //                OpenChannel();
        //            }
        //        }


        public static ServiceParamWcf GetOneProcessGuiForETL(Guid guid)
        {
            System.Net.NetworkInformation.PhysicalAddress macAddr = Net.GetMacAddress();

            //CheckStatusChannel();

            for (int tryCon = 0; tryCon < numberTry; tryCon++)
            {
                try
                {
                    OpenChannel();
                    ServiceParamWcf ret = objDistributed.GetOneProcessGuiForETL(guid, new RequestorInfo()
                    {
                        macAddr = macAddr.ToString(), machineName = Environment.MachineName
                    });
                    CloseChannel();
                    return(ret);
                }
                catch (CommunicationException)
                {
                    throw;
                    //new CustomLog().CommunicationException(ex);
                    //CheckStatusChannel();
                }
                catch (Exception)
                {
                    //new CustomLog().Exception(ex);
                    throw;
                }
            }

            return(null);
        }
 void Processing(ref GridProteinFolding.Core.eFolding.Main objProcess,
                 ref GridProteinFolding.Middle.Helpers.ConfigurationHelpers.Param newParam,
                 ref ServiceParamWcf paramWCF)
 {
     //PROCESS MAIN
     returnOfProcess = objProcess.Process(ref newParam);
     objProcess      = null;
 }
        public bool Run(ServiceParamWcf paramWCF)
        {
            Param param = new Param();

            param.dataToProcess = new DataToProcess()
            {
                Guid = paramWCF.param.dataToProcess.Guid
            };
            param.dataToProcess.maxInterations = paramWCF.param.dataToProcess.maxInterations;
            param.dataToProcess.totalSitio     = paramWCF.param.dataToProcess.totalSitio;
            param.dataToProcess.Guid           = paramWCF.param.dataToProcess.Guid;
            param.dataToProcess.temperature    = paramWCF.param.dataToProcess.temperature;
            param.dataToProcess.modelType      = paramWCF.param.dataToProcess.modelType;
            param.dataToProcess.crypt          = paramWCF.param.dataToProcess.crypt;
            param.dataToProcess.isem           = paramWCF.param.dataToProcess.isem;

            param.files = new Files()
            {
                Debug = paramWCF.param.files.Debug
            };

            param.dataToResults = new DataToResults();
            param.dataToResults.valueDiscard   = paramWCF.param.dataToResults.valueDiscard;
            param.dataToResults.valueDivResult = paramWCF.param.dataToResults.valueDivResult;

            param.output = new Output();
            param.output.configuration = paramWCF.param.output.configuration;
            //param.output.configurationJumpStep = paramWCF.param.output.configurationJumpStep;
            param.output.evolution    = paramWCF.param.output.evolution;
            param.output.distribution = paramWCF.param.output.distribution;
            param.output.debug        = paramWCF.param.output.debug;
            param.output.histogram    = paramWCF.param.output.histogram;
            param.output.trajectory   = paramWCF.param.output.trajectory;

            Applications objGeneratingResultsReference = new Applications(param);

            objGeneratingResultsReference.Do();
            objGeneratingResultsReference = null;

            param    = null;
            paramWCF = null;


            return(true);
        }
        private bool AfterSleep()
        {
            bool retRun = false;

            try
            {
                Guid[] guids = Proxy.GetGuidsToApplications();

                if (guids != null)
                {
                    foreach (Guid guid in guids)
                    {
                        ServiceParamWcf paramWCF = Proxy.GetOneProcessGuiForETL(guid);

                        if (paramWCF != null)
                        {
                            ConsoleColor oldColour = Console.ForegroundColor;
                            GICO.ForegroundColor(ConsoleColor.Yellow);

                            GICO.WriteLine(string.Empty);
                            GICO.WriteLine(String.Format("Guid running: {0}", guid.ToString()));

                            GICO.ForegroundColor(oldColour);

                            retRun = Run(paramWCF);

                            Proxy.SetOneProcessByGuid(paramWCF.param.dataToProcess.Guid, BasicEnums.State.ResultsProcessed);

                            GICO.WriteLine(String.Format("Finished Guid: {0}", guid.ToString()));
                            GICO.WriteLine(string.Empty);
                        }
                    }
                }
                return(retRun);
            }
            catch (EndpointNotFoundException)
            {
                //new CustomLog().EndpointNotFoundException(ex);
            }

            return(false);
        }
        private bool Run(ServiceParamWcf paramWCF)
        {
            GridProteinFolding.Core.eFolding.Main objProcess = new GridProteinFolding.Core.eFolding.Main();

            //Executa REQUISICAO
            GridProteinFolding.Middle.Helpers.ConfigurationHelpers.Param newParam = new GridProteinFolding.Middle.Helpers.ConfigurationHelpers.Param();
            //Preparar os parametros para execução
            Param temp = paramWCF.param;

            GridProteinFolding.Middle.Helpers.ConfigurationHelpers.Param.PreperParams(ref temp, ref newParam);

            #region Atualiza Status local
            if (Status(paramWCF.param.dataToProcess.Guid) == (int)BasicEnums.State.Processing)
            {
                Sql.entityProcess = SetStatusProcessandoLocalDBToProcessing(newParam, BasicEnums.State.Processing);
            }
            #endregion

            try
            {
                //if (Status(paramWCF.param.dataToProcess.Guid) == (int)BasicEnums.State.Waiting)
                //{
                //    DisplayMessage(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, BasicEnums.State.Waiting.ToString()));
                //    Sql.entityProcess = SetStatusProcessando(newParam, BasicEnums.State.Processing);
                //}

                if (Status(paramWCF.param.dataToProcess.Guid) == (int)BasicEnums.State.Processing)
                {
                    DisplayMessage(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, BasicEnums.State.Processing.ToString()));

                    Processing(ref objProcess, ref newParam, ref paramWCF);

                    if (returnOfProcess)
                    {
                        UpdateStatus(newParam, BasicEnums.State.Processed);
                    }
                    else
                    {
                        UpdateStatus(newParam, BasicEnums.State.Error);
                        DisplayMessage(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, BasicEnums.State.Error.ToString()));
                    }
                }

                if (Status(paramWCF.param.dataToProcess.Guid) == (int)BasicEnums.State.Processed)
                {
                    DisplayMessage(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, BasicEnums.State.Processed.ToString()));
                    UpdateStatus(newParam, returnOfProcess == true ? BasicEnums.State.Upload : BasicEnums.State.Error);
                    //System.Threading.Thread.Sleep(1000);
                }

                if (Status(paramWCF.param.dataToProcess.Guid) == (int)BasicEnums.State.Upload)
                {
                    DisplayMessage(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, (BasicEnums.State.Upload.ToString())));
                    returnOfProcess = true;
                    //Upload dos resultados
                    Upload(paramWCF);
                    //Atualiza Status
                    UpdateStatus(newParam, returnOfProcess == true ? BasicEnums.State.BULK : BasicEnums.State.Error);
                    //System.Threading.Thread.Sleep(500);
                }

                if (Status(paramWCF.param.dataToProcess.Guid) == (int)BasicEnums.State.ClearTempClient)
                {
                    if (AppConfigClient.Param == null)
                    {
                        AppConfigClient.Param = newParam;
                    }
                    //Limpar folder cliente utilizado no processamento
                    new GridProteinFolding.Core.eFolding.IO.Directory().ClearProcessClientFolder();

                    //Atualiza Status
                    UpdateStatus(newParam, returnOfProcess == true ? BasicEnums.State.ClearTempServer : BasicEnums.State.Error);
                    DisplayMessage(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, returnOfProcess == true ? BasicEnums.State.ClearTempServer.ToString() : BasicEnums.State.Error.ToString()));
                }

                GICO.WriteLine(ExtendedString.Format("{0}> {1}...", paramWCF.param.dataToProcess.Guid, "Process of simulation finished!"));


                return(returnOfProcess);
            }
            catch (Exception ex)
            {
                new CustomLog().Exception(ex);

                UpdateStatus(newParam, BasicEnums.State.Error);

                return(false);
            }
            //finally
            //{
            //    GridProteinFolding.Data.SQLite.SQLite.CloseDatabase();
            //}
        }