Ejemplo n.º 1
0
        /// <summary>
        /// Builds the frame from JSON text
        /// </summary>
        /// <param name="textFrame">The text of JSON frame.</param>
        /// <returns></returns>
        public IFrame BuildFrame(String textFrame)
        {
            metadata = JObject.Parse(textFrame);
            StmLevel frameLevel = StmLevel.STM1;

            if (metadata["Level"] != null)
            {
                frameLevel = FrameBuilder.getStmLevel(metadata["Level"]);
            }
            Frame returnFrame = new Frame(frameLevel);

            if (metadata["Msoh"].HasValues)
            {
                returnFrame.Msoh = (Header)FrameBuilder.EvaluateContent((JObject)metadata["Msoh"]);
            }
            if (metadata["Rsoh"].HasValues)
            {
                returnFrame.Rsoh = (Header)FrameBuilder.EvaluateContent((JObject)metadata["Rsoh"]);
            }
            if (FrameBuilder.isJArray(metadata["Content"]))
            {
                returnFrame.Content = FrameBuilder.evaluateContents((JArray)metadata["Content"]);
            }
            else
            {
                return(null);
            }
            return(returnFrame);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Evaluates the content. Read JSON object create IContent
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 private static IContent EvaluateContent(JObject content)
 {
     try
     {
         if (FrameBuilder.isVirtualContainer(content["Type"])) //VirtualContainer
         {
             //Create new VC with level from JSON file
             VirtualContainer newVC = new VirtualContainer(FrameBuilder.getVCLevel(content["Level"]));
             newVC.Pointer = content["Pointer"].ToString();
             newVC.POH     = (POH)FrameBuilder.EvaluateContent((JObject)content["POH"]);
             if (FrameBuilder.isJArray(content["Content"]))
             {
                 newVC.Content = FrameBuilder.evaluateContents((JArray)content["Content"]);
             }
             else //There is no value Content of VC is null
             {
                 newVC.Content = null;
             }
             return(newVC);
         }
         else if (FrameBuilder.isContainer(content["Type"]))
         {
             Container newContainer = new Container(content["Content"].ToString());
             return(newContainer);
         }
         else if (FrameBuilder.isHeader(content["Type"]))
         {
             string checksum  = content["Checksum"].ToString();
             string eow       = content["EOW"].ToString();
             string dcc       = content["DCC"].ToString();
             Header newHeader = new Header(checksum, eow, dcc);
             return(newHeader);
         }
         else if (FrameBuilder.isPOH(content["Type"]))
         {
             SignalLabelType signalType = FrameBuilder.getSignalType(content["SignalLabel"]);
             POH             poh        = new POH(signalType);
             return(poh);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
 }