示例#1
0
 public IActionResult AppToken(AppKey appKey)
 {
     _sourceControl.StoreAppTokenForUser(appKey.Key);
     return(Redirect("/"));
 }
示例#2
0
        private void CreateUser(HttpContext context)
        {
            string username = context.Param(SiteParameters.USER_NAME);
            string email = context.Param(SiteParameters.USER_EMAIL);
            string password = context.Param(SiteParameters.PASSWORD);
            string appKeyStr = context.Param(SiteParameters.APP_KEY);
            var appKey = new AppKey(appKeyStr);

            UserManagementService.CreateUser(username, email, password, appKey);
        }
示例#3
0
 /// <summary>
 /// Gets a <seealso cref="bool"/> config value.
 /// </summary>
 /// <param name="key">The config key.</param>
 /// <returns>The boolean value.</returns>
 internal static bool GetBool(AppKey key)
 {
     return(_inner[string.Format("{0}:{1}", MAIN_APP_KEY, key)].ToLowerInvariant().Equals(bool.TrueString.ToLowerInvariant()));
 }
示例#4
0
 /// <summary>
 /// Gets a <seealso cref="int"/> config value.
 /// </summary>
 /// <param name="key">The config key.</param>
 /// <returns>The int value.</returns>
 internal static int GetInt32(AppKey key)
 {
     int.TryParse(_inner[string.Format("{0}:{1}", MAIN_APP_KEY, key)], out int intValue);
     return(intValue);
 }
 private async Task <App> addOrUpdateApp(AppKey appKey)
 {
     return(await appFactory.Apps().AddOrUpdate(appKey, appKey.Name.DisplayText, clock.Now()));
 }
示例#6
0
 /// <summary>
 /// Gets a <seealso cref="string"/> config value.
 /// </summary>
 /// <param name="key">The config key.</param>
 /// <returns>The string value.</returns>
 internal static string GetString(AppKey key)
 {
     return(_inner[string.Format("{0}:{1}", MAIN_APP_KEY, key)]);
 }
示例#7
0
        public void ProcessRequest(HttpContext context)
        {
            string result = null;

            try
            {
                SiteResponse response;
                string username = context.Param(SiteParameters.USER_NAME);
                string email = context.Param(SiteParameters.EMAIL);
                string password = context.Param(SiteParameters.PASSWORD);
                var appKey = new AppKey(context.Param(SiteParameters.APP_KEY));

                var user = UserManagementService.CreateUser(username, email, password, appKey);

                response = new SiteResponse
                {
                    response = user,
                    status = SiteResponse.Status.Success,
                    syncKey = "are we using this?"
                };

                result = JSONHelper.Serialize<SiteResponse>(response, new []{typeof(User)});
            }
            catch (UserManagementServiceException umse)
            {
                ExceptionHelper.Code exceptionCode = ExceptionHelper.Code.UnexpectedException;
                string message = umse.Message;

                switch (umse.Code)
                {
                    case UserManagementServiceException.ErrorCode.UnexpectedError:
                        break;
                    case UserManagementServiceException.ErrorCode.ObjectNotFound:
                        exceptionCode = ExceptionHelper.Code.InvalidLogin;
                        break;
                    case UserManagementServiceException.ErrorCode.InvalidOperationOnResource:
                        exceptionCode = ExceptionHelper.Code.InvalidOperation;
                        break;
                    case UserManagementServiceException.ErrorCode.AccessDenied:
                        exceptionCode = ExceptionHelper.Code.AccessDenied;
                        break;
                    case UserManagementServiceException.ErrorCode.CouldNotConnectToDatabase:
                        message = "Could not connect to the database. " + message;
                        break;
                    default:
                        message = "Unknown ErrorCode: " + umse.Code + ". Message: " + message;
                        break;
                }

                result = JSONHelper.Serialize(ExceptionHelper.Handle(umse, exceptionCode, message, log));
            }
            catch (Exception e)
            {
                result = JSONHelper.Serialize(ExceptionHelper.Handle(e, log));
            }
            finally
            {
                context.Response.ContentType = MediaTypeNames.Text.Plain;
                context.Response.Write(result);
            }
        }
示例#8
0
            static string GetValue(AppKey key, string defaultValue)
            {
                string value = ConfigurationManager.AppSettings[key];

                return(string.IsNullOrWhiteSpace(value) ? defaultValue : value);
            }
        protected override void Execute(CodeActivityContext executionContext)
        {
            EntityReference DocumentTemplateIdValue = DocumentTemplateId.Get(executionContext);
            Boolean         EnableLoggingValue      = EnableLogging.Get(executionContext);
            string          ProductUriValue         = ProductUri.Get(executionContext);
            string          AppSIDValue             = AppSID.Get(executionContext);
            string          AppKeyValue             = AppKey.Get(executionContext);
            Boolean         DeleteTemplateValue     = DeleteTemplate.Get(executionContext);
            Boolean         DeleteDocumentValue     = DeleteDocument.Get(executionContext);

            OutputAttachmentId.Set(executionContext, new EntityReference("annotation", Guid.Empty));
            CloudAppConfig config = new CloudAppConfig();

            config.ProductUri = ProductUriValue;
            config.AppSID     = AppSIDValue;
            config.AppKey     = AppKeyValue;
            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                if (EnableLoggingValue)
                {
                    Log("WorkFlow Started", service);
                }

                string PrimaryEntityName = context.PrimaryEntityName;
                Guid   PrimaryEntityId   = context.PrimaryEntityId;
                if (EnableLoggingValue)
                {
                    Log("Retrieving Attachment From Template", service);
                }
                QueryExpression RetrieveNoteQuery = new QueryExpression("annotation");
                RetrieveNoteQuery.ColumnSet = new ColumnSet(new string[] { "filename", "documentbody", "mimetype" });
                RetrieveNoteQuery.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, DocumentTemplateIdValue.Id));
                EntityCollection TemplateAttachments = service.RetrieveMultiple(RetrieveNoteQuery);
                if (EnableLoggingValue)
                {
                    Log("Attachment Retrieved Successfully", service);
                }

                if (TemplateAttachments != null && TemplateAttachments.Entities.Count > 0)
                {
                    Entity AttachmentTemplate = TemplateAttachments.Entities[0];
                    if (AttachmentTemplate.Contains("mimetype") && AttachmentTemplate.Contains("documentbody"))
                    {
                        string FileName = "";
                        if (AttachmentTemplate.Contains("filename"))
                        {
                            FileName = AttachmentTemplate["filename"].ToString();
                        }
                        config.FileName = FileName;
                        byte[]       DocumentBody = Convert.FromBase64String(AttachmentTemplate["documentbody"].ToString());
                        MemoryStream fileStream   = new MemoryStream(DocumentBody);

                        if (EnableLoggingValue)
                        {
                            Log("Upload Template on Storage", service);
                        }
                        UploadFileOnStorage(config, fileStream);

                        if (EnableLoggingValue)
                        {
                            Log("Get Fields List", service);
                        }
                        string[] Fields = GetFieldsName(config).ToArray();

                        if (EnableLoggingValue)
                        {
                            Log("Retrieving Fields Values From CRM", service);
                        }
                        Entity   PrimaryEntity = service.Retrieve(PrimaryEntityName, PrimaryEntityId, new ColumnSet(Fields));
                        string[] Values        = new string[Fields.Length];
                        if (PrimaryEntity != null)
                        {
                            for (int i = 0; i < Fields.Length; i++)
                            {
                                if (PrimaryEntity.Contains(Fields[i]))
                                {
                                    if (PrimaryEntity[Fields[i]].GetType() == typeof(OptionSetValue))
                                    {
                                        Values[i] = PrimaryEntity.FormattedValues[Fields[i]].ToString();
                                    }
                                    else if (PrimaryEntity[Fields[i]].GetType() == typeof(EntityReference))
                                    {
                                        Values[i] = ((EntityReference)PrimaryEntity[Fields[i]]).Name;
                                    }
                                    else
                                    {
                                        Values[i] = PrimaryEntity[Fields[i]].ToString();
                                    }
                                }
                                else
                                {
                                    Values[i] = "";
                                }
                            }
                        }

                        if (EnableLoggingValue)
                        {
                            Log("Generating Xml", service);
                        }
                        string Xml = GenerateXML(Fields, Values);

                        if (EnableLoggingValue)
                        {
                            Log("Executing MailMerge", service);
                        }
                        string OutputFileName = ExecuteMailMerge(config, Xml);

                        if (EnableLoggingValue)
                        {
                            Log("Downloading File From Cloud", service);
                        }
                        MemoryStream OutputFile = DownloadFile(config, OutputFileName);

                        if (EnableLoggingValue)
                        {
                            Log("Generating CRM Attachment", service);
                        }
                        byte[] byteData    = OutputFile.ToArray();
                        string encodedData = System.Convert.ToBase64String(byteData);
                        Entity NewNote     = new Entity("annotation");
                        NewNote.Attributes.Add("objectid", new EntityReference(PrimaryEntityName, PrimaryEntityId));
                        NewNote.Attributes.Add("subject", FileName);
                        NewNote.Attributes.Add("documentbody", encodedData);
                        NewNote.Attributes.Add("mimetype", @"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
                        NewNote.Attributes.Add("notetext", "Document Created using Aspose Cloud");
                        NewNote.Attributes.Add("filename", FileName);
                        Guid NewNoteId = service.Create(NewNote);

                        if (EnableLoggingValue)
                        {
                            Log("Removing Documents from Storage", service);
                        }
                        if (DeleteTemplateValue)
                        {
                            DeleteDocumentFromStorage(config, FileName);
                        }
                        if (DeleteDocumentValue)
                        {
                            DeleteDocumentFromStorage(config, OutputFileName);
                        }

                        OutputAttachmentId.Set(executionContext, new EntityReference("annotation", NewNoteId));
                    }
                    else
                    {
                        if (EnableLoggingValue)
                        {
                            Log("Attachment Doesnot contain any document", service);
                        }
                    }
                }
                else
                {
                    if (EnableLoggingValue)
                    {
                        Log("No Attachments in the Template Provided", service);
                    }
                }

                if (EnableLoggingValue)
                {
                    Log("Workflow Executed Successfully", service);
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message, service);
                throw ex;
            }
        }
示例#10
0
 public Task <ResultContainer <AppUserModel[]> > GetSystemUsers([FromBody] AppKey model)
 {
     return(api.Group("Users").Action <AppKey, AppUserModel[]>("GetSystemUsers").Execute(model));
 }
 public SelfAppClientDomain(IHttpContextAccessor httpContextAccessor, AppKey appKey)
 {
     this.httpContextAccessor = httpContextAccessor;
     this.appKey = appKey;
 }
 public Task <AppUser> SystemUser(AppKey appKey, string machineName)
 => User(AppUserName.SystemUser(appKey, machineName));
示例#13
0
 public Task <ResultContainer <AppVersionModel[]> > GetVersions([FromBody] AppKey model)
 {
     return(api.Group("AppRegistration").Action <AppKey, AppVersionModel[]>("GetVersions").Execute(model));
 }
示例#14
0
        /// <summary>加载时</summary>
        protected override void OnLoaded()
        {
            if (AppKey.IsNullOrEmpty()) AppKey = SysConfig.Current.Name;

            base.OnLoaded();
        }
示例#15
0
        public async Task StartRequest(IStartRequestModel startRequest)
        {
            try
            {
                var session = await appFactory.Sessions().Session(startRequest.SessionKey);

                if (session.ID.IsNotValid())
                {
                    session = await startPlaceholderSession(startRequest.SessionKey, new GeneratedKey().Value());
                }
                XtiPath path;
                try
                {
                    path = XtiPath.Parse(startRequest.Path);
                }
                catch
                {
                    path = new XtiPath(AppName.Unknown);
                }
                if (string.IsNullOrWhiteSpace(path.Group))
                {
                    path = path.WithGroup("Home");
                }
                if (string.IsNullOrWhiteSpace(path.Action))
                {
                    path = path.WithAction("Index");
                }
                var appKey = new AppKey(path.App, AppType.Values.Value(startRequest.AppType));
                var app    = await appFactory.Apps().App(appKey);

                var version = await app.Version(path.Version);

                var resourceGroup = await version.ResourceGroup(path.Group);

                var resource = await resourceGroup.Resource(path.Action);

                var modCategory = await resourceGroup.ModCategory();

                var modifier = await modCategory.Modifier(path.Modifier);

                var request = await appFactory.Requests().Request(startRequest.RequestKey);

                if (request.ID.IsValid())
                {
                    await request.Edit
                    (
                        session,
                        resource,
                        modifier,
                        startRequest.Path,
                        startRequest.TimeStarted
                    );
                }
                else
                {
                    await session.LogRequest
                    (
                        startRequest.RequestKey,
                        resource,
                        modifier,
                        startRequest.Path,
                        startRequest.TimeStarted
                    );
                }
            }
            catch (Exception ex)
            {
                await handleError(ex);
            }
        }