Esempio n. 1
0
        private static void OnSelectedEntityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var ctrl = d as MainWindow;

            if (ctrl == null)
            {
                return;
            }
            switch (e.Property.Name)
            {
            case "Model":
                var model = e.NewValue as IfcStore;
                if (model != null && model.FileName != null)
                {
                    try
                    {
                        ctrl.ModelFacility = FacilityFromIfcConverter.FacilityFromModel(model);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error in generating Facility from model " + model.FileName, ex);
                        ctrl.ModelFacility = null;
                    }
                }
                else
                {
                    ctrl.ModelFacility = null;
                }
                ctrl.TestValidation();
                break;

            case "SelectedEntity":
                break;
            }
        }
 private object GetFacility(RunWorkerCompletedEventArgs args)
 {
     if (args.Result is IfcStore)
     {
         // a valid bim model
         //
         _model           = args.Result as IfcStore;
         ActivityProgress = 0;
         // prepare the facility
         SubmissionFacility = FacilityFromIfcConverter.FacilityFromModel(_model);
         return(SubmissionFacility);
     }
     else if (args.Result is Facility) //all ok; this is the model facility
     {
         return(args.Result);
     }
     return(null);
 }
Esempio n. 3
0
        private void CreateWorker()
        {
            _worker = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };
            _worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                ActivityProgress = args.ProgressPercentage;
                ActivityStatus   = (string)args.UserState;
                Debug.WriteLine("{0}% {1}", args.ProgressPercentage, (string)args.UserState);
            };

            _worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (args.Result is XbimModel) //all ok
                {
                    _model           = args.Result as XbimModel;
                    ActivityProgress = 0;
                    // prepare the facility
                    SubmissionFacility = FacilityFromIfcConverter.FacilityFromModel(_model);

                    if (SubmissionFacility == null)
                    {
                        return;
                    }
                    var jsonFileName = Path.ChangeExtension(SubmissionFileSource, "json");
                    if (!File.Exists(jsonFileName))
                    {
                        SubmissionFacility.WriteJson(jsonFileName);
                    }

                    ValidateLoadedFacilities();
                }
                else if (args.Result is Facility) //all ok; this is the model facility
                {
                    ValidateLoadedFacilities();
                }
                else //we have a problem
                {
                    var errMsg = args.Result as String;
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        ActivityStatus = "Error Opening File";
                    }
                    if (args.Result is Exception)
                    {
                        var sb     = new StringBuilder();
                        var ex     = args.Result as Exception;
                        var indent = "";
                        while (ex != null)
                        {
                            sb.AppendFormat("{0}{1}\n", indent, ex.Message);
                            ex      = ex.InnerException;
                            indent += "\t";
                        }
                        ActivityStatus = "Error Opening Ifc File\r\n\r\n" + sb;
                    }
                    ActivityProgress = 0;
                    ActivityStatus   = "Error/Ready";
                }
            };
        }