예제 #1
0
파일: Operations.cs 프로젝트: achilex/MgDev
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DATANAME", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DATATYPE", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DATA", param, true);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                string       extension  = CommonUtility.GetExtension(param["DATANAME"]);
                string       mimeType   = CommonUtility.GetMimeType(extension);
                MgByteSource dataSource = new MgByteSource(param["DATA"]);
                dataSource.SetMimeType(mimeType);
                MgByteReader dataReader = dataSource.GetReader();

                _resourceService.SetResourceData(resId, param["DATANAME"], param["DATATYPE"], dataReader);

                return(TestResult.FromByteReader(null));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
예제 #2
0
 public static void SetResourceFromXml(HtzMgHelper helper, MgResourceIdentifier resourceId, XmlDocument doc)
 {
     byte[] layerDef = new UTF8Encoding().GetBytes(doc.InnerXml);
     MgByteSource byteSource = new MgByteSource(layerDef, layerDef.Length);
     byteSource.SetMimeType("text/xml");
     helper.ResourceService.SetResource(resourceId, byteSource.GetReader(), null);
 }
        public void SetResourceContent(string resourceId, string resourceContent)
        {
            MgResourceIdentifier resId = new MgResourceIdentifier(resourceId);

            byte[]       bytes = Encoding.UTF8.GetBytes(resourceContent);
            MgByteSource src   = new MgByteSource(bytes, bytes.Length);

            src.SetMimeType(MgMimeType.Xml);
            ResourceService.SetResource(resId, src.GetReader(), null);
        }
예제 #4
0
        public MgdLayer CreateBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId)
        {
            // Load the layer definition template into
            // a XmlDocument object, find the "ResourceId" element, and
            // modify its content to reference the temporary
            // feature source.

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Layers.BufferLayerDefinition);
            XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];

            featureSourceNode.InnerText = bufferFeatureResId.ToString();

            // Get the updated layer definition from the XmlDocument
            // and save it to the session repository using the
            // ResourceService object.

            MgByteSource byteSource = null;

            using (MemoryStream ms = new MemoryStream())
            {
                doc.Save(ms);
                ms.Position = 0L;

                //Note we do this to ensure our XML content is free of any BOM characters
                byte[]   layerDefinition = ms.ToArray();
                Encoding utf8            = Encoding.UTF8;
                String   layerDefStr     = new String(utf8.GetChars(layerDefinition));
                layerDefinition = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);

                byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
                byteSource.SetMimeType(MgMimeType.Xml);
            }

            MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");

            resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

            // Create an MgLayer object based on the new layer definition
            // and return it to the caller.

            MgdLayer bufferLayer = new MgdLayer(tempLayerResId, resourceService);

            bufferLayer.SetName("Buffer");
            bufferLayer.SetLegendLabel("Buffer");
            bufferLayer.SetDisplayInLegend(true);
            bufferLayer.SetSelectable(false);

            return(bufferLayer);
        }
예제 #5
0
        public MgdLayer CreateBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId)
        {
            // Load the layer definition template into
            // a XmlDocument object, find the "ResourceId" element, and
            // modify its content to reference the temporary
            // feature source.

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(Layers.BufferLayerDefinition);
            XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];
            featureSourceNode.InnerText = bufferFeatureResId.ToString();

            // Get the updated layer definition from the XmlDocument
            // and save it to the session repository using the
            // ResourceService object.

            MgByteSource byteSource = null;
            using (MemoryStream ms = new MemoryStream())
            {
                doc.Save(ms);
                ms.Position = 0L;

                //Note we do this to ensure our XML content is free of any BOM characters
                byte[] layerDefinition = ms.ToArray();
                Encoding utf8 = Encoding.UTF8;
                String layerDefStr = new String(utf8.GetChars(layerDefinition));
                layerDefinition = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);

                byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
                byteSource.SetMimeType(MgMimeType.Xml);
            }

            MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");

            resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

            // Create an MgLayer object based on the new layer definition
            // and return it to the caller.

            MgdLayer bufferLayer = new MgdLayer(tempLayerResId, resourceService);
            bufferLayer.SetName("Buffer");
            bufferLayer.SetLegendLabel("Buffer");
            bufferLayer.SetDisplayInLegend(true);
            bufferLayer.SetSelectable(false);

            return bufferLayer;
        }
예제 #6
0
        public void TestCase_ApplyResourcePackage()
        {
            try
            {
                var fact = new MgdServiceFactory();
                var service = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                Assert.Throws<MgNullArgumentException>(() => service.ApplyResourcePackage(null));

                MgByteSource source = new MgByteSource(packageName);
                source.SetMimeType(MgMimeType.Binary);
                MgByteReader reader = source.GetReader();

                service.ApplyResourcePackage(reader);
            }
            catch (MgException ex)
            {
                Assert.Fail(ex.Message);
                ex.Dispose();
            }
        }
예제 #7
0
        public void TestCase_ApplyResourcePackage()
        {
            try
            {
                var fact    = new MgdServiceFactory();
                var service = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                Assert.Throws <MgNullArgumentException>(() => service.ApplyResourcePackage(null));

                MgByteSource source = new MgByteSource(packageName);
                source.SetMimeType(MgMimeType.Binary);
                MgByteReader reader = source.GetReader();

                service.ApplyResourcePackage(reader);
            }
            catch (MgException ex)
            {
                Assert.Fail(ex.Message);
                ex.Dispose();
            }
        }
예제 #8
0
    // Create a temporary Layer to display geocode results.
    public MgLayer CreateLocationMarkerLayer(MgResourceService resourceService, MgResourceIdentifier locationMarkerDataResId, String sessionId)
    {
        // Load the AddressMarker layer definition template into
        // a ASPX XML object, find the "ResourceId" element, and
        // modify it's content to reference the temporary
        // feature source.

        XmlDocument doc = new XmlDocument();
        doc.PreserveWhitespace = true;
        string path =HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "Extensions/findlocation/templates/locationmarker.xml";
        doc.Load(path);
        XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId").Item(0);
        XmlNode resContent = doc.CreateTextNode(locationMarkerDataResId.ToString());
        featureSourceNode.AppendChild(resContent);

        // Get the updated layer definition from the DOM object
        // and save it to the session repository using the
        // ResourceService object.
        MemoryStream xmlStream = new MemoryStream();
        doc.Save(xmlStream);
        byte[] layerDefinition = xmlStream.ToArray();
        Encoding utf8 = Encoding.UTF8;
        String layerDefStr = new String(utf8.GetChars(layerDefinition));
        layerDefinition = new byte[layerDefStr.Length - 1];
        int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);
        MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
        byteSource.SetMimeType(MgMimeType.Xml);

        MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//LocationMarker.LayerDefinition");
        //MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Library://findLocation/" + sessionId + "/LocationMarker.LayerDefinition");
        resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

        // Create an MgLayer object based on the new layer definition
        // and return it to the caller.

        MgLayer locationLayer = new MgLayer(tempLayerResId, resourceService);
        locationLayer.SetName("LocationMarker");
        locationLayer.SetLegendLabel("LocationMarker");
        locationLayer.SetDisplayInLegend(false);
        locationLayer.SetSelectable(false);

        return locationLayer;
    }
예제 #9
0
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����Ԥ�����XML������
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    private MgLayer createTempParcelLayer(MgResourceService resService, MgResourceIdentifier resId, string sessionId)
    {
        MgLayer tempParcelLayer = null;

        // ����XML�ĵ�
        XmlDocument doc = new XmlDocument();
        doc.PreserveWhitespace = false;
        doc.Load(@"C:\inetpub\wwwroot\MapguideTutorial\CH05-2\tempParcels.xml");
        // ��XML�ĵ��е�ResourceId���滻Ϊ�������ԴID���˴�ӦΪ�������ĻỰ�ִ��е���ʱ��ԴID
        XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId").Item(0);
        XmlNode resContent = doc.CreateTextNode(resId.ToString());
        featureSourceNode.AppendChild(resContent);
        // ����XML
        MemoryStream xmlStream = new MemoryStream();
        doc.Save(xmlStream);
        byte[] layerDef = xmlStream.ToArray();
        Encoding utf8 = Encoding.UTF8;
        string layerDefStr = new string(utf8.GetChars(layerDef));
        layerDef = new byte[layerDefStr.Length - 1];
        int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDef, 0);

        MgByteSource byteSource = new MgByteSource(layerDef, layerDef.Length);
        byteSource.SetMimeType(MgMimeType.Xml);
        // ������Դ
        MgResourceIdentifier tempParcelLayerId = new MgResourceIdentifier("Session:" + sessionId + "//TempParcel.LayerDefinition");
        resService.SetResource(tempParcelLayerId, byteSource.GetReader(), null);
        //������ʱ��
        tempParcelLayer = new MgLayer(tempParcelLayerId, resService);
        tempParcelLayer.SetName("TempParcels");
        tempParcelLayer.SetLegendLabel("New Parcels");
        tempParcelLayer.SetDisplayInLegend(true);
        tempParcelLayer.SetSelectable(false);

        return tempParcelLayer;
    }
예제 #10
0
        public override void SetResourceXmlData(string resourceid, System.IO.Stream content, System.IO.Stream header)
        {
            bool exists = ResourceExists(resourceid);

            var res = GetResourceService();
            byte[] bufHeader = header == null ? new byte[0] : Utility.StreamAsArray(header);
            byte[] bufContent = content == null ? new byte[0] : Utility.StreamAsArray(content);
            //MgByteReader rH = bufHeader.Length == 0 ? null : new MgByteReader(bufHeader, bufHeader.Length, "text/xml");
            //MgByteReader rC = bufContent.Length == 0 ? null : new MgByteReader(bufContent, bufContent.Length, "text/xml");
            MgByteReader rH = null;
            MgByteReader rC = null;

            if (bufHeader.Length > 0)
            {
                MgByteSource source = new MgByteSource(bufHeader, bufHeader.Length);
                source.SetMimeType("text/xml");
                rH = source.GetReader();
            }

            if (bufContent.Length > 0)
            {
                MgByteSource source = new MgByteSource(bufContent, bufContent.Length);
                source.SetMimeType("text/xml");
                rC = source.GetReader();
            }

            res.SetResource(new MgResourceIdentifier(resourceid), rC, rH);
            LogMethodCall("MgResourceService::SetResource", true, resourceid, "MgByteReader", "MgByteReader");
            if (exists)
                OnResourceUpdated(resourceid);
            else
                OnResourceAdded(resourceid);
        }
 public void SetResourceContent(string resourceId, string resourceContent)
 {
     MgResourceIdentifier resId = new MgResourceIdentifier(resourceId);
     byte[] bytes = Encoding.UTF8.GetBytes(resourceContent);
     MgByteSource src = new MgByteSource(bytes, bytes.Length);
     src.SetMimeType(MgMimeType.Xml);
     ResourceService.SetResource(resId, src.GetReader(), null);
 }