Exemplo n.º 1
0
 public iCalendarCollectionInstance LoadCalendar(Base64EncodedByteArrayInstance data)
 {
     using (var ms = new MemoryStream(data.Data))
     {
         var result = iCalendar.LoadFromStream(ms);
         return(new iCalendarCollectionInstance(this.Engine.Object.InstancePrototype, (iCalendarCollection)result));
     }
 }
Exemplo n.º 2
0
        public SPUserTokenInstance Construct(Base64EncodedByteArrayInstance bytes)
        {
            if (bytes == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A byte array must be specified as the first argument.");
            }

            return(new SPUserTokenInstance(this.InstancePrototype, new SPUserToken(bytes.Data)));
        }
Exemplo n.º 3
0
        public void AddNow(string leafName, Base64EncodedByteArrayInstance data)
        {
            if (data == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A Base64EncodedByteArrayInstance must be supplied as the attachment data to add.");
            }

            m_attachmentCollection.AddNow(leafName, data.Data);
        }
Exemplo n.º 4
0
        public Base64EncodedByteArrayInstance OpenBinary()
        {
            var result = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, m_fileVersion.OpenBinary())
            {
                FileName = m_fileVersion.File.Name,
                MimeType = StringHelper.GetMimeTypeFromFileName(m_fileVersion.File.Name)
            };

            return(result);
        }
        public AttachmentInstance UploadAttachment(object entityId, string fileName, Base64EncodedByteArrayInstance attachment)
        {
            if (entityId == null || entityId == Null.Value || entityId == Undefined.Value)
            {
                throw new JavaScriptException(Engine, "Error", "An entity id or an entity must be defined as the first parameter.");
            }

            var id = ConvertFromJsObjectToGuid(entityId);

            return(new AttachmentInstance(Engine, m_repository.UploadAttachment(id, fileName, attachment.Data)));
        }
Exemplo n.º 6
0
        public AttachmentInstance Construct(Base64EncodedByteArrayInstance attachment)
        {
            if (attachment == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "An attachment must be specified as the first argument.");
            }

            var ms = new MemoryStream(attachment.Data);

            return(new AttachmentInstance(this.Engine, new Attachment(ms, attachment.FileName, attachment.MimeType)));
        }
Exemplo n.º 7
0
        public static ObjectInstance RecordToObjectInstance(this IDataReader rdr, ScriptEngine engine)
        {
            ObjectInstance e = engine.Object.Construct();

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                object propertyValue;
                var    value = rdr[i];

                if (DBNull.Value.Equals(value))
                {
                    propertyValue = Null.Value;
                }
                else if (value is DateTime)
                {
                    propertyValue = JurassicHelper.ToDateInstance(engine, (DateTime)value);
                }
                else if (value is Byte)
                {
                    propertyValue = Convert.ToInt32((Byte)value);
                }
                else if (value is Int16)
                {
                    propertyValue = Convert.ToInt32((Int16)value);
                }
                else if (value is Int64)
                {
                    propertyValue = Convert.ToDouble((Int64)value);
                }
                else if (value is decimal)
                {
                    propertyValue = Convert.ToDouble((decimal)value);
                }
                else if (value is Guid)
                {
                    propertyValue = ((Guid)value).ToString();
                }
                else if (value is Byte[])
                {
                    propertyValue = new Base64EncodedByteArrayInstance(engine.Object.InstancePrototype, (Byte[])value);
                }
                else if (value.GetType().FullName == "Microsoft.SqlServer.Types.SqlHierarchyId")
                {
                    propertyValue = value.ToString();
                }
                else
                {
                    propertyValue = value;
                }

                e.SetPropertyValue(rdr.GetName(i), propertyValue, false);
            }
            return(e);
        }
        public LinkedResourceInstance Construct(Base64EncodedByteArrayInstance linkedResource)
        {
            if (linkedResource == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A linkedResource must be specified as the first argument.");
            }

            var ms = new MemoryStream(linkedResource.Data);

            return(new LinkedResourceInstance(this.Engine, new LinkedResource(ms, linkedResource.MimeType)));
        }
        public Base64EncodedByteArrayInstance ListCacheContents(SPSiteInstance site)
        {
            if (site == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "An instance of a site object must be specified as the first argument.");
            }

            using (var ms = new MemoryStream())
            {
                PublishingCache.ListCacheContents(ms, false, site.Site);
                var blob = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, ms.ToArray());
                return(blob);
            }
        }
Exemplo n.º 10
0
        public Base64EncodedByteArrayInstance Convert(HtmlToImageDocumentInstance document, object fileName)
        {
            var pdfBytes = m_converter.Convert(document.HtmlToImageDocument);
            var result   = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, pdfBytes)
            {
                MimeType = "image/jpeg"
            };

            if (fileName != null && fileName != Null.Value && fileName != Undefined.Value)
            {
                result.FileName = fileName.ToString();
            }

            return(result);
        }
Exemplo n.º 11
0
        public Base64EncodedByteArrayInstance LoadFileAsByteArray(string fileUrl)
        {
            SPFile file;

            if (!SPHelper.TryGetSPFile(fileUrl, out file))
            {
                throw new JavaScriptException(Engine, "Error", "Could not locate the specified file:  " + fileUrl);
            }

            var data   = file.OpenBinary(SPOpenBinaryOptions.None);
            var result = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, data)
            {
                FileName = file.SourceLeafName.IsNullOrWhiteSpace() ? file.Name : file.SourceLeafName
            };

            return(result);
        }
Exemplo n.º 12
0
        public Base64EncodedByteArrayInstance OpenBinary(string openOptions)
        {
            Base64EncodedByteArrayInstance result;

            if (String.IsNullOrEmpty(openOptions) || openOptions == Undefined.Value.ToString())
            {
                result = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, m_file.OpenBinary());
            }
            else
            {
                var openOptionsValue = (SPOpenBinaryOptions)Enum.Parse(typeof(SPOpenBinaryOptions), openOptions);
                result = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, m_file.OpenBinary(openOptionsValue));
            }

            result.ETag     = m_file.ETag;
            result.FileName = m_file.Name;
            result.MimeType = StringHelper.GetMimeTypeFromFileName(m_file.Name);
            return(result);
        }
        private object ReadValue(JsonReader reader)
        {
            while (reader.TokenType == JsonToken.Comment)
            {
                if (!reader.Read())
                {
                    throw JsonSerializationException.Create(reader, "Unexpected end when reading ObjectInstance.");
                }
            }

            switch (reader.TokenType)
            {
            case JsonToken.StartObject:
                return(ReadObject(reader));

            case JsonToken.StartArray:
                return(ReadArray(reader));

            case JsonToken.Date:
                var dateInstance = JurassicHelper.ToDateInstance(this.Engine, (DateTime)reader.Value);
                return(dateInstance);

            case JsonToken.Null:
                return(Null.Value);

            case JsonToken.Undefined:
                return(Undefined.Value);

            case JsonToken.Bytes:
                var byteArray = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, (byte[])reader.Value);
                return(byteArray);

            case JsonToken.Boolean:
            case JsonToken.Float:
            case JsonToken.Integer:
            case JsonToken.String:
                return(reader.Value);

            default:
                throw JsonSerializationException.Create(reader, "Unexpected token when converting ObjectInstance: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
            }
        }
        public Base64EncodedByteArrayInstance DownloadAttachment(object entityId, string fileName)
        {
            if (entityId == null || entityId == Null.Value || entityId == Undefined.Value)
            {
                throw new JavaScriptException(Engine, "Error", "An entity id or an entity must be defined as the first parameter.");
            }

            var id = ConvertFromJsObjectToGuid(entityId);

            var attachment   = m_repository.GetAttachment(id, fileName);
            var streamResult = m_repository.DownloadAttachment(id, fileName);

            var result = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, streamResult.ReadToEnd())
            {
                MimeType = attachment.MimeType,
                FileName = attachment.FileName
            };

            return(result);
        }
Exemplo n.º 15
0
        public Base64EncodedByteArrayInstance GetBytes(object fileName)
        {
            var serializer = new iCalendarSerializer();

            byte[] data;
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(m_iCalendar, ms, Encoding.UTF8);
                data = ms.ToArray();
            }

            var result = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, data)
            {
                MimeType = "text/calendar"
            };

            if (fileName != null && fileName != Undefined.Value)
            {
                result.FileName = TypeConverter.ToString(fileName);
            }

            return(result);
        }
Exemplo n.º 16
0
        public Base64EncodedByteArrayInstance ExtractFarmSolutionByName(string solutionName)
        {
            var solution = m_farm.Solutions.FirstOrDefault(s => s.Name == solutionName);

            if (solution == null)
            {
                return(null);
            }

            var fileName = Utilities.GetTempFileName(".wsp");

            solution.SolutionFile.SaveAs(fileName);

            Base64EncodedByteArrayInstance result;

            using (var solutionFile = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var data = solutionFile.ReadToEnd();
                result = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, data);
            }

            return(result);
        }
        public SPWebPartInstance ImportWebPart(Base64EncodedByteArrayInstance webPart)
        {
            if (webPart == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A byte array must be supplied as the first argument.");
            }


            using (var ms = new MemoryStream(webPart.Data))
            {
                var    reader = XmlReader.Create(ms);
                string errorMessage;
                var    result = m_limitedWebPartManager.ImportWebPart(reader, out errorMessage) as WebPart;

                if (errorMessage.IsNullOrWhiteSpace() == false)
                {
                    throw new JavaScriptException(this.Engine, "Error", errorMessage);
                }

                return(result == null
                    ? null
                    : new SPWebPartInstance(this.Engine.Object.InstancePrototype, result));
            }
        }
Exemplo n.º 18
0
        public void SaveBinary(Base64EncodedByteArrayInstance data, object saveBinaryParameters)
        {
            if (saveBinaryParameters != null && saveBinaryParameters != Undefined.Value && saveBinaryParameters != Null.Value)
            {
                var p = new SPFileSaveBinaryParameters();
                if (data.ETag.IsNullOrWhiteSpace() == false)
                {
                    p.ETagMatch = data.ETag;
                }

                var objSaveBinaryParameters = saveBinaryParameters as ObjectInstance;
                if (objSaveBinaryParameters != null)
                {
                    //TODO: Finish this...

                    if (objSaveBinaryParameters.HasProperty("checkInComment"))
                    {
                        p.CheckInComment = TypeConverter.ToString(objSaveBinaryParameters.GetPropertyValue("CheckInComment"));
                    }

                    if (objSaveBinaryParameters.HasProperty("eTagMatch"))
                    {
                        p.ETagMatch = TypeConverter.ToString(objSaveBinaryParameters.GetPropertyValue("eTagMatch"));
                    }
                }

                using (var stream = new MemoryStream(data.Data))
                {
                    m_file.SaveBinary(stream, p);
                }
            }
            else
            {
                m_file.SaveBinary(data.Data);
            }
        }
        public EntityInstance ImportEntity(string path, object entityId, string @namespace, Base64EncodedByteArrayInstance archiveData)
        {
            if (entityId == Null.Value || entityId == Undefined.Value || entityId == null)
            {
                throw new JavaScriptException(Engine, "Error", "Entity Id must be specified.");
            }

            if (@namespace == null)
            {
                throw new JavaScriptException(Engine, "Error", "Namespace must be specified.");
            }

            if (archiveData == null)
            {
                throw new JavaScriptException(Engine, "Error", "Archive Data must be specified.");
            }

            var id = ConvertFromJsObjectToGuid(entityId);

            Entity entity = String.IsNullOrEmpty(path)
              ? m_repository.ImportEntity(id, @namespace, archiveData.Data)
              : m_repository.ImportEntity(path, id, @namespace, archiveData.Data);

            return(entity == null
              ? null
              : new EntityInstance(Engine, entity));
        }
Exemplo n.º 20
0
        public SPDocumentSetInstance Import(Base64EncodedByteArrayInstance bytes, string name, SPFolderInstance parentFolder, object ctid, object properties, object user)
        {
            if (bytes == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A base64 encoded byte array must be supplied as the first argument.");
            }

            if (name.IsNullOrWhiteSpace())
            {
                throw new JavaScriptException(this.Engine, "Error", "The name of the new document set must be specified.");
            }

            if (parentFolder == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "The parent folder must be specified.");
            }

            if (ctid == Undefined.Value && properties == Undefined.Value && user == Undefined.Value)
            {
                var r = DocumentSet.Import(bytes.Data, name, parentFolder.Folder);
                if (r == null)
                {
                    return(null);
                }

                return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, parentFolder.Folder.ParentWeb.Site,
                                                 parentFolder.Folder.ParentWeb, r));
            }



            var spCtId = ctid as SPContentTypeIdInstance;

            if (ctid == null || ctid == Null.Value || ctid == Undefined.Value || spCtId == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "The Content Type Id of the imported document set must be specified.");
            }

            var spUser = user as SPUserInstance;

            if (user == null || user == Null.Value || user == Undefined.Value || spUser == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "The user of the imported document set must be specified.");
            }

            var htProperties = new Hashtable();

            if (properties != null && properties != Null.Value && properties != Undefined.Value)
            {
                htProperties = SPHelper.GetFieldValuesHashtableFromPropertyObject(properties);
            }

            var result = DocumentSet.Import(bytes.Data, name, parentFolder.Folder, spCtId.ContentTypeId, htProperties, spUser.User);

            if (result == null)
            {
                return(null);
            }

            return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, parentFolder.Folder.ParentWeb.Site,
                                             parentFolder.Folder.ParentWeb, result));
        }