public static bool NeedsRebuild(IInstanceBuilderContext context, ViewNode viewNode, string closedDocumentPath)
        {
            bool flag;
            bool flag1;

            if (!PlatformTypes.UserControl.Equals(viewNode.Type))
            {
                DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode;
                IProperty             property     = documentNode.TypeResolver.ResolveProperty(DesignTimeProperties.ClassProperty);
                if (documentNode != null && !documentNode.Properties.Contains(property))
                {
                    string xamlSourcePath = viewNode.Type.XamlSourcePath;
                    if (!string.IsNullOrEmpty(xamlSourcePath))
                    {
                        if (closedDocumentPath != null && closedDocumentPath.Equals(xamlSourcePath))
                        {
                            return(true);
                        }
                        uint?           changeStampWhenInstantiated = null;
                        IPreviewControl instance = viewNode.Instance as IPreviewControl;
                        if (instance != null)
                        {
                            changeStampWhenInstantiated = instance.ChangeStampWhenInstantiated;
                        }
                        IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode;
                        if (instantiatedElementViewNode != null)
                        {
                            foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                            {
                                instance = instantiatedElement as IPreviewControl;
                                if (instance == null)
                                {
                                    continue;
                                }
                                if (changeStampWhenInstantiated.HasValue && instance.ChangeStampWhenInstantiated.HasValue)
                                {
                                    uint?nullable = changeStampWhenInstantiated;
                                    uint?changeStampWhenInstantiated1 = instance.ChangeStampWhenInstantiated;
                                    if ((nullable.GetValueOrDefault() != changeStampWhenInstantiated1.GetValueOrDefault() ? true : nullable.HasValue != changeStampWhenInstantiated1.HasValue))
                                    {
                                        flag = true;
                                        return(flag);
                                    }
                                }
                                if (changeStampWhenInstantiated.HasValue)
                                {
                                    continue;
                                }
                                changeStampWhenInstantiated = instance.ChangeStampWhenInstantiated;
                            }
                        }
                        try
                        {
                            XamlDocument documentRoot = (XamlDocument)context.DocumentRootResolver.GetDocumentRoot(xamlSourcePath);
                            if (documentRoot == null)
                            {
                                return(false);
                            }
                            else
                            {
                                bool flag2 = UserControlInstanceBuilderHelper.ShouldUseDocumentForPreview(context, documentRoot);
                                if (changeStampWhenInstantiated.HasValue != flag2)
                                {
                                    flag1 = true;
                                }
                                else if (!changeStampWhenInstantiated.HasValue)
                                {
                                    flag1 = false;
                                }
                                else
                                {
                                    uint?nullable1   = changeStampWhenInstantiated;
                                    uint changeStamp = documentRoot.ChangeStamp;
                                    flag1 = (nullable1.GetValueOrDefault() != changeStamp ? true : !nullable1.HasValue);
                                }
                                flag = flag1;
                            }
                        }
                        catch (IOException oException)
                        {
                            return(false);
                        }
                        return(flag);
                    }
                }
            }
            return(false);
        }
示例#2
0
        private static void PreviewFile(string path, object file, Type PreviewType, object caller, System.Windows.Point?pos)
        {
            System.Threading.Thread tt = new System.Threading.Thread(delegate()
            {
                try
                {
                    if (file != null || File.Exists(path) || Directory.Exists(path))
                    {
                        if (PreviewType == null)
                        {
                            MessageBox.Show("Preview not available");
                        }
                        else
                        {
                            Type t = PreviewType;
                            if (t.GetInterface("IPreviewControl") != null)
                            {
                                Form f       = new Form();
                                Panel pnl    = new Panel();
                                pnl.Dock     = System.Windows.Forms.DockStyle.Fill;
                                pnl.Location = new System.Drawing.Point(0, 0);
                                pnl.Name     = "pnlPreview";
                                pnl.Size     = new System.Drawing.Size(96, 77);
                                pnl.TabIndex = 1;
                                f.Controls.Add(pnl);
                                if (pnl.Controls.Count > 0)
                                {
                                    Control pOld = pnl.Controls[0];
                                    pOld.Dispose();
                                }
                                pnl.Controls.Clear();
                                IPreviewControl p = (IPreviewControl)Activator.CreateInstance(t);
                                pnl.Controls.Add((Control)p);
                                ((Control)p).Dock = DockStyle.Fill;

                                f.Load += delegate(object sender, EventArgs e)
                                {
                                    p.Preview(path);
                                };
                                f.StartPosition = FormStartPosition.CenterScreen;
                                f.ControlBox    = false;
                                f.Text          = "";
                                //f.SetDesktopLocation(
                                //f.FormBorderStyle = FormBorderStyle.None;
                                f.PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs e)
                                {
                                    if (e.KeyCode == Keys.Space)
                                    {
                                        f.Close();
                                    }
                                };
                                ((Control)p).PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs e)
                                {
                                    if (e.KeyCode == Keys.Space)
                                    {
                                        f.Close();
                                    }
                                };
                                f.FormClosing += delegate(object sender, FormClosingEventArgs e)
                                {
                                    if (OpenPreview == f)
                                    {
                                        OpenPreview = null;
                                    }
                                };
                                OpenPreview = f;
                                Application.Run(f);
                            }
                            else
                            {
                                IPreview p  = (IPreview)Activator.CreateInstance(t);
                                OpenPreview = p;
                                p.Preview(file, caller, pos);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("An error occured while loading preview control");
                }
            });
            tt.SetApartmentState(System.Threading.ApartmentState.STA);
            tt.Start();
        }