示例#1
0
        void ITextElement.Process(DocxNode node)
        {
            if (IsHidden(node))
            {
                return;
            }

            string contentType;
            string progId;
            string data = node.ExtractAttributeValue("data");

            if (IsImage(data))
            {
                var interchanger = context.GetInterchanger();
                interchanger.ProcessImage(context, data, node);
            }
            else if (TryFormat(data, out contentType, out progId))
            {
                EmbeddedObject embeddedObject = ProcessObject(data, contentType, progId);

                if (embeddedObject != null)
                {
                    Run run = node.Parent.AppendChild(new Run(embeddedObject));
                    RunCreated(node, run);
                }
            }
        }
示例#2
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (IsHidden(node))
            {
                return;
            }

            string contentType;
            string progId;
            string data = node.ExtractAttributeValue("data");

            if (IsImage(data))
            {
                var interchanger = context.GetInterchanger();
                interchanger.ProcessImage(context, data, node, ref paragraph);
            }
            else if (TryFormat(data, out contentType, out progId))
            {
                EmbeddedObject embeddedObject = ProcessObject(data, contentType, progId);

                if (embeddedObject != null)
                {
                    if (paragraph == null)
                    {
                        paragraph = node.Parent.AppendChild(new Paragraph());
                        OnParagraphCreated(node, paragraph);
                    }

                    Run run = paragraph.AppendChild(new Run(embeddedObject));
                    RunCreated(node, run);
                }
            }
        }
    /// <summary>
    /// Gets Paragraph that includes the embedded object
    /// </summary>
    private static Paragraph GetEmbeededObjectParagraph(string fileType, string imageID, string imageStyle, string embeddedPackageID)
    {
        EmbeddedObject embeddedObject = new EmbeddedObject();
        string         shapeID        = GetUniqueXmlItemID();

        V.Shape shape = new V.Shape()
        {
            Id = shapeID, Style = imageStyle
        };
        V.ImageData imageData = new V.ImageData()
        {
            Title = "", RelationshipId = imageID
        };
        shape.Append(imageData);
        OVML.OleObject oleObject = new OVML.OleObject()
        {
            Type       = OVML.OleValues.Embed,
            ProgId     = fileType,
            ShapeId    = shapeID,
            DrawAspect = OVML.OleDrawAspectValues.Icon,
            ObjectId   = GetUniqueXmlItemID(),
            Id         = embeddedPackageID
        };
        embeddedObject.Append(shape);
        embeddedObject.Append(oleObject);
        Paragraph paragraphImage = new Paragraph();
        Run       runImage       = new Run(embeddedObject);

        paragraphImage.Append(runImage);
        return(paragraphImage);
    }
示例#4
0
    public static void RemoveEmbeddedObjectProcess(EmbeddedObject embeddedObject)
    {
        //disconnect
        embeddedObject.Remove();
        try
        {
            if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "SampleScene")
            {
                GameObject.FindObjectOfType <BodyPartSelectorManager>().ResetSelectors();
                GameObject.FindObjectOfType <EmbeddedObjectSelectorManager>().ResetSelectors();
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError($"RemoveEmbeddedObjectProcess: {e}");
        }

        UpdateAllBodyPartHeartConnections();

        //remove from being child of bodypart
        if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "SampleScene")
        {
            embeddedObject.transform.SetParent(MonoBehaviour.FindObjectOfType <EmbeddedObjectSelectorManager>().transform);
        }

        MonoBehaviour.FindObjectOfType <ActionTracker>().surgery_remove_implants += 1;
    }
示例#5
0
        public bool itIsPic(Paragraph p)
        {
            IEnumerable <Run> runlist = p.Elements <Run>();

            foreach (Run r in runlist)
            {
                if (r != null)
                {
                    Drawing          d       = r.GetFirstChild <Drawing>();
                    Picture          pic     = r.GetFirstChild <Picture>();
                    EmbeddedObject   objects = r.GetFirstChild <EmbeddedObject>();
                    AlternateContent Alt     = r.GetFirstChild <AlternateContent>();
                    if (d != null || pic != null || objects != null)
                    {
                        return(true);
                    }
                    else if (Alt != null)
                    {
                        AlternateContentChoice   AltChoice   = Alt.GetFirstChild <AlternateContentChoice>();
                        AlternateContentFallback AltFallback = Alt.GetFirstChild <AlternateContentFallback>();
                        if (AltChoice != null && AltFallback != null)
                        {
                            if ((AltChoice.GetFirstChild <Drawing>() != null || AltFallback.GetFirstChild <Picture>() != null))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
 private Schema CreateEmbeddedObjectSchema(EmbeddedObject embeddedObject, OpenApiMetadataResource openApiMetadataResource)
 {
     return(new Schema
     {
         @ref = OpenApiMetadataDocumentHelper.GetDefinitionReference(
             _openApiMetadataDefinitionsFactoryNamingStrategy.GetEmbeddedObjectReferenceName(openApiMetadataResource, embeddedObject))
     });
 }
 private void NewSelector(EmbeddedObject embeddedObject, GameObject selectorPrefab, GameObject notPartOfMainPanel)
 {
     if (!(embeddedObject.parentBodyPart is null))
     {
         GameObject selector = GameObject.Instantiate(selectorPrefab, embeddedObjectSelectorsPanel.transform);
         embeddedObjectSelectors.Add(selector.GetComponent <EmbeddedObjectSelector>());
         selector.GetComponent <EmbeddedObjectSelector>().embeddedObject = embeddedObject;
     }
        private EmbeddedObject CreateEmbeddedObjectOrFunction(object obj)
        {
            var            del            = obj as Delegate;
            EmbeddedObject embeddedObject = del != null?
                                            CreateEmbeddedFunction(del) : CreateEmbeddedObject(obj);

            return(embeddedObject);
        }
示例#9
0
 private Schema CreateEmbeddedObjectSchema(EmbeddedObject embeddedObject, SwaggerResource swaggerResource)
 {
     return(new Schema
     {
         @ref = SwaggerDocumentHelper.GetDefinitionReference(
             _swaggerDefinitionsFactoryNamingStrategy.GetEmbeddedObjectReferenceName(swaggerResource, embeddedObject))
     });
 }
 public string GetEmbeddedObjectReferenceName(
     SwaggerResource swaggerResource,
     EmbeddedObject embeddedObject)
 {
     return(CreateCompositeChildModelTypeName(
                swaggerResource.Resource.Name,
                embeddedObject.ObjectType.Name,
                embeddedObject.Parent));
 }
示例#11
0
 public EmbeddedObjectHost(EmbeddedObject embeddedObject, int charIndex,
                           Control parentControl, Style paragraphStyle, Style inlineStyle)
 {
     this.embeddedObject = embeddedObject;
     this.charIndex      = charIndex;
     this.parentControl  = parentControl;
     this.paragraphStyle = paragraphStyle;
     this.inlineStyle    = inlineStyle;
 }
 public EmbeddedObjectHost(EmbeddedObject embeddedObject, int charIndex,
     Control parentControl, Style paragraphStyle, Style inlineStyle)
 {
     this.embeddedObject = embeddedObject;
     this.charIndex = charIndex;
     this.parentControl = parentControl;
     this.paragraphStyle = paragraphStyle;
     this.inlineStyle = inlineStyle;
 }
        private EmbeddedObject CreateEmbeddedFunction(Delegate del)
        {
            JsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) =>
            {
#if NET40
                MethodInfo method = del.Method;
#else
                MethodInfo method = del.GetMethodInfo();
#endif
                ParameterInfo[] parameters    = method.GetParameters();
                object[]        processedArgs = GetHostItemMemberArguments(args, parameters.Length);

                ReflectionHelpers.FixArgumentTypes(ref processedArgs, parameters);

                object result;

                try
                {
                    result = del.DynamicInvoke(processedArgs);
                }
                catch (Exception e)
                {
                    JsValue   undefinedValue   = JsValue.Undefined;
                    Exception exception        = UnwrapException(e);
                    var       wrapperException = exception as WrapperException;
                    JsValue   errorValue       = wrapperException != null?
                                                 CreateErrorFromWrapperException(wrapperException)
                                                     :
                                                     JsErrorHelpers.CreateError(string.Format(
                                                                                    Strings.Runtime_HostDelegateInvocationFailed, exception.Message))
                    ;

                    JsContext.SetException(errorValue);

                    return(undefinedValue);
                }

                JsValue resultValue = MapToScriptType(result);

                return(resultValue);
            };

            GCHandle delHandle = GCHandle.Alloc(del);
            IntPtr   delPtr    = GCHandle.ToIntPtr(delHandle);
            JsValue  objValue  = JsValue.CreateExternalObject(delPtr, _embeddedObjectFinalizeCallback);

            JsValue functionValue = JsValue.CreateFunction(nativeFunction);

            SetNonEnumerableProperty(functionValue, ExternalObjectPropertyName, objValue);

            var embeddedObject = new EmbeddedObject(del, functionValue,
                                                    new List <JsNativeFunction> {
                nativeFunction
            });

            return(embeddedObject);
        }
示例#14
0
 public string GetEmbeddedObjectReferenceName(
     OpenApiMetadataResource openApiMetadataResource,
     EmbeddedObject embeddedObject)
 {
     return(CreateCompositeChildModelTypeName(
                openApiMetadataResource.Resource.Name,
                embeddedObject.ObjectType.Name,
                embeddedObject.Parent));
 }
示例#15
0
            protected override void Arrange()
            {
                var domainModel = DomainModelDefinitionsProviderHelper.DomainModelProvider.GetDomainModel();

                var resource = domainModel.ResourceModel.GetAllResources()
                               .First(r => r.Name.Equals("Assessment"));

                var embeddedObject = resource.EmbeddedObjects.First(e => e.PropertyName.Equals("AssessmentContentStandard"));

                _embeddedObject = embeddedObject;
            }
示例#16
0
        /// <summary>
        /// Add embedded object
        /// </summary>
        /// <param name="embeddedObject"></param>
        /// <returns></returns>
        private string AddEmbeddedObject(EmbeddedObject embeddedObject)
        {
            foreach (OpenXmlElement element in embeddedObject.Elements())
            {
                if (element is DocumentFormat.OpenXml.Vml.Shape)
                {
                    return(DrawShape((DocumentFormat.OpenXml.Vml.Shape)element));
                }
            }

            return("");
        }
    public void NewEmbeddedObject(EmbeddedObject embeddedObject)
    {
        if (embeddedObject is Bullet)
        {
            NewSelector(embeddedObject, bulletSelectorPrefab, externalEmbeddedObjectSelectorsPanel);
        }

        if (embeddedObject is Bomb)
        {
            NewSelector(embeddedObject, bombSelectorPrefab, externalEmbeddedObjectSelectorsPanel);
        }
    }
示例#18
0
    private bool ImplantBomb()
    {
        BodyPart limb = RandomLimb();

        Debug.Log($"Bomb implanted in {limb.name}");
        textLog.NewLogEntry($"There's an explosive device in the {limb.name}");

        EmbeddedObject newBomb = FindObjectOfType <ObjectSpawner>().SpawnBomb("bomb");

        newBomb.Embed(limb);

        return(true);
    }
示例#19
0
        private EmbeddedObject ProcessObject(string filePath, string contentType, string progId)
        {
            if (TryCreateAbsoluteUri(filePath, out Uri uri))
            {
                int    width, height;
                string relationshipId = string.Concat("rId", (++context.RelationshipId).ToString());

                EmbeddedPackagePart embeddedPackagePart = context.MainDocumentPart.AddNewPart <EmbeddedPackagePart>(contentType,
                                                                                                                    relationshipId);

                using (Stream stream = GetStream(uri))
                {
                    embeddedPackagePart.FeedData(stream);
                }

                ImagePart imagePart = context.MainDocumentPart.AddImagePart(ImagePartType.Jpeg);

                using (MemoryStream mem = GetImageStream(Path.GetFileName(filePath), out width, out height))
                {
                    imagePart.FeedData(mem);
                }

                V.Shape shape = new V.Shape()
                {
                    Id = string.Concat("_x0000_i", context.RelationshipId.ToString()), Ole = false, Type = "#_x0000_t75", Style = "width:" + width.ToString() + "pt;height:" + height.ToString() + "pt"
                };
                V.ImageData imageData = new V.ImageData()
                {
                    Title = "", RelationshipId = context.MainDocumentPart.GetIdOfPart(imagePart)
                };

                shape.Append(imageData);

                EmbeddedObject embeddedObject = new EmbeddedObject()
                {
                    DxaOriginal = "9360", DyaOriginal = "450"
                };
                embeddedObject.Append(shape);

                OVML.OleObject oleObject = new OVML.OleObject()
                {
                    Type = OVML.OleValues.Embed, ProgId = progId, ShapeId = string.Concat("_x0000_i", context.RelationshipId.ToString()), DrawAspect = OVML.OleDrawAspectValues.Content, ObjectId = string.Concat("_", context.RelationshipId.ToString()), Id = relationshipId
                };

                embeddedObject.Append(oleObject);

                return(embeddedObject);
            }

            return(null);
        }
示例#20
0
        public string GetEmbeddedObjectReferenceName(
            OpenApiMetadataResource openApiMetadataResource,
            EmbeddedObject embeddedObject)
        {
            var schemaPrefix = embeddedObject
                               .ObjectType
                               .Entity
                               .DomainModel
                               .SchemaNameMapProvider
                               .GetSchemaMapByPhysicalName(embeddedObject.ObjectType.Entity.Schema)
                               .ProperCaseName;

            return(OpenApiMetadataDocumentHelper.CamelCaseSegments($"{schemaPrefix}_{embeddedObject.ObjectType.Name}"));
        }
示例#21
0
        //判断是否是图 参数picloc为图在第几段,所有可能的图都加进来了
        protected bool isPic(int picloc, Body body)
        {
            bool flag = false;

            if (matchPicName(picloc, body))
            {
                flag = true;
            }
            Paragraph p = null;

            if (body.ChildElements.GetItem(picloc).GetType().ToString() == "DocumentFormat.OpenXml.Wordprocessing.Paragraph")
            {
                p = (Paragraph)body.ChildElements.GetItem(picloc);
            }
            if (p != null)
            {
                IEnumerable <Run> runlist = p.Elements <Run>();
                foreach (Run r in runlist)
                {
                    if (r != null)
                    {
                        Drawing          d       = r.GetFirstChild <Drawing>();
                        Picture          pic     = r.GetFirstChild <Picture>();
                        EmbeddedObject   objects = r.GetFirstChild <EmbeddedObject>();
                        AlternateContent Alt     = r.GetFirstChild <AlternateContent>();
                        if (((d != null || pic != null)) || (flag == true && objects != null))
                        {
                            if (p.InnerText.Trim().Length < 65)
                            {
                                return(true);
                            }
                        }
                        else if (Alt != null)
                        {
                            AlternateContentChoice   AltChoice   = Alt.GetFirstChild <AlternateContentChoice>();
                            AlternateContentFallback AltFallback = Alt.GetFirstChild <AlternateContentFallback>();
                            if (AltChoice != null && AltFallback != null)
                            {
                                if (flag == true && (AltChoice.GetFirstChild <Drawing>() != null || AltFallback.GetFirstChild <Picture>() != null))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
        private EmbeddedObject CreateEmbeddedObject(object obj)
        {
            GCHandle objHandle = GCHandle.Alloc(obj);
            IntPtr   objPtr    = GCHandle.ToIntPtr(objHandle);
            JsValue  objValue  = JsValue.CreateExternalObject(objPtr, _embeddedObjectFinalizeCallback);

            var embeddedObject = new EmbeddedObject(obj, objValue);

            ProjectFields(embeddedObject);
            ProjectProperties(embeddedObject);
            ProjectMethods(embeddedObject);
            FreezeObject(objValue);

            return(embeddedObject);
        }
示例#23
0
    private bool ShouldBeHighlighted(EmbeddedObject embeddedObject)
    {
        if (buttonActions.selectedGameObject == null)
        {
            return(false);
        }

        //if embedded object is selected
        if (embeddedObject.gameObject == buttonActions.selectedGameObject)
        {
            return(true);
        }

        return(false);
    }
示例#24
0
    public static void EmbedObject(EmbeddedObject embeddedObject, BodyPart bodypart, float seconds, int goldCost, float bloodLossRateInduced, float damageInduced)
    {
        if (!(embeddedObject.parentBodyPart is null))
        {
            Debug.Log("That object is already inside something! Don't do that!");
            return;
        }

        if (!embeddedObject.EmbedValidity(bodypart))
        {
            Debug.Log("That is not a valid bodypart to implant that object into!");
            return;
        }

        StaticCoroutine.Start(EmbedObjectCoroutine(embeddedObject, bodypart, seconds, goldCost, bloodLossRateInduced, damageInduced));
    }
示例#25
0
        private List <CompositePropertyProjection> GetPropertyProjectionsForNonAggregateRoot(
            CompositeDefinitionProcessorContext processorContext,
            EmbeddedObject currentMember,
            IEnumerable <XElement> propertyElements,
            string containingElementName)
        {
            var selectedElements      = CompositeDefinitionHelper.CreateSelectedElements(propertyElements);
            var validPropertiesByName = CompositeDefinitionHelper.ValidPropertiesByName(processorContext, currentMember.ObjectType.PropertyByName);
            var validProperties       = CompositeDefinitionHelper.GetValidProperties(selectedElements, validPropertiesByName);

            ValidateSelectedElements(selectedElements, validProperties, containingElementName, processorContext.ShouldIncludeResourceSubtype());

            return(validProperties
                   .Select(pn => new CompositePropertyProjection(currentMember.ObjectType.AllPropertyByName[pn.Name], pn.DisplayName))
                   .ToList());
        }
示例#26
0
            protected override void Arrange()
            {
                AssemblyLoader.EnsureLoaded <Marker_EdFi_Ods_Composites_Test>();

                var compositeMetadataProvider = new CompositesMetadataProvider();

                var resourceModel =
                    DomainModelDefinitionsProviderHelper.DomainModelProvider.GetDomainModel()
                    .ResourceModel;

                var definitionProcessor =
                    new CompositeDefinitionProcessor
                    <CompositeResourceModelBuilderContext, global::EdFi.Ods.Common.Models.Resource.Resource>(
                        new CompositeResourceModelBuilder());

                // It is possible to add validation on composite names within the MetadataController logic if it's needed.
                // Get all the category names
                var categoryNames =
                    compositeMetadataProvider.GetAllCategories()
                    .First(c => c.Name.Equals("test") && c.DisplayName.Equals("Test"));

                IReadOnlyList <XElement> compositeDefinitions;

                compositeMetadataProvider.TryGetCompositeDefinitions(categoryNames.OrganizationCode, categoryNames.Name, out compositeDefinitions);

                var compositeResources = new List <global::EdFi.Ods.Common.Models.Resource.Resource>();

                foreach (var compositeDefinition in compositeDefinitions)
                {
                    // Enable this for composite xml validation.
                    definitionProcessor.UseCompositeValidation();

                    var compositeResource = definitionProcessor.Process(
                        compositeDefinition,
                        resourceModel,
                        new CompositeResourceModelBuilderContext());

                    compositeResources.Add(compositeResource);
                }

                var compositesResource = compositeResources.First(c => c.Name.Equals("BaseAssessmentUnflattenedEmbeddedObject"));

                _embeddedObject = compositesResource.EmbeddedObjects.First(e => e.PropertyName.Equals("AssessmentContentStandard"));
            }
示例#27
0
        public void PptxObject()
        {
            using MemoryStream mem = new MemoryStream();
            WordDocument doc  = new WordDocument(mem);
            string       path = TestUtility.GetPath("/Html");

            doc.BaseURL = path;
            doc.Process(new HtmlParser(TestUtility.GetHtmlFromFile("/Html/pptxobjecttag.htm")));

            Assert.IsNotNull(doc.Document.Body);
            Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);

            Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph;

            Assert.IsNotNull(paragraph);

            Run run = paragraph.ChildElements[0] as Run;

            Assert.IsNotNull(run);
            Assert.AreEqual(1, run.ChildElements.Count);

            EmbeddedObject embeddedObject = run.ChildElements[0] as EmbeddedObject;

            Assert.IsNotNull(embeddedObject);
            Assert.AreEqual(2, embeddedObject.ChildElements.Count);

            V.Shape shape = embeddedObject.ChildElements[0] as V.Shape;
            Assert.IsNotNull(shape);

            OVML.OleObject oleObject = embeddedObject.ChildElements[1] as OVML.OleObject;
            Assert.IsNotNull(oleObject);

            Assert.AreEqual(OVML.OleValues.Embed, oleObject.Type.Value);
            Assert.AreEqual("PowerPoint.Show.12", oleObject.ProgId.Value);

            OpenXmlValidator validator = new OpenXmlValidator();
            var errors = validator.Validate(doc.WordprocessingDocument);

            errors.PrintValidationErrors();
            Assert.AreEqual(0, errors.Count());
        }
示例#28
0
    private bool ShootOrgan()
    {
        Organ organ = RandomOrgan();

        Debug.Log($"Shot {organ.name}");
        textLog.NewLogEntry($"The {organ.name} has been shot.");

        organ.damage         = Mathf.Min(organ.damage + 30, organ.damageMax);
        organ.bloodLossRate += 10;

        if (organ.connectedBodyParts.Count > 0)
        {
            BodyPart parentBodyPart = organ.connectedBodyParts[0];
            parentBodyPart.damage         = Mathf.Min(parentBodyPart.damage + 30, parentBodyPart.damageMax);
            parentBodyPart.bloodLossRate += 10;

            EmbeddedObject newBullet = FindObjectOfType <ObjectSpawner>().SpawnBullet("bullet");
            newBullet.Embed(organ);
        }

        return(true);
    }
示例#29
0
    public static void EmbedObjectProcess(EmbeddedObject embeddedObject, BodyPart bodypart)
    {
        //connect
        embeddedObject.Embed(bodypart);
        try
        {
            if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "SampleScene")
            {
                GameObject.FindObjectOfType <BodyPartSelectorManager>().ResetSelectors();
                GameObject.FindObjectOfType <EmbeddedObjectSelectorManager>().ResetSelectors();
                MonoBehaviour.FindObjectOfType <BodyPartStatusManager>().UpdateStatusCollection();
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError($"EmbedObjectProcess: {e}");
        }

        UpdateAllBodyPartHeartConnections();

        MonoBehaviour.FindObjectOfType <ActionTracker>().surgery_implants += 1;
    }
示例#30
0
    private bool ShootLimb()
    {
        BodyPart limb = RandomLimb();

        Debug.Log($"Shot {limb.name}");
        textLog.NewLogEntry($"The {limb.name} has been shot.");

        limb.damage         = Mathf.Min(limb.damage + 30, limb.damageMax);
        limb.bloodLossRate += 10;

        if (limb is Organ && limb.connectedBodyParts.Count > 0)
        {
            BodyPart parentBodyPart = limb.connectedBodyParts[0];
            parentBodyPart.damage         = Mathf.Min(parentBodyPart.damage + 30, parentBodyPart.damageMax);
            parentBodyPart.bloodLossRate += 10;
        }

        EmbeddedObject newBullet = FindObjectOfType <ObjectSpawner>().SpawnBullet("bullet");

        newBullet.Embed(limb);

        return(true);
    }
        /// <summary>
        /// Creates a JavaScript value from an host object if the it does not already exist
        /// </summary>
        /// <param name="obj">Instance of host type</param>
        /// <returns>JavaScript value created from an host object</returns>
        public JsValue GetOrCreateScriptObject(object obj)
        {
            if (!_embeddedObjectStorageInitialized)
            {
                lock (_embeddedObjectStorageInitializationSynchronizer)
                {
                    if (!_embeddedObjectStorageInitialized)
                    {
                        _lazyEmbeddedObjects            = new ConcurrentDictionary <EmbeddedObjectKey, Lazy <EmbeddedObject> >();
                        _embeddedObjectFinalizeCallback = EmbeddedObjectFinalizeCallback;

                        _embeddedObjectStorageInitialized = true;
                    }
                }
            }

            var            embeddedObjectKey = new EmbeddedObjectKey(obj);
            EmbeddedObject embeddedObject    = _lazyEmbeddedObjects.GetOrAdd(
                embeddedObjectKey,
                key => new Lazy <EmbeddedObject>(() => CreateEmbeddedObjectOrFunction(obj))
                ).Value;

            return(embeddedObject.ScriptValue);
        }
        /// <summary>
        /// Generates the run to embed in the document so that objects can be viewed inline.
        /// </summary>
        /// <param name="imagePartId">ID of the image icon from GetIdOfPart.</param>
        /// <param name="objectPartId">ID of the object association from GetIdOfPart.</param>
        /// <param name="extension">File extension</param>
        /// <returns>A run linking all items.</returns>
        private Run GetObjectRun(string imagePartId, string objectPartId, string extension)
        {
            String shapePrefix = "_x0000_i";
            int shapeId = this.shapeId++;
            int objectId = this.objectId++;
            EmbeddedObject embeddedObject = new EmbeddedObject()
            {
                DxaOriginal = "1531",
                DyaOriginal = "990"
            };
            //EmbeddedObjectInit only needs to run if there are no objects already within the document.
            if (!objectsPresent)
            {
                embeddedObject.Append(EmbeddedObjectInit());
                objectsPresent = true;
            }
            V.Shape shape = new V.Shape()
            {
                Id = shapePrefix + shapeId,
                Style = "width:76.35pt;height:49.45pt",
                Ole = null,
                Type = "#_x0000_t75"
            };
            V.ImageData imageData = new V.ImageData()
            {
                Title = "",
                RelationshipId = imagePartId
            };
            shape.Append(imageData);
            embeddedObject.Append(shape);

            String progId = GetProgId(extension);
            Ovml.OleObject oleObject = new Ovml.OleObject()
            {
                Type = Ovml.OleValues.Embed,
                ProgId = progId,
                ShapeId = shapePrefix + shapeId,
                DrawAspect = Ovml.OleDrawAspectValues.Icon,
                ObjectId = "_" + objectId,
                Id = objectPartId
            };
            embeddedObject.Append(oleObject);

            Run r = new Run();
            r.Append(embeddedObject);
            return r;
        }
示例#33
0
        /// <summary>
        /// Add embedded object
        /// </summary>
        /// <param name="embeddedObject"></param>
        /// <returns></returns>
        private string AddEmbeddedObject(EmbeddedObject embeddedObject)
        {
            foreach (OpenXmlElement element in embeddedObject.Elements())
                if (element is DocumentFormat.OpenXml.Vml.Shape)
                    return DrawShape((DocumentFormat.OpenXml.Vml.Shape)element);

            return "";
        }