Esempio n. 1
0
 public Viewer(ForgeObjectInfo item, string accessToken)
 {
     InitializeComponent();
     _item         = item;
     _accessToken  = accessToken;
     this.Closing += Viewer_Closing;
 }
Esempio n. 2
0
        private async Task JobProgressTask(ForgeObjectInfo item, IProgress <ProgressInfo> progress, CancellationToken ct, TaskScheduler uiScheduler)
        {
            progress.Report(new ProgressInfo(0, "Initializing..."));
            while (!ct.IsCancellationRequested)
            {
                try {
                    ProgressInfo info = await JobProgressRequest(item);

                    if (info == null)
                    {
                        progress.Report(new ProgressInfo(0, "Error"));
                        break;
                    }
                    progress.Report(info);
                    if (info.pct >= 100 || info.msg == "success")
                    {
                        item.TranslationRequested = StateEnum.Busy;
                        if (_callback != null)
                        {
                            this.Dispatcher.Invoke(_callback, new Object [] { item });
                        }
                        break;
                    }
                } catch (Exception /*ex*/) {
                }
            }
        }
Esempio n. 3
0
        protected async Task <ProgressInfo> JobProgressRequest(ForgeObjectInfo item)
        {
            try {
                DerivativesApi md = new DerivativesApi();
                md.Configuration.AccessToken = _accessToken;
                string urn = MainWindow.URN(item.Properties.bucketKey, item);
                ApiResponse <dynamic> response = await md.GetManifestAsyncWithHttpInfo(urn);

                MainWindow.httpErrorHandler(response, "Initializing...");
                item.Manifest = response.Data;
                int pct = 100;
                if (response.Data.progress != "complete")
                {
                    try {
                        string st  = response.Data.progress;
                        Regex  rgx = new Regex("[^0-9]*");
                        st  = rgx.Replace(st, "");
                        pct = int.Parse(st);
                    } catch (Exception) {
                        pct = 0;
                    }
                }
                string msg = response.Data.status;
                return(new ProgressInfo(pct, msg));
            } catch (Exception /*ex*/) {
                return(new ProgressInfo(0, "Initializing..."));
            }
        }
Esempio n. 4
0
        private /*async*/ void ForgeObjects_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Handled(e);
            propertyGrid.SelectedObject = null;
            if (ForgeObjects.SelectedItems.Count != 1)
            {
                return;
            }
            ForgeObjectInfo item = ForgeObjects.SelectedItem as ForgeObjectInfo;

            //propertyGrid.SelectedObject =item.Properties ;
            propertyGrid.SelectedObject = new ItemProperties(item);
        }
Esempio n. 5
0
        private void Launch_Viewer(object sender, RoutedEventArgs e)
        {
            Handled(e);
            if (ForgeObjects.SelectedItems.Count != 1)
            {
                MessageBox.Show("We can launch only one viewer at a time for now!", APP_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            ForgeObjectInfo item = ForgeObjects.SelectedItem as ForgeObjectInfo;
            string          urn  = URN((string)BucketsInRegion.SelectedItem, item, true);
            string          url  = "https://models.autodesk.io/view.html?urn=" + urn + "&accessToken=" + accessToken;

            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(url));
        }
Esempio n. 6
0
        public static string URN(string bucketKey, ForgeObjectInfo item, bool bSafe = true)
        {
            string urn = "urn:adsk.objects:os.object:" + bucketKey + "/" + item.Name;

            try {
                if (item.Properties != null)
                {
                    urn = item.Properties.objectId;
                }
                urn = bSafe ? SafeBase64Encode(urn) : Base64Encode(urn);
            } catch (Exception /*ex*/) {
            }
            return(urn);
        }
Esempio n. 7
0
        private async Task RequestManifest(ForgeObjectInfo item)
        {
            try {
                item.ManifestRequested = StateEnum.Busy;
                DerivativesApi md = new DerivativesApi();
                md.Configuration.AccessToken = accessToken;
                string urn = URN((string)BucketsInRegion.SelectedItem, item);
                ApiResponse <dynamic> response = await md.GetManifestAsyncWithHttpInfo(urn);

                httpErrorHandler(response, "Failed to get manifest");
                item.Manifest = response.Data;
            } catch (Exception /*ex*/) {
                item.Manifest = null;
            } finally {
                item.ManifestRequested = StateEnum.Idle;
            }
        }
Esempio n. 8
0
        private async Task RequestProperties(ForgeObjectInfo item)
        {
            try {
                item.PropertiesRequested = StateEnum.Busy;
                ObjectsApi ossObjects = new ObjectsApi();
                ossObjects.Configuration.AccessToken = accessToken;
                ApiResponse <dynamic> response = await ossObjects.GetObjectDetailsAsyncWithHttpInfo((string)BucketsInRegion.SelectedItem, item.Name);

                httpErrorHandler(response, "Failed to get object details");
                response.Data.region = (string)ForgeRegion.SelectedItem;
                item.Properties      = response.Data;
            } catch (Exception /*ex*/) {
                item.Properties = null;
            } finally {
                item.PropertiesRequested = StateEnum.Idle;
            }
        }
Esempio n. 9
0
        private async Task <bool> DeleteManifestOnServer(ForgeObjectInfo item)
        {
            try {
                DerivativesApi md = new DerivativesApi();
                md.Configuration.AccessToken = accessToken;
                string urn = URN((string)BucketsInRegion.SelectedItem, item);
                ApiResponse <dynamic> response = await md.DeleteManifestAsyncWithHttpInfo(urn);

                httpErrorHandler(response, "Failed to delete manifest");
                item.Manifest             = null;
                item.TranslationRequested = StateEnum.Idle;
            } catch (Exception ex) {
                item.TranslationRequested = StateEnum.Idle;
                Debug.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
Esempio n. 10
0
        private async Task <bool> DownloadFileObjectNoUI(ForgeObjectInfo item, string folder)
        {
            try {
                ObjectsApi ossObjects = new ObjectsApi();
                ossObjects.Configuration.AccessToken = accessToken;
                ApiResponse <dynamic> response = await ossObjects.GetObjectAsyncWithHttpInfo((string)BucketsInRegion.SelectedItem, item.Properties.objectKey);

                httpErrorHandler(response, "Failed to download file");
                Stream downloadObj = response.Data as Stream;
                downloadObj.Position = 0;
                string outputFilename = System.IO.Path.Combine(folder, item.Name);
                using (FileStream outputFile = new FileStream(outputFilename, FileMode.Create))
                    downloadObj.CopyTo(outputFile);
            } catch (Exception ex) {
                Debug.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
        protected void AssignProperties(ForgeObjectInfo item)
        {
            Bucket    = item.Properties.bucketKey;
            Region    = item.Properties.region;
            ObjectKey = item.Properties.objectKey;
            ObjectID  = item.Properties.objectId;
            Size      = MainWindow.SizeSuffix(item.Properties.size);
            SHA1      = item.Properties.sha1;
            Location  = item.Properties.location;

            bool bVersion     = false;
            bool bRegisterKey = false;

            if (item.Manifest != null)
            {
                bVersion     = MainWindow.hasOwnProperty(item.Manifest, "version");
                bRegisterKey = MainWindow.hasOwnProperty(item.Manifest, "registerKeys");
                if (bVersion)
                {
                    Version        = item.Manifest.version;
                    HasThumbnail   = bool.Parse(item.Manifest.derivatives [0].hasThumbnail);
                    Status         = item.Manifest.status;
                    Progress       = item.Manifest.progress;
                    DerivativeType = item.Manifest.derivatives [0].outputType;
                    DerivativeName = item.Manifest.derivatives [0].name;
                }
                else if (bRegisterKey)
                {
                    RegisterKey    = item.Manifest.registerKeys [0];
                    Status         = item.Manifest.result;
                    DerivativeType = item.Manifest.acceptedJobs.output.formats [0].type;
                }
            }
            ShowProperty("Version", bVersion);
            ShowProperty("HasThumbnail", bVersion);
            ShowProperty("Status", bVersion || bRegisterKey);
            ShowProperty("Progress", bVersion);
            ShowProperty("DerivativeType", bVersion || bRegisterKey);
            ShowProperty("DerivativeName", bVersion);
            ShowProperty("RegisterKey", bRegisterKey);
        }
Esempio n. 12
0
        protected async Task <bool> DownloadExecute(ForgeObjectInfo item, string folder)
        {
            DownloadProgress wnd = new DownloadProgress(item.Name);

            wnd.Show();

            try {
                ObjectsApi ossObjects = new ObjectsApi();
                ossObjects.Configuration.AccessToken = accessToken;
                ApiResponse <dynamic> response = await ossObjects.GetObjectAsyncWithHttpInfo((string)BucketsInRegion.SelectedItem, item.Properties.objectKey);

                httpErrorHandler(response, "Failed to download file");
                Stream downloadObj = response.Data as Stream;
                downloadObj.Position = 0;
                string outputFilename = System.IO.Path.Combine(folder, item.Name);
                using (FileStream outputFile = new FileStream(outputFilename, FileMode.Create))
                    downloadObj.CopyTo(outputFile);
                wnd.ReportProgress(new ProgressInfo(100, "File download succeeded"));
            } catch (Exception ex) {
                wnd.ReportProgress(new ProgressInfo(0, ex.Message));
                return(false);
            }
            return(true);
        }
Esempio n. 13
0
        private async Task <bool> TranslateObject(ObservableCollection <ForgeObjectInfo> items, ForgeObjectInfo item)
        {
            try {
                string          urn      = URN((string)BucketsInRegion.SelectedItem, item, false);
                JobPayloadInput jobInput = new JobPayloadInput(
                    urn,
                    System.IO.Path.GetExtension(item.Name).ToLower() == ".zip",
                    item.Name
                    );
                JobPayloadOutput jobOutput = new JobPayloadOutput(
                    new List <JobPayloadItem> (
                        new JobPayloadItem [] {
                    new JobPayloadItem(
                        JobPayloadItem.TypeEnum.Svf,
                        new List <JobPayloadItem.ViewsEnum> (
                            new JobPayloadItem.ViewsEnum [] {
                        JobPayloadItem.ViewsEnum._2d, JobPayloadItem.ViewsEnum._3d
                    }
                            ),
                        null
                        )
                }
                        )
                    );
                JobPayload     job    = new JobPayload(jobInput, jobOutput);
                bool           bForce = true;
                DerivativesApi md     = new DerivativesApi();
                md.Configuration.AccessToken = accessToken;
                ApiResponse <dynamic> response = await md.TranslateAsyncWithHttpInfo(job, bForce);

                httpErrorHandler(response, "Failed to register file for translation");
                item.TranslationRequested = StateEnum.Busy;
                item.Manifest             = response.Data;

                JobProgress jobWnd = new JobProgress(item, accessToken);
                jobWnd._callback = new JobCompletedDelegate(this.TranslationCompleted);
                jobWnd.Owner     = this;
                jobWnd.Show();
            } catch (Exception /*ex*/) {
                item.TranslationRequested = StateEnum.Idle;
                return(false);
            }
            return(true);
        }
Esempio n. 14
0
 public JobProgress(ForgeObjectInfo item, string accessToken)
 {
     _item        = item;
     _accessToken = accessToken;
     InitializeComponent();
 }
Esempio n. 15
0
 public void TranslationCompleted(ForgeObjectInfo item)
 {
     ForgeObjects.Items.Refresh();
 }
 public ItemProperties(ForgeObjectInfo item)
 {
     AssignProperties(item);
     item.PropertyChanged += PropertyHasChanged;
 }
Esempio n. 17
0
        private async Task <bool> DeleteObjectOnServer(ObservableCollection <ForgeObjectInfo> items, ForgeObjectInfo item)
        {
            try {
                ObjectsApi ossObjects = new ObjectsApi();
                ossObjects.Configuration.AccessToken = accessToken;
                ApiResponse <dynamic> response = await ossObjects.DeleteObjectAsyncWithHttpInfo((string)BucketsInRegion.SelectedItem, item.Name);

                httpErrorHandler(response, "Failed to delete file");
                items.Remove(item);
            } catch (Exception ex) {
                Debug.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }