Exemplo n.º 1
0
        /// <summary>Convert brep to specified format.</summary>
        /// <param name="content">Brep to convert (base64 encoded string).</param>
        /// <param name="sourceFormat">Source format of brep.</param>
        /// <param name="targetFormat">Target format of brep</param>
        /// <returns>Converted brep (base64 encoded string).</returns>
        /// <exception cref="Exceptions.ConnectionFailureException">Throws if network connection is down.</exception>
        /// <exception cref="Exceptions.UnathorizedException">Throws if provided cookies were obsolete.</exception>
        /// <exception cref="Exceptions.ServerUnavailableException">Throws if Flux server is down.</exception>
        /// <exception cref="Exceptions.InternalSDKException">Throws for unhandled SDK exceptions.</exception>
        public string ConvertBrep(string content, string sourceFormat, string targetFormat)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            #region Create object wrapper for brep

            var brep = new BrepToConvert.SceneObject.BrepPrimitive();
            brep.Primitive = "brep";
            brep.Format    = sourceFormat;
            brep.Content   = content;

            var entities = new BrepToConvert.SceneObject.EntitiesObject();
            entities.Brep = brep;

            BrepToConvert.SceneObject scene = new BrepToConvert.SceneObject();
            scene.Entities = entities;
            var initObj = new BrepToConvert.SceneObject.OperationObj();
            initObj.Name = "result";
            initObj.Op   = new string[] { "repr", targetFormat, "brep@1" };

            scene.Operations = new object[] { initObj };

            var brepToConvert = new BrepToConvert();
            brepToConvert.Scene = scene;

            #endregion

            var request = WriteBrepToRequest(brepToConvert);

            try
            {
                using (var response = HttpWebClientHelper.GetResponse(request))
                {
                    dynamic responseJson     = DataSerializer.DynamicDeserialize(StreamUtils.GetDecompressedResponseStream(response));
                    dynamic convertedContent = responseJson.Output.Results.value.result.content;
                    if (convertedContent != null)
                    {
                        object contentStr = convertedContent;
                        return(contentStr.ToString());
                    }
                }
            }
            catch (Exceptions.FluxException ex)
            {
                log.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw new Exceptions.InternalSDKException(ex.Message);
            }

            return(null);
        }
Exemplo n.º 2
0
        private void WebSocket_OnMessage(object sender, WebSocketSharp.MessageEventArgs e)
        {
            //connection alive -> restart timer
            if (webSocketState != FluxWebSocketStates.Reconnecting)
            {
                RestartConnectionTimer();
            }

            try
            {
                //ToDo: fix
                dynamic msgObj = DataSerializer.DynamicDeserialize(e.Data);

                //playing ping-pong with server
                if (msgObj.type == "PING")
                {
                    Send("{ \"type\": \"PONG\" }");
                    return;
                }

                if (msgObj.type == "DATATABLE")
                {
                    if (msgObj.body.Type == "NOTIFICATION")
                    {
                        if (OnNotificationMessage != null)
                        {
                            var notificationStr = msgObj.body.Data.ToString();
                            OnNotificationMessage(DataSerializer.Deserialize <Notification>(notificationStr));
                        }
                    }
                    else if (msgObj.body.Type == "ERROR")
                    {
                        if (OnErrorMessage != null)
                        {
                            dynamic errMsg      = msgObj.body.Data;
                            var     errorMsgStr = errMsg.ToString();
                            OnErrorMessage(new Error(errorMsgStr));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }