public async Task <Result> Add(ESightAppliance appliance)
        {
            return(await Task.Run(() =>
            {
                try
                {
                    if (OM12Connection.Exsits(ESightAppliance.EntityClassName, $"Host='{appliance.Host}'"))
                    {
                        return Result.Failed(101, $"ESight {appliance.Host} already exsits.");
                    }

                    IncrementalDiscoveryData incrementalDiscoveryData = new IncrementalDiscoveryData();

                    // add appliance record
                    ManagementPackClass MPClass = GetMPClass();
                    CreatableEnterpriseManagementObject EMOAppliance =
                        new CreatableEnterpriseManagementObject(OM12Connection.HuaweiESightMG, MPClass);
                    IDictionary <string, ManagementPackProperty> props =
                        OM12Connection.GetManagementPackProperties(EMOAppliance);
                    EMOAppliance[props["Host"]].Value = appliance.Host;
                    EMOAppliance[props["Port"]].Value = appliance.Port;
                    EMOAppliance[props["AliasName"]].Value = appliance.AliasName;
                    EMOAppliance[props["SystemId"]].Value = appliance.SystemId;
                    EMOAppliance[props["LoginAccount"]].Value = appliance.LoginAccount;
                    EMOAppliance[props["LoginPassword"]].Value = RijndaelManagedCrypto.Instance
                                                                 .EncryptForCS(appliance.LoginPassword);
                    EMOAppliance[props["LastModifiedOn"]].Value = DateTime.UtcNow;
                    EMOAppliance[props["CreatedOn"]].Value = DateTime.UtcNow;

                    EMOAppliance[props["OpenID"]].Value = Guid.NewGuid().ToString("D");
                    EMOAppliance[props["SubscribeID"]].Value = Guid.NewGuid().ToString("D");
                    EMOAppliance[props["SubKeepAliveStatus"]].Value = 0;
                    EMOAppliance[props["SubscriptionAlarmStatus"]].Value = 0;
                    EMOAppliance[props["SubscriptionNeDeviceStatus"]].Value = 0;

                    EMOAppliance[props["SubKeepAliveError"]].Value = string.Empty;
                    EMOAppliance[props["SubscripeAlarmError"]].Value = string.Empty;
                    EMOAppliance[props["SubscripeNeDeviceError"]].Value = string.Empty;
                    //EMOAppliance[props["LatestConnectInfo"]].Value = string.Empty;

                    //EMOAppliance[props["LatestStatus"]].Value = Constants.ESightConnectionStatus.NONE;

                    ManagementPackClass baseEntity = OM12Connection.GetManagementPackClass("System.Entity");
                    EMOAppliance[baseEntity, "DisplayName"].Value = appliance.Host;
                    incrementalDiscoveryData.Add(EMOAppliance);
                    incrementalDiscoveryData.Commit(OM12Connection.HuaweiESightMG);
                    return Result.Done();
                }
                catch (Exception e)
                {
                    return Result.Failed(100, $"Internal error caused by {e.Message}", e);
                }
            }));
        }
 public static ManagementPackClass GetMPClass()
 {
     return(OM12Connection.GetManagementPackClass(ESightAppliance.EntityClassName));
 }