/////////////////////////////////////////////////////////////////////////////////
        // Constructor
        //
        /////////////////////////////////////////////////////////////////////////////////
        public MainWindow()
        {
            InitializeComponent();

            _viewDataClient = new AdnViewDataClient(
               Credentials.BASE_URL,
               Credentials.CONSUMER_KEY,
               Credentials.CONSUMER_SECRET);

            Authenticate();

            this.Closing += MainWindow_Closing;
        }
Exemplo n.º 2
0
        public TranslationNotifier(
            AdnViewDataClient client,
            string fileId,
            int pollingPeriod = 1000)
        {
            _worker        = null;
            _client        = client;
            _fileId        = fileId;
            _pollingPeriod = pollingPeriod;

            _syncCtrl = new Control();
            _syncCtrl.CreateControl();
        }
Exemplo n.º 3
0
        /////////////////////////////////////////////////////////////////////////////////
        // Constructor
        //
        /////////////////////////////////////////////////////////////////////////////////
        public MainWindow()
        {
            InitializeComponent();

            _viewDataClient = new AdnViewDataClient(
                Credentials.BASE_URL,
                Credentials.CONSUMER_KEY,
                Credentials.CONSUMER_SECRET);

            Authenticate();

            this.Closing += MainWindow_Closing;
        }
        public TranslationNotifier(
            AdnViewDataClient client,
            string fileId,
            int pollingPeriod = 1000)
        {
            _worker = null;
            _client = client;
            _fileId = fileId;
            _pollingPeriod = pollingPeriod;

            _syncCtrl = new Control();
            _syncCtrl.CreateControl();
        }
Exemplo n.º 5
0
        async protected override void OnExecute(NameValueMap context)
        {
            FileUploadForm fUp = new FileUploadForm();

            fUp.UserName = Util.GetUser();
            fUp.EMail    = Util.GetEmail();

            var syncContext = SynchronizationContext.Current;

            var dialogResult = fUp.ShowDialog();

            SynchronizationContext.SetSynchronizationContext(
                syncContext);

            if (dialogResult != System.Windows.Forms.DialogResult.OK)
            {
                Terminate();
                return;
            }

            if (fUp.StoreDetails)
            {
                Util.StoreUserInfo(fUp.UserName, fUp.EMail);
            }

            // the gallery bucket
            var bucketKey = "adn-viewer-gallery";

            // Generates unique file key
            string objectKey = Guid.NewGuid().ToString() + ".dwf";

            // Generate temp filename
            string filename = System.IO.Path.GetTempFileName() + ".dwf";

            if (!Util.ExportDwf(
                    AddInSite.Application,
                    AddInSite.Application.ActiveDocument,
                    filename))
            {
                Terminate();
                return;
            }

            AdnViewDataClient viewDataClient = new AdnViewDataClient(
                UserSettings.BASE_URL,
                UserSettings.CONSUMER_KEY,
                UserSettings.CONSUMER_SECRET);

            var tokenResult = await viewDataClient.AuthenticateAsync();

            if (!tokenResult.IsOk())
            {
                Util.LogError("Authentication failed: " + tokenResult.Error.Reason);

                System.IO.File.Delete(filename);
                Terminate();
                return;
            }

            var fi = FileUploadInfo.CreateFromFile(objectKey, filename);

            var bucketData = new BucketCreationData(
                bucketKey,
                BucketPolicyEnum.kPersistent);

            var response = await viewDataClient.UploadAndRegisterAsync(
                bucketData, fi);

            if (!response.IsOk())
            {
                Util.LogError("Error: " + response.Error.Reason);

                System.IO.File.Delete(filename);
                Terminate();
                return;
            }

            if (response is RegisterResponse)
            {
                RegisterResponse registerResponse = response as RegisterResponse;

                if (registerResponse.Result.ToLower() != "success")
                {
                    Util.LogError("Registration failed: " + registerResponse.Result);

                    System.IO.File.Delete(filename);
                    Terminate();
                    return;
                }

                var name = AddInSite.Application.ActiveDocument.DisplayName;

                var modelName = name.Substring(0, name.Length - 4);

                var fileId = viewDataClient.GetFileId(
                    bucketKey,
                    objectKey);

                var dbModel = new DBModel(
                    new Author(fUp.UserName, fUp.EMail),
                    modelName,
                    fileId,
                    fileId.ToBase64());

                AdnGalleryClient galleryClient = new AdnGalleryClient(
                    Util.GetGalleryUrl());

                var modelResponse = await galleryClient.AddModelAsync(
                    dbModel);

                if (!modelResponse.IsOk())
                {
                    Util.LogError("Error: " + modelResponse.Error.ToString());

                    System.IO.File.Delete(filename);
                    Terminate();
                    return;
                }

                var url = Util.GetGalleryUrl() + "/#/viewer?id=" +
                          modelResponse.Model.Id;

                if (fUp.ShowProgress)
                {
                    var notifier = new TranslationNotifier(
                        viewDataClient,
                        fileId,
                        2000);

                    var fProgress = new ProgressForm(
                        modelName,
                        url,
                        notifier);

                    fProgress.Show();

                    notifier.Activate();
                }

                System.IO.File.Delete(filename);
            }

            Terminate();
        }
Exemplo n.º 6
0
        async static public void UploadToGallery()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            // validates if file has name (ie saved at least once)
            FileInfo info = new FileInfo(db.Filename);

            if (info.Extension == ".dwt")
            {
                Util.LogError("Please save the drawing before uploading to the gallery, aborting...");
                return;
            }

            var syncContext = SynchronizationContext.Current;

            FileUploadForm fUp = new FileUploadForm();

            fUp.UserName = Util.GetUser();
            fUp.EMail    = Util.GetEmail();

            var dialogResult = Application.ShowModalDialog(fUp);

            if (dialogResult != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            if (fUp.StoreDetails)
            {
                Util.StoreUserInfo(fUp.UserName, fUp.EMail);
            }

            SynchronizationContext.SetSynchronizationContext(
                syncContext);

            // the gallery bucket
            var bucketKey = "adn-viewer-gallery";

            // Generates unique file key
            string objectKey = Guid.NewGuid().ToString() + ".dwg";

            // Generate temp filename
            string filename = Path.GetTempFileName() + ".dwg";

            db.SaveAs(filename, DwgVersion.Current);

            AdnViewDataClient viewDataClient = new AdnViewDataClient(
                UserSettings.BASE_URL,
                UserSettings.CONSUMER_KEY,
                UserSettings.CONSUMER_SECRET);

            var tokenResult = await viewDataClient.AuthenticateAsync();

            if (!tokenResult.IsOk())
            {
                Util.LogError("Authentication failed: " + tokenResult.Error.Reason);

                System.IO.File.Delete(filename);
                return;
            }

            var fi = FileUploadInfo.CreateFromFile(objectKey, filename);

            var bucketData = new BucketCreationData(
                bucketKey,
                BucketPolicyEnum.kPersistent);

            var response = await viewDataClient.UploadAndRegisterAsync(
                bucketData, fi);

            if (!response.IsOk())
            {
                Util.LogError("Error: " + response.Error.Reason);

                System.IO.File.Delete(filename);
                return;
            }

            if (response is RegisterResponse)
            {
                RegisterResponse registerResponse = response as RegisterResponse;

                if (registerResponse.Result.ToLower() != "success")
                {
                    Util.LogError("Registration failed: " + registerResponse.Result);

                    System.IO.File.Delete(filename);
                    return;
                }

                var modelName = info.Name.Substring(0, info.Name.Length - 4);

                var fileId = viewDataClient.GetFileId(
                    bucketKey,
                    objectKey);

                var dbModel = new DBModel(
                    new Author(fUp.UserName, fUp.EMail),
                    modelName,
                    fileId,
                    fileId.ToBase64());

                AdnGalleryClient galleryClient = new AdnGalleryClient(
                    Util.GetGalleryUrl());

                var modelResponse = await galleryClient.AddModelAsync(
                    dbModel);

                if (!modelResponse.IsOk())
                {
                    Util.LogError("Error: " + modelResponse.Error.ToString());

                    System.IO.File.Delete(filename);
                    return;
                }

                var url = Util.GetGalleryUrl() + "/#/viewer?id=" +
                          modelResponse.Model.Id;

                if (fUp.ShowProgress)
                {
                    var notifier = new TranslationNotifier(
                        viewDataClient,
                        fileId,
                        2000);

                    var fProgress = new ProgressForm(
                        modelName,
                        url,
                        notifier);

                    Application.ShowModelessDialog(fProgress);

                    notifier.OnTranslationCompleted +=
                        OnTranslationCompleted;

                    notifier.Activate();
                }

                ed.WriteMessage("\nYou successfully uploaded a new model to the gallery!");
                ed.WriteMessage("\nYour model is viewable at the following url:");

                ed.WriteMessage("\n" + url + "\n");

                System.IO.File.Delete(filename);
            }
        }
Exemplo n.º 7
0
        async static public void UploadToGallery(
            string filename,
            string modelname)
        {
            System.Windows.Forms.IWin32Window revit_window
                = new JtWindowHandle(
                      Autodesk.Windows.ComponentManager.ApplicationWindow);

            var syncContext = SynchronizationContext.Current;

            FileUploadForm fUp = new FileUploadForm();

            fUp.UserName = Util.GetUser();
            fUp.EMail    = Util.GetEmail();

            var dialogResult = fUp.ShowDialog(revit_window);

            if (dialogResult != System.Windows.Forms.DialogResult.OK)
            {
                Util.LogError("Upload cancelled.");

                return;
            }

            if (fUp.StoreDetails)
            {
                Util.StoreUserInfo(fUp.UserName, fUp.EMail);
            }

            SynchronizationContext.SetSynchronizationContext(
                syncContext);

            // The gallery bucket

            var bucketKey = "adn-viewer-gallery";

            string consumer_key, consumer_secret;

            if (!Util.GetConsumerCredentials(
                    "C:/credentials.txt",
                    out consumer_key,
                    out consumer_secret))
            {
                Util.LogError("Consumer credentials retrieval failed.");
                return;
            }

            AdnViewDataClient viewDataClient = new AdnViewDataClient(
                UserSettings.BASE_URL,
                consumer_key,
                consumer_secret);

            var tokenResult = await viewDataClient.AuthenticateAsync();

            if (!tokenResult.IsOk())
            {
                Util.LogError("Authentication failed: "
                              + tokenResult.Error.Reason);

                return;
            }

            // Generate unique file key

            string objectKey = Guid.NewGuid().ToString()
                               + ".rvt";

            var fi = FileUploadInfo.CreateFromFile(
                objectKey, filename);

            var bucketData = new BucketCreationData(
                bucketKey,
                BucketPolicyEnum.kPersistent);

            var response
                = await viewDataClient.UploadAndRegisterAsync(
                      bucketData, fi);

            if (!response.IsOk())
            {
                Util.LogError("Error: " + response.Error.Reason);

                return;
            }

            if (response is RegisterResponse)
            {
                RegisterResponse registerResponse = response as RegisterResponse;

                if (registerResponse.Result.ToLower() != "success")
                {
                    Util.LogError("Registration failed: " + registerResponse.Result);

                    return;
                }

                var fileId = viewDataClient.GetFileId(
                    bucketKey,
                    objectKey);

                var dbModel = new DBModel(
                    new Author(fUp.UserName, fUp.EMail),
                    modelname,
                    fileId,
                    fileId.ToBase64());

                string url = Util.GalleryUrl;

                AdnGalleryClient galleryClient = new AdnGalleryClient(
                    url);

                DBModelResponse modelResponse
                    = await Util.AddModelToGalleryAsync(
                          dbModel);

                if (!modelResponse.IsOk())
                {
                    Util.LogError(string.Format("Error: '{0}' {1}",
                                                modelResponse.Error.ToString(),
                                                null == modelResponse.Model ? "model is null" : ""));

                    return;
                }

                url = url + "/#/viewer?id=" + modelResponse.Model.Id;

                if (fUp.ShowProgress)
                {
                    var notifier = new TranslationNotifier(
                        viewDataClient,
                        fileId,
                        2000);

                    var fProgress = new ProgressForm(
                        modelname,
                        url,
                        notifier);

                    fProgress.Show(revit_window);

                    notifier.OnTranslationCompleted +=
                        OnTranslationCompleted;

                    notifier.Activate();
                }
                string msg = "You successfully "
                             + " uploaded a new model to the gallery.\r\n"
                             + "Your model is viewable at the following url:\r\n"
                             + url;

                Util.LogError(msg);

                TaskDialog dlg = new TaskDialog(
                    "Gallery Upload");

                dlg.MainInstruction = "Upload succeeded";
                dlg.MainContent     = msg;
                dlg.Show();
            }
        }