예제 #1
0
        // Upload children and collect json info,
        // set references
        bool uploadSubDocs(string strFile, ref string refJson)
        {
            // 1) Get all referenced files and collect json ref
            string strName = Path.GetFileName(strFile);

            // 2) Upload subdocs and collect JSON info
            Inv.ApprenticeServerComponent app = new Inv.ApprenticeServerComponent();
            Inv.ApprenticeServerDocument  doc = app.Open(strFile);
            //IList<string> urns = new List<string>();
            Inv.FilesEnumerator files = doc.File.ReferencedFiles;
            foreach (Inv.File file in files)
            {
                string subUrn = "";
                if (uploadFile(file.FullFileName, ref subUrn))
                {
                    string strSubName = Path.GetFileName(file.FullFileName);
                    refJson +=
                        "{ \"file\" : \"" + subUrn + "\"," +
                        "\"metadata\" : { " +
                        //              "\"childPath\" : \"" + file.FullFileName + "\"," +
                        //              "\"parentPath\" : \"" + strFile + "\"" +
                        "\"childPath\" : \"" + strSubName + "\"," +
                        "\"parentPath\" : \"" + strName + "\"" +
                        "},";
                }

                uploadSubDocs(file.FullFileName, ref refJson);
            }

            return(true);
        }
예제 #2
0
        // Upload file, upload children and collect json info,
        // set references
        bool uploadSubDocs_old(string strFile, ref string fileUrn)
        {
            // 1) Upload file
            if (!uploadFile(strFile, ref fileUrn))
            {
                return(false);
            }

            // 2) Get all referenced files and collect json ref
            string strName = Path.GetFileName(strFile);
            string refJson =
                "{ " +
                "\"master\" : \"urn:adsk.objects:os.object:alexbicalhobucket2/A1.iam\"," +
                "\"dependencies\" : [";

            Inv.ApprenticeServerComponent app = new Inv.ApprenticeServerComponent();
            Inv.ApprenticeServerDocument  doc = app.Open(strFile);
            IList <string> urns = new List <string>();

            Inv.FilesEnumerator files = doc.File.ReferencedFiles;
            foreach (Inv.File subDoc in files)
            {
                string subUrn = "";
                if (uploadSubDocs(subDoc.FullFileName, ref subUrn))
                {
                    string strSubName = Path.GetFileName(subDoc.FullFileName);
                    refJson +=
                        "{ \"file\" : \"urn:adsk.objects:os.object:alexbicalhobucket2/A1A1.iam\"," +
                        "\"metadata\" : { " +
                        "\"childPath\" : \"" + strSubName + "\"," +
                        "\"parentPath\" : \"" + strName + "\"" +
                        "},";
                }
            }

            // 3) Set the reference for the main file
            if (files.Count > 0)
            {
                refJson += "] }";

                RestRequest request = new RestRequest();
                request.Resource = "/oss/v1/setreference";
                request.Method   = Method.POST;
                request.AddParameter("Authorization", "Bearer " + _token, ParameterType.HttpHeader);
                request.AddParameter("Content-Type", "application/json", ParameterType.HttpHeader);

                // Bucketname is the name of the bucket.
                request.AddParameter("application/json", refJson, ParameterType.RequestBody);

                IRestResponse response = _client.Execute(request);
                logText(request.Method.ToString() + " " + request.Resource);
                logText(response.StatusCode.ToString() + ": " + response.StatusDescription);
            }

            return(true);
        }