Ejemplo n.º 1
0
            public IpMappingListViewItem(IpMappingItem item, HttpApiPage page)
                : base(item.Address)
            {
                Item  = item;
                _page = page;
                SubItems.Add(new ListViewSubItem(this, item.Port));
                SubItems.Add(new ListViewSubItem(this, BindingUtility.GetAppName(item.AppId)));
                SubItems.Add(new ListViewSubItem(this, item.AppId));
                SubItems.Add(new ListViewSubItem(this, item.Hash));
                SubItems.Add(new ListViewSubItem(this, item.Store));

                string flag = "Broken";

                using X509Store personal = new X509Store(item.Store, StoreLocation.LocalMachine);
                try
                {
                    personal.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                    var found = personal.Certificates.Find(X509FindType.FindByThumbprint, item.Hash, false);
                    if (found.Count > 0)
                    {
                        flag = "Healthy";
                    }

                    personal.Close();
                }
                catch (CryptographicException)
                {
                    flag = "Unknown";
                }

                SubItems.Add(new ListViewSubItem(this, flag));
            }
        public static void HandleBindingDragAndDrop(TrackAsset dropTarget, Type requiredBindingType)
        {
            var objectBeingDragged = DragAndDrop.objectReferences[0];

            var action = BindingUtility.GetBindingAction(requiredBindingType, objectBeingDragged);
            DragAndDrop.visualMode = action == BindingAction.DoNotBind
                ? DragAndDropVisualMode.Rejected
                : DragAndDropVisualMode.Link;

            if (action == BindingAction.DoNotBind || Event.current.type != EventType.DragPerform)
                return;

            var director = TimelineEditor.inspectedDirector;

            switch (action)
            {
                case BindingAction.BindDirectly:
                {
                    BindingUtility.Bind(director, dropTarget, objectBeingDragged);
                    break;
                }
                case BindingAction.BindToExistingComponent:
                {
                    var gameObjectBeingDragged = objectBeingDragged as GameObject;
                    Debug.Assert(gameObjectBeingDragged != null, "The object being dragged was detected as being a GameObject");

                    BindingUtility.Bind(director, dropTarget, gameObjectBeingDragged.GetComponent(requiredBindingType));
                    break;
                }
                case BindingAction.BindToMissingComponent:
                {
                    var gameObjectBeingDragged = objectBeingDragged as GameObject;
                    Debug.Assert(gameObjectBeingDragged != null, "The object being dragged was detected as being a GameObject");

                    var typeNameOfComponent = requiredBindingType.ToString().Split(".".ToCharArray()).Last();
                    var bindMenu = new GenericMenu();

                    bindMenu.AddItem(
                        EditorGUIUtility.TextContent("Create " + typeNameOfComponent + " on " + gameObjectBeingDragged.name),
                        false,
                        nullParam => BindingUtility.Bind(director, dropTarget, Undo.AddComponent(gameObjectBeingDragged, requiredBindingType)),
                        null);

                    bindMenu.AddSeparator("");
                    bindMenu.AddItem(EditorGUIUtility.TrTextContent("Cancel"), false, userData => {}, null);
                    bindMenu.ShowAsContext();

                    break;
                }
                default:
                {
                    //no-op
                    return;
                }
            }

            DragAndDrop.AcceptDrag();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks the configuration elements and redirects to an error page if something is missing or wrong.
        /// </summary>
        private void CheckConfiguration()
        {
            if (Validated)
            {
                return;
            }

            Validated = BindingUtility.ValidateConfiguration(ConfigurationFactory.Instance.Configuration);
        }
        /// <summary>
        /// Checks the configuration elements and redirects to an error page if something is missing or wrong.
        /// </summary>
        private void CheckConfiguration()
        {
            if (Validated)
            {
                return;
            }

            Validated = BindingUtility.ValidateConfiguration();
        }
        public static DragAndDropVisualMode HandleHierarchyPaneDragAndDrop(IEnumerable <UnityObject> objectsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, PlayableDirector director, TypeResolver typeResolver, TrackAsset insertBefore = null)
        {
            if (timeline == null)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            // if we are over a target track, defer to track binding system (implemented in TrackGUIs), unless we are a groupTrack
            if (targetTrack != null && (targetTrack as GroupTrack) == null)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (targetTrack != null && targetTrack.lockedInHierarchy)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            var tracksWithBinding = objectsBeingDropped.SelectMany(TypeUtility.GetTracksCreatableFromObject).Distinct();

            if (!tracksWithBinding.Any())
            {
                return(DragAndDropVisualMode.None);
            }

            if (perform)
            {
                Action <Type> onResolve = trackType =>
                {
                    foreach (var obj in objectsBeingDropped)
                    {
                        if (!obj.IsPrefab() && TypeUtility.IsTrackCreatableFromObject(obj, trackType))
                        {
                            var newTrack = TimelineHelpers.CreateTrack(timeline, trackType, targetTrack, string.Empty);
                            if (insertBefore != null)
                            {
                                if (targetTrack != null)
                                {
                                    targetTrack.MoveLastTrackBefore(insertBefore);
                                }
                                else
                                {
                                    timeline.MoveLastTrackBefore(insertBefore);
                                }
                            }
                            BindingUtility.BindWithEditorValidation(director, newTrack, obj);
                        }
                    }
                    TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
                };
                typeResolver(tracksWithBinding, onResolve, k_SelectTrackWithBinding);
            }

            return(DragAndDropVisualMode.Copy);
        }
Ejemplo n.º 6
0
 public IpMappingListViewItem(IpMappingItem item, HttpApiPage page)
     : base(item.Address)
 {
     Item  = item;
     _page = page;
     SubItems.Add(new ListViewSubItem(this, item.Port));
     SubItems.Add(new ListViewSubItem(this, BindingUtility.GetAppName(item.AppId)));
     SubItems.Add(new ListViewSubItem(this, item.AppId));
     SubItems.Add(new ListViewSubItem(this, item.Hash));
     SubItems.Add(new ListViewSubItem(this, item.Store));
 }
Ejemplo n.º 7
0
        public void CheckError()
        {
            var selectedTransform = Selection.activeTransform;

            if (selectedTransform == null)
            {
                Debug.LogError("No transform is selected");
                return;
            }
            else
            {
                var transformPath = GetGameObjectPath(selectedTransform);
                Debug.LogFormat("Check DataBinding for {0}", transformPath);
            }

            // get all binders
            var binderList = selectedTransform.GetComponentsInChildren <MonoBehaviour>(true).Where(x => x.GetType().IsBinder());

            var usedList = new List <IDataContext>();

            // iterate binder list
            foreach (var item in binderList)
            {
                // get data context
                var dc = BindingUtility.FindDataContext(item.transform);
                if (dc == null)
                {
                    continue;
                }

                if (!usedList.Contains(dc))
                {
                    usedList.Add(dc);
                }
            }

            // get all data context
            var dataContextList = selectedTransform.GetComponentsInChildren <IDataContext>(true);

            foreach (var item in dataContextList)
            {
                if (!usedList.Contains(item))
                {
                    var    go   = item as MonoBehaviour;
                    string path = GetGameObjectPath(go.transform);
                    string info = string.Format("Find unused DataContext, path={0}", path);
                    Debug.LogWarning(info, go);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks the configuration elements and redirects to an error page if something is missing or wrong.
        /// </summary>
        /// <param name="ctx"></param>
        private void CheckConfiguration(HttpContext ctx)
        {
            if (validated)
            {
                return;
            }

            string errorMessage;

            validated = BindingUtility.ValidateConfiguration(out errorMessage);
            if (!validated)
            {
                HandleError(ctx, errorMessage);
            }
        }
Ejemplo n.º 9
0
        private void RefreshList()
        {
            BindingUtility.SyncListToDictionary(inventory.ItemList, viewModelDictionary, pendingList, AddItem, RemoveItem);

            BindingUtility.SyncListOrder(inventory.ItemList, viewModelList, viewModelDictionary, pendingList);

            if (selectedItem != null)
            {
                // check if selected item is removed
                if (!viewModelDictionary.ContainsKey(selectedItem))
                {
                    SelectItem(null);
                }
            }
        }
Ejemplo n.º 10
0
        private List <string> GetBindingSourceList(MonoBehaviour monoObject)
        {
            var list = new List <string>();

            var type = monoObject.GetType();

            // get all public fields end with 'path'
            var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance).Where(x => x.FieldType == typeof(string) && x.Name.EndsWith("path", StringComparison.InvariantCultureIgnoreCase));

            foreach (var field in fields)
            {
                var value = field.GetValue(monoObject) as string;
                if (value != null)
                {
                    list.Add(value);
                }
            }

            // get binder attribute
            var binderAttribute = BindingUtility.GetAttribute <BinderAttribute>(type, false);

            if (!string.IsNullOrEmpty(binderAttribute.SourcePathListMethod))
            {
                var method = type.GetMethod(binderAttribute.SourcePathListMethod, BindingFlags.Public | BindingFlags.Instance);

                if (method != null)
                {
                    // call method to get path list
                    var sourcePathList = method.Invoke(monoObject, null) as IEnumerable <string>;
                    list.AddRange(sourcePathList);
                }
            }

            var resultList = new List <string>();

            // remove empty
            foreach (var item in list)
            {
                if (string.IsNullOrEmpty(item))
                {
                    continue;
                }

                resultList.Add(item);
            }

            return(resultList);
        }
 protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
 {
     return(new[]
     {
         new ServiceInstanceListener(
             (context) =>
         {
             // Use HTTP binding so that the client that coordinates the end-to-end test
             // can talk to this service via reverse proxy.
             return new WcfCommunicationListener <ILoadDriver>(
                 context,
                 this,
                 BindingUtility.CreateHttpBinding(),
                 (string)null);
         })
     });
 }
Ejemplo n.º 12
0
        private void CbAddressTextChanged(object sender, EventArgs e)
        {
            if (Helper.IsRunningOnMono())
            {
                return;
            }

            var toElevate = BindingUtility.Verify(cbType.Text, cbAddress.Text, txtPort.Text, cbCertificates.SelectedItem as CertificateInfo);

            btnOK.Enabled = toElevate != null;
            if (!toElevate.HasValue || !toElevate.Value)
            {
                JexusManager.NativeMethods.RemoveShieldFromButton(btnOK);
            }
            else
            {
                JexusManager.NativeMethods.TryAddShieldToButton(btnOK);
            }
        }
Ejemplo n.º 13
0
        private void Create()
        {
            using var dialog = new NewReservedUrlDialog(Module, this);
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (BindingUtility.AddReservedUrl(dialog.Item.UrlPrefix))
            {
                Items.Add(dialog.Item);
                OnHttpApiSettingsSaved();
            }
            else
            {
                var service = (IManagementUIService)GetService(typeof(IManagementUIService));
                service.ShowMessage("Invalid URL prefix input is detected.", Name, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 14
0
        void RefreshList()
        {
            // sync collection
            BindingUtility.SyncListToDictionary(inventory.ItemList, controlDictionary, pendingList, AddItemView, RemoveItemView);

            // update order
            BindingUtility.SyncViewOrder(inventory.ItemList, controlDictionary, pendingList);

            // workaround for update grid view
            LayoutRebuilder.MarkLayoutForRebuild(container);

            if (selectedItem != null)
            {
                // check if selected item is removed
                if (!controlDictionary.ContainsKey(selectedItem))
                {
                    SelectItem(null);
                }
            }
        }
Ejemplo n.º 15
0
        private void TxtNameTextChanged(object sender, EventArgs e)
        {
            if (Helper.IsRunningOnMono())
            {
                return;
            }

            var toElevate = BindingUtility.Verify(cbType.Text, cbAddress.Text, txtPort.Text, cbCertificates.SelectedItem as CertificateInfo);

            btnOK.Enabled = toElevate != null && !string.IsNullOrWhiteSpace(txtName.Text) &&
                            !string.IsNullOrWhiteSpace(txtPath.Text);
            if (!toElevate.HasValue || !toElevate.Value)
            {
                NativeMethods.RemoveShieldFromButton(btnOK);
            }
            else
            {
                NativeMethods.TryAddShieldToButton(btnOK);
            }
        }
        private static ILoadDriver[] CreateLoadDrivers(string reverseProxyAddress, ServicePartitionList partitionList)
        {
            ILoadDriver[] loadDrivers = new ILoadDriver[partitionList.Count];
            int           i           = 0;

            foreach (Partition partition in partitionList)
            {
                // We use the reverse proxy to communicate with each partition of the
                // load driver service (which hosts the clients).
                string uri = GetUriExposedByReverseProxy(
                    LoadDriverServiceUri.AbsoluteUri,
                    partition,
                    reverseProxyAddress);
                loadDrivers[i] = ChannelFactory <ILoadDriver> .CreateChannel(
                    BindingUtility.CreateHttpBinding(),
                    new EndpointAddress(uri));

                i++;
            }
            return(loadDrivers);
        }
Ejemplo n.º 17
0
        private void CreateBinding()
        {
            if (updateMode == UpdateMode.SetProperty)
            {
                // create one way to source binding
                binding = new Binding(valuePath, this, "AnalogValue", Binding.BindingMode.OneWayToSource);
                binding.SetFlags(Binding.ControlFlags.ResetSourceValue);
            }
            else if (updateMode == UpdateMode.CallAction)
            {
                // create one way binding
                binding = new Binding(valueChangedPath, this, "AnalogValueChanged");
                binding.SetFlags(Binding.ControlFlags.ResetTargetValue);
            }
            else
            {
                Debug.LogError("Unsupported update mode");
                return;
            }

            BindingUtility.AddBinding(binding, transform, out dataContext);
        }
Ejemplo n.º 18
0
 void OnDestroy()
 {
     BindingUtility.RemoveBinding(binding, dataContext);
 }
Ejemplo n.º 19
0
        public NewSiteDialog(IServiceProvider serviceProvider, SiteCollection collection)
            : base(serviceProvider)
        {
            InitializeComponent();
            cbType.SelectedIndex = 0;
            if (collection == null)
            {
                throw new InvalidOperationException("null collection");
            }

            if (collection.Parent == null)
            {
                throw new InvalidOperationException("null server for site collection");
            }

            btnBrowse.Visible = collection.Parent.IsLocalhost;
            txtPool.Text      = collection.Parent.ApplicationDefaults.ApplicationPoolName;
            btnChoose.Enabled = collection.Parent.Mode != WorkingMode.Jexus;
            txtHost.Text      = collection.Parent.Mode == WorkingMode.IisExpress ? "localhost" : string.Empty;
            DialogHelper.LoadAddresses(cbAddress);
            if (!collection.Parent.SupportsSni)
            {
                cbSniRequired.Enabled = false;
            }

            var container = new CompositeDisposable();

            FormClosed += (sender, args) => container.Dispose();

            container.Add(
                Observable.FromEventPattern <EventArgs>(cbType, "SelectedIndexChanged")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                txtPort.Text            = cbType.Text == "http" ? "80" : "443";
                txtCertificates.Visible = cbType.SelectedIndex == 1;
                cbSniRequired.Visible   = cbType.SelectedIndex == 1;
                cbCertificates.Visible  = cbType.SelectedIndex == 1;
                btnSelect.Visible       = cbType.SelectedIndex == 1;
                btnView.Visible         = cbType.SelectedIndex == 1;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnBrowse, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                DialogHelper.ShowBrowseDialog(txtPath);
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                foreach (var ch in SiteCollection.InvalidSiteNameCharacters())
                {
                    if (txtName.Text.Contains(ch))
                    {
                        MessageBox.Show("The site name cannot contain the following characters: '\\, /, ?, ;, :, @, &, =, +, $, ,, |, \", <, >'.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }

                foreach (var ch in SiteCollection.InvalidSiteNameCharactersJexus())
                {
                    if (txtName.Text.Contains(ch) || txtName.Text.StartsWith("~"))
                    {
                        MessageBox.Show("The site name cannot contain the following characters: '~,  '.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }

                if (!collection.Parent.Verify(txtPath.Text))
                {
                    MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (!IPEndPointIsValid(out IPAddress address, out int port))
                {
                    return;
                }

                var invalid = "\"/\\[]:|<>+=;,?*$%#@{}^`".ToCharArray();
                foreach (var ch in invalid)
                {
                    if (txtHost.Text.Contains(ch))
                    {
                        MessageBox.Show("The specified host name is incorrect. The host name must use a valid host name format and cannot contain the following characters: \"/\\[]:|<>+=;,?*$%#@{}^`. Example: www.contoso.com.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }

                if (collection.Parent.Mode == WorkingMode.IisExpress)
                {
                    if (txtHost.Text != "localhost")
                    {
                        MessageBox.Show(
                            "The specific host name is not recommended for IIS Express. The host name should be localhost.",
                            Text,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                    }
                }

                long largestId = 0;
                foreach (Site site in collection)
                {
                    if (site.Id > largestId)
                    {
                        largestId = site.Id;
                    }
                }

                largestId++;

                NewSite = new Site(collection)
                {
                    Name = txtName.Text, Id = largestId
                };
                var host    = txtHost.Text.DisplayToHost();
                var info    = cbType.Text == "https" ? (CertificateInfo)cbCertificates.SelectedItem : null;
                var binding = new Binding(
                    cbType.Text,
                    string.Format("{0}:{1}:{2}", address.AddressToDisplay(), port, host.HostToDisplay()),
                    info?.Certificate.GetCertHash() ?? new byte[0],
                    info?.Store,
                    cbSniRequired.Checked ? SslFlags.Sni : SslFlags.None,
                    NewSite.Bindings);
                if (collection.FindDuplicate(binding, null, null) != false)
                {
                    var result = MessageBox.Show(string.Format("The binding '{0}' is assigned to another site. If you assign the same binding to this site, you will only be able to start one of the sites. Are you sure that you want to add this duplicate binding?", binding), Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result != DialogResult.Yes)
                    {
                        collection.Remove(NewSite);
                        return;
                    }
                }

                if (collection.Parent.Mode == WorkingMode.IisExpress)
                {
                    var result = binding.FixCertificateMapping(info?.Certificate);
                    if (!string.IsNullOrEmpty(result))
                    {
                        collection.Remove(NewSite);
                        MessageBox.Show(string.Format("The binding '{0}' is invalid: {1}", binding, result), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                var app  = NewSite.Applications.Add(Application.RootPath, txtPath.Text);
                app.Name = string.Empty;
                app.ApplicationPoolName = txtPool.Text;
                NewSite.Bindings.Add(binding);
                DialogResult = DialogResult.OK;
            }));

            var certificatesSelected = Observable.FromEventPattern <EventArgs>(cbCertificates, "SelectedIndexChanged");

            container.Add(
                certificatesSelected
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                btnView.Enabled = cbCertificates.SelectedIndex > 0;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(txtName, "TextChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(txtPath, "TextChanged"))
                .Merge(Observable.FromEventPattern <EventArgs>(txtPort, "TextChanged"))
                .Merge(Observable.FromEventPattern <EventArgs>(cbAddress, "TextChanged"))
                .Merge(certificatesSelected)
                .Sample(TimeSpan.FromSeconds(1))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (Helper.IsRunningOnMono())
                {
                    return;
                }

                var toElevate = IPEndPointIsValid(out IPAddress address, out int port, false) ? BindingUtility.Verify(cbType.Text, cbAddress.Text, txtPort.Text, cbCertificates.SelectedItem as CertificateInfo) : false;
                btnOK.Enabled = toElevate != null && !string.IsNullOrWhiteSpace(txtName.Text) &&
                                !string.IsNullOrWhiteSpace(txtPath.Text);
                if (!toElevate.HasValue || !toElevate.Value)
                {
                    NativeMethods.RemoveShieldFromButton(btnOK);
                }
                else
                {
                    NativeMethods.TryAddShieldToButton(btnOK);
                }
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnView, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var info = (CertificateInfo)cbCertificates.SelectedItem;
                DialogHelper.DisplayCertificate(info.Certificate, this.Handle);
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnChoose, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var dialog = new SelectPoolDialog(txtPool.Text, collection.Parent);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                txtPool.Text = dialog.Selected.Name;
            }));
        }
Ejemplo n.º 20
0
        private void SetupBuildArgs(List <KeyValuePair <string, string> > nameList)
        {
            // add common types
            var commonTypeList  = GetCommonTypes();
            var propertyTypeSet = new HashSet <Type>(commonTypeList);

            // load type
            foreach (var item in nameList)
            {
                // convert to .net type
                var typeName = item.Key.Replace('/', '+');

                // get type
                var type = BindingEditorUtility.GetClassByName(typeName).FirstOrDefault();
                if (type == null)
                {
                    Debug.LogWarningFormat("Invalid type name {0}", typeName);
                    continue;
                }

                // get property
                var property = type.GetProperty(item.Value);
                if (property == null)
                {
                    Debug.LogWarningFormat("Invalid property name {0}", item.Value);
                    continue;
                }

                var aotType = GetAotType(property.PropertyType);
                if (!propertyTypeSet.Contains(aotType))
                {
                    // add it
                    propertyTypeSet.Add(aotType);
                }
            }

            // combine with custom properties
            Combine(propertyTypeSet, GetCustomProperties());

            // sort type set
            var sortedList = GetSortedTypeList(propertyTypeSet);

            // set property list
            foreach (var item in sortedList)
            {
                var newItem = new BuildArgs.PropertyItem()
                {
                    propertyType = item,
                };

                buildArgs.propertyList.Add(newItem);
            }

            // get implicit operators
            var types = ImplicitConverter.GetTypes();
            var operatorDictionary = BindingUtility.GetImplicitOperators(types);

            // set implicit operator list
            foreach (var item in operatorDictionary)
            {
                var newItem = new BuildArgs.ImplicitOperatorItem()
                {
                    sourceType = item.Key.Item1,
                    targetType = item.Key.Item2,
                };

                buildArgs.implicitOperatorList.Add(newItem);
            }
        }
Ejemplo n.º 21
0
        public BindingDialog(IServiceProvider serviceProvider, Binding binding1, Site site)
            : base(serviceProvider)
        {
            InitializeComponent();
            Binding = binding1;
            Text    = Binding == null ? "Create Site Binding" : "Edit Site Binding";
            DialogHelper.LoadAddresses(cbAddress);
            txtPort.Text         = "80";
            cbType.SelectedIndex = 0;
            if (!site.Server.SupportsSni)
            {
                cbSniRequired.Enabled = false;
            }

            if (Binding == null)
            {
                txtHost.Text = site.Server.Mode == WorkingMode.IisExpress ? "localhost" : string.Empty;
            }
            else
            {
                cbType.Text    = Binding.Protocol;
                cbType.Enabled = Binding == null;
                cbAddress.Text = Binding.EndPoint.Address.AddressToCombo();
                txtPort.Text   = Binding.EndPoint.Port.ToString();
                txtHost.Text   = Binding.Host.HostToDisplay();
                if (site.Server.SupportsSni)
                {
                    cbSniRequired.Checked = Binding.GetIsSni();
                }
            }

            var container = new CompositeDisposable();

            FormClosed += (sender, args) => container.Dispose();

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                IPAddress address;
                try
                {
                    address = cbAddress.Text.ComboToAddress();
                }
                catch (Exception)
                {
                    MessageBox.Show("The specified IP address is invalid. Specify a valid IP address.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                int port;
                try
                {
                    port = int.Parse(txtPort.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("The server port number must be a positive integer between 1 and 65535", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (port < 1 || port > 65535)
                {
                    MessageBox.Show("The server port number must be a positive integer between 1 and 65535", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                var invalid = "\"/\\[]:|<>+=;,?*$%#@{}^`".ToCharArray();
                foreach (var ch in invalid)
                {
                    if (txtHost.Text.Contains(ch))
                    {
                        MessageBox.Show("The specified host name is incorrect. The host name must use a valid host name format and cannot contain the following characters: \"/\\[]:|<>+=;,?*$%#@{}^`. Example: www.contoso.com.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }

                if (site.Server.Mode == WorkingMode.IisExpress)
                {
                    if (txtHost.Text != "localhost")
                    {
                        MessageBox.Show(
                            "The specific host name is not recommended for IIS Express. The host name should be localhost.",
                            Text,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                    }
                }

                var certificate = cbCertificates.SelectedItem as CertificateInfo;
                var host        = txtHost.Text.DisplayToHost();
                var binding     = new Binding(
                    cbType.Text,
                    $"{address.AddressToDisplay()}:{port}:{host.HostToDisplay()}",
                    cbType.Text == "https" ? certificate?.Certificate.GetCertHash() : new byte[0],
                    cbType.Text == "https" ? certificate?.Store : null,
                    cbSniRequired.Checked ? SslFlags.Sni : SslFlags.None,
                    site.Bindings);
                var matched = site.Parent.FindDuplicate(binding, site, Binding);
                if (matched == true)
                {
                    var result = ShowMessage(
                        $"The binding '{binding}' is assigned to another site. If you assign the same binding to this site, you will only be able to start one of the sites. Are you sure that you want to add this duplicate binding?",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1);
                    if (result != DialogResult.Yes)
                    {
                        return;
                    }
                }

                if (matched == null)
                {
                    ShowMessage(
                        "The specific port is being used by a different binding.",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1);
                    return;
                }

                var conflicts = binding.DetectConflicts();
                if (conflicts)
                {
                    var result = ShowMessage(
                        $"This binding is already being used. If you continue you might overwrite the existing certificate for this IP Address:Port or Host Name:Port combination. Do you want to use this binding anyway?",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1);
                    if (result != DialogResult.Yes)
                    {
                        return;
                    }
                }

                if (Binding == null)
                {
                    Binding = binding;
                }
                else
                {
                    Binding.Reinitialize(binding);
                }

                if (site.Server.Mode == WorkingMode.IisExpress)
                {
                    var result = Binding.FixCertificateMapping(certificate?.Certificate);
                    if (!string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show($"The binding '{Binding}' is invalid: {result}", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                DialogResult = DialogResult.OK;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(cbType, "SelectedIndexChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(this, "Load"))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                txtPort.Text            = cbType.Text == "http" ? "80" : "443";
                txtCertificates.Visible = cbType.SelectedIndex == 1;
                cbSniRequired.Visible   = cbType.SelectedIndex == 1;
                cbCertificates.Visible  = cbType.SelectedIndex == 1;
                btnSelect.Visible       = cbType.SelectedIndex == 1;
                btnView.Visible         = cbType.SelectedIndex == 1;
            }));

            var certificatesSelected = Observable.FromEventPattern <EventArgs>(cbCertificates, "SelectedIndexChanged");

            container.Add(
                certificatesSelected
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                btnView.Enabled = cbCertificates.SelectedIndex > 0;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(cbAddress, "TextChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(txtPort, "TextChanged"))
                .Merge(certificatesSelected)
                .Sample(TimeSpan.FromSeconds(1))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (Helper.IsRunningOnMono())
                {
                    return;
                }

                var toElevate = BindingUtility.Verify(cbType.Text, cbAddress.Text, txtPort.Text, cbCertificates.SelectedItem as CertificateInfo);
                btnOK.Enabled = toElevate != null;
                if (!toElevate.HasValue || !toElevate.Value)
                {
                    JexusManager.NativeMethods.RemoveShieldFromButton(btnOK);
                }
                else
                {
                    JexusManager.NativeMethods.TryAddShieldToButton(btnOK);
                }
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnView, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                DialogHelper.DisplayCertificate(((CertificateInfo)cbCertificates.SelectedItem).Certificate, Handle);
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnSelect, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                // TODO:
            }));
        }
Ejemplo n.º 22
0
        private void CreateBinding()
        {
            binding = new Binding(path, this, "StringValue");

            BindingUtility.AddBinding(binding, transform, out dataContext);
        }
Ejemplo n.º 23
0
        void OnDestroy()
        {
            ResetCurrentView();

            BindingUtility.RemoveBinding(binding, dataContext);
        }
Ejemplo n.º 24
0
        private void SetDataContextInfo(Transform root, TreeNode treeNode)
        {
            if (!enableExtraInfo)
            {
                return;
            }

            // get all binders
            var binderList = root.GetComponentsInChildren <MonoBehaviour>(true).Where(x => x.GetType().IsBinder());

            var dictionary = new Dictionary <IDataContext, List <string> >();

            // iterate binder list
            foreach (var item in binderList)
            {
                // get data context
                var dc = BindingUtility.FindDataContext(item.transform);
                if (dc == null)
                {
                    continue;
                }

                if (!dictionary.ContainsKey(dc))
                {
                    // add new entry
                    dictionary.Add(dc, new List <string>());
                }

                var list       = dictionary[dc];
                var sourceList = GetBindingSourceList(item);

                foreach (var source in sourceList)
                {
                    if (list.Contains(source))
                    {
                        continue;
                    }

                    list.Add(source);
                }
            }

            // get all data context node
            var nodeList = new List <NodeGUI>();

            GetNodeList(treeNode, NodeType.DataContext, nodeList);

            foreach (var item in nodeList)
            {
                var dc = item.target as IDataContext;

                if (!dictionary.ContainsKey(dc))
                {
                    string path = GetGameObjectPath(item.target.transform);
                    string info = string.Format("Find unused DataContext, path={0}", path);
                    Debug.LogWarning(info, item.target);
                    continue;
                }

                var sourceList = dictionary[dc];

                // set extra info
                var sourceInfo = CollectSourceInfo(sourceList);
                item.ExtraInfo = sourceInfo;
            }
        }