Пример #1
0
 public CService(
     ForgeAPI.Interface.IForgeAPIConfiguration configuration,
     ForgeAPI.Interface.REST.IService restService)
 {
     m_Configuration = configuration;
     m_RESTService   = restService;
 }
Пример #2
0
 public CService(
     ForgeAPI.Interface.IFactory factory,
     ForgeAPI.Interface.IForgeAPIConfiguration configuration,
     ForgeAPI.Interface.REST.IService restService,
     ForgeAPI.Interface.Utility.IService utilityService,
     Newtonsoft.Json.Serialization.DefaultContractResolver contractResolver)
 {
     m_Factory        = factory;
     m_Configuration  = configuration;
     m_RESTService    = restService;
     m_UtilityService = utilityService;
     m_Resolver       = contractResolver;
 }
Пример #3
0
        private void UpdateForge()
        {
            ContainerBuilder builder;

            ForgeAPI.Interface.Authentication.IService authService;
            ForgeAPI.Interface.Authentication.IToken   authToken;
            ForgeAPI.Interface.Utility.IService        utility;
            ForgeAPI.Interface.IFactory factory;

            builder = new ContainerBuilder();
            builder.AddForgeAPI();

            using (var container = builder.Build())
            {
                SetStatus("Getting Forge Authentication Token");

                m_RESTService = container.Resolve <ForgeAPI.Interface.REST.IService>();

                #region Authenticate

                authService = container.Resolve <ForgeAPI.Interface.Authentication.IService>();
                authToken   = authService.Authenticate(
                    new List <ForgeAPI.Interface.Enums.E_AccessScope>()
                {
                    ForgeAPI.Interface.Enums.E_AccessScope.Bucket_Create,
                    ForgeAPI.Interface.Enums.E_AccessScope.Bucket_Delete,
                    ForgeAPI.Interface.Enums.E_AccessScope.Bucket_Read,
                    ForgeAPI.Interface.Enums.E_AccessScope.Data_Read,
                    ForgeAPI.Interface.Enums.E_AccessScope.Data_Write
                });

                #endregion

                factory = container.Resolve <ForgeAPI.Interface.IFactory>();
                utility = container.Resolve <ForgeAPI.Interface.Utility.IService>();

                int index = 1;
                foreach (Outputs.CArtifact artifact in m_Outputs.ArtifactList)
                {
                    string prefix;

                    prefix =
                        $"Processing {index} of {m_Outputs.ArtifactList.Count} [{artifact.FileName}]";

                    #region Upload To Data Management

                    SetStatus($"{prefix} - Uploading To Data Management");

                    {
                        ForgeAPI.Interface.DataManagement.Objects.UploadObject.IInputs  inputs;
                        ForgeAPI.Interface.DataManagement.Objects.UploadObject.IOutputs outputs;
                        ForgeAPI.Interface.DataManagement.Objects.IService service;

                        inputs  = factory.CreateInputs <ForgeAPI.Interface.DataManagement.Objects.UploadObject.IInputs>(authToken);
                        service = container.Resolve <ForgeAPI.Interface.DataManagement.Objects.IService>();

                        inputs.FileName    = System.IO.Path.GetFileName(artifact.FileLocation);
                        inputs.FileData    = System.IO.File.ReadAllBytes(artifact.FileLocation);
                        inputs.ContentType = "application/octet-stream";
                        inputs.BucketKey   = m_Inputs.BucketKey;
                        inputs.ObjectName  = inputs.FileName;

                        outputs = service.UploadObject(inputs);

                        if (outputs.Success() == false)
                        {
                            throw new Exception(outputs.FailureReason());
                        }

                        artifact.URN        = outputs.ObjectID;
                        artifact.URNEncoded = utility.ConvertToBase64(artifact.URN);
                    }

                    #endregion

                    #region Add Derivative Job

                    SetStatus($"{prefix} - Adding Derivative Job");

                    {
                        ForgeAPI.Interface.ModelDerivative.Derivatives.AddJob.IInputs           inputs;
                        ForgeAPI.Interface.ModelDerivative.Derivatives.AddJob.IOutputFormat_SVF svfFormat;
                        ForgeAPI.Interface.ModelDerivative.Derivatives.AddJob.IOutputs          outputs;
                        ForgeAPI.Interface.ModelDerivative.Derivatives.IService service;

                        service = container.Resolve <ForgeAPI.Interface.ModelDerivative.Derivatives.IService>();

                        inputs = factory.CreateInputs <ForgeAPI.Interface.ModelDerivative.Derivatives.AddJob.IInputs>(
                            authToken);

                        inputs.ReplaceExistingDerivatives        = true;
                        inputs.Input.URNEncoded                  = utility.ConvertToBase64(artifact.URN);
                        inputs.Input.IsCompressed                = false;
                        inputs.Output.DestinationSettings.Region = ForgeAPI.Interface.Enums.E_Region.US;

                        svfFormat = factory.Create <ForgeAPI.Interface.ModelDerivative.Derivatives.AddJob.IOutputFormat_SVF>();

                        #region Set View Types

                        if (artifact.Type == Enums.E_ArtifactType.DWF_Drawing ||
                            artifact.Type == Enums.E_ArtifactType.DXF ||
                            artifact.Type == Enums.E_ArtifactType.IDW)
                        {
                            svfFormat.ViewList.Add(ForgeAPI.Interface.Enums.E_SVFViewType._2D);
                        }
                        else if (
                            artifact.Type == Enums.E_ArtifactType.DWF_Model ||
                            artifact.Type == Enums.E_ArtifactType.IPT ||
                            artifact.Type == Enums.E_ArtifactType.SAT ||
                            artifact.Type == Enums.E_ArtifactType.SAT_V7)
                        {
                            svfFormat.ViewList.Add(ForgeAPI.Interface.Enums.E_SVFViewType._3D);
                        }

                        #endregion

                        inputs.Output.FormatList.Add(svfFormat);

                        outputs = service.AddJob(inputs);

                        if (outputs.Success() == false)
                        {
                            throw new Exception(outputs.FailureReason());
                        }
                    }

                    #endregion

                    #region Derivative Status Loop

                    SetStatus($"{prefix} - Waiting For Derivative Job Completion");

                    while (true)
                    {
                        ForgeAPI.Interface.ModelDerivative.Derivatives.IService             service;
                        ForgeAPI.Interface.ModelDerivative.Derivatives.GetManifest.IInputs  inputs;
                        ForgeAPI.Interface.ModelDerivative.Derivatives.GetManifest.IOutputs outputs;

                        inputs              = factory.CreateInputs <ForgeAPI.Interface.ModelDerivative.Derivatives.GetManifest.IInputs>(authToken);
                        inputs.URN          = artifact.URN;
                        inputs.URNIsEncoded = false;

                        service = container.Resolve <ForgeAPI.Interface.ModelDerivative.Derivatives.IService>();

                        outputs = service.GetManifest(inputs);

                        if (outputs.Success())
                        {
                            if (outputs.Status == ForgeAPI.Interface.Enums.E_TranslationStatus.Failed ||
                                outputs.Status == ForgeAPI.Interface.Enums.E_TranslationStatus.Timeout)
                            {
                                throw new Exception($"Derivative Processing Failed [{artifact.FileName}]");
                            }

                            if (outputs.Status == ForgeAPI.Interface.Enums.E_TranslationStatus.Success)
                            {
                                break;
                            }
                        }
                        else
                        {
                            throw new Exception(outputs.FailureReason());
                        }

                        Thread.Sleep(1000);
                    }

                    #endregion

                    index++;
                }
            }
        }