Beispiel #1
0
 public static void AddSafeName(this List<Channel> l, Channel value)
 {
     if (l.Find(c => c.Name == value.Name) == null)
         l.Add(value);
 }
Beispiel #2
0
 public static void GetChanMessages(this boSessionState _sessionState, Channel chan, int numberOfMessages)
 {
     if (AppCache.MessageList.Where(m => m.ChannelId == chan.Id).OrderBy(m => m.PrivateDateTime).Take(numberOfMessages).ToList().Count == 0)
     {
         _sessionState.GetMessages().Where(m => m.ChannelId == chan.Id).OrderBy(m => m.PrivateDateTime).Take(numberOfMessages).ToList().ForEach(m =>
         {
             if (m.PublicData.Type == MessageTypes.File)
             {
                 _sessionState.AuthClient();
                 m.PrivateData = null;
                 var url = _sessionState.Client.GetMediaLinkAsync(m.PublicData.Value).Result.Url;
                 m.PublicData.Value = url;
             }
             AppCache.MessageList.AddSafeName(m);
         });
     }
 }
Beispiel #3
0
 public static SafeModeResult SaveUser(this boSessionState _sessionState, Channel value)
 {
     var result = _sessionState.db.GetCollection<User>("User").Save(value, SafeMode.True);
     if (result.Ok)
         AppCache.ChannelList.AddSafeName(value);
     return result;
 }
Beispiel #4
0
        public static Channel GetChannel(this boSessionState _sessionState, string name, string password, PubnubAPI pubnub)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
                return null;
            Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.PublicData.Password == password).FirstOrDefault();
            if (result == null)
            {
                //try to get channel from mongodb
                result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault();
                if (result == null)
                {
                    //save new channel
                    result = new Channel();
                    result.Name = name;
                    result.PublicData = new ChannelResource() { Password = password, CreatedDateTime = DateTime.Now };
                    result.PrivateData = AppCache.AESProvider.EncryptToString(JsonConvert.SerializeObject(result.PublicData));
                    _sessionState.SaveChannel(result);
                    //add channel in cache
                    AppCache.ChannelList.AddSafeName(result);
                    if (pubnub != null)
                    {
                        List<object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name);
                    }
                }
                else if(result.PublicData.Password != password)
                    result = null;

            }
            return result;
        }
Beispiel #5
0
 public static Channel GetChannel(this boSessionState _sessionState, string name)
 {
     if (string.IsNullOrEmpty(name))
         return null;
     Channel result = AppCache.ChannelList.Where(c => c.Name == name).FirstOrDefault();
     if (result == null)
     {
         result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();
         if (result == null)
             result = new Channel();
         AppCache.ChannelList.AddSafeName(result);
     }
     return result;
 }
        private void uploadToCloud(string filename, string uploadFileName, HttpContext context, Message msg, Channel chan, string file)
        {
            if (filename.EndsWith("png") || filename.EndsWith("jpeg") || filename.EndsWith("jpg") || filename.EndsWith("gif") || filename.EndsWith("bmp"))
            {
                try
                {
                    msg.PublicData.Type = MessageTypes.Image;
                    var configuration = new AccountConfiguration("saykor", "277334748579534", "mUjzZ-X3jOuNKGswrAjocB-D-Rc");

                    var uploader = new Uploader(configuration);
                    string publicId = Path.GetFileNameWithoutExtension(filename);
                    Stream stream;
                    if (string.IsNullOrEmpty(uploadFileName) == true) // IE Browsers
                        stream = context.Request.Files[0].InputStream;
                    else // Other Browsers
                        stream = context.Request.InputStream;

                    var uploadResult = uploader.Upload(new UploadInformation(filename, stream)
                    {
                        PublicId = publicId,
                        Format = filename.Substring(filename.Length - 3),
                    });
                    msg.PublicData.Value = filename;
                }
                catch (Exception ex)
                {
                    context.Response.Write("{ 'success': " + ex.Message + " }");
                    return;
                }
            }
            else
            {
                //upload to dropbox
                string cloudPath = "/" + chan.Name + "/" + filename;
                _sessionState.AuthClient();
                var result = _sessionState.Client.UploadFileAsync(new FileResource(file), cloudPath).Result;
                msg.PublicData.Value = cloudPath;
            }
        }
Beispiel #7
0
 private Message AddMessage(Channel chan, string message, MessageTypes type)
 {
     Message msg = new Message();
     msg.ChannelId = chan.Id;
     msg.PrivateDateTime = DateTime.Now;
     msg.CreatedDateTime = msg.PrivateDateTime.ToString();
     msg.PublicData = new MessageResource() { Type = type, Value = message };
     msg.PrivateData = AppCache.AESProvider.EncryptToString(JsonConvert.SerializeObject(msg.PublicData));
     _sessionState.SaveMessage(msg);
     AppCache.MessageList.AddSafeName(msg);
     SaveSession();
     return msg;
 }