Пример #1
0
        /// <summary>
        /// Emits the node/edge/internal class object attribute initialization code in graph exporting
        /// for an attribute of internal class object type with the given value into the stream writer.
        /// </summary>
        private static void EmitAttributeInitialization(MainGraphExportContext mainGraphContext, IAttributeBearer owner,
                                                        AttributeType attrType, object value, INamedGraph graph, StreamWriter sw)
        {
            if (owner is IGraphElement)
            {
                String persistentName = graph.GetElementName((IGraphElement)owner);
                sw.Write("@(\"{0}\").{1} = ", persistentName, attrType.Name);
            }
            else
            {
                String persistentName = mainGraphContext.GetOrAssignPersistentName((IObject)owner);
                sw.Write("@@(\"{0}\").{1} = ", persistentName, attrType.Name);
            }

            StringBuilder deferredInits = new StringBuilder();

            if (value == null)
            {
                sw.Write("null");
            }
            else if (value is IObject)
            {
                IObject obj = (IObject)value;
                EmitObjectFetchingOrCreation(mainGraphContext, obj.Type, obj, graph, sw, deferredInits);
            }
            else // container
            {
                EmitAttribute(mainGraphContext, attrType, value, graph, sw, deferredInits);
            }
            sw.WriteLine();
            sw.Write(deferredInits);
        }
Пример #2
0
 void EmitObjectAttributeAssignmentCreatingAsNeeded(IObject owner, AttributeType attrType,
                                                    MainGraphExportContext mainExportContext, RecordingState recordingState)
 {
     if (!mainExportContext.HasPersistentName(owner))
     {
         StringBuilder deferredInits = new StringBuilder();
         GRSExport.EmitObjectCreation(mainExportContext, owner.Type, owner, graph, recordingState.writer, deferredInits);
         recordingState.writer.WriteLine();
         recordingState.writer.Write(deferredInits.ToString());
     }
     recordingState.writer.Write("@@(\"" + mainExportContext.GetOrAssignPersistentName((IObject)owner) + "\")." + attrType.Name + " = ");
 }
Пример #3
0
 private static void EmitObjectFetchingOrCreation(MainGraphExportContext mainGraphContext,
                                                  ObjectType objType, IObject obj, INamedGraph graph, StreamWriter sw, StringBuilder deferredInits)
 {
     if (mainGraphContext.HasPersistentName(obj))
     {
         sw.Write("@@(\"{0}\")", mainGraphContext.GetOrAssignPersistentName(obj));
     }
     else
     {
         EmitObjectCreation(mainGraphContext, objType, obj, graph, sw, deferredInits);
     }
 }
Пример #4
0
        public static void EmitObjectCreation(MainGraphExportContext mainGraphContext,
                                              ObjectType objType, IObject obj, INamedGraph graph, StreamWriter sw, StringBuilder deferredInits)
        {
            sw.Write("new {0}@(% = \"{1}\"", objType.PackagePrefixedName, mainGraphContext.GetOrAssignPersistentName(obj));
            foreach (AttributeType attrType in objType.AttributeTypes)
            {
                if (IsInternalClassObjectUsedInAttribute(attrType))
                {
                    continue;
                }

                sw.Write(", {0} = ", attrType.Name);
                EmitAttribute(mainGraphContext, attrType, obj.GetAttribute(attrType.Name), graph, sw, deferredInits);
            }
            sw.Write(")");
            ++mainGraphContext.numInternalClassObjects;

            foreach (AttributeType attrType in objType.AttributeTypes)
            {
                if (!IsInternalClassObjectUsedInAttribute(attrType))
                {
                    continue;
                }

                object       value      = obj.GetAttribute(attrType.Name);
                MemoryStream memStream  = new MemoryStream();
                StreamWriter deferredSw = new StreamWriter(memStream);
                EmitAttributeInitialization(mainGraphContext, obj, attrType, value, graph, deferredSw);
                deferredSw.Flush();
                memStream.Seek(0, SeekOrigin.Begin);
                byte[] buffer   = new byte[memStream.Length];
                int    read     = memStream.Read(buffer, 0, (int)memStream.Length);
                String deferred = System.Text.Encoding.UTF8.GetString(buffer);
                deferredInits.Append(deferred);
            }
        }