public void WindowSnap_OnWindowStateNormalRestoreButtonContentChange_NewContentEqualsRestore()
        {
            // Arrange
            ITerminalContext context = new TestTerminalContext();

            context.UserAccount = new UserPublic()
            {
                ID = 1, FirstName = "Adam", LastName = "A", OAuthID = "12345"
            };
            MainWindowViewModel viewModel = new MainWindowViewModel(context);
            var thread = new Thread(() =>
            {
                WindowModel windowModel = new WindowModel()
                {
                    OpenedWindow = new Window()
                };

                context.WindowManager.OpenedViews.Add(nameof(MainWindowViewModel), windowModel);

                // ACT
                viewModel.WindowSnap();

                // ASSERT
                viewModel.RestoreButtonContent.Should().Be("\xE739");
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
 private void Awake()
 {
     windowModelGameObject = GameObject.Find("WindowModel");
     windowModel           = windowModelGameObject.GetComponent <WindowModel>();
     spriteRenderer        = GetComponent <SpriteRenderer>();
     tileCollider          = GetComponent <BoxCollider2D>();
 }
Exemple #3
0
        /// <summary>
        /// 从所有子窗体中查找指定的类名
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="lpClassName"></param>
        /// <returns></returns>
        public static WindowModel FindChildWindow(WindowModel parent, string lpClassName, string title = null)
        {
            WindowModel res = WindowModel.Empty;

            FindChildWindow(parent, lpClassName, ref res, title);
            return(res);
        }
        public void WindowSnap_OnWindowStateNormalWindowBorderThicknessChange_NewThicknessEqualsZero()
        {
            // Arrange
            ITerminalContext context = new TestTerminalContext();

            context.UserAccount = new UserPublic()
            {
                ID = 1, FirstName = "Adam", LastName = "A", OAuthID = "12345"
            };
            MainWindowViewModel viewModel = new MainWindowViewModel(context);
            var thread = new Thread(() =>
            {
                WindowModel windowModel = new WindowModel()
                {
                    OpenedWindow = new Window()
                };

                context.WindowManager.OpenedViews.Add(nameof(MainWindowViewModel), windowModel);

                // ACT
                viewModel.WindowSnap();

                // ASSERT
                viewModel.GetWindowHandler().OpenedWindow.BorderThickness.Should().BeEquivalentTo(new Thickness(0));
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
Exemple #5
0
        public static WindowModel FindWindowStartsWith(string lpClassName, string lpWindowName, bool IsSelfProcessId = true)
        {
            WindowModel wm = WindowModel.Empty;
            var         ca = IntPtr.Zero;

            while (true)
            {
                var ip = User32Api.FindWindowEx(IntPtr.Zero, ca, lpClassName, null);
                if (ip != IntPtr.Zero)
                {
                    wm = new WindowModel(ip);
                    if (IsSelfProcessId && wm.ProcessId != ProcessId)
                    {
                        ca = ip;
                        continue;
                    }
                    if (wm.Title.StartsWith(lpWindowName))
                    {
                        return(wm);
                    }
                    else
                    {
                        ca = ip;
                    }
                }
                return(WindowModel.Empty);
            }
        }
Exemple #6
0
        /// <summary>
        /// Default constructor, creates an Instance of the WindowViewModel class
        /// </summary>
        public WindowViewModel(Window window)
        {
            this.m_Model = new WindowModel();

            this.m_Window         = window;
            this.m_Window.Loaded += (sender, e) => {
                ChildDataContext = new MainViewViewModel();
            };
            this.m_Window.Closed += (sender, e) => {
                if (m_EditTemplateWindow != null)
                {
                    m_EditTemplateWindow.Close();
                }

                ((MainViewViewModel)ChildDataContext).Closing();
                ChildDataContext = null;
            };


            // Setting up Commands for the Window, MainWindow.
            ExitCommand = new RelayCommand(() => {
                if (m_EditTemplateWindow != null)
                {
                    m_EditTemplateWindow.Close();
                }
                m_Window.Close();
            });
            EditTemplateCommand = new RelayCommand(() => {
                m_EditTemplateWindow         = new EditTemplateWindow();
                m_EditTemplateWindow.Closed += (sender, e) => { m_EditTemplateWindow = null; };
                m_EditTemplateWindow.Show();
            });
        }
Exemple #7
0
        public StopWindow()
        {
            this.model = new WindowModel();
            this.DataContext = this.model;

            this.InitializeComponent();
        }
Exemple #8
0
        /// <summary>
        /// Handler for Closed event, triggered when window is about to close.
        /// </summary>
        /// <param name="sender">Window object</param>
        /// <param name="model">Window model object related to the window</param>
        private void WindowClosed(object sender, EventArgs args, WindowModel model)
        {
            Window window = (Window)sender;

            window.Closed -= new EventHandler((s, e) => WindowClosed(s, e, model));

            OpenedViews.Remove(model);
        }
        public WindowViewModel(WindowModel windowModel)
        {
            // モデル設定
            _windowModel = windowModel;

            // ウィンドウ座標紐づけ
            X = _windowModel.ToReactivePropertyAsSynchronized(m => m.X);
            Y = _windowModel.ToReactivePropertyAsSynchronized(m => m.Y);
        }
Exemple #10
0
        /// <summary>
        /// Opens window for specific view model using name convention. Attaches event handler for Window.Closed.
        /// </summary>
        /// <param name="viewModel">View model name</param>
        public void OpenWindow(object viewModel)
        {
            if (!CheckIfAlreadyOpened(viewModel))
            {
                WindowModel model = CreateWindoModel(viewModel);

                model.OpenedWindow.Closed += new EventHandler((s, e) => WindowClosed(s, e, model));
                model.OpenedWindow.Show();
            }
        }
Exemple #11
0
        /// <summary>
        /// Creates new ModelWindow for Window of type T
        /// </summary>
        /// <typeparam name="T">Window type</typeparam>
        public void OpenWindow <T>() where T : Window
        {
            if (!CheckIfAlreadyOpened(typeof(T)))
            {
                WindowModel model = CreateWindoModelAndShow <T>();

                model.OpenedWindow.Closed += new EventHandler((s, e) => WindowClosed(s, e, model));
                model.OpenedWindow.Show();
            }
        }
Exemple #12
0
            /// <summary>
            /// 从所有子窗体中查找指定的类名
            /// </summary>
            /// <param name="parent"></param>
            /// <param name="lpClassName"></param>
            /// <returns></returns>
            public WindowModel FindChildWindow(string lpClassName, string title = null)
            {
                if (!this)
                {
                    return(Empty);
                }
                WindowModel res = Empty;

                WindowHelp.FindChildWindow(this, lpClassName, ref res, title);
                return(res);
            }
        internal WindowViewModel(IProgressBarManager progressBarManager, IFilesListManager filesListManager)
        {
            _model = new WindowModel(progressBarManager, filesListManager);
            _model.PropertyChanged += (s, e) => OnPropertyChanged(e.PropertyName);
            _model.SetEmptyState();

            SetZipState = new BindCommand(param =>
            {
                string fileName = FilesHelper.PickZipDialog();
                if (!string.IsNullOrEmpty(fileName))
                {
                    _model.SetZipState(fileName);
                }
            });

            SetFolderState = new BindCommand(param =>
            {
                string folderPath = FilesHelper.PickFolderDialog();
                if (!string.IsNullOrEmpty(folderPath))
                {
                    _model.SetFolderState(folderPath);
                }
            });

            SetEmptyState = new BindCommand(param =>
            {
                _model.SetEmptyState();
            });

            ProcessDragAndDrop = new BindCommand(param =>
            {
                string[] files = (string[])param;

                if (files == null || files.Length != 1)
                {
                    WindowHelper.ShowError("Drag-and-Drop support only one record.");
                }

                string path = files[0];

                if (FilesHelper.IsFolder(path))
                {
                    _model.SetFolderState(path);
                }
                else if (FilesHelper.IsZipFile(path))
                {
                    _model.SetZipState(path);
                }
                else
                {
                    WindowHelper.ShowError("File format isn't supported.");
                }
            });
        }
Exemple #14
0
        public static MenuBar Create(Window window, WindowModel model)
        {
            MenuBar result = new MenuBar();

            foreach (GenericMenu menuModel in model.Menus)
            {
                MenuItem menuContainer = new MenuItem(menuModel.Title);
                menuContainer.Submenu = BuildMenu(window, menuModel);
                result.Append(menuContainer);
            }
            return(result);
        }
        /// <summary>
        /// Insert <see cref="WindowModel"/> into database using parametrized query
        /// </summary>
        /// <param name="windowModel"></param>
        public async void InsertWindowModel(WindowModel windowModel)
        {
            OpenConnection();

            var query = "INSERT INTO [WindowModels] ([Left], [Top], [Width], [Height], [State]) VALUES (@Left, @Top, @Width, @Height, @State)";

            using (var command = new SQLiteCommand(query, _SQLiteConnection))
            {
                var parameter = new SQLiteParameter
                {
                    ParameterName = "@Left",
                    Value         = windowModel.Left,
                    DbType        = DbType.Double
                };
                command.Parameters.Add(parameter);

                parameter = new SQLiteParameter
                {
                    ParameterName = "@Top",
                    Value         = windowModel.Top,
                    DbType        = DbType.Double
                };
                command.Parameters.Add(parameter);

                parameter = new SQLiteParameter
                {
                    ParameterName = "@Width",
                    Value         = windowModel.Width,
                    DbType        = DbType.Double
                };
                command.Parameters.Add(parameter);

                parameter = new SQLiteParameter
                {
                    ParameterName = "@Height",
                    Value         = windowModel.Height,
                    DbType        = DbType.Double
                };
                command.Parameters.Add(parameter);

                parameter = new SQLiteParameter
                {
                    ParameterName = "@State",
                    Value         = windowModel.State,
                    DbType        = DbType.Int16
                };
                command.Parameters.Add(parameter);

                await command.ExecuteNonQueryAsync();
            }

            CloseConnection();
        }
Exemple #16
0
        /// <summary>
        /// Handler  for modal dialog window Closed event, triggered when dialog window is about to close.
        /// </summary>
        /// <param name="sender">Window object</param>
        /// <param name="model">>Window model object related to the window</param>
        private void ResultWindowClosed(object sender, EventArgs args, WindowModel model)
        {
            Window window = (Window)sender;

            window.Closed -= new EventHandler((s, e) => ResultWindowClosed(s, e, model));

            OpenedViews.Remove(model);

            var vm = window.DataContext as IResultViewModel;

            model.ReturnedObjectResult = vm.ObjectResult;
            model.IsValueReturned      = true;
        }
Exemple #17
0
        public bool Render(float rotation)
        {
            Matrix worldMatrix, viewMatrix, projectionMatrix;
            float  refractionScale;

            // First set the refraction scale to modify how much perturbation occurs in the glass.
            // Set the refraction scale for the glass shader.
            refractionScale = 0.01f;

            // Clear the buffers to begin the scene.
            D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

            // Get the world, view, and projection matrices from the camera and d3d objects.
            worldMatrix      = D3D.WorldMatrix;
            viewMatrix       = Camera.ViewMatrix;
            projectionMatrix = D3D.ProjectionMatrix;

            // Then render the 3D spinning cube scene as normal.
            // Multiply the world matrix by the rotation.
            Matrix.RotationY(rotation, out worldMatrix);

            // Put the cube model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Render the cube model using the texture shader.
            if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First()))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Now render the window model using the glass shader with the color texture, normal map, refraction render to texture, and refraction scale as input.
            // Translate to back where the window model will be rendered.
            Matrix.Translation(0.0f, 0.0f, -1.5f, out worldMatrix);

            // // Put the window model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            WindowModel.Render(D3D.DeviceContext);

            // Render the window model using the glass shader.
            if (!GlassShader.Render(D3D.DeviceContext, WindowModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, WindowModel.TextureCollection.Select(item => item.TextureResource).First(), WindowModel.TextureCollection.Select(item => item.TextureResource).ToArray()[1], RenderTexture.ShaderResourceView, refractionScale))
            {
                return(false);
            }

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
Exemple #18
0
        //window
        #region 创建窗口
        private static Window CreateWindow(string name, string screen, double left = -999999, double top = -999999, double width = -999999, double height = -999999, bool newViewModel = false)
        {
            //var selectWindow = GetWindowByScreen(name, screen);
            //if (selectWindow != null)
            //{
            //    return selectWindow;
            //}
            var viewModel = GetCreateViewModel(name, newViewModel);

            Type   type      = Type.GetType("ProjectEye.Views." + name);
            Window objWindow = (Window)type.Assembly.CreateInstance(type.FullName);

            objWindow.Uid         = name;
            objWindow.DataContext = viewModel;
            objWindow.Closed     += new EventHandler(window_closed);
            if (left > -999999)
            {
                objWindow.Left = left;
            }
            if (top > -999999)
            {
                objWindow.Top = top;
            }
            if (width > -999999)
            {
                objWindow.Width = width;
            }
            if (height > -999999)
            {
                objWindow.Height = height;
            }

            if (viewModel != null)
            {
                var basicModel = viewModel as IViewModel;
                if (basicModel != null)
                {
                    basicModel.ScreenName     = screen.Replace("\\", "");
                    basicModel.WindowInstance = objWindow;
                    basicModel.OnChanged();
                }
            }

            var windowModel = new WindowModel();

            windowModel.window = objWindow;
            windowModel.screen = screen;

            windowList.Add(windowModel);
            return(objWindow);
        }
Exemple #19
0
        /// <summary>
        /// Extracts window name from passed view model object and adds new WindowModel to OpenedViews list.
        /// </summary>
        /// <param name="viewModel">View model object</param>
        /// <returns>WindowModel object</returns>
        private WindowModel CreateWindoModel(object viewModel)
        {
            var modelType      = viewModel.GetType();
            var windowTypeName = modelType.Name.Replace("ViewModel", "View");
            var windowTypes    = from t in modelType.Assembly.GetTypes()
                                 where t.IsClass && t.Name == windowTypeName
                                 select t;

            WindowModel model = GetWindowModelFromWindowName(windowTypes.Single(), viewModel);

            OpenedViews.Add(model);

            return(model);
        }
        /// <summary>
        /// Get all <see cref="WindowModel"/> from database
        /// </summary>
        /// <returns></returns>
        public WindowModel GetWindowModel()
        {
            OpenConnection();

            WindowModel windowModels = new WindowModel();

            const string query = "SELECT * FROM [WindowModels]";

            using (_SQLiteConnection)
            {
                windowModels = _SQLiteConnection.QuerySingleOrDefault <WindowModel>(query);
            }

            return(windowModels);
        }
Exemple #21
0
        /// <summary>
        /// 查找窗口
        /// </summary>
        /// <param name="lpClassName"></param>
        /// <param name="lpWindowName"></param>
        /// <returns></returns>
        public static WindowModel FindWindow(string lpClassName, string lpWindowName, bool IsSelfProcessId = true)
        {
            WindowModel wm = WindowModel.Empty;
            var         ip = User32Api.FindWindow(lpClassName, lpWindowName);

            if (ip != IntPtr.Zero)
            {
                wm = new WindowModel(ip);
                if (IsSelfProcessId && wm.ProcessId != ProcessId)
                {
                    wm = WindowModel.Empty;
                }
            }
            return(wm);
        }
Exemple #22
0
        private void OnTimeElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            var mouse  = new MouseModel();
            var window = WindowModel.FindByPositionOrNull(mouse.Position.X, mouse.Position.Y);

            if (window != null)
            {
                var rect = window.GetRectangle();

                var clearBeforeDraw = !window.Equals(prevWindow);
                WindowModel.DrawRect(rect.X, rect.Y, rect.Width, rect.Height, clearBeforeDraw);

                prevWindow = window;
            }
        }
Exemple #23
0
        /// <summary>
        /// 截屏2
        /// </summary>
        /// <param name="windowModel"></param>
        /// <returns></returns>
        public static Bitmap BitBlt(WindowModel windowModel)
        {
            windowModel.SetAction();
            IntPtr   dcTmp    = Gdi32Help.CreateDC("DISPLAY", "DISPLAY", (IntPtr)null, (IntPtr)null);
            Graphics gScreen  = Graphics.FromHdc(dcTmp);
            Bitmap   image    = new Bitmap(windowModel.WindowRectangle.Width, windowModel.WindowRectangle.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Graphics gImage   = Graphics.FromImage(image);
            IntPtr   dcImage  = gImage.GetHdc();
            IntPtr   dcScreen = gScreen.GetHdc();

            Gdi32Help.BitBlt(dcImage, 0, 0, windowModel.WindowRectangle.Width, windowModel.WindowRectangle.Height, dcScreen, windowModel.WindowRectangle.Left, windowModel.WindowRectangle.Top, 0x00CC0020);
            gScreen.ReleaseHdc(dcScreen);
            gImage.ReleaseHdc(dcImage);
            return(image);
        }
Exemple #24
0
        public static List <WindowModel> GetWindow(string sortcode)
        {
            var query = "SELECT mat.Id, bkw.SortCode, mat.NameEnglish, mat.NameGerman, mat.NameFrench, mat.IdKbob, mat.Disposal, " +
                        "mat.IdDisposal, mat.Density, mat.DensityUnit, mat.Ubp13Embodied, mat.Ubp13EoL, mat.TotalEmbodied, " +
                        "mat.TotalEoL, mat.RenewableEmbodied, mat.RenewableEoL, mat.NonRenewableEmbodied, mat.NonRenewableEoL, " +
                        "mat.GHGEmbodied, mat.GHGEoL, bkw.FramePercentage, bw.Uvalue, bw.Gvalue " +
                        "FROM KbobMaterial mat " +
                        "LEFT JOIN dbo.BtkKbobWindow bkw " +
                        "ON mat.Id = bkw.IdKbob " +
                        "LEFT JOIN dbo.BtkWindows bw " +
                        "ON bkw.SortCode = bw.SortCode " +
                        "WHERE bkw.SortCode = '" + sortcode + "'";

            DBConnectComp         db       = new DBConnectComp();
            DataTable             data     = db.SelectData(query);
            var                   results  = new List <WindowModel>();
            IEnumerable <DataRow> dataRows = null;

            dataRows = from row in data.AsEnumerable()
                       select row;

            foreach (DataRow item in dataRows)
            {
                var tmp     = new WindowModel();
                var percent = (decimal)item[20] / 100;

                tmp.SortCode             = item[1].ToString();
                tmp.NameEnglish          = item[2].ToString();
                tmp.NameGerman           = item[3].ToString();
                tmp.NameFrench           = item[4].ToString();
                tmp.UBP13Embodied        = (decimal)item[10] * percent;
                tmp.UBP13EoL             = (decimal)item[11] * percent;
                tmp.TotalEmbodied        = (decimal)item[12] * percent;
                tmp.TotalEoL             = (decimal)item[13] * percent;
                tmp.RenewableEmbodied    = (decimal)item[14] * percent;
                tmp.RenewableEoL         = (decimal)item[15] * percent;
                tmp.NonRenewableEmbodied = (decimal)item[16] * percent;
                tmp.NonRenewableEoL      = (decimal)item[17] * percent;
                tmp.GHGEmbodied          = (decimal)item[18] * percent;
                tmp.GHGEoL = (decimal)item[19] * percent;
                tmp.Uvalue = item[21] == null ? 0 : (decimal)item[21];
                tmp.Gvalue = item[22] == null ? 0 : (decimal)item[22];

                results.Add(tmp);
            }

            return(results);
        }
Exemple #25
0
        public NewWindow()
        {
            this.model = new WindowModel();

            this.DataContext = this.model;
            this.InitializeComponent();

            this.pasteContent = (PasteControl)this.data.Content;
            this.pasteContent.OnLog = this.logging.AddLog;

            this.linkListContent = (LinkListControl)this.Resources["Select"];
            this.linkListContent.OnLog = this.logging.AddLog;

            this.resourceListContent = (ResourceListControl)this.Resources["Confirm"];
            this.resourceListContent.OnLog = this.logging.AddLog;
        }
Exemple #26
0
 internal static void FindChildWindow(WindowModel parent, string lpClassName, ref WindowModel res, string title = null)
 {
     foreach (var p in parent.Child)
     {
         if (p.ClassName == lpClassName && (title == null || title == p.Title))
         {
             res = p;
             return;
         }
         if (res)
         {
             return;
         }
         FindChildWindow(p, lpClassName, ref res, title);
     }
 }
Exemple #27
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public MainWindowViewModel()
        {
            _db = new ApplicationContext();

            var window = _db.GetWindowModel();

            if (window == null)
            {
                CurrentWindow = new WindowModel(1, 400, 100, 1000, 700, 0);
                _db.InsertWindowModel(CurrentWindow);
            }
            else
            {
                CurrentWindow = window;
            }
        }
Exemple #28
0
        /// <summary>
        /// Creates new WindowModel based on Window type.
        /// </summary>
        /// <typeparam name="T">Window type</typeparam>
        /// <returns>WindowModel</returns>
        private WindowModel CreateWindoModelAndShow <T>() where T : Window
        {
            Window      window = (T)Activator.CreateInstance(typeof(T));
            WindowModel model  = new WindowModel()
            {
                OpenedWindow           = window,
                AssignedViewModel      = window.DataContext,
                IsValueReturned        = false,
                ReturnedDialogResult   = null,
                ReturnedObjectResult   = null,
                ReturnedFilePathResult = null
            };

            OpenedViews.Add(model);

            return(model);
        }
Exemple #29
0
        /// <summary>
        /// 截屏1
        /// </summary>
        /// <param name="windowModel"></param>
        /// <returns></returns>
        public static Bitmap PrintWindow(WindowModel windowModel)
        {
            IntPtr hscrdc  = User32Api.GetWindowDC(windowModel.IntPtr); //返回hWnd参数所指定的窗口的设备环境。
            int    width   = windowModel.WindowRectangle.Width;
            int    height  = windowModel.WindowRectangle.Height;
            IntPtr hbitmap = Gdi32Help.CreateCompatibleBitmap(hscrdc, width, height); //该函数创建与指定的设备环境相关的设备兼容的位图
            IntPtr hmemdc  = Gdi32Help.CreateCompatibleDC(hscrdc);                    //该函数创建一个与指定设备兼容的内存设备上下文环境(DC)

            Gdi32Help.SelectObject(hmemdc, hbitmap);                                  //该函数选择一对象到指定的设备上下文环境中,该新对象替换先前的相同类型的对象
            User32Api.PrintWindow(windowModel.IntPtr, hmemdc, 0);
            Bitmap bmp = Bitmap.FromHbitmap(hbitmap);

            //Clipboard.SetImage(bmp);
            Gdi32Help.DeleteDC(hscrdc); //删除用过的对象  
            Gdi32Help.DeleteDC(hmemdc); //删除用过的对象  
            return(bmp);
        }
Exemple #30
0
        /// <summary>
        /// Creates instance of new window basing on window type, returns new instance of WindowModel object.
        /// </summary>
        /// <param name="type">Window type</param>
        /// <param name="viewModel">View model related to the window</param>
        /// <returns>WindowModel object</returns>
        private WindowModel GetWindowModelFromWindowName(Type type, object viewModel)
        {
            Window window = (Window)Activator.CreateInstance(type);

            window.DataContext = viewModel;

            WindowModel model = new WindowModel()
            {
                OpenedWindow           = window,
                AssignedViewModel      = viewModel,
                IsValueReturned        = false,
                ReturnedDialogResult   = null,
                ReturnedObjectResult   = null,
                ReturnedFilePathResult = null
            };

            return(model);
        }
Exemple #31
0
 /// <summary>
 /// Method to invoke when the SaveConfigCommand command is executed.
 /// </summary>
 private async Task OnSaveConfigCommandExecuteAsync()
 {
     try
     {
         var saveFileService = ServiceLocator.Default.ResolveType <ISaveFileService>();
         saveFileService.Filter = "Kflop Loggging Configuration File|*.kfl";
         if (!string.IsNullOrEmpty(SaveConfigPath))
         {
             saveFileService.InitialDirectory = Path.GetDirectoryName(SaveConfigPath);
             if (!Directory.Exists(saveFileService.InitialDirectory))
             {
                 saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
             }
             saveFileService.FileName = Path.GetFileNameWithoutExtension(SaveConfigPath);
         }
         else
         {
             saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
         }
         if (saveFileService.DetermineFile())
         {
             if (SaveConfigPath != saveFileService.FileName)
             {
                 SaveConfigPath = saveFileService.FileName;
             }
             using (var fileStream = File.Create(saveFileService.FileName))
             {
                 var configuration = new SerializationConfiguration
                 {
                     Culture = new System.Globalization.CultureInfo("en-US")
                 };
                 WindowModel.Save(fileStream, Catel.Data.SerializationMode.Xml, configuration);
             }
             LogTo.Info("Saved configuration to: {0}", SaveConfigPath);
         }
     }
     catch (Exception ex)
     {
         string errmsg = string.Format("Error saving configuration: {0}", ex.Message);
         LogTo.Error(errmsg);
         await Shared.Utility.ShowErrorMsgAsync(this, errmsg);
     }
 }
Exemple #32
0
        /// <summary>
        /// Opens new window for specific view model using name convention. Window may return object. Attaches event handler for Window.Closed.
        /// </summary>
        /// <param name="viewModel">View model name</param>
        /// <returns>Object</returns>
        public async Task <object> OpenResultWindow(object viewModel)
        {
            if (!CheckIfAlreadyOpened(viewModel))
            {
                WindowModel model = CreateWindoModel(viewModel);

                model.OpenedWindow.Closed += new EventHandler((s, e) => ResultWindowClosed(s, e, model));
                model.OpenedWindow.ShowDialog();

                while (!model.IsValueReturned)
                {
                    await Task.Delay(100);
                }

                return(model.ReturnedObjectResult);
            }

            return(null);
        }
Exemple #33
0
 public static ResourceModel FromResource(Resource resource, WindowModel owner)
 {
     return new ResourceModel
     {
         Owner = owner,
         Source = resource,
         Name = resource.Name,
         Hosting = resource.Hosting,
         Size = resource.Size
     };
 }