Example #1
0
        //check if abort message was send by client
        private bool isDisconnected(NetMessageHandler handler, string sessionId)
        {
            sendClientMessage(handler, StatusMessage.StatusEnum.OK);

            StatusMessage statusMess = handler.GetSynchMessage() as StatusMessage;

            if (((statusMess != null) && (statusMess.Status == StatusMessage.StatusEnum.Aborted)) || (!handler.Connected()))
            {
                try
                {
                    m_log.Info("Got abort message or connection was disconnected. ID: " + m_threadsID[sessionId].ToString());
                    //sending abort messeges to workers
                    for (int i = 0; i < m_renderAbortHandlers[m_threadsID[sessionId]].Count; ++i)
                    {
                        try
                        {
                            m_renderAbortHandlers[m_threadsID[sessionId]][i].AddMessage(new ToAbortRenderMessage());
                        }
                        catch (Exception e)
                        {
                            m_log.Warning("renderQueue was already deleted. Error: " + m_renderAbortHandlers[m_threadsID[sessionId]][i].ToString() + ". ID: " + m_threadsID[sessionId].ToString());
                            m_log.Warning(e.Message);
                        }
                    }
                    MessageQueue <MergerMessage> abortQueue    = new MessageQueue <MergerMessage>(m_threadsID[sessionId].ToString() + "abort");
                    AbortMergeMessage            mergerMessage = new AbortMergeMessage("uniqueBlob" + m_threadsID[sessionId].ToString() + '_' + sessionId.ToString(), m_threadsID[sessionId]);
                    abortQueue.AddMessage(mergerMessage);
                    m_renderAbortHandlers.Remove(m_threadsID[sessionId]);
                    m_log.Info("Aborted by user. ID: " + m_threadsID[sessionId].ToString());
                    return(true);
                }
                catch (Exception e)
                {
                    m_log.Error("Error for ID " + m_threadsID[sessionId] + " when checking connection status:" + e.Message);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        private void processConnection(TcpClient client)
        {
            m_connectionWaitHandle.Set();   //unblock listener thread

            string sessionID = Guid.NewGuid().ToString();

            m_log.Info("Thread GUID: " + sessionID);
            lock (m_IDLock)
            {
                m_threadsID.Add(sessionID, m_scenesId.GetNewSceneID());
            }
            MessageQueue <DispetcherMessage> dispatcherHandler = new MessageQueue <DispetcherMessage>(m_threadsID[sessionID].ToString(), true);

            m_log.Info("Start");

            //get scene info
            NetMessageHandler handler = new NetMessageHandler(client, 30);
            NetMessage        message = null;

            m_connectionHandlers.Add(sessionID, handler);

            while (true)
            {
                try
                {
                    message = handler.GetSynchMessage();

                    if (message == null)
                    {
                        continue;
                    }
                }
                catch (Exception)
                {
                    sendError(handler, "Can't read connection message");
                    return;
                }

                SceneMessage sceneMessage;
                bool         userAuthorized = false;

                //User authorization
                if (message is AuthorizationMessage)
                {
                    var loginMessage = message as AuthorizationMessage;

                    if (Utils.DataBaseUtils.CheckLoginCorrect(loginMessage.Login, loginMessage.Pwd) == false)
                    {
                        m_log.Info("Wrong password. ID: " + m_threadsID[sessionID].ToString());
                        sendAuthorizationResultMessage(false, handler);
                        return;
                    }
                    else
                    {
                        m_log.Info("User had been authorized. ID: " + m_threadsID[sessionID].ToString());
                        userAuthorized = true;
                        sendAuthorizationResultMessage(true, handler);
                    }
                }
                else if (message is SceneMessage)
                {
                    if (!userAuthorized)
                    {
                        m_log.Warning("User not authorized.");
                    }

                    sceneMessage = message as SceneMessage;

                    try
                    {
                        if (sceneMessage.RequiredSpp == 0 && sceneMessage.TotalTime < DocConstants.MINIMUM_RENDER_TIME)
                        {
                            m_log.Warning("Minimum render time is 60 sec");
                            sendError(handler, "Minimum render time is 60 sec");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.Error("Unexpected problem when checking password: "******". ID: " + m_threadsID[sessionID].ToString());
                        sendError(handler, "Error requesting database");
                        return;
                    }
                    //get scene file
                    byte[] sceneFile = null;
                    try
                    {
                        sceneFile = new byte[sceneMessage.SceneFileSize];
                        handler.GetFile(sceneFile);
                    }
                    catch (Exception ex)
                    {
                        m_log.Error("Error uploading scene" + ex.Message);
                        sendError(handler, "Error uploading scene");
                        return;
                    }

                    if (!m_instanceManager.Require(sceneMessage.InstanceCnt)) //gives new worker and merger
                    //instances if needed
                    {
                        sendError(handler, "Error while allocating instances. Try again later");
                        return;
                    }
                    try
                    {
                        sendClientMessage(handler, StatusMessage.StatusEnum.OK);
                    }
                    catch (Exception e)
                    {
                        m_log.Error("Error sending sync message" + e.Message);
                    }
                    try
                    {
                        m_log.Info("ProcessingScene. ID: " + m_threadsID[sessionID].ToString());
                        processingScene(handler, sceneMessage, sceneFile, sessionID, dispatcherHandler);
                        m_log.Info("/ProcessingScene. ID: " + m_threadsID[sessionID].ToString());
                        m_log.Info("WaitingProcess. ID: " + m_threadsID[sessionID].ToString());
                        waitingProcess(handler, sessionID, sceneMessage, dispatcherHandler);
                        m_log.Info("/WaitingProcess. ID: " + m_threadsID[sessionID].ToString());
                    }
                    catch (Exception ex)
                    {
                        isDisconnected(handler, sessionID);
                        sendError(handler, ex.Message);
                        m_log.Error("Processing error: " + ex.Message + ". ID: " + m_threadsID[sessionID].ToString());
                    }
                    m_log.Info("Workers had finished. ID: " + m_threadsID[sessionID].ToString());
                    //free resources
                    try
                    {
                        m_threadsID.Remove(sessionID);
                        m_instanceManager.FreeResources(sceneMessage.InstanceCnt);
                    }
                    catch (Exception e)
                    {
                        m_log.Error("Error when freeing resources" + e.Message);
                    }
                    m_log.Info("resources was freed. ");
                    m_log.Info("sceneMessage.InstanceCount : " + sceneMessage.InstanceCnt);
                    m_log.Info("Finish");
                    return;
                }
                else
                {
                    m_log.Info("message type: " + message.ToString());
                    m_log.Warning("SceneInfo: Incorrect or damaged scene file.");
                    sendError(handler, Resources.MEESAGE_INCORRECT_SCENE);
                    return;
                }
            }
        }