public void Create()
        {
            ServiceObject MailMessageServiceObject = new ServiceObject();

            MailMessageServiceObject.Name = "mailmessage";
            MailMessageServiceObject.MetaData.DisplayName = "Mail Message";
            MailMessageServiceObject.Active = true;

            AllProps     = GetAllProperties();
            MessageProps = GetProperties();

            foreach (Property prop in AllProps)
            {
                MailMessageServiceObject.Properties.Add(prop);
            }

            // add methods
            MailMessageServiceObject.Methods.Add(GetAllMessages());
            MailMessageServiceObject.Methods.Add(GetMessages());
            MailMessageServiceObject.Methods.Add(SearchMessageBySubject());
            MailMessageServiceObject.Methods.Add(SearchMessageBySubjectUID());
            MailMessageServiceObject.Methods.Add(SearchMessageByBody());
            MailMessageServiceObject.Methods.Add(SearchMessageByBodyUID());
            MailMessageServiceObject.Methods.Add(SearchMessageByFrom());
            MailMessageServiceObject.Methods.Add(SearchMessageByFromUID());
            MailMessageServiceObject.Methods.Add(GetMessageByUID());
            MailMessageServiceObject.Methods.Add(GetMessageBySubject());
            serviceBroker.Service.ServiceObjects.Add(MailMessageServiceObject);
        }
        private object PrepareResponse(ServiceObject serviceObject)
        {
            var functionList = new List <String>();

            foreach (var function in serviceObject.Functions)
            {
                var parameters = String.Empty;
                foreach (var parameter in function.Parameters.OrderBy(a => a.Order))
                {
                    var comma = parameter.Order == function.Parameters.Max(a => a.Order) ? String.Empty : ", ";
                    parameters += parameter.Type + comma;
                }
                functionList.Add(String.Format("{0} {1}({2});", function.ReturnType, function.Name, parameters));
            }
            var name        = serviceObject.OriginServiceName;
            var totalObject = serviceObject.ObjectTypes.Count;
            var objectList  = new List <String>();

            foreach (var objectType in serviceObject.ObjectTypes)
            {
                var parameters = String.Empty;
                foreach (var attribute in objectType.Attributes)
                {
                    var comma = objectType.Attributes.Any(a => attribute == a) ? ", " : "";
                    parameters += attribute + comma;
                }
                objectList.Add(String.Format("{0} - ({1});", objectType.Type, parameters));
            }
            return(new { name, totalFunctions = serviceObject.Functions.Count, functions = functionList, totalObject, objects = objectList });
        }
        public override List <ServiceObject> DescribeServiceObjects()
        {
            List <ServiceObject> soList = new List <ServiceObject>();

            ServiceObject so = Helper.CreateServiceObject("FilestoZip", "Files To Zip");

            //so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.FilesToZip.ZipFile, SoType.File, "Zip File"));
            FileProperty zipFile = new FileProperty(Constants.SOProperties.FilesToZip.ZipFile, new MetaData(), String.Empty, String.Empty);

            zipFile.MetaData.DisplayName = Constants.SOProperties.FilesToZip.ZipFile;
            zipFile.MetaData.Description = "Zip File";
            so.Properties.Add(zipFile);

            so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.FilesToZip.FileName, SoType.Text, "Zip File Name."));
            so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.FilesToZip.ADOSMOQuery, SoType.Text, "Query to get the Files. File in the first column"));

            //FilesToZip
            Method mFilesToZipSmartObject = Helper.CreateMethod(Constants.Methods.FilesToZip.FilesToZipMethod, "Compress Files to Zip", MethodType.Read);

            mFilesToZipSmartObject.InputProperties.Add(Constants.SOProperties.FilesToZip.ADOSMOQuery);
            mFilesToZipSmartObject.Validation.RequiredProperties.Add(Constants.SOProperties.FilesToZip.ADOSMOQuery);
            mFilesToZipSmartObject.InputProperties.Add(Constants.SOProperties.FilesToZip.FileName);
            mFilesToZipSmartObject.Validation.RequiredProperties.Add(Constants.SOProperties.FilesToZip.FileName);
            mFilesToZipSmartObject.ReturnProperties.Add(Constants.SOProperties.FilesToZip.ZipFile);

            so.Methods.Add(mFilesToZipSmartObject);

            soList.Add(so);

            return(soList);
        }
        private void ExecuteGetContentTypesByParent()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string parentCtName = base.GetStringParameter(Constants.SOProperties.ContentTypeParent, true);
            string siteURL      = GetSiteURL();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;
                context.Load(spWeb);

                var ctColl = spWeb.AvailableContentTypes;
                context.Load(ctColl);

                IQueryable <ContentType> filterQuery = ctColl.Where(ct => parentCtName == ct.Parent.Name);

                IEnumerable <ContentType> _results = context.LoadQuery <ContentType>(filterQuery);

                context.ExecuteQuery();


                foreach (var item in _results)
                {
                    DataRow dataRow = results.NewRow();

                    PopulateDataRow(item, dataRow);

                    results.Rows.Add(dataRow);
                }
            }
        }
        public void Create()
        {
            ServiceObject MailMessageServiceObject = new ServiceObject();
            MailMessageServiceObject.Name = "mailmessage";
            MailMessageServiceObject.MetaData.DisplayName = "Mail Message";
            MailMessageServiceObject.Active = true;

            AllProps = GetAllProperties();
            MessageProps = GetProperties();

            foreach (Property prop in AllProps)
            {
                MailMessageServiceObject.Properties.Add(prop);
            }

            // add methods
            MailMessageServiceObject.Methods.Add(GetAllMessages());
            MailMessageServiceObject.Methods.Add(GetMessages());
            MailMessageServiceObject.Methods.Add(SearchMessageBySubject());
            MailMessageServiceObject.Methods.Add(SearchMessageBySubjectUID());
            MailMessageServiceObject.Methods.Add(SearchMessageByBody());
            MailMessageServiceObject.Methods.Add(SearchMessageByBodyUID());
            MailMessageServiceObject.Methods.Add(SearchMessageByFrom());
            MailMessageServiceObject.Methods.Add(SearchMessageByFromUID());
            MailMessageServiceObject.Methods.Add(GetMessageByUID());
            MailMessageServiceObject.Methods.Add(GetMessageBySubject());
            serviceBroker.Service.ServiceObjects.Add(MailMessageServiceObject);
        }
Beispiel #6
0
        private void Join()
        {
            string        query         = GetStringProperty(Constants.SOProperties.ADOHelper.ADOQuery, true);
            string        delimiter     = GetStringProperty(Constants.SOProperties.ADOHelper.Delimiter, true);
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            DataTable adoResults = new DataTable();

            using (SOConnection connection = new SOConnection(base.BaseAPIConnectionString))
                using (SOCommand command = new SOCommand(query, connection))
                    using (SODataAdapter adapter = new SODataAdapter(command))
                    {
                        connection.DirectExecution = true;
                        connection.Open();
                        adapter.Fill(adoResults);
                    }
            string result = "";

            foreach (DataRow dRow in adoResults.Rows)
            {
                result += dRow[0].ToString() + delimiter;
            }
            result = result.Remove(result.LastIndexOf(delimiter));

            DataRow resultsRow = results.NewRow();

            resultsRow[Constants.SOProperties.ADOHelper.Result] = result;
            results.Rows.Add(resultsRow);
        }
Beispiel #7
0
        public void ReadThreadIdentity()
        {
            if (GetBoolProperty(Constants.SOProperties.Identity.UserWindowsImpersonation))
            {
                System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
            }
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            DataRow dr = results.NewRow();

            dr[Constants.SOProperties.Identity.WindowsIdentityName]               = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            dr[Constants.SOProperties.Identity.WindowsIdentityAuthType]           = System.Security.Principal.WindowsIdentity.GetCurrent().AuthenticationType;
            dr[Constants.SOProperties.Identity.CurrentPrincipalName]              = System.Threading.Thread.CurrentPrincipal.Identity.Name;
            dr[Constants.SOProperties.Identity.CurrentPrincipalIdentityType]      = System.Threading.Thread.CurrentPrincipal.Identity.GetType().ToString();
            dr[Constants.SOProperties.Identity.CurrentPrincipalAuthType]          = System.Threading.Thread.CurrentPrincipal.Identity.AuthenticationType;
            dr[Constants.SOProperties.Identity.ServiceBrokerUserName]             = ServiceBroker.Service.ServiceConfiguration.ServiceAuthentication.UserName;
            dr[Constants.SOProperties.Identity.ServiceBrokerPassword]             = ServiceBroker.Service.ServiceConfiguration.ServiceAuthentication.Password;
            dr[Constants.SOProperties.Identity.ServiceBrokerAuthType]             = ServiceBroker.Service.ServiceConfiguration.ServiceAuthentication.AuthenticationMode.ToString();
            dr[Constants.SOProperties.Identity.DefaultNetworkCredentialsDomain]   = System.Net.CredentialCache.DefaultNetworkCredentials.Domain;
            dr[Constants.SOProperties.Identity.DefaultNetworkCredentialsPassword] = System.Net.CredentialCache.DefaultNetworkCredentials.Password;
            dr[Constants.SOProperties.Identity.DefaultNetworkCredentialsUsername] = System.Net.CredentialCache.DefaultNetworkCredentials.UserName;
            dr[Constants.SOProperties.Identity.CallingFQN]                = CallingFQN;
            dr[Constants.SOProperties.Identity.UserCultureName]           = System.Globalization.CultureInfo.CurrentCulture.Name;
            dr[Constants.SOProperties.Identity.UserCultureDisplayName]    = System.Globalization.CultureInfo.CurrentCulture.DisplayName;
            dr[Constants.SOProperties.Identity.UserCultureDateTimeFormat] = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
            dr[Constants.SOProperties.Identity.UserCultureLCID]           = System.Globalization.CultureInfo.CurrentCulture.LCID;
            dr[Constants.SOProperties.Identity.UserCultureNumberFormat]   = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
            results.Rows.Add(dr);
        }
Beispiel #8
0
        private void RunScriptCode()
        {
            string powerShellScript    = GetStringProperty(Constants.SOProperties.SimplePowerShell.PowerShellScript, true);
            string serializedVariables = GetStringProperty(Constants.SOProperties.SimplePowerShell.Variables, false);

            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            //deserialize variables
            List <PowerShellVariablesDC> variablesList = new List <PowerShellVariablesDC>();

            if (!String.IsNullOrEmpty(serializedVariables))
            {
                variablesList = PowerShellSerializationHelper.DeserializeArrayToList(serializedVariables);
            }

            //run script
            string scriptOutput = PowerShellHelper.RunScriptCode(powerShellScript, variablesList);

            DataRow dr = results.NewRow();

            dr[Constants.SOProperties.SimplePowerShell.ScriptOutput] = scriptOutput;
            if (variablesList.Count != 0)
            {
                dr[Constants.SOProperties.SimplePowerShell.Variables] = PowerShellSerializationHelper.SerializeList(variablesList);
            }
            else
            {
                dr[Constants.SOProperties.SimplePowerShell.Variables] = String.Empty;
            }

            results.Rows.Add(dr);
        }
        public void GetMultipleCellValuesList()
        {
            //Get input properties
            FileProperty excelFile               = GetFileProperty(Constants.SOProperties.ExcelDocumentServices.ExcelFile, true);
            string       worksheetName           = GetStringProperty(Constants.SOProperties.ExcelDocumentServices.WorksheetName, true);
            string       multipleCellCoordinates = GetStringProperty(Constants.SOProperties.ExcelDocumentServices.MultipleCellCoordinates, true);

            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            string smoCellValues = ExcelServiceHelper.GetMultipleCellValueFromFile(excelFile, worksheetName, multipleCellCoordinates);

            string[] cellNames  = multipleCellCoordinates.Split(';');
            string[] cellValues = smoCellValues.Split(';');

            for (int i = 0; i < cellNames.Length; i++)
            {
                DataRow dr = results.NewRow();

                dr[Constants.SOProperties.ExcelDocumentServices.CellName]  = cellNames[i];
                dr[Constants.SOProperties.ExcelDocumentServices.CellValue] = cellValues[i];
                results.Rows.Add(dr);
            }
        }
        private void ExecuteResetFolderInheritanceByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle  = serviceObject.GetListTitle();
            string siteURL    = GetSiteURL();
            string folderName = base.GetStringProperty(Constants.SOProperties.FolderName, true);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list, d => d.RootFolder);
                context.ExecuteQuery();

                Folder currentFolder = null;
                try
                {
                    currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName.Trim('/')));
                    context.Load(currentFolder);
                    context.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderWasNotFound, folderName), ex);
                }

                currentFolder.ListItemAllFields.ResetRoleInheritance();
                context.ExecuteQuery();
            }
        }
        public void Create()
        {
            //List<Property> SPSearchProps = GetSPSearchProperties();

            List<Property> SPSearchProps = GetSPSearchProperties();

            ServiceObject SPSearchServiceObject = new ServiceObject();
            SPSearchServiceObject.Name = "spsearchdocument";
            SPSearchServiceObject.MetaData.DisplayName = "SharePoint Document Search";

            SPSearchServiceObject.MetaData.ServiceProperties.Add("objecttype", "search");

            SPSearchServiceObject.Active = true;

            foreach (Property prop in SPSearchProps)
            {
                if (!SPSearchServiceObject.Properties.Contains(prop.Name))
                {
                    SPSearchServiceObject.Properties.Add(prop);
                }
            }

            SPSearchServiceObject.Methods.Add(CreateSearch(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateSearchRead(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateDeserializeSearchResults(SPSearchProps));

            serviceBroker.Service.ServiceObjects.Add(SPSearchServiceObject);
        }
        private void AddGetDocumentSetsMethod(ServiceObject so)
        {
            Method mGetDocumentSets = Helper.CreateMethod(Constants.Methods.GetDocumentSets, "Retrieve document Sets", MethodType.List);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mGetDocumentSets);
            }

            foreach (Property prop in so.Properties)
            {
                if (prop.IsDocSetName())
                {
                    mGetDocumentSets.InputProperties.Add(prop);
                    mGetDocumentSets.ReturnProperties.Add(prop);
                }
                if (!prop.IsInternal() &&
                    !prop.IsFile())
                {
                    mGetDocumentSets.InputProperties.Add(prop);
                    mGetDocumentSets.ReturnProperties.Add(prop);
                }
                if (so.IsSPFolderEnabled() && (prop.IsFolderName() || prop.IsRecursivelyName()))
                {
                    mGetDocumentSets.InputProperties.Add(prop);
                }
                if (prop.IsLinkToItem())
                {
                    mGetDocumentSets.ReturnProperties.Add(prop);
                }
            }

            so.Methods.Add(mGetDocumentSets);
        }
        private void AddGetDocSetMethod(ServiceObject so)
        {
            Method mGetDocSet = Helper.CreateMethod(Constants.Methods.GetDocumentSetByName, "Get Document set", MethodType.Read);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mGetDocSet);
            }

            foreach (Property prop in so.Properties)
            {
                if (!prop.IsInternal() &&
                    !prop.IsFile())
                {
                    mGetDocSet.ReturnProperties.Add(prop);
                }

                if (prop.IsDocSetName())
                {
                    mGetDocSet.InputProperties.Add(prop);
                    mGetDocSet.Validation.RequiredProperties.Add(prop);
                }
                if (so.IsSPFolderEnabled() && (prop.IsFolderName()))
                {
                    mGetDocSet.InputProperties.Add(prop);
                }

                if (prop.IsLinkToItem())
                {
                    mGetDocSet.ReturnProperties.Add(prop);
                }
            }

            so.Methods.Add(mGetDocSet);
        }
        private void AddRenameDocumentSetMethod(ServiceObject so)
        {
            Method mRenameDocSet = Helper.CreateMethod(Constants.Methods.RenameDocumentSetByName, "Rename a Document set", MethodType.Execute);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mRenameDocSet);
            }

            foreach (Property prop in so.Properties)
            {
                if (prop.IsDocSetName() || prop.IsNewDocumentSetName())
                {
                    mRenameDocSet.InputProperties.Add(prop);
                    mRenameDocSet.Validation.RequiredProperties.Add(prop);
                }
                if (so.IsSPFolderEnabled() && (prop.IsFolderName()))
                {
                    mRenameDocSet.InputProperties.Add(prop);
                }
                if (prop.IsLinkToItem())
                {
                    mRenameDocSet.ReturnProperties.Add(prop);
                }
            }

            so.Methods.Add(mRenameDocSet);
        }
Beispiel #15
0
        private void DeleteRoleItem()
        {
            ServiceObject serviceObject = this.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();

            string          roleName  = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);
                Role role = urmServer.GetRole(roleName);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
                }

                string   roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                RoleItem remItem      = null;

                foreach (RoleItem ri in role.RoleItems)
                {
                    if (string.Compare(ri.Name, roleItemName, true) == 0)
                    {
                        remItem = ri;
                    }
                }
                if (remItem != null)
                {
                    role.RoleItems.Remove(remItem);
                }
                urmServer.UpdateRole(role);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Standardize the interaction for a retrying a ServiceObject.Load() call,
        /// removing bad properties until the call succeeds.
        /// </summary>
        /// <param name="obj">Object to load</param>
        /// <param name="propSet">PropertySet to load for the object</param>
        public static void PerformRetryableLoad(ServiceObject obj, PropertySet propSet)
        {
            bool retry = true;

            while (retry)
            {
                try
                {
                    obj.Service.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                    obj.Load(propSet);
                    retry = false;
                }
                catch (ServiceResponseException srex)
                {
                    DebugLog.WriteVerbose("Handled exception when retrieving property", srex);

                    // Give the user the option of removing the bad properites from the request
                    // and retrying.
                    if (ErrorDialog.ShowServiceExceptionMsgBox(srex, true, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        // Remove the bad properties from the PropertySet and try again.
                        foreach (PropertyDefinitionBase propDef in srex.Response.ErrorProperties)
                        {
                            propSet.Remove(propDef);
                        }

                        retry = true;
                    }
                    else
                    {
                        retry = false;
                    }
                }
            }
        }
Beispiel #17
0
        private void AddUpdateItemByIdMethod(ServiceObject so)
        {
            Method mUpdateItemById = Helper.CreateMethod(Constants.Methods.UpdateItemById, "Update list or library metadata by it's ID", MethodType.Update);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mUpdateItemById);
            }

            foreach (Property prop in so.Properties)
            {
                if (string.Compare(prop.Name, Constants.SOProperties.ID, true) == 0)
                {
                    mUpdateItemById.InputProperties.Add(prop);
                    mUpdateItemById.Validation.RequiredProperties.Add(prop);
                    mUpdateItemById.ReturnProperties.Add(prop);
                }
                if (!prop.IsReadOnly() && !prop.IsInternal() && !prop.IsFile())
                {
                    mUpdateItemById.InputProperties.Add(prop);
                }
                if (prop.IsLinkToItem())
                {
                    mUpdateItemById.ReturnProperties.Add(prop);
                }
            }
            so.Methods.Add(mUpdateItemById);
        }
        /// <summary>
        /// Remove all existing shares for a current user
        /// </summary>
        private void RemoveAllShares()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                // None for userstatus means the users is not configured, throw an exception
                if (UserStatuses.None == k2Con.GetUserStatus())
                {
                    throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser);
                }

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);
                if (wsColl != null && wsColl.Count > 0)
                {
                    k2Con.UnShareAll();
                }

                k2Con.Close();
            }

            // Necessary to prevent unwanted errors when configuring status
            SetStatus(UserStatuses.Available);
        }
Beispiel #19
0
        private void AddGetItemByIdMethod(ServiceObject so)
        {
            Method mGetItemById = Helper.CreateMethod(Constants.Methods.GetItemById, "Retrieve metadata for one item by it's ID", MethodType.Read);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mGetItemById);
            }
            foreach (Property prop in so.Properties)
            {
                if (string.Compare(prop.Name, Constants.SOProperties.ID, true) == 0)
                {
                    mGetItemById.InputProperties.Add(prop);
                    mGetItemById.Validation.RequiredProperties.Add(prop);
                }

                if (!prop.IsInternal() && !prop.IsFile())
                {
                    mGetItemById.ReturnProperties.Add(prop);
                }
                if (so.IsDocumentLibrary() && prop.IsFileName())
                {
                    mGetItemById.ReturnProperties.Add(prop);
                }
                if (prop.IsLinkToItem())
                {
                    mGetItemById.ReturnProperties.Add(prop);
                }
            }

            so.Methods.Add(mGetItemById);
        }
        /// <summary>
        /// List all existing shares for a current user
        /// </summary>
        private void ListSharedUsers()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                // None for userstatus means the users is not configured, throw an exception
                if (UserStatuses.None == k2Con.GetUserStatus())
                {
                    throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser);
                }

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                foreach (WorklistShare ws in wsColl)
                {
                    //throw new ApplicationException("collection count is: "+ wsColl.Count.ToString());
                    foreach (WorkType wt in ws.WorkTypes)
                    {
                        foreach (Destination dest in wt.Destinations)
                        {
                            DataRow dr = results.NewRow();
                            dr[Constants.SOProperties.OutOfOffice.DestinationUser] = dest.Name.ToString();
                            results.Rows.Add(dr);
                        }
                    }
                }

                k2Con.Close();
            }
        }
Beispiel #21
0
        public override List <ServiceObject> DescribeServiceObjects()
        {
            ServiceObject so = Helper.CreateServiceObject("SimplePowershell", "An easy and simple way to execute some PowerShell code.");

            so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.SimplePowerShell.PowerShellScript, SoType.Memo, "The PowerShell script to execute. This is a string containing the script. Not a file location."));
            so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.SimplePowerShell.Variables, SoType.Memo, "A JSON serialized array of PowerShell variables."));
            so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.SimplePowerShell.ScriptOutput, SoType.Memo, "The full output of the script, as if it was executed on the console."));
            so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.SimplePowerShell.PowerShellFilePath, SoType.Memo, "The path to PowerShell script file."));

            if (AllowPowershellScript)
            {
                //RunScript
                Method mRunScriptCode = Helper.CreateMethod(Constants.Methods.SimplePowerShell.RunScriptCode, "Runs the bit of PowerShell script provided in PowerShellScript. Returns the ScriptOutput and adds the variables that are needed.", MethodType.Read);
                mRunScriptCode.InputProperties.Add(Constants.SOProperties.SimplePowerShell.PowerShellScript);
                mRunScriptCode.Validation.RequiredProperties.Add(Constants.SOProperties.SimplePowerShell.PowerShellScript);
                mRunScriptCode.InputProperties.Add(Constants.SOProperties.SimplePowerShell.Variables);
                mRunScriptCode.ReturnProperties.Add(Constants.SOProperties.SimplePowerShell.ScriptOutput);
                mRunScriptCode.ReturnProperties.Add(Constants.SOProperties.SimplePowerShell.Variables);
                so.Methods.Add(mRunScriptCode);
            }

            //RunScriptByFilePath
            Method mRunScriptByFilePath = Helper.CreateMethod(Constants.Methods.SimplePowerShell.RunScriptByFilePath, "Runs the bit of PowerShell script provided from file by path. Returns the ScriptOutput and adds the variables that are needed.", MethodType.Read);

            mRunScriptByFilePath.InputProperties.Add(Constants.SOProperties.SimplePowerShell.PowerShellFilePath);
            mRunScriptByFilePath.Validation.RequiredProperties.Add(Constants.SOProperties.SimplePowerShell.PowerShellFilePath);
            mRunScriptByFilePath.InputProperties.Add(Constants.SOProperties.SimplePowerShell.Variables);
            mRunScriptByFilePath.ReturnProperties.Add(Constants.SOProperties.SimplePowerShell.ScriptOutput);
            mRunScriptByFilePath.ReturnProperties.Add(Constants.SOProperties.SimplePowerShell.Variables);
            so.Methods.Add(mRunScriptByFilePath);

            return(new List <ServiceObject> {
                so
            });
        }
Beispiel #22
0
        private void AddFieldProperty(ServiceObject so, Field fd)
        {
            switch (fd.FieldTypeKind)
            {
            case FieldType.Lookup:
            case FieldType.User:
                so.Properties.Add(CreateFieldProperty(Constants.InternalProperties.Suffix_ID, SoType.Text, fd, fd.ReadOnlyField));
                so.Properties.Add(CreateFieldProperty(Constants.InternalProperties.Suffix_Value, SoType.Text, fd, true));
                break;

            case FieldType.File:

                Property fileNameProp = NewProperty(Constants.SOProperties.FileName, Constants.SOProperties.FileName_DisplayName, true, SoType.Text,
                                                    Constants.SOProperties.FileName_DisplayName);

                so.Properties.Add(fileNameProp);
                break;

            case FieldType.Invalid:
                if (string.Compare(fd.TypeAsString, Constants.SharePointProperties.TaxanomyFieldType) == 0 || string.Compare(fd.TypeAsString, Constants.SharePointProperties.TaxanomyFieldTypeMulti) == 0)
                {
                    so.Properties.Add(CreateFieldProperty(Constants.InternalProperties.Suffix_Value, SoType.Text, fd, true));
                }
                break;
            }
        }
        private void GetWorklist()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = base.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                WorklistCriteria wc = new WorklistCriteria();
                wc.Platform = base.Platform;
                AddFieldFilters(wc);
                if (base.GetBoolProperty(Constants.SOProperties.ClientWorklist.IncludeShared) == true)
                {
                    wc.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Me", WCCompare.Equal, WCWorklistItemOwner.Me);
                    wc.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Other", WCCompare.Equal, WCWorklistItemOwner.Other);
                }
                if (base.GetBoolProperty(Constants.SOProperties.ClientWorklist.ExcludeAllocated) == true)
                {
                    wc.AddFilterField(WCLogical.And, WCField.WorklistItemStatus, WCCompare.NotEqual, WorklistStatus.Allocated);
                }
                Worklist wl = k2Con.OpenWorklist(wc);

                foreach (WorklistItem wli in wl)
                {
                    AddRowToDataTable(results, wli);
                }

                k2Con.Close();
            }
        }
Beispiel #24
0
 private void AddContentTypeServiceObjectMethods(ServiceObject ctSo)
 {
     AddGetContentTypeByNameMethod(ctSo);
     AddGetContentTypeByIdMethod(ctSo);
     AddGetContentTypesMethod(ctSo);
     AddGetContentTypesByParentMethod(ctSo);
 }
Beispiel #25
0
        public void WhoAmI()
        {
            if (GetBoolProperty(Constants.SOProperties.Identity.UserWindowsImpersonation))
            {
                System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
            }

            string k2imp = GetStringProperty(Constants.SOProperties.Identity.K2ImpersonateUser, false);

            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = new Connection())
            {
                k2Con.Open(K2ClientConnectionSetup);
                if (!string.IsNullOrEmpty(k2imp))
                {
                    k2Con.ImpersonateUser(k2imp);
                }

                DataRow dr = results.NewRow();
                dr[Constants.SOProperties.Identity.FQN] = k2Con.User.FQN;
                dr[Constants.SOProperties.Identity.IdentityDescription] = k2Con.User.Description;
                dr[Constants.SOProperties.Identity.IdentityDisplayName] = k2Con.User.DisplayName;
                dr[Constants.SOProperties.Identity.UserEmail]           = k2Con.User.Email;
                dr[Constants.SOProperties.Identity.UserManager]         = k2Con.User.Manager;
                dr[Constants.SOProperties.Identity.UserName]            = k2Con.User.Name;
                dr[Constants.SOProperties.Identity.UserUserLabel]       = k2Con.User.UserLabel;
                dr[Constants.SOProperties.Identity.CallingFQN]          = CallingFQN;
                results.Rows.Add(dr);
                k2Con.Close();
            }
        }
        private void ADOQuery2Excel()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results  = ServiceBroker.ServicePackage.ResultTable;
            string    fileName = GetStringProperty(Constants.SOProperties.ExportToExcel.FileName, true);
            string    query    = GetStringProperty(Constants.SOProperties.ExportToExcel.ADOQuery, true);

            DataTable SOQueryResult = new DataTable();

            using (SOConnection connection = new SOConnection(base.BaseAPIConnectionString))
                using (SOCommand command = new SOCommand(query, connection))
                    using (SODataAdapter adapter = new SODataAdapter(command))
                    {
                        connection.DirectExecution = true;
                        adapter.Fill(SOQueryResult);
                    }
            DataRow dr = results.NewRow();
            //Calling the helper method with dataresult and expecting a File in return.
            CreateExcel excel = new CreateExcel();

            dr[Constants.SOProperties.ExportToExcel.ExcelFile] = excel.ConvertDataTable2Excelfile(SOQueryResult, fileName).ToString();

            results.Rows.Add(dr);
        }
        private void AddDeleteDocumentSetMethod(ServiceObject so)
        {
            Method mDeleteDocSet = Helper.CreateMethod(Constants.Methods.DeleteDocumentSetByName, "Delete a Document set", MethodType.Delete);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mDeleteDocSet);
            }

            if (base.IsListTitleParametrized)
            {
                Helper.AddStringParameter(mDeleteDocSet, Constants.InternalProperties.ListTitle);
            }

            foreach (Property prop in so.Properties)
            {
                if (prop.IsDocSetName())
                {
                    mDeleteDocSet.InputProperties.Add(prop);
                    mDeleteDocSet.Validation.RequiredProperties.Add(prop);
                }
                if (so.IsSPFolderEnabled() && (prop.IsFolderName()))
                {
                    mDeleteDocSet.InputProperties.Add(prop);
                }
            }

            so.Methods.Add(mDeleteDocSet);
        }
        private void ListQuery()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string query = serviceObject.Methods[0].MetaData.GetServiceElement <string>("Query");

            using (SOConnection connection = new SOConnection(base.BaseAPIConnectionString))
            {
                using (SOCommand command = new SOCommand(query, connection))
                {
                    using (SODataAdapter adapter = new SODataAdapter(command))
                    {
                        foreach (Property prop in serviceObject.Properties)
                        {
                            if (prop.Value != null)
                            {
                                command.Parameters.AddWithValue(prop.Name, prop.Value);
                            }
                        }
                        connection.DirectExecution = true;
                        connection.Open();
                        adapter.Fill(results);
                    }
                }
                connection.Close();
            }
        }
        private void ExecuteGetContentTypeByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string ctName = base.GetStringProperty(Constants.SOProperties.ContentTypeName, true);

            string siteURL = GetSiteURL();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;
                context.Load(spWeb);

                var ctColl = spWeb.AvailableContentTypes;
                context.Load(ctColl);
                context.ExecuteQuery();

                var cType = ctColl.FirstOrDefault(c => c.Name == ctName);

                if (cType != null)
                {
                    DataRow dataRow = results.NewRow();

                    PopulateDataRow(cType, dataRow);

                    results.Rows.Add(dataRow);
                }
            }
        }
Beispiel #30
0
        private void AddGetItemByNameMethod(ServiceObject so)
        {
            Method mGetItemByName = Helper.CreateMethod(Constants.Methods.GetItemByName, "Retrieve metadata for one item by it's document name", MethodType.List);

            if (base.IsDynamicSiteURL)
            {
                Helper.AddSiteURLParameter(mGetItemByName);
            }
            foreach (Property prop in so.Properties)
            {
                if (string.Compare(prop.Name, Constants.SOProperties.FileName, true) == 0)
                {
                    mGetItemByName.InputProperties.Add(prop);
                    mGetItemByName.Validation.RequiredProperties.Add(prop);
                }

                if (so.IsSPFolderEnabled() == true && (
                        prop.IsFolderName() || prop.IsRecursivelyName()))
                {
                    mGetItemByName.InputProperties.Add(prop);
                }

                if ((!prop.IsInternal() && !prop.IsFile()) || prop.IsLinkToItem() || (so.IsDocumentLibrary() && prop.IsFileName()))
                {
                    mGetItemByName.ReturnProperties.Add(prop);
                }
            }

            so.Methods.Add(mGetItemByName);
        }
Beispiel #31
0
        public void UserInfoTestWithContactUpdate()
        {
            var action = new Action <IRestResponse <object>, RestRequestAsyncHandle>(CallbackResponse);

            var client = new RestClient(URL);
            // var key = ApplicationAuthenticator.GetS2SAccessTokenForProdMSAAsync();
            var request = new RestRequest("UserInfo/", Method.PUT)
            {
                RequestFormat = DataFormat.Json
            };
            Contact contactContent = new Contact()
            {
                firstname = "testfirstnameupdate", emailid = "*****@*****.**", UPN = "UnitTestUser123"
            };

            //string contactJson = JsonConvert.SerializeObject(contactContent);

            request.AddBody(contactContent);
            request.AddHeader("Accept", "*/*");
            request.AddHeader("Content-Type", "application/json");

            var response = client.Put(request);

            Thread.Sleep(1000);
            if (!string.IsNullOrEmpty(response.Content))
            {
                string content = response.Content.Remove(0, 1);
                content = content.Remove(content.Length - 1, 1).Replace("\\", "");

                ServiceObject returnValue = JsonConvert.DeserializeObject <ServiceObject>(content);
                Assert.IsNotNull(returnValue.ServiceUserID);
                _serviceID = returnValue.ServiceUserID;
                Assert.AreEqual(_serviceID, returnValue.ServiceUserID);
            }
        }
        public void Create()
        {
            //List<Property> SPSearchProps = GetSPSearchProperties();

            List <Property> SPSearchProps = GetSPSearchProperties();

            ServiceObject SPSearchServiceObject = new ServiceObject();

            SPSearchServiceObject.Name = "spsearchdocument";
            SPSearchServiceObject.MetaData.DisplayName = "SharePoint Document Search";

            SPSearchServiceObject.MetaData.ServiceProperties.Add("objecttype", "search");

            SPSearchServiceObject.Active = true;

            foreach (Property prop in SPSearchProps)
            {
                if (!SPSearchServiceObject.Properties.Contains(prop.Name))
                {
                    SPSearchServiceObject.Properties.Add(prop);
                }
            }

            SPSearchServiceObject.Methods.Add(CreateSearch(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateSearchRead(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateDeserializeSearchResults(SPSearchProps));

            serviceBroker.Service.ServiceObjects.Add(SPSearchServiceObject);
        }
Beispiel #33
0
        /// <summary>
        /// Defines the public interface for the SmartObject service.
        /// </summary>
        /// <returns></returns>
        public override string DescribeSchema()
        {
            //set base info
            this.Service.Name = "GAPCustomService";
            this.Service.MetaData.DisplayName = "GAP Custom Service";
            this.Service.MetaData.Description = "Custom service for GAP";

            //create the service object
            ServiceObject so = new ServiceObject();
            so.Name = "GAPCustomServiceObject";
            so.MetaData.DisplayName = "GAP Stub Service";
            so.MetaData.Description = "Use for GAP Stub Service";
            so.Active = true;
            this.Service.ServiceObjects.Add(so);

            //create field definition
            Property property1 = new Property();
            property1.Name = "MyGAPField1";
            property1.MetaData.DisplayName = "My Field 1";
            property1.MetaData.Description = "My Field 1";
            property1.Type = "Integer";
            property1.SoType = SoType.Number;
            so.Properties.Add(property1);

            //create field definition
            Property property2 = new Property();
            property2.Name = "MyGAPField2";
            property2.MetaData.DisplayName = "My Field 2";
            property2.MetaData.Description = "My Field 2";
            property2.Type = "System.String";
            property2.SoType = SoType.Text;
            so.Properties.Add(property2);

            //create load method
            Method method1 = new Method();
            method1.Name = "Load";
            method1.MetaData.DisplayName = "Load";
            method1.MetaData.Description = "Load a single record of data.";
            method1.Type = MethodType.Read;
            method1.Validation.RequiredProperties.Add(property1);
            method1.InputProperties.Add(property1);
            method1.ReturnProperties.Add(property1);
            method1.ReturnProperties.Add(property2);
            so.Methods.Add(method1);

            //create list method
            Method method2 = new Method();
            method2.Name = "List";
            method2.MetaData.DisplayName = "List";
            method2.MetaData.Description = "Load collection of data";
            method2.Type = MethodType.List;
            method2.Validation.RequiredProperties.Add(property1);
            method2.InputProperties.Add(property1);
            method2.ReturnProperties.Add(property1);
            method2.ReturnProperties.Add(property2);
            so.Methods.Add(method2);

            return base.DescribeSchema();
        }
Beispiel #34
0
        /// <summary>
        /// Adds SmartObject properties to the given serviceObject and SmartObject method
        /// for the parameters of the method provided.
        /// 
        /// This uses the webservice assembly to check if the parameter might be a custom object.
        /// </summary>
        /// <param name="serviceObject"></param>
        /// <param name="method"></param>
        /// <param name="smoMethod"></param>
        /// <param name="webServiceAssembly"></param>
        public static void CreateInputParameters(ServiceObject serviceObject, Method smoMethod, MethodInfo method, Assembly webServiceAssembly)
        {
            ParameterInfo[] parameters = method.GetParameters();

            // We first do some checking to see if we support what we need to input.
            foreach (ParameterInfo pi in parameters)
            {
                if (pi.ParameterType.Assembly == webServiceAssembly && parameters.Length > 1)
                {
                    throw new NotSupportedException(string.Format("The method {0} has a Container Object. This is not the only parameter. We do not support this because a SmartObject is a flat object with properties.", method.Name));
                }

                if (pi.ParameterType.IsArray)
                {
                    throw new NotSupportedException(string.Format("The method {0} has an Array for it's input parameters. We do not support this because a SmartObject doesn't accept a list as one property.", method.Name));
                }
            }

            // Check if it is 1 parameter of a specific type. This is a so-called request object. If we find this
            // We use the properties of that object as input. We only support a 'flat'-container object as our SMO is flat as well.
            if (parameters.Length == 1 && parameters[0].ParameterType.Assembly == webServiceAssembly)
            {
                ParameterInfo pi = parameters[0];

                PropertyInfo[] props = pi.ParameterType.GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    if (MapHelper.IsSimpleMapableType(prop.PropertyType)) // only add simple types..
                    {
                        Property property = CreateSmoProperty(prop.Name, prop.PropertyType);
                        AddServiceObjectProperty(serviceObject, property);
                        smoMethod.InputProperties.Add(property);
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("The input parameter (property) {0} of the request object is of type {1} which is not a type supported by SmartObjects.", pi.Name, pi.ParameterType.ToString()));
                    }
                }
            }
            else // It's not a request object, so we simply check all the parameters.
            {
                foreach (ParameterInfo pi in method.GetParameters())
                {
                    if (MapHelper.IsSimpleMapableType(pi.ParameterType)) // only add simple types
                    {
                        Property property = CreateSmoProperty(pi.Name, pi.ParameterType);
                        AddServiceObjectProperty(serviceObject, property);
                        smoMethod.InputProperties.Add(property);
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("The input parameter {0} is of type {1} which is not a type supported by SmartObjects.", pi.Name, pi.ParameterType.ToString()));
                    }
                }
            }
        }
        /// <summary>
        /// Creates the property instance.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <returns>ComplexProperty.</returns>
        internal override ComplexProperty CreatePropertyInstance(ServiceObject owner)
        {
            Folder folder = owner as Folder;

            EwsUtilities.Assert(
                folder != null,
                "PermissionCollectionPropertyDefinition.CreatePropertyInstance",
                "The owner parameter is not of type Folder or a derived class.");

            return new FolderPermissionCollection(folder);
        }
 /// <summary>
 /// Describes the functionality of the service object
 /// </summary>
 /// <returns>Returns the service object definition.</returns>
 internal ServiceObject DescribeServiceObject()
 {
     _so = new ServiceObject("WorklistItemAction");
     _so.Type = "WorklistItemAction";
     _so.Active = true;
     _so.MetaData.DisplayName = "Worklist Item Action";
     _so.MetaData.Description = "Used for to perform actions on worklist items";
     _so.Properties = DescribeProperties();
     _so.Methods = DescribeMethods();
     return _so;
 }
        internal virtual ServiceObject DescribeServiceObject()
        {
            this._svcObject = new ServiceObject("BasicWorklistItem");
            this._svcObject.Type = "BasicWorklistItem";
            this._svcObject.Active = true;
            this._svcObject.MetaData.DisplayName = "Basic Worklist Item";
            this._svcObject.MetaData.Description = "Represents a Basic WorklistItem";
            this._svcObject.Properties = DescribeProperties();
            this._svcObject.Methods = DescribeMethods();

            return this._svcObject;
        }
Beispiel #38
0
        /// <summary>
        /// Get information about a service such as its name, status, start method
        /// </summary>
        /// <param name="serviceName">The name of the service to get details about</param>
        /// <returns>Returns a ServiceObject with details regarding the service</returns>
        public ServiceObject GetServiceInfo(string serviceName)
        {
            ServiceObject so = new ServiceObject();

            ManagementObject wmiService;
            wmiService = new ManagementObject("Win32_Service.Name='" + serviceName + "'");
            wmiService.Get();

            so.Name = wmiService.Properties["Name"].Value.ToString();
            so.DisplayName = wmiService.Properties["Caption"].Value.ToString();
            so.Description = wmiService.Properties["Description"].Value.ToString();
            so.State = wmiService.Properties["State"].Value.ToString();
            so.StartMode = wmiService.Properties["StartMode"].Value.ToString();
            so.Status = wmiService.Properties["Status"].Value.ToString();

            return so;
        }
        public void Create()
        {
            ServiceObject MailAttachmentServiceObject = new ServiceObject();
            MailAttachmentServiceObject.Name = "mailattachment";
            MailAttachmentServiceObject.MetaData.DisplayName = "Mail Attachment";
            MailAttachmentServiceObject.Active = true;

            AllProps = GetAllProperties();
            MessageProps = GetProperties();

            foreach (Property prop in AllProps)
            {
                MailAttachmentServiceObject.Properties.Add(prop);
            }

            // add methods
            MailAttachmentServiceObject.Methods.Add(GetAllAttachments());
            MailAttachmentServiceObject.Methods.Add(GetAttachment());
            serviceBroker.Service.ServiceObjects.Add(MailAttachmentServiceObject);
        }
        public void Create()
        {
            List<Property> CRMTaskProps = GetCRMTaskProperties();

            ServiceObject CRMTaskServiceObject = new ServiceObject();
            CRMTaskServiceObject.Name = "crmtask";
            CRMTaskServiceObject.MetaData.DisplayName = "CRM Task";

            // JJK: not sure I need this
            CRMTaskServiceObject.MetaData.ServiceProperties.Add("objecttype", "task");

            CRMTaskServiceObject.Active = true;

            foreach (Property prop in CRMTaskProps)
            {
                CRMTaskServiceObject.Properties.Add(prop);
            }            

            serviceBroker.Service.ServiceObjects.Add(CRMTaskServiceObject);

        }
Beispiel #41
0
        /// <summary>
        /// Get information about all the services on the Windows box
        /// </summary>
        /// <returns>Returns a collection of ServiceObjects</returns>
        public ServiceObject[] GetServices()
        {
            ServiceController[] scServices;
            scServices = ServiceController.GetServices();

            ServiceObject[] collection;
            List<ServiceObject> tempCol = new List<ServiceObject>();

            foreach (ServiceController scTemp in scServices)
            {
                ServiceObject so = new ServiceObject();

                ManagementObject wmiService;
                wmiService = new ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'");
                wmiService.Get();

                so.Name = wmiService.Properties["Name"].Value.ToString();
                so.DisplayName = wmiService.Properties["Caption"].Value.ToString();
                if (wmiService.Properties["Description"].Value != null)
                {
                    so.Description = wmiService.Properties["Description"].Value.ToString();
                }
                else
                {
                    so.Description = "No Description Provided";
                }

                so.State = wmiService.Properties["State"].Value.ToString();
                so.StartMode = wmiService.Properties["StartMode"].Value.ToString();
                so.Status = wmiService.Properties["Status"].Value.ToString();

                tempCol.Add(so);

            }

            collection = tempCol.ToArray();
            return collection;
        }
        public void DescribeSchema()
        {
            string schemaPath = Environment.CurrentDirectory + @"\K2.Demo.CRM.Functions.ServiceBroker.xml";
            SchemaObject schemaObject = SchemaManager.LoadSchemaXMLFile(schemaPath);

            //Populate the details of the current instance of the service base and create an instance of the service object

            SvcI.Name = schemaObject.ServiceInstanceName;
            SvcI.MetaData.DisplayName = schemaObject.ServiceInstanceDisplayName;
            SvcI.MetaData.Description = schemaObject.ServiceInstanceDescription;

            //Create the service object instance
            ServiceObject SO = new ServiceObject(schemaObject.ServiceInstanceName);
            SO.MetaData.DisplayName = schemaObject.ServiceInstanceDisplayName;
            SO.Active = true;

            //Create the properties for the serviceObject
            //Create a property for the serviceObject
            Property prop = null;

            //Dynamic Properties;
            foreach (SchemaObject.SchemaProperty sProp in schemaObject.SchemaProperties)
            {
                prop = SchemaManager.CreateProperty(sProp.Name,sProp.DisplayName, sProp.Description, sProp.TrueType,sProp.K2Type);
                //Add this property to the service object properties collection
                SO.Properties.Add(prop);
            }

            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = null;
            foreach (SchemaObject.SchemaMethod sMeth in schemaObject.SchemaMethods)
            {
                meth = SchemaManager.CreateMethod(sMeth.Name,sMeth.DisplayName,sMeth.Description,sMeth.K2Type,sMeth.InputProperties,sMeth.RequiredProperties,sMeth.ReturnProperties);
                SO.Methods.Add(meth);
            }

            SvcI.ServiceObjects.Add(SO);
        }
        public void Create()
        {
            //List<Property> SPSearchProps = GetSPSearchProperties();

            List<Property> SPSearchProps = GetSPSearchProperties();

            ServiceObject SPSearchServiceObject = new ServiceObject();
            SPSearchServiceObject.Name = "spsearch";
            SPSearchServiceObject.MetaData.DisplayName = "SharePoint Search";

            SPSearchServiceObject.MetaData.ServiceProperties.Add("objecttype", "search");

            SPSearchServiceObject.Active = true;

            foreach (Property prop in SPSearchProps)
            {
                if (!SPSearchServiceObject.Properties.Contains(prop.Name))
                {
                    SPSearchServiceObject.Properties.Add(prop);
                }
            }

            SPSearchServiceObject.Methods.Add(CreateSearch(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateSearchRead(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateDeserializeSearchResults(SPSearchProps));

            if (this.Configuration.AdvancedSearchOptions)
            {
                SPSearchServiceObject.Methods.Add(CreateSearchRaw(SPSearchProps));
                SPSearchServiceObject.Methods.Add(CreateSearchRawRead(SPSearchProps));
            }

            SPSearchServiceObject.Methods.Add(CreateListSourceIds(SPSearchProps));
            SPSearchServiceObject.Methods.Add(CreateListOtherSourceIds(SPSearchProps));

            serviceBroker.Service.ServiceObjects.Add(SPSearchServiceObject);
        }
        public void ExecuteListOtherSourceIds(Property[] inputs, RequiredProperties required, Property[] returns, MethodType methodType, ServiceObject serviceObject)
        {
            serviceObject.Properties.InitResultTable();
            System.Data.DataRow dr;

            foreach (var Source in SPSearchSource.GetOtherSourceIds())
            {
                dr = serviceBroker.ServicePackage.ResultTable.NewRow();
                Guid sid = Guid.Empty;
                if (Guid.TryParse(Source.Key, out sid))
                {
                    dr["sourceid"] = sid;
                    dr["sourcename"] = Source.Value;
                }
                serviceBroker.ServicePackage.ResultTable.Rows.Add(dr);
            }

        }
        public void ExecuteSearchRead(Property[] inputs, RequiredProperties required, Property[] returns, MethodType methodType, ServiceObject serviceObject)
        {
            SPExecute Excute = new SPExecute(this.serviceBroker, this.Configuration);
            Excute.ExecuteSearchRead(inputs, required, returns, methodType, serviceObject);

            //serviceObject.Properties.InitResultTable();

            //try
            //{
            //    RESTSearchResultsSerialized SerializedResults = new RESTSearchResultsSerialized();

            //    if (serviceObject.Methods[0].Name.Equals("spsearchread"))
            //    {
            //        SerializedResults = Utilities.BrokerUtils.ExecuteSharePointSearch(inputs, required, Configuration, serviceBroker);
            //    }

            //    if (serviceObject.Methods[0].Name.Equals("spsearchrawread"))
            //    {
            //        SerializedResults = Utilities.BrokerUtils.ExecuteSharePointSearchRaw(inputs, required, Configuration, serviceBroker);
            //    }

            //    if (SerializedResults != null)
            //    {
            //        if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.Search))
            //        {
            //            returns.Where(p => p.Name.Equals("search", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.Search;
            //        }
                    
            //        if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.SiteUrl))
            //        {
            //            returns.Where(p => p.Name.Equals("searchsiteurl", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.Search;
            //        }
                    
            //        if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.FileExtensionsString))
            //        {
            //            returns.Where(p => p.Name.Equals("fileextensionsfilter", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.FileExtensionsString;
            //        }

            //        if (SerializedResults.Inputs.SourceId != null && SerializedResults.Inputs.SourceId != Guid.Empty)
            //        {
            //            returns.Where(p => p.Name.Equals("sourceid", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.SourceId;
            //        }
                    
            //        if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.SortString))
            //        {
            //            returns.Where(p => p.Name.Equals("sort", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.SortString;
            //        }
                    
            //        if (SerializedResults.Inputs.StartRow.HasValue && SerializedResults.Inputs.StartRow.Value > -1)
            //        {
            //            returns.Where(p => p.Name.Equals("startrow", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.StartRow.Value;
            //        }

            //        if (SerializedResults.Inputs.RowLimit.HasValue && SerializedResults.Inputs.RowLimit.Value > 0)
            //        {
            //            returns.Where(p => p.Name.Equals("rowlimit", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.RowLimit.Value;
            //        }

            //        if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.Properties))
            //        {
            //            returns.Where(p => p.Name.Equals("properties", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.Properties;
            //        }

            //        if (SerializedResults.Inputs.EnableStemming.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("enablestemming", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.EnableStemming.Value;
            //        }

            //        if (SerializedResults.Inputs.TrimDuplicates.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("trimduplicates", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.TrimDuplicates.Value;
            //        }

            //        if (SerializedResults.Inputs.EnableQueryRules.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("enablequeryrules", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.EnableQueryRules.Value;
            //        }

            //        if (SerializedResults.Inputs.ProcessBestBets.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("processbestbets", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.ProcessBestBets.Value;
            //        }

            //        if (SerializedResults.Inputs.ProcessPersonal.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("processpersonal", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.ProcessPersonal.Value;
            //        }

            //        if (SerializedResults.Inputs.EnableNicknames.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("enablenicknames", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.EnableNicknames.Value;
            //        }

            //        if (SerializedResults.Inputs.EnablePhonetic.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("enablephonetic", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.Inputs.EnablePhonetic.Value;
            //        }

            //        if (SerializedResults.ExecutionTime.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("executiontime", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.ExecutionTime.Value;
            //        }

            //        if (SerializedResults.ResultRows.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("resultrows", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.ResultRows.Value;
            //        }

            //        if (SerializedResults.TotalRows.HasValue)
            //        {
            //            returns.Where(p => p.Name.Equals("totalrows", StringComparison.OrdinalIgnoreCase)).First().Value = SerializedResults.TotalRows.Value;
            //        }

            //        string resultsJson = JsonConvert.SerializeObject(SerializedResults);

            //        returns.Where(p => p.Name.Equals("serializedresults", StringComparison.OrdinalIgnoreCase)).First().Value = resultsJson;

            //        returns.Where(p => p.Name.Equals("responsestatus", StringComparison.OrdinalIgnoreCase)).First().Value = ResponseStatus.Success;
            //    }
            //    else
            //    {
            //        throw new Exception("No results returned.");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    returns.Where(p => p.Name.Equals("responsestatus", StringComparison.OrdinalIgnoreCase)).First().Value = ResponseStatus.Error;
            //    returns.Where(p => p.Name.Equals("responsestatusdescription", StringComparison.OrdinalIgnoreCase)).First().Value = ex.Message;
            //}
            //serviceObject.Properties.BindPropertiesToResultTable();
        }
        public void ExecuteSearch(Property[] inputs, RequiredProperties required, Property[] returns, MethodType methodType, ServiceObject serviceObject)
        {
            SPExecute Excute = new SPExecute(this.serviceBroker, this.Configuration);
            Excute.ExecuteSearch(inputs, required, returns, methodType, serviceObject);

            //serviceObject.Properties.InitResultTable();
            //System.Data.DataRow dr;
            //try
            //{
            //    RESTSearchResultsSerialized SerializedResults = null;

            //    // if deserializesearchresults
            //    if(serviceObject.Methods[0].Name.Equals("deserializesearchresults"))
            //    { 
            //        Property SerializedProp = inputs.Where(p => p.Name.Equals("serializedresults", StringComparison.OrdinalIgnoreCase)).First();
            //        string json = string.Empty;
            //        json = SerializedProp.Value.ToString();

            //        SerializedResults = JsonConvert.DeserializeObject<RESTSearchResultsSerialized>(json.Trim());

            //        if (string.IsNullOrWhiteSpace(json) || SerializedResults == null)
            //        {
            //            throw new Exception("Failed to deserialize search results");
            //        }
            //    }

            //    if (serviceObject.Methods[0].Name.Equals("spsearch"))
            //    {
            //        // if Search
            //        SerializedResults = Utilities.BrokerUtils.ExecuteSharePointSearch(inputs, required, Configuration, serviceBroker);
            //    }

            //    if (serviceObject.Methods[0].Name.Equals("spsearchraw"))
            //    {
            //        // if Search Raw Read
            //        SerializedResults = Utilities.BrokerUtils.ExecuteSharePointSearchRaw(inputs, required, Configuration, serviceBroker);
            //    }


            //    if (SerializedResults != null)
            //    {
            //        // needs updating for REST
            //        foreach (ResultRow result in SerializedResults.SearchResults.Rows)
            //        {
            //            dr = serviceBroker.ServicePackage.ResultTable.NewRow();

            //            if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.Search))
            //            {
            //                dr["search"] = SerializedResults.Inputs.Search;
            //            }

            //            if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.SiteUrl))
            //            {
            //                dr["searchsiteurl"] = SerializedResults.Inputs.Search;
            //            }

            //            if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.FileExtensionsString))
            //            {
            //                dr["fileextensionsfilter"] = SerializedResults.Inputs.FileExtensionsString;
            //            }

            //            if (SerializedResults.Inputs.SourceId != null && SerializedResults.Inputs.SourceId != Guid.Empty)
            //            {                            
            //                dr["sourceid"] = SerializedResults.Inputs.SourceId;                            
            //            }

            //            if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.SortString))
            //            {
            //                dr["sort"] = SerializedResults.Inputs.SortString;
            //            }

            //            if (SerializedResults.Inputs.StartRow.HasValue && SerializedResults.Inputs.StartRow.Value > -1)
            //            {
            //                dr["startrow"] = SerializedResults.Inputs.StartRow.Value;
            //            }

            //            if (SerializedResults.Inputs.RowLimit.HasValue && SerializedResults.Inputs.RowLimit.Value > 0)
            //            {
            //                dr["rowlimit"] = SerializedResults.Inputs.RowLimit.Value;
            //            }

            //            if (!string.IsNullOrWhiteSpace(SerializedResults.Inputs.Properties))
            //            {
            //                dr["properties"] = SerializedResults.Inputs.Properties;
            //            }

            //            if (SerializedResults.Inputs.EnableStemming.HasValue && SerializedResults.Inputs.EnableStemming.Value)
            //            {
            //                dr["enablestemming"] = SerializedResults.Inputs.EnableStemming.Value;
            //            }

            //            if (SerializedResults.Inputs.TrimDuplicates.HasValue && SerializedResults.Inputs.TrimDuplicates.Value)
            //            {
            //                dr["trimduplicates"] = SerializedResults.Inputs.TrimDuplicates.Value;
            //            }

            //            if (SerializedResults.Inputs.EnableQueryRules.HasValue && SerializedResults.Inputs.EnableQueryRules.Value)
            //            {
            //                dr["enablequeryrules"] = SerializedResults.Inputs.EnableQueryRules.Value;
            //            }

            //            if (SerializedResults.Inputs.ProcessBestBets.HasValue && SerializedResults.Inputs.ProcessBestBets.Value)
            //            {
            //                dr["processbestbets"] = SerializedResults.Inputs.ProcessBestBets.Value;
            //            }

            //            if (SerializedResults.Inputs.ProcessPersonal.HasValue && SerializedResults.Inputs.ProcessPersonal.Value)
            //            {
            //                dr["processpersonal"] = SerializedResults.Inputs.ProcessPersonal.Value;
            //            }

            //            if (SerializedResults.Inputs.EnableNicknames.HasValue && SerializedResults.Inputs.EnableNicknames.Value)
            //            {
            //                dr["enablenicknames"] = SerializedResults.Inputs.EnableNicknames.Value;
            //            }

            //            if (SerializedResults.Inputs.EnablePhonetic.HasValue && SerializedResults.Inputs.EnablePhonetic.Value)
            //            {
            //                dr["enablephonetic"] = SerializedResults.Inputs.EnablePhonetic.Value;
            //            }
                        
            //            if (SerializedResults.ExecutionTime.HasValue)
            //            {
            //                dr["executiontime"] = SerializedResults.ExecutionTime.Value;                            
            //            }

            //            if (SerializedResults.ResultRows.HasValue)
            //            {
            //                dr["resultrows"] = SerializedResults.ResultRows.Value;
            //            }
            //            if (SerializedResults.TotalRows.HasValue)
            //            {
            //                dr["totalrows"] = SerializedResults.TotalRows.Value;
            //            }

            //            List<string> missingprops = new List<string>();
            //            foreach (ResultCell cell in result.Cells)
            //            {
            //                if (dr.Table.Columns.Contains(cell.Key.ToLower()))
            //                {
            //                    if (cell.Value != null)
            //                    {
            //                        dr[cell.Key.ToLower()] = cell.Value;
            //                    }
            //                }
            //                else
            //                {
            //                    missingprops.Add(cell.Key);
            //                }
            //            }

            //            dr["responsestatus"] = ResponseStatus.Success;
            //            serviceBroker.ServicePackage.ResultTable.Rows.Add(dr);
            //        }
            //    }
            //    else
            //    {
            //        throw new Exception("No results returned.");
            //    }

            //}
            //catch (Exception ex)
            //{
            //    dr = serviceBroker.ServicePackage.ResultTable.NewRow();
            //    dr["responsestatus"] = ResponseStatus.Error;
            //    dr["responsestatusdescription"] = ex.Message;
            //    serviceBroker.ServicePackage.ResultTable.Rows.Add(dr);
            //}

            ////serviceObject.Properties.BindPropertiesToResultTable();
        }
Beispiel #47
0
 /// <summary>
 /// Create a service object with a name and description.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="description"></param>
 /// <returns></returns>
 public static ServiceObject CreateServiceObject(string name, string description)
 {
     ServiceObject so = new ServiceObject
     {
         Name = name,
         MetaData = new MetaData(AddSpaceBeforeCaptialLetter(name), description),
         Active = true
     };
     return so;
 }
Beispiel #48
0
 /// <summary>
 ///     Construct DTO model without payload object using WebApiServiceException.
 /// </summary>
 /// <param name="exception">the exception</param>
 public DtoModelOutgoing(ManagedException exception, IPayload errorDetails = null)
 {
     Payload = errorDetails;
     Service = new ServiceObject(exception.ErrorCode, exception.ErrorMessage);
 }
Beispiel #49
0
 private static void AddServiceObjectProperty(ServiceObject serviceObject, Property property)
 {
     if (!serviceObject.Properties.Contains(property.Name))
     {
         serviceObject.Properties.Add(property);
     }
     else
     {
         // We only support one web service with unique parameters. This could actually be different if we prefix the property with a method name.
         if (serviceObject.Properties[property.Name].SoType != property.SoType)
         {
             throw new Exception("Custom object contains property with the same name as one of the parameters to the web service, but which is of a different type.");
         }
     }
 }
 /// <summary>
 /// Implements the OnChange event handler for the item associated with the attachment.
 /// </summary>
 /// <param name="serviceObject">The service object that triggered the OnChange event.</param>
 private void ItemChanged(ServiceObject serviceObject)
 {
     if (this.Owner != null)
     {
         this.Owner.PropertyBag.Changed();
     }
 }
Beispiel #51
0
        /// <summary>
        /// Add output properties to the given serviceObject and smoMethod using the given method.
        /// 
        /// The method returns directly if the smoMethod is of type Execute.
        /// 
        /// It uses the method's ReturnType to determine the properties needed.
        /// For simple types it will create one output property. If the returnType commes from within the webServiceAssembly, 
        /// it must be a container object with simple types in it. If it does not contain simple types, we cannot support it because a smartobject is a flat structure.
        /// If the returnType is an array, it may contain a container object, but again, that needs to have simple types.
        /// </summary>
        /// <param name="serviceObject"></param>
        /// <param name="method"></param>
        /// <param name="smoMethod"></param>
        /// <param name="webServiceAssembly"></param>
        public static void CreateOutputProperties(ServiceObject serviceObject, Method smoMethod, MethodInfo method, Assembly webServiceAssembly)
        {
            if (smoMethod.Type == MethodType.Execute)
            {
                return; // execute does not have return parameters!
            }

            Type returnType = method.ReturnType;

            if (MapHelper.IsSimpleMapableType(returnType)) // A simple return value
            {
                Property property = CreateSmoProperty(returnType.Name, returnType);
                AddServiceObjectProperty(serviceObject, property);
                smoMethod.ReturnProperties.Add(property);
            }
            else if (returnType.IsArray) // The return value is an array.
            {
                if (smoMethod.Type != MethodType.List)
                {
                    throw new NotSupportedException("We retrieved an array, but the method is not a list method.");
                }

                returnType = returnType.GetElementType();
                if (returnType.Assembly == webServiceAssembly) // it is an array of a container object.
                {
                    foreach (PropertyInfo prop in returnType.GetProperties())
                    {
                        if (!MapHelper.IsSimpleMapableType(prop.PropertyType))
                        {
                            throw new NotSupportedException("The return type of the web service is a Container Object inside an Array.The Container Object contains a non-simple type which we cannot support.");
                        }

                        Property property = CreateSmoProperty(prop.Name, prop.PropertyType);
                        AddServiceObjectProperty(serviceObject, property);
                        smoMethod.ReturnProperties.Add(property);
                    }
                }
                else if (MapHelper.IsSimpleMapableType(returnType))
                {
                    Property property = CreateSmoProperty(returnType.Name, returnType);
                    AddServiceObjectProperty(serviceObject, property);
                    smoMethod.ReturnProperties.Add(property);
                }
                else
                {
                    throw new NotSupportedException(string.Format("Return type is an array of element {0}. Which is not supported.", returnType.ToString()));
                }
            }
            else if (returnType.Assembly == webServiceAssembly) // Not a simple type, not an array, it must be a complex object.
            {
                foreach (PropertyInfo prop in returnType.GetProperties())
                {
                    if (!MapHelper.IsSimpleMapableType(prop.PropertyType))
                    {
                        throw new NotSupportedException("The return type of the web service is a Container Object or an Array. But it contains non simple types.");
                    }

                    Property property = CreateSmoProperty(prop.Name, prop.PropertyType);
                    AddServiceObjectProperty(serviceObject, property);
                    smoMethod.ReturnProperties.Add(property);
                }
            }
            else
            {
                throw new NotSupportedException("Could not create output properties. The returntype is not a Simple type, an array or not a simple type....");
            }
        }
Beispiel #52
0
 /// <summary>
 ///     Construct DTO model using payload object.
 ///     The error code is ZERO and error message is NULL.
 /// </summary>
 /// <param name="payload">the DTO payload object</param>
 public DtoModelOutgoing(IPayload payload)
 {
     Payload = payload;
     Service = new ServiceObject();
 }
 public void ExecuteSearchRead(Property[] inputs, RequiredProperties required, Property[] returns, MethodType methodType, ServiceObject serviceObject)
 {
     SPExecute Excute = new SPExecute(this.serviceBroker, this.Configuration);
     Excute.ExecuteSearchRead(inputs, required, returns, methodType, serviceObject);
 }
        public void ExecuteCreateTask(Property[] inputs, RequiredProperties required, Property[] returns, MethodType methodType, ServiceObject serviceObject)
        {
            serviceObject.Properties.InitResultTable();

            Functions.CRMFunctions CRMFunctions = new Functions.CRMFunctions(Utilities.FunctionsUtils.GetCRMConfig(serviceBroker.Service.ServiceConfiguration));

            Functions.CRMTask CRMTaskInput = new Functions.CRMTask();
            Functions.CRMTask CRMTaskResult = null;

            try
            {

                PropertyInfo[] PropInfoCRMTask = CRMTaskResult.GetType().GetProperties(BindingFlags.Public);

                foreach (Property prop in inputs)
                {
                    if (prop.Value != null)
                    {
                        //PropertyInfo RefProp = PropInfoCRMTask.Where(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)).First();
                        PropertyInfo RefProp = PropInfoCRMTask.GetType().GetProperty(prop.Name);
                        if (RefProp != null)
                        {
                            //prop.Value = Utilities.ReflectionUtils.GetPropValue(CRMTaskResult, RefProp.Name);
                            Utilities.ReflectionUtils.SetPropValue<Functions.CRMTask>(CRMTaskInput, prop.Name, prop.Value);

                        }
                    }
                }


                //required
                //CRMTaskInput.Category = inputs.Where(p => p.Name.Equals("category", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                //CRMTaskInput.Description = inputs.Where(p => p.Name.Equals("description", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                ////required
                //CRMTaskInput.DueDate = DateTime.Parse(inputs.Where(p => p.Name.Equals("duedate", StringComparison.OrdinalIgnoreCase)).First().Value.ToString());

                ////required
                //CRMTaskInput.Duration = int.Parse(inputs.Where(p => p.Name.Equals("duration", StringComparison.OrdinalIgnoreCase)).First().Value.ToString());
                
                //CRMTaskInput.OwnerFQN = inputs.Where(p => p.Name.Equals("ownerfqn", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                //CRMTaskInput.Owner = inputs.Where(p => p.Name.Equals("owner", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                //CRMTaskInput.OwnerId = inputs.Where(p => p.Name.Equals("ownerid", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                ////required
                //CRMTaskInput.Priority = int.Parse(inputs.Where(p => p.Name.Equals("priority", StringComparison.OrdinalIgnoreCase)).First().Value.ToString());
                
                //CRMTaskInput.Regarding = inputs.Where(p => p.Name.Equals("regarding", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                //CRMTaskInput.RegardingId = inputs.Where(p => p.Name.Equals("regardingid", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                ////required
                //CRMTaskInput.State = int.Parse(inputs.Where(p => p.Name.Equals("state", StringComparison.OrdinalIgnoreCase)).First().Value.ToString());
                
                ////required
                //CRMTaskInput.Status = int.Parse(inputs.Where(p => p.Name.Equals("status", StringComparison.OrdinalIgnoreCase)).First().Value.ToString());
                
                ////required
                //CRMTaskInput.Subcategory = inputs.Where(p => p.Name.Equals("subcategory", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                ////required
                //CRMTaskInput.Subject = inputs.Where(p => p.Name.Equals("subject", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                
                //CRMTaskInput.K2SerialNumber = inputs.Where(p => p.Name.Equals("k2serialnumber", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                //CRMTaskInput.K2ProcessName = inputs.Where(p => p.Name.Equals("k2processname", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();
                //CRMTaskInput.K2ActivityName = inputs.Where(p => p.Name.Equals("k2activityname", StringComparison.OrdinalIgnoreCase)).First().Value.ToString();

                //int procInstId;
                //if (int.TryParse(inputs.Where(p => p.Name.Equals("k2processinstanceid", StringComparison.OrdinalIgnoreCase)).First().Value.ToString(), out procInstId))
                //{
                //    CRMTaskInput.K2ProcessInstanceId = procInstId;
                //}
                
                CRMTaskResult = CRMFunctions.CRMCreateTask(CRMTaskInput);

                //List<string> OProps = new List<string>();
                //OProps.Where(p => p == "").First();

                if (CRMTaskResult != null)
                {

                    //foreach(PropertyInfo prop in CRMTaskResult.GetType().GetProperties(BindingFlags.Public))
                    foreach(Property prop in returns)
                    {
                        //PropertyInfo RefProp = PropInfoCRMTask.Where(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)).First();
                        PropertyInfo RefProp = PropInfoCRMTask.GetType().GetProperty(prop.Name);
                        if( RefProp != null)
                        {
                            prop.Value = Utilities.ReflectionUtils.GetPropValue(CRMTaskResult, RefProp.Name);
                        }

                        //PropertyInfo aa = PropInfoCRMTask.Where(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)).First();


                        //if (returns.Where(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)).First() != null)
                        //{
                        //    returns.Where(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)).First().Value = Utilities.ReflectionUtils.GetPropValue(CRMTaskResult, prop.Name);
                        //}

                    }
                    returns.Where(p => p.Name.Equals("responsestatus")).First().Value = ResponseStatus.Success;
                }
                else
                {
                    throw new Exception("CRMTaskResult is null.");
                }

            }
            catch (Exception ex)
            {
                returns.Where(p => p.Name.Equals("responsestatus")).First().Value = ResponseStatus.Error;
                returns.Where(p => p.Name.Equals("responsestatusdescription")).First().Value = ex.Message;
            }

            serviceObject.Properties.BindPropertiesToResultTable();
        }
Beispiel #55
0
 public DtoModelOutgoing(IEnumerable<DtoModelOutgoing> payloads)
 {
     Payload = payloads;
     Service = new ServiceObject();
 }
Beispiel #56
0
 /// <summary>
 ///     Construct DTO model without payload object using error code and message.
 /// </summary>
 /// <param name="errorCode">the error code</param>
 /// <param name="errorMessage">the error user friendly message</param>
 public DtoModelOutgoing(ErrorCodes errorCode, string errorMessage)
 {
     Payload = null;
     Service = new ServiceObject(errorCode, errorMessage);
 }
 /// <summary>
 /// Describes the functionality of the service object
 /// </summary>
 /// <returns>Returns the service object definition.</returns>
 internal ServiceObject DescribeServiceObject()
 {
     ServiceObject so = new ServiceObject("BasicWorklistItem");
     so.Type = "BasicWorklistItem";
     so.Active = true;
     so.MetaData.DisplayName = "Basic Worklist Item";
     so.MetaData.Description = "Represents a Basic WorklistItem";
     so.Properties = DescribeProperties();
     so.Methods = DescribeMethods();
     return so;
 }
Beispiel #58
0
 /// <summary>
 /// Create a ServiceObject from a System.Reflection.MethodInfo object.
 /// 
 /// Uses the method.Name for the ServiceObject name and description.
 /// </summary>
 public static ServiceObject CreateServiceObject(MethodInfo method)
 {
     ServiceObject serviceObject = new ServiceObject();
     serviceObject.Name = method.Name;
     serviceObject.MetaData.DisplayName = method.Name;
     serviceObject.MetaData.Description = "Webservice method " + method.Name;
     serviceObject.Active = true;
     return serviceObject;
 }
        /// <summary>
        /// Executes the Service Object method and returns any data.
        /// </summary>
        /// <param name="inputs">A Property[] array containing all the allowed input properties.</param>
        /// <param name="required">A RequiredProperties collection containing the required properties.</param>
        /// <param name="returns">A Property[] array containing all the allowed return properties.</param>
        /// <param name="methodType">A MethoType indicating what type of Service Object method was called.</param>
        /// <param name="serviceObject">A ServiceObject containing populated properties for use with the method call.</param>
        public void Execute(Property[] inputs, RequiredProperties required, Property[] returns, MethodType methodType, ServiceObject serviceObject)
        {
            crmconfig = new CRMConfig
            {
                CRMURL = crmurl,
                CRMOrganization = crmorganization
            };


            #region Container


            if (serviceObject.Methods[0].Name.Equals("loadcontainer"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteLoadContainer(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("listcontainers"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteListContainers(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("createcontainer"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteCreateContainer(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("setcontainerpermissions"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteSetPermissions(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("setcontainermetadata"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteSetMetadata(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("loadcontainermetadatavalue"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteLoadMetadataValue(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("listcontainermetadata"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteListMetadata(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("deletecontainer"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteDeleteContainer(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("listcontainerfolders"))
            {
                BlobContainer container = new BlobContainer(serviceBroker);
                container.ExecuteListContainerFolders(inputs, required, returns, methodType, serviceObject);
            }

            #endregion Container


            #region Blob


            if (serviceObject.Methods[0].Name.Equals("loadblob"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteLoadBlob(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("setblobmetadata"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteSetBlobMetadata(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("loadblobmetadatavalue"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteLoadBlobMetadataValue(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("listblobmetadata"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteListBlobMetadata(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("deleteblob"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteDeleteBlob(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("uploadblob"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteUploadBlob(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("uploadblobfrombase64"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteUploadBlobFromBase64(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("uploadblobfromfilesystem"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteUploadBlobFromFilePath(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("uploadblobfromurl"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteUploadBlobFromUrl(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("listblobs"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteListBlobs(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("downloadblob"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteDownloadBlob(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("downloadblobtobase64"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteDownloadBlobAsBase64(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("downloadblobtofilesystem"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteDownloadBlobToFileSystem(inputs, required, returns, methodType, serviceObject);
            }

            if (serviceObject.Methods[0].Name.Equals("setblobproperties"))
            {
                BlobBlob blob = new BlobBlob(serviceBroker);
                blob.ExecuteSetBlobProperties(inputs, required, returns, methodType, serviceObject);
            }

            #endregion Blob

        }
Beispiel #60
0
 /// <summary>
 ///     Construct DTO model without payload object using WebApiServiceException.
 /// </summary>
 /// <param name="exception">the exception</param>
 public DtoModelOutgoing(ManagedException exception, IEnumerable<IPayload> errorDetails)
 {
     Payload = errorDetails;
     Service = new ServiceObject(exception.ErrorCode, exception.ErrorMessage);
 }