コード例 #1
0
            // Factory

            public static CopyPasteItemBase FactoryConvertFrom(AdminShell.Referable rf)
            {
                // try fake a copy paste item (order matters!)
                CopyPasteItemBase res = CopyPasteItemSME.ConvertFrom(rf);

                if (res == null)
                {
                    res = CopyPasteItemSubmodel.ConvertFrom(rf);
                }
                if (res == null)
                {
                    res = CopyPasteItemIdentifiable.ConvertFrom(rf);
                }

                // ok
                return(res);
            }
コード例 #2
0
            public static CopyPasteBuffer FromClipboardString(string cps)
            {
                // access
                if (cps == null)
                {
                    return(null);
                }
                cps = cps.Trim();
                if (cps.Length < 1)
                {
                    return(null);
                }

                // quite likely to crash
                try
                {
                    // be very straight for allowed formats
                    var isSingleObject = cps.StartsWith("{");
                    var isArrayObject  = cps.StartsWith("[");

                    // try simple way
                    if (isSingleObject)
                    {
                        // TODO (MIHO, 2021-06-22): think of converting Referable to IAasElement
                        var obj = AdminShellSerializationHelper.DeserializeFromJSON <AdminShell.Referable>(cps);

                        // try fake a copy paste item (order matters!)
                        var cpi = CopyPasteItemBase.FactoryConvertFrom(obj);
                        if (cpi != null)
                        {
                            return new CopyPasteBuffer()
                                   {
                                       Valid          = true,
                                       ExternalSource = true,
                                       Duplicate      = true,
                                       Items          = new ListOfCopyPasteItem(cpi)
                                   }
                        }
                        ;
                    }
                    else
                    if (isArrayObject)
                    {
                        // make array of object
                        var objarr = AdminShellSerializationHelper
                                     .DeserializePureObjectFromJSON <List <AdminShell.Referable> >(cps);
                        if (objarr != null)
                        {
                            // overall structure
                            var cpb = new CopyPasteBuffer()
                            {
                                Valid          = true,
                                ExternalSource = true,
                                Duplicate      = true,
                                Items          = new ListOfCopyPasteItem()
                            };

                            // single items
                            foreach (var obj in objarr)
                            {
                                var cpi = CopyPasteItemBase.FactoryConvertFrom(obj);
                                if (cpi != null)
                                {
                                    cpb.Items.Add(cpi);
                                }
                            }

                            // be picky with validity
                            if (cpb.Items.Count > 0)
                            {
                                return(cpb);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Singleton.Error(ex, "when trying to decode clipboad text");
                }

                // ups
                return(null);
            }
コード例 #3
0
 public void Clear()
 {
     this.valid     = false;
     this.duplicate = false;
     this.item      = null;
 }