예제 #1
0
        public override void Awake(Scene scene)
        {
            base.Awake(scene);

            bool alreadyTriggered = persistent && SceneAs <Level>().Session.GetFlag(id.ToString());

            foreach (EntityTriggerListener listener in scene.Tracker.GetComponents <EntityTriggerListener>())
            {
                Entity entity = listener.Entity;
                if (entity.X >= left && entity.X <= right && entity.Y >= top && entity.Y <= bottom)
                {
                    if (alreadyTriggered)
                    {
                        listener.OnStartTriggered?.Invoke();
                    }
                    else
                    {
                        listeners.Add(listener);
                    }
                }
            }

            if (alreadyTriggered)
            {
                RemoveSelf();
            }
        }
        public override void Added(Scene scene)
        {
            base.Added(scene);

            if (!spawnedAsFollower)
            {
                if (SceneAs <Level>().Session.GetFlag("collected_seeds_of_" + BerryID.ToString()))
                {
                    // if all seeds for this berry were already collected (the berry was already formed), commit remove self.
                    RemoveSelf();
                }
                else
                {
                    // if the seed already follows the player, commit remove self.
                    foreach (MaxHelpingHandSession.MultiRoomStrawberrySeedInfo sessionSeedInfo in MaxHelpingHandModule.Instance.Session.CollectedMultiRoomStrawberrySeeds)
                    {
                        if (sessionSeedInfo.Index == index && sessionSeedInfo.BerryID.ID == BerryID.ID && sessionSeedInfo.BerryID.Level == BerryID.Level)
                        {
                            RemoveSelf();
                            break;
                        }
                    }
                }
            }
        }
예제 #3
0
        public async Task <IList <Chat> > GetChatsForUser(EntityID user)
        {
            var filter =
                Builders <Chat> .Filter.Where(
                    x => x.Members.Contains(user.ToString()));

            var res = await chatsCollection.FindAsync(filter);

            var chat = res.ToList();

            return(chat);
        }
예제 #4
0
        public async Task <Chat> GetById(EntityID chatId)
        {
            var filter =
                Builders <Chat> .Filter.Where(
                    x => x.ChatID == chatId.ToString());

            var res = await chatsCollection.FindAsync(filter);

            var chat = res.FirstOrDefault();

            return(chat);
        }
예제 #5
0
        public async Task <Chat> GetPrivateChat(EntityID u1, EntityID u2)
        {
            var filter =
                Builders <Chat> .Filter.Where(
                    x => x.Members.Contains(u1.ToString()) && x.Members.Contains(u2.ToString()) && x.Members.Length == 2 && x.IsPrivateChat);

            var res = await chatsCollection.FindAsync(filter);

            var chat = res.FirstOrDefault();

            return(chat);
        }
예제 #6
0
        private string CreateNavigateUrl()
        {
            string url = ConvertRelativeUrlToAbsoluteUrl(DeliveryPage);

            UriBuilder builder = new UriBuilder(url);


            //Uri uri = new Uri(baseUri, DeliveryPage);// + "&a=CreateBug&IssueID=' + issueID + '&HideTemplate=true&Title=' + UrlEncode(title) + "&Description=" + UrlEncode(description)
            if (CommandKey != String.Empty && CommandName != String.Empty)
            {
                builder = AppendQueryString(builder, CommandKey + "=" + CommandName);
            }
            builder = AppendQueryString(builder, "HideTemplate=true");
            builder = AppendQueryString(builder, "AutoReturn=true");
            //builder = AppendQueryString(builder,  EntityIDKey + "=" + EntityID.ToString());
            builder = AppendQueryString(builder, EntityType + "ID=" + EntityID.ToString());
            builder = AppendQueryString(builder, "RequesterID=" + ClientID);


            return(builder.ToString());
        }
        //public string K2Server = string.Empty;
        //public string K2HostServerConnectionString = string.Empty;
        //public string K2WorkflowServerConnectionString = string.Empty;
        //public string K2ProcessName = string.Empty;
        //public string K2StartOption = string.Empty;
        //public string K2EntityInfo = "";
        //public string K2EntityToStartFor = string.Empty;
        //public string K2StartProcess = string.Empty;
        //public string K2Folio = string.Empty;

        protected override void Execute(CodeActivityContext executionContext)
        {
            Guid   EntityID;
            string CRMEntityName = string.Empty;

            string K2ProcessFullName     = string.Empty;
            string K2Folio               = string.Empty;
            int    K2ProcesPriority      = 2;
            string K2ServicesBaseUri     = string.Empty;
            string K2EntityIdDataField   = string.Empty;
            string K2EntityNameDataField = string.Empty;
            string K2ContextXMLDataField = string.Empty;
            string K2OriginatorDataField = string.Empty;

            //Create the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            //Create the context
            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            // Get K2 Settings
            #region K2 Settings
            //Get Connection Settings

            // all users need read access to the K2 Settings and K2 Associations Entity
            // need to find a way to give all users access by default
            // TODO: revert to system user to read K2settings

            EntityCollection k2settings = service.RetrieveMultiple(new FetchExpression(Resources.K2SettingsFetchXML));

            foreach (Entity setting in k2settings.Entities)
            {
                string name  = setting["k2_name"].ToString();
                string value = setting["k2_value"].ToString();

                switch (name)
                {
                case "K2ServicesBaseUri":
                    K2ServicesBaseUri = value;
                    break;
                }
            }
            #endregion K2 Settings

            EntityID      = context.PrimaryEntityId;
            CRMEntityName = context.PrimaryEntityName.ToLower();


            // get inputs from WF activity configuration
            K2ProcessFullName     = InputProcessFullName.Get <string>(executionContext);
            K2EntityIdDataField   = InputEntityIdDataField.Get <string>(executionContext);
            K2EntityNameDataField = InputEntityNameDataField.Get <string>(executionContext);
            K2Folio = InputFolio.Get <string>(executionContext);
            K2OriginatorDataField = InputOriginatorDataField.Get <string>(executionContext);

            // JK: 20130603 - removed
            //K2ProcesPriority = InputPriority.Get<int>(executionContext);


            // JK: 20130603 - value read from k2settings entity
            //K2ServicesBaseUri = InputServiceBaseUri.Get<string>(executionContext);


            ColumnSet allColumns = new ColumnSet(true);

            // get entity WF is running against
            Entity currentEntity = service.Retrieve(CRMEntityName, EntityID, allColumns);

            // get system user entity of user starting WF
            Entity originatorUserEntity = service.Retrieve("systemuser", context.UserId, allColumns);


            string originator = string.Empty;

            string ProcessStartXml = Properties.Resources.K2ServicesStartProcess;

            try
            {
                if (originatorUserEntity != null && originatorUserEntity["domainname"] != null)
                {
                    originator = originatorUserEntity["domainname"].ToString();
                }

                // create process start xml for service -- needs validation & error handling
                ProcessStartXml = ProcessStartXml.Replace("[FULLNAME]", K2ProcessFullName).Replace("[FOLIO]", K2Folio).Replace("[PRIORITY]", K2ProcesPriority.ToString())
                                  .Replace("[ENTITY ID]", K2EntityIdDataField).Replace("[ENTITY ID VALUE]", EntityID.ToString()).Replace("[ENTITY NAME]", K2EntityNameDataField).Replace("[ENTITY NAME VALUE]", CRMEntityName)
                                  .Replace("[CRM ORIGINATOR]", K2OriginatorDataField).Replace("[CRM ORIGINATOR VALUE]", originator);;

                XmlDocument xmlstart = new XmlDocument();
                xmlstart.LoadXml(ProcessStartXml);

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(K2ServicesBaseUri + "REST.svc/Process/Instances/StartInstance?synchronous=false");
                request.UseDefaultCredentials = true;
                request.Method      = "POST";
                request.ContentType = "application/xml";

                // hack to get content length, required if not running .net 4
                //using (MemoryStream stream = new MemoryStream())
                //{
                //    using (var writer = new StreamWriter(stream))
                //    {
                //        writer.Write(ProcessStartXml);
                //        request.ContentLength = stream.Length;
                //        writer.Close();
                //    }
                //}

                using (var writer = XmlWriter.Create(request.GetRequestStream()))
                {
                    xmlstart.WriteTo(writer);
                }

                WebResponse  response       = null;
                Stream       responseStream = null;
                StreamReader responseReader = null;

                try
                {
                    request.Timeout = 20000;

                    response = request.GetResponse();

                    // if you want to check the response from the service call
                    //if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK /* 200 */ )
                    //{
                    //    responseStream = response.GetResponseStream();
                    //    responseReader = new StreamReader(responseStream);
                    //    string responseString = responseReader.ReadToEnd();


                    //}
                    //else
                    //{
                    //throw new Exception("Process start failed");
                    //}
                    System.Diagnostics.EventLog.WriteEntry("SourceCode.Logging.Extension.EventLogExtension", string.Format("K2 process {0} started successfully for Entity ID: {1}, Entity Logical Name: {2}.", K2ProcessFullName, EntityID, CRMEntityName), System.Diagnostics.EventLogEntryType.Information);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("SourceCode.Logging.Extension.EventLogExtension", string.Format("Error starting K2 process {0} for Entity ID: {1}, Entity Logical Name: {2}. Error: {3}", K2ProcessFullName, EntityID, CRMEntityName, ex.Message), System.Diagnostics.EventLogEntryType.Error);
            }
        }
예제 #8
0
 static public string EntityToString(int index)
 {
     id = (EntityID)index;
     return(id.ToString("D"));
 }
예제 #9
0
 public override string ToString()
 {
     return(EntityType.AssemblyQualifiedName + ":" + EntityID.ToString() + ":" + Recursive.ToString() + ":" + ContextType.AssemblyQualifiedName);
 }