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 Subsystem(int priority, int importance, string name, int maxOverload = 1)
        {
            Priority     = priority;
            Importance   = importance;
            Name         = name;
            MaxOverload  = maxOverload;
            StatusReport = new ExtendedString();

            InitStatusReport();
        }
        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();
            //}
        }
        private bool CallServer(GridProteinFolding.Data.XMLData.Entity.Process process)
        {
            bool retRun = false;

            try
            {
                ServiceParamWcf paramWCF;

                bool oneProcessPeerGuid = false;
                //Se não existir pendência no cliente
                if (process == null)
                {
                    paramWCF = ProxyServiceClient.GetOneProcess();
                }
                else
                {
                    paramWCF           = ProxyServiceClient.GetOneProcessGui(process.guid);
                    oneProcessPeerGuid = true;

                    //Implementar a mudança de STATUS - qdo ocorrer erro POS processamento = UPLOAD e etc
                    //variavel RET (estara dentro Run) tem q estar setada pra TRUE...senao dara ERRO 99...
                    //Proxy.SetStatus(paramWCF, BasicEnums.State.Upload);
                }

                if (paramWCF != null)
                {
                    ConsoleColor oldColour = Console.ForegroundColor;
                    GICO.ForegroundColor(ConsoleColor.Yellow);
                    DisplayMessage(string.Empty);
                    DisplayMessage(ExtendedString.Format("{0}> {1}", paramWCF.param.dataToProcess.Guid, Resource.Started));

                    GICO.ForegroundColor(oldColour);
                    if (oneProcessPeerGuid)
                    {
                        DisplayMessage(ExtendedString.Format("{0}> {1}", paramWCF.param.dataToProcess.Guid, Resource.GetOneProcess));
                    }
                    else
                    {
                        DisplayMessage(ExtendedString.Format("{0}> {1}", paramWCF.param.dataToProcess.Guid, Resource.GetOneProcessGui));
                    }

                    //Responde que esta sendo PROCESSADO
                    DisplayMessage(ExtendedString.Format("{0}> {1}", paramWCF.param.dataToProcess.Guid, Resource.Running));

                    retRun = Run(paramWCF);

                    DisplayMessage(ExtendedString.Format("{0}> {1}", paramWCF.param.dataToProcess.Guid, Resource.Finished));
                    DisplayMessage(string.Empty);
                }

                return(retRun);
            }
            catch (EndpointNotFoundException ex)
            {
                ConsoleColor oldColour = Console.ForegroundColor;
                GICO.ForegroundColor(ConsoleColor.Red);
                DisplayMessage(ex.Message);
                GICO.ForegroundColor(oldColour);

                new CustomLog().EndpointNotFoundException(ex);
            }

            return(false);
        }
Example #5
0
        static void WriteFrameResultsToConsole(int frameNum, ProgressiveDataSetFrame frame)
        {
            var tableKind = WellKnownDataSet.Unknown;

            switch (frame.FrameType)
            {
            case FrameType.DataSetHeader:
            {
                // This is the first frame we'll get back
                var frameex = frame as ProgressiveDataSetHeaderFrame;
                var banner  = $"[{frameNum}] DataSet/HeaderFrame: Version={frameex.Version}, IsProgressive={frameex.IsProgressive}";
                Console.WriteLine(banner);
                Console.WriteLine();
            }
            break;

            case FrameType.TableHeader:
                // (Progressive mode only)
                // This frame appears once for each table, before the table's data
                // is reported.
            {
                var frameex = frame as ProgressiveDataSetDataTableSchemaFrame;
                var banner  = $"[{frameNum}] DataTable/SchemaFrame: TableId={frameex.TableId}, TableName={frameex.TableName}, TableKind={frameex.TableKind}";
                WriteSchema(banner, frameex.TableSchema);
            }
            break;

            case FrameType.TableFragment:
                // (Progressive mode only)
                // This frame provides one part of the table's data
            {
                var frameex = frame as ProgressiveDataSetDataTableFragmentFrame;
                var banner  = $"[{frameNum}] DataTable/FragmentFrame: TableId={frameex.TableId}, FieldCount={frameex.FieldCount}, FrameSubType={frameex.FrameSubType}";
                WriteProgressiveResults(banner, frameex);
            }
            break;

            case FrameType.TableCompletion:
                // (Progressive mode only)
                // This frame announces the completion of a table (no more data in it).
            {
                var frameex = frame as ProgressiveDataSetTableCompletionFrame;
                var banner  = $"[{frameNum}] DataTable/TableCompletionFrame: TableId={frameex.TableId}, RowCount={frameex.RowCount}";
                Console.WriteLine(banner);
                Console.WriteLine();
            }
            break;

            case FrameType.TableProgress:
                // (Progressive mode only)
                // This frame appears periodically to provide a progress estimateion.
            {
                var frameex = frame as ProgressiveDataSetTableProgressFrame;
                var banner  = $"[{frameNum}] DataTable/TableProgressFrame: TableId={frameex.TableId}, TableProgress={frameex.TableProgress}";
                Console.WriteLine(banner);
                Console.WriteLine();
            }
            break;

            case FrameType.DataTable:
            {
                // This frame represents one data table (in all, when progressive results
                // are not used or there's no need for multiple-frames-per-table).
                // There are usually multiple such tables in the response, differentiated
                // by purpose (TableKind).
                // Note that we can't skip processing the data -- we must consume it.

                var frameex = frame as ProgressiveDataSetDataTableFrame;
                var banner  = $"[{frameNum}] DataTable/DataTableFrame: TableId={frameex.TableId}, TableName={frameex.TableName}, TableKind={frameex.TableKind}";
                WriteResults(banner, frameex.TableData);
            }
            break;

            case FrameType.DataSetCompletion:
            {
                // This is the last frame in the data set.
                // It provides information on the overall success of the query:
                // Whether there were any errors, whether it got cancelled mid-stream,
                // and what exceptions were raised if either is true.
                var frameex = frame as ProgressiveDataSetCompletionFrame;
                var banner  = $"[{frameNum}] DataSet/CompletionFrame: HasErrors={frameex.HasErrors}, Cancelled={frameex.Cancelled}, Exception={ExtendedString.SafeToString(frameex.Exception)}";
                Console.WriteLine(banner);
                Console.WriteLine();
            }
            break;

            case FrameType.LastInvalid:
            default:
                // In general this should not happen
                break;
            }
        }
        static void Main(string[] args)
        {
            //Check Folders
            GridProteinFolding.WCF.ServiceDistributed.Service.CheckWorkFolders();

            //Run Hosts
            ServiceHost hostService           = new ServiceHost(typeof(Service));
            ServiceHost hostDocumentManagment = new ServiceHost(typeof(DocumentManagment));

            //ServiceHost hostGeneratingResults = new ServiceHost(typeof(GeneratingResults));


            try
            {
                #region hostService
                hostService.Open();
                ServiceDescription serviceDesciption = hostService.Description;

                foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                {
                    ConsoleColor oldColour = Console.ForegroundColor;
                    GICO.ForegroundColor(ConsoleColor.Red);
                    GICO.WriteLine(ExtendedString.Format("Endpoint - address:  {0}", endpoint.Address));
                    GICO.WriteLine(ExtendedString.Format("         - binding name:\t\t{0}", endpoint.Binding.Name));
                    GICO.WriteLine(ExtendedString.Format("         - contract name:\t\t{0}", endpoint.Contract.Name));
                    GICO.ForegroundColor(oldColour);
                }
                #endregion

                #region hostDocumentManagment
                hostDocumentManagment.Open();
                serviceDesciption = hostDocumentManagment.Description;

                foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                {
                    ConsoleColor oldColour = Console.ForegroundColor;
                    GICO.ForegroundColor(ConsoleColor.Red);
                    GICO.WriteLine(ExtendedString.Format("Endpoint - address:  {0}", endpoint.Address));
                    GICO.WriteLine(ExtendedString.Format("         - binding name:\t\t{0}", endpoint.Binding.Name));
                    GICO.WriteLine(ExtendedString.Format("         - contract name:\t\t{0}", endpoint.Contract.Name));
                    GICO.WriteLine();
                    GICO.ForegroundColor(oldColour);
                }
                #endregion


                //#region hostGeneratingResults
                //hostGeneratingResults.Open();
                //serviceDesciption = hostGeneratingResults.Description;

                //foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                //{
                //    ConsoleColor oldColour = Console.ForegroundColor;
                //    GICO.ForegroundColor(ConsoleColor.Red);
                //    GICO.WriteLine(String.Format("Endpoint - address:  {0}", endpoint.Address));
                //    GICO.WriteLine(String.Format("         - binding name:\t\t{0}", endpoint.Binding.Name));
                //    GICO.WriteLine(String.Format("         - contract name:\t\t{0}", endpoint.Contract.Name));
                //    GICO.WriteLine();
                //    GICO.ForegroundColor(oldColour);
                //}
                //#endregion
                GICO.WriteLine("Service Distributed: Service is up and running!");

                GICO.WriteLine();
                ConsoleKeyInfo key;

                Console.WriteLine("Press the Escape (Esc) key to quit: \n");
                do
                {
                    key = Console.ReadKey();
                } while (key.Key != ConsoleKey.Escape);
            }
            catch (Exception ex)
            {
                GICO.WriteLine(ex.Message.ToString());
                GICO.WriteLine(ex.InnerException.ToString());

                Console.ReadKey();
            }
            finally
            {
                if (hostService.State != CommunicationState.Closed && hostService.State != CommunicationState.Faulted)
                {
                    hostService.Close();
                }

                hostService = null;


                if (hostDocumentManagment.State != CommunicationState.Closed && hostDocumentManagment.State != CommunicationState.Faulted)
                {
                    hostDocumentManagment.Close();
                }

                hostDocumentManagment = null;
            }
        }