예제 #1
0
        private static attachment ConstructSimpleAttachment(string[] newStatus, attachment attachment, string amazonLocaleUrlAndTag)
        {
            // Only do simple attachment containing status
            attachment = new attachment();

            attachment.caption = null;
            attachment.name    = newStatus[1];

            attachment.href = amazonLocaleUrlAndTag;

            if (!string.IsNullOrEmpty(amazonLocaleUrlAndTag))
            {
                attachment.href += "&url=search-alias%3Daps&field-keywords=" + HttpUtility.UrlEncode(newStatus[1]);
            }

            attachment.description = null;
            attachment.properties  = new attachment_property()
            {
                category = null,
                ratings  = null
            };

            attachment.media = null;

            return(attachment);
        }
예제 #2
0
        public void PublishToMyWall()
        {
            try
            {
                attachment att = new attachment
                {
                    name    = "",
                    href    = "",
                    caption = "has used the application",
                    media   = new List <attachment_media>()
                };

                attachment_media_image attMEd = new attachment_media_image
                {
                    src  = "",
                    href = ""
                };
                att.media.Add(attMEd);

                action_link a = new action_link
                {
                    text = "",
                    href = ""
                };
                IList <action_link> tempA = new List <action_link> {
                    a
                };

                fbService.Stream.PublishAsync(myWallTextBox.Text, att, tempA, null, 0, PublishAsyncCompleted, null);
            }
            catch (Exception)
            {
            }
        }
예제 #3
0
        public IHttpActionResult Putattachment(int id, attachment attachment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != attachment.ID)
            {
                return(BadRequest());
            }

            db.Entry(attachment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!attachmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #4
0
        public ActionResult Attachments(int report_id, string mode, string type)
        {
            user user = (user)Session[ECGlobalConstants.CurrentUserMarcker];

            // DEBUG
            //user = user ?? db.user.FirstOrDefault(x => x.id == 2);
            //user = user ?? db.user.FirstOrDefault(x => x.id == 167);
            //
            if (user == null || user.id == 0)
            {
                return(RedirectToAction("Index", "Account"));
            }

            if ((mode == "upload") || (mode == "upload_rd"))
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];
                    if (file.ContentLength == 0)
                    {
                        continue;
                    }
                    var report = db.report.FirstOrDefault(x => x.id == report_id);

                    var a = new attachment();
                    a.file_nm        = file.FileName;
                    a.extension_nm   = System.IO.Path.GetExtension(file.FileName);
                    a.path_nm        = "";
                    a.report_id      = report_id;
                    a.status_id      = 2;
                    a.effective_dt   = DateTime.Now;
                    a.expiry_dt      = DateTime.Now;
                    a.last_update_dt = DateTime.Now;
                    a.user_id        = user.id;

                    type = mode == "upload_rd" ? "reporter" : "staff";
                    a.visible_reporter       = type == "reporter" ? true : false;
                    a.visible_mediators_only = type == "staff" ? true : false;

                    db.attachment.Add(a);
                    db.SaveChanges();

                    var dir      = Server.MapPath(String.Format("~/upload/reports/{0}", report.guid));
                    var filename = String.Format("{0}_{1}{2}", user.id, DateTime.Now.Ticks, System.IO.Path.GetExtension(file.FileName));
                    a.path_nm = String.Format("\\upload\\reports\\{0}\\{1}", report.guid, filename);
                    db.SaveChanges();

                    if (!System.IO.Directory.Exists(dir))
                    {
                        System.IO.Directory.CreateDirectory(dir);
                    }
                    file.SaveAs(string.Format("{0}\\{1}", dir, filename));
                }
            }
            if (mode == "upload_rd")
            {
                return(RedirectToAction("Attachments", "ReporterDashboard", new { id = user.id }));
            }
            return(RedirectToAction("Attachments", new { report_id = report_id }));
        }
        public ActionResult Create(attachment attachment, HttpPostedFileBase fileToUpload)
        {
            if (ModelState.IsValid)
            {
                var filevalid = fileToUpload as HttpPostedFileBase;
                if (filevalid == null)
                {
                    ViewBag.pid   = attachment.projectid;
                    ViewBag.isid  = attachment.issueid;
                    ViewBag.error = "File is Required";
                    return(View(attachment));
                }
                //save the uploaded file in a variable
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    //for the file name
                    var fileName = Path.GetFileName(file.FileName);
                    //for not doubling
                    string path2 = Path.GetRandomFileName();
                    fileName = path2 + fileName;
                    //for saving file path
                    var path = Path.Combine(Server.MapPath("~/Upload/"), fileName);
                    //for saving file
                    attachment.attachmentdest = fileName;

                    file.SaveAs(path);//saved the file in path
                }


                db.attachments.Add(attachment);
                db.SaveChanges();


                String username = Convert.ToString(Session["UserName"]);

                db.SaveChanges();
                var ii = db.issues.Select(x => x).Where(x => x.id == attachment.issueid).FirstOrDefault();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Add Attachment";
                activitystr.description = username + " Added Attachment " + attachment.Name + " To Issue " + ii.keyname;
                activitystr.issueid     = attachment.issueid;
                activitystr.issuekey    = ii.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = attachment.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();


                return(RedirectToAction("Details", "issues", new { id = attachment.issueid }));
            }

            ViewBag.pid  = attachment.projectid;
            ViewBag.isid = attachment.issueid;
            return(View(attachment));
        }
예제 #6
0
        public static attachment SaveFile(HttpFileCollectionBase files, string file, string newFielPath)
        {
            var fileItem = files[file];

            if (files.Count <= 0)
            {
                return(null);
            }
            if (fileItem.ContentLength <= 0)
            {
                return(null);
            }

            var fileName = DateTime.Now.Ticks + Path.GetExtension(fileItem.FileName);

            fileItem.SaveAs(UploadTarget + fileName);
            string     extension = Path.GetExtension(fileItem.FileName);
            string     path      = @"\" + UploadedDirectory + @"\" + fileName;
            attachment attach    = new attachment
            {
                report_message_id = null,
                status_id         = 2, //soglasno letter
                path_nm           = path,
                file_nm           = fileItem.FileName,
                extension_nm      = extension,
                user_id           = 1,
                effective_dt      = System.DateTime.Now,
                expiry_dt         = System.DateTime.Now,
                last_update_dt    = System.DateTime.Now
            };

            //return @"\" + UploadedDirectory + @"\" + fileName;
            return(attach);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            attachment attachment = db.attachments.Find(id);

            db.attachments.Remove(attachment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //
        // GET: /attachment/Details/5

        public ActionResult Details(int id = 0)
        {
            attachment attachment = db.attachments.Find(id);

            if (attachment == null)
            {
                return(HttpNotFound());
            }
            return(View(attachment));
        }
예제 #9
0
        public void AddAttachment(int bugId, attachment attachment)
        {
            var bug = GetById(bugId);

            if (bug.attachmentCollection == null)
            {
                bug.attachmentCollection = new attachmentCollection();
            }

            bug.attachmentCollection.Add(attachment);
        }
예제 #10
0
        private static string GetAttachmentFileName(attachment attachment)
        {
            var name = attachment.filename;

            if (string.IsNullOrEmpty(name))
            {
                name = attachment.desc;
            }

            return(name);
        }
예제 #11
0
        public IHttpActionResult Getattachment(int id)
        {
            attachment attachment = db.attachment.Find(id);

            if (attachment == null)
            {
                return(NotFound());
            }

            return(Ok(attachment));
        }
예제 #12
0
        public IHttpActionResult Postattachment(attachment attachment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.attachment.Add(attachment);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = attachment.ID }, attachment));
        }
예제 #13
0
        /// <summary>
        /// Publishes the specified achievements.
        /// </summary>
        /// <param name="achievements">The achievements.</param>
        /// <param name="steamUserId">The steam user id.</param>
        /// <param name="facebookUserId">The facebook user id.</param>
        public void Publish(IEnumerable <Achievement> achievements, string steamUserId, long facebookUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            if (_testMode)
            {
                return;
            }

            foreach (Achievement achievement in achievements)
            {
                string description = String.Format("earned the {0} achievement in {1}.", achievement.Name,
                                                   achievement.Game.Name);

                string gameStatsLink = String.Format(
                    "http://steamcommunity.com/id/{0}/stats/{1}",
                    steamUserId, achievement.Game.Abbreviation);

                string gameAchievementsLink = gameStatsLink + "?tab=achievements";

                attachment attachment = new attachment
                {
                    caption = achievement.Description,
                    name    = achievement.Name,
                    href    = gameAchievementsLink,
                    media   = new List <attachment_media>
                    {
                        new attachment_media_image
                        {
                            src  = achievement.ImageUrl,
                            href = gameAchievementsLink
                        }
                    }
                };

                List <action_link> links = new List <action_link>
                {
                    new action_link
                    {
                        text = achievement.Game.Abbreviation + " stats",
                        href = gameStatsLink
                    }
                };

                // Normally, facebookUserId wouldn't be required if this was called from a normal page, but we're calling it from a WCF service.
                _api.Stream.Publish(description, attachment, links, null, facebookUserId);
            }
        }
예제 #14
0
        public void publishTest4()
        {
            attachment attachment = new attachment();

            attachment.caption     = "www.youtube.com";
            attachment.name        = "ninja cat";
            attachment.href        = "http://www.youtube.com/watch?v=muLIPWjks_M";
            attachment.description = "a sneaky cat";
            attachment.properties  = new List <attachment_property>()
            {
                new attachment_property
                {
                    name  = "category",
                    value = new attachment_property_value
                    {
                        href = "http://www.youtube.com/browse?s=mp&t=t&c=15",
                        text = "humor"
                    }
                },
                new attachment_property
                {
                    name  = "ratings",
                    value = new attachment_property_value {
                        text = "5 stars"
                    }
                }
            };
            attachment.media = new List <attachment_media>()
            {
                new attachment_media_video()
                {
                    video_src   = "http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1",
                    preview_img = "http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=",
                    video_link  = "http://www.youtube.com/watch?v=muLIPWjks_M",
                    video_title = "ninja cat"
                }
            };
            var link = new action_link();

            link.href = "http://www.youtube.com/my_videos_upload";
            link.text = "Upload a video";

            var links = new List <action_link>()
            {
                link
            };
            var actual = _api.Stream.Publish("Watch this video!", attachment, links, null, 0);

            Assert.IsNotNull(actual);
        }
예제 #15
0
        public IHttpActionResult Deleteattachment(int id)
        {
            attachment attachment = db.attachment.Find(id);

            if (attachment == null)
            {
                return(NotFound());
            }

            db.attachment.Remove(attachment);
            db.SaveChanges();

            return(Ok(attachment));
        }
        public ActionResult Edit(int id = 0)
        {
            attachment attachment = db.attachments.Find(id);
            // for checking if the user is allowed
            var adminproj = db.pojectdevs.Select(x => x).Where(x => x.projectid == attachment.projectid && x.devname == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }

            ViewBag.pid  = attachment.projectid;
            ViewBag.isid = attachment.issueid;
            return(View(attachment));
        }
예제 #17
0
        public void publishTest3()
        {
            attachment attachment = new attachment();

            attachment.caption     = "www.icanhascheezburger.com";
            attachment.name        = "I am bursting with joy";
            attachment.href        = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/";
            attachment.description = "a funny looking cat";
            attachment.properties  = new List <attachment_property>()
            {
                new attachment_property
                {
                    name  = "category",
                    value = new attachment_property_value
                    {
                        href = "http://www.icanhascheezburger.com/category/humor",
                        text = "humor"
                    }
                },
                new attachment_property
                {
                    name  = "ratings",
                    value = new attachment_property_value {
                        text = "5 stars"
                    }
                }
            };
            attachment.media = new List <attachment_media>()
            {
                new attachment_media_image()
                {
                    src  = "http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg",
                    href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/"
                }
            };
            var link = new action_link();

            link.href = "http://mine.icanhascheezburger.com/default.aspx?tiid=1192742&recap=1#step2";
            link.text = "Recaption this";

            var links = new List <action_link>()
            {
                link
            };
            var actual = _api.Stream.Publish("testing stream.publish with image attachment", attachment, links, null, 0);

            Assert.IsNotNull(actual);
        }
        public static void PostAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            string appKey    = WebConfigurationManager.AppSettings["APIKey"];
            string appSecret = WebConfigurationManager.AppSettings["Secret"];
            List <Enums.ExtendedPermissions> permissions =
                new List <Enums.ExtendedPermissions> {
                Enums.ExtendedPermissions.publish_stream
            };
            IFrameCanvasSession session = new IFrameCanvasSession(appKey, appSecret, permissions);
            Api api = new Api(session);

            AchievementManager        manager            = new AchievementManager();
            IEnumerable <Achievement> latestAchievements = manager.GetLatestAchievements(steamUserId);

            foreach (Achievement achievement in latestAchievements)
            {
                string description = String.Format("earned the {0} achievement in {1}.", achievement.Name,
                                                   achievement.Game.Name);
                attachment attachment = new attachment
                {
                    caption = achievement.Description,
                    name    = achievement.Name,
                    href    = String.Format("http://steamcommunity.com/id/{0}/stats/{1}",
                                            steamUserId, achievement.Game.Abbreviation),
                    media = new List <attachment_media>
                    {
                        new attachment_media_image
                        {
                            src  = achievement.ImageUrl,
                            href =
                                String.Format(
                                    "http://steamcommunity.com/id/{0}/stats/{1}?tab=achievements",
                                    steamUserId, achievement.Game.Abbreviation)
                        }
                    }
                };

                api.Stream.Publish(description, attachment, null, null, 0);
            }
        }
예제 #19
0
        public void PublishToAFriendWall()
        {
            try
            {
                attachment att = new attachment
                {
                    // Name of link
                    name = "",
                    // URL of link
                    href    = "",
                    caption = "",
                    media   = new List <attachment_media>()
                };

                attachment_media_image attMEd = new attachment_media_image
                {
                    // Image source
                    src = "",
                    // URL to go to if clicked
                    href = ""
                };
                att.media.Add(attMEd);

                action_link a = new action_link
                {
                    text = "What's this",
                    //URL to go to if clicked
                    href = ""
                };
                IList <action_link> tempA = new List <action_link> {
                    a
                };

                // Use the typed friend UID to publish the typed message
                fbService.Stream.PublishAsync(friendWallTextBox.Text, att, tempA, uidTextBox.Text, 0, PublishAsyncCompleted, null);
            }
            catch (Exception)
            {
            }
        }
        public ActionResult Edit(attachment attachment)
        {
            if (ModelState.IsValid)
            {
                attachment oldattachment = db.attachments.Find(attachment.id);
                // for the activity stream
                String old = oldattachment.Name;
                oldattachment.Name = attachment.Name;

                db.SaveChanges();



                String username = Convert.ToString(Session["UserName"]);

                db.SaveChanges();
                var ii = db.issues.Select(x => x).Where(x => x.id == attachment.issueid).FirstOrDefault();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Edit Attachment";
                activitystr.description = username + " Edited Attachment " + old + " In Issue " + ii.keyname + " To " + attachment.Name;
                activitystr.issueid     = attachment.issueid;
                activitystr.issuekey    = ii.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = attachment.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();



                return(RedirectToAction("Details", "issues", new { id = attachment.issueid }));
            }
            ViewBag.issueid   = new SelectList(db.issues, "id", "keyname", attachment.issueid);
            ViewBag.projectid = new SelectList(db.projects, "id", "projectkey", attachment.projectid);
            return(View(attachment));
        }
        public ActionResult Delete(int id = 0)
        {
            attachment attachment = db.attachments.Find(id);
            // for checking if the user is allowed
            var adminproj = db.pojectdevs.Select(x => x).Where(x => x.projectid == attachment.projectid && x.devname == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            db.attachments.Remove(attachment);
            db.SaveChanges();


            String username = Convert.ToString(Session["UserName"]);

            db.SaveChanges();
            var ii = db.issues.Select(x => x).Where(x => x.id == attachment.issueid).FirstOrDefault();

            //for adding assign action to activity stream
            MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
            activitystr.actiontype  = "Delete Attachment";
            activitystr.description = username + " Deleted Attachment " + attachment.Name + " In Issue " + ii.keyname;
            activitystr.issueid     = attachment.issueid;
            activitystr.issuekey    = ii.keyname;
            activitystr.actiondate  = DateTime.Now.ToString();
            activitystr.projectid   = attachment.projectid;
            int uid = int.Parse(Session["UserId"] + "");

            activitystr.userid = uid;
            db.activitystreams.Add(activitystr);
            db.SaveChanges();



            return(RedirectToAction("Details", "issues", new { id = attachment.issueid }));
        }
예제 #22
0
        private void PostAppAddMessage(Api api, string profileid)
        {
            if (string.IsNullOrEmpty(profileid))
            {
                Syslog.Write(new Exception("Cannot post to stream"));
                return;
            }

            var image = new attachment_media_image()
            {
                href = GeneralConstants.FACEBOOK_APP_URL,
                src  = string.Format("{0}/Content/img/logo2.png", GeneralConstants.FACEBOOK_HOST),
                type = attachment_media_type.image
            };

            var attachment = new attachment
            {
                media = new List <attachment_media>()
                {
                    image
                },
                caption     = GeneralConstants.FACEBOOK_APP_URL,
                name        = "tradelr for Facebook",
                href        = GeneralConstants.FACEBOOK_APP_URL,
                description = "Display your products from tradelr.com on Facebook."
            };

            try
            {
                api.Stream.Publish("added tradelr to my profile", attachment, null, null, long.Parse(profileid));
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
            }
        }
예제 #23
0
 partial void Deleteattachment(attachment instance);
예제 #24
0
 partial void Insertattachment(attachment instance);
예제 #25
0
 partial void Updateattachment(attachment instance);
예제 #26
0
	private void attach_attachments(attachment entity)
	{
		this.SendPropertyChanging();
		entity.ticket = this;
	}
예제 #27
0
	private void detach_attachments(attachment entity)
	{
		this.SendPropertyChanging();
		entity.comment = null;
	}
예제 #28
0
        private static FileId SaveAttachmentFile(attachment attachment)
        {
            byte[] data = Convert.FromBase64String(attachment.data.Value);

            return(AttachmentFolder.Save(new MemoryStream(data)));
        }
예제 #29
0
        /// <summary>
        /// Updates Facebook status
        /// </summary>
        /// <param name="newStatus"></param>
        private void UpdateFacebook(string[] newStatus)
        {
            if (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_Facebook")))
            {
                if (MyAddIn.FbApi != null && !string.IsNullOrEmpty(MyAddIn.FbApi.AccessToken))
                {
                    try
                    {
                        bool updateConfirmed = true;

                        // Confirm Facebook update from the user
                        if (bool.Parse(CommonFunctions.GetSetting("ConfirmUpdate_Facebook")))
                        {
                            DialogResult confirmUpdateResult = ShowDialog("Publish to Facebook: '" + newStatus[0] + "'?", true, 10, DialogButtons.Yes | DialogButtons.No);

                            // If update isn't confirmed or dialog times out, do not prompt for confirmation again
                            if (confirmUpdateResult == DialogResult.No || confirmUpdateResult == DialogResult.Timeout)
                            {
                                updateConfirmed = false;
                                _previousStatus = newStatus[0];
                            }
                        }

                        if (updateConfirmed)
                        {
                            try
                            {
                                attachment attachment    = null;
                                bool       streamEnabled = bool.Parse(CommonFunctions.GetSetting("Service_Facebook_StreamEnabled"));
                                bool       statusEnabled = bool.Parse(CommonFunctions.GetSetting("Service_Facebook_StatusEnabled"));

                                if (streamEnabled)
                                {
                                    string amazonLocaleApiUrl = CommonFunctions.GetSetting("Service_All_AmazonLocaleUrl");

                                    // If Amazon queries are enabled for current media
                                    if (!string.IsNullOrEmpty(newStatus[1]))
                                    {
                                        string[] amazonDetails = { "", "", "", "", "", "", "" };
                                        // Title, DetailUrl, ImageUrl, Error, AverageRating, Artist

                                        amazonDetails = Query.SearchItems(newStatus[1], newStatus[2], amazonDetails, amazonLocaleApiUrl);

                                        // If ASIN exists, continue search
                                        if (!string.IsNullOrEmpty(amazonDetails[4]))
                                        {
                                            amazonDetails = Query.LookupItem(amazonDetails, amazonLocaleApiUrl);

                                            if (string.IsNullOrEmpty(amazonDetails[3]))
                                            {
                                                attachment = new attachment();

                                                // For videos/tv, show video/tv title as a link
                                                if (newStatus[2].Equals("Video") && newStatus[2].StartsWith("TV"))
                                                {
                                                    attachment.caption = "";
                                                    attachment.name    = amazonDetails[0]; // Artist
                                                }
                                                else
                                                {
                                                    attachment.caption = amazonDetails[0]; // Album
                                                    attachment.name    = amazonDetails[6]; // Artist
                                                }

                                                attachment.href        = amazonDetails[1];
                                                attachment.description = null;
                                                attachment.properties  = new attachment_property()
                                                {
                                                    category = null, /*new attachment_category()
                                                                      * {
                                                                      * href = "",
                                                                      * text = ""
                                                                      * }*/
                                                    ratings  = !string.IsNullOrEmpty(amazonDetails[5]) ? amazonDetails[5] + " stars" : null
                                                };

                                                attachment.media = new List <attachment_media>()
                                                {
                                                    new attachment_media_image()
                                                    {
                                                        src  = amazonDetails[2],
                                                        href = amazonDetails[1]
                                                    }
                                                };
                                            }
                                        }
                                        else
                                        {
                                            attachment = null;
                                        }
                                    }
                                    else
                                    {
                                        attachment = null;
                                    }

                                    // Finally post to user's Wall and News feed
                                    if (!string.IsNullOrEmpty(MyAddIn.FbApi.StreamPublish(newStatus[0], attachment, null, "", 0)))
                                    {
                                        _previousStatus = newStatus[0];

                                        MyAddIn.StatusHasBeenChanged = true;
                                    }
                                }

                                if (statusEnabled)
                                {
                                    if (string.IsNullOrEmpty(MyAddIn.FbApi.SetStatus(newStatus[0], true)))
                                    {
                                        _previousStatus = newStatus[0];

                                        MyAddIn.StatusHasBeenChanged = true;
                                    }
                                }
                            }
                            catch (Facebook.Exceptions.FacebookSigningException)
                            {
                                MyAddIn.FbApi.AccessToken = "";
                                CommonFunctions.SetSetting("Facebook_AccessToken", "");

                                ShowDialog("Facebook session is invalid, opening login screen...", false, 2, DialogButtons.Ok);
                            }
                            catch (Facebook.Exceptions.FacebookTimeoutException)
                            {
                                MyAddIn.FbApi.AccessToken = "";
                                CommonFunctions.SetSetting("Facebook_AccessToken", "");

                                ShowDialog("Facebook session is invalid, opening login screen...", false, 2, DialogButtons.Ok);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ShowDialog("Unable to publish to Facebook." + e.Message, false, 2, DialogButtons.Ok);
                    }
                }
            }
        }
예제 #30
0
        /// <summary>
        /// Uses Stream.Publish to publish stream
        /// </summary>
        /// <param name="message"></param>
        /// <param name="attachment"></param>
        /// <param name="action_links"></param>
        /// <param name="target_id"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public string StreamPublish(string message, attachment attachment, Dictionary <string, string> action_links, string target_id, int uid)
        {
            var parameterList = new Dictionary <string, string>();

            AddOptionalParameter(parameterList, "message", message);

            if (attachment != null)
            {
                if (attachment.properties.ratings != null)
                {
                    if (!string.IsNullOrEmpty(attachment.properties.ratings))
                    {
                        AddOptionalParameter(parameterList, "description", "Average rating: " + attachment.properties.ratings);
                    }
                }

                if (attachment.media != null)
                {
                    foreach (var item in attachment.media)
                    {
                        if (item.type == attachment_media_type.image)
                        {
                            var image = item as attachment_media_image;
                            AddOptionalParameter(parameterList, "picture", image.src);

                            break;
                        }
                    }
                }
                //var dict = new Dictionary<string, string>();

                //if (!string.IsNullOrEmpty(attachment.name))
                //{
                //    AddOptionalParameter(parameterList, "name", attachment.name);
                //}

                if (!string.IsNullOrEmpty(attachment.href))
                {
                    AddOptionalParameter(parameterList, "link", attachment.href);
                }

                //if (!string.IsNullOrEmpty(attachment.caption))
                //{
                //    AddOptionalParameter(parameterList, "caption", attachment.caption);
                //}
            }

            //if (action_links != null)
            //{
            //    var list = new List<string>();
            //    foreach (var item in action_links)
            //    {
            //        var dict = new Dictionary<string, string>{
            //        {"text", item.Key},
            //        {"href", item.Value}
            //    };
            //        list.Add(JSONHelper.ConvertToJSONAssociativeArray(dict));
            //    }
            //    AddJSONArray(parameterList, "action_links", list);
            //}

            /*
             * Pure GRAPH UI, for future use
             *
             * StringBuilder url = new StringBuilder(Resources.Stream);
             * url.Append("&message=");
             * url.Append(message);
             * url.Append("&link=");
             * url.Append(attachment.href);
             * url.Append("&caption=");
             * url.Append(attachment.caption);
             * url.Append("&name=");
             * url.Append(attachment.name);
             *
             *
             * if (attachment.properties.ratings != null)
             * {
             *  if (!string.IsNullOrEmpty(attachment.properties.ratings))
             *  {
             *      url.Append("&description=Average rating:");
             *      url.Append(attachment.properties.ratings);
             *  }
             * }
             *
             * if (attachment.media != null)
             * {
             *  foreach (var item in attachment.media)
             *  {
             *      if (item.type == attachment_media_type.image)
             *      {
             *          var image = item as attachment_media_image;
             *          url.Append("&picture=");
             *          url.Append(image.src);
             *      }
             *  }
             * }
             */
            return(ExecuteApiCallString(parameterList, true, Resources.Stream));
        }
예제 #31
0
        public static void Add(dbDataContext db, string fileName, int ticket_ref, long size, int comment_ref)
        {
            attachment a = new attachment();
            a.attachment_name = fileName;
            a.attachment_size = size.ToString();
            a.submitted = DateTime.Now;
            a.ticket_ref = ticket_ref;
            a.active = true;
            if (comment_ref > 0) a.comment_ref = comment_ref;

            db.attachments.InsertOnSubmit(a);
        }
        public override void PostInserted(Post post)
        {
            // Send post to FaceBook
            try
            {
                ConnectSession session = new ConnectSession(ApiKey, AppSecret);
                session.SessionKey = SessionKey;

                if (session.IsConnected())
                {
                    Macros macros = new Macros();
                    Api    api    = new Api(session);

                    string fullUrl = macros.FullUrl(post.Url);

                    attachment attachment = new attachment();
                    attachment.name        = post.Title;
                    attachment.href        = fullUrl;
                    attachment.description = post.Excerpt("", "", "", 200);

                    action_link link = new action_link();
                    link.href = fullUrl;
                    link.text = "Read the full entry";
                    List <action_link> links = new List <action_link>();
                    links.Add(link);

                    if (!String.IsNullOrEmpty(post.ImageUrl))
                    {
                        attachment_media_image image = new attachment_media_image();
                        image.src  = macros.FullUrl(post.ImageUrl);
                        image.href = fullUrl;
                        image.type = attachment_media_type.image;

                        List <attachment_media> media = new List <attachment_media>();
                        media.Add(image);

                        attachment.media = media;
                    }

                    foreach (long pageId in this.PageIdList)
                    {
                        try
                        {
                            api.Stream.Publish("", attachment, links, "", pageId);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Facebook Plugin", "Failed to submit status to Facebook. {0}", ex.Message);
                        }
                    }
                }
                else
                {
                    Log.Error("Facebook Plugin", "Facebook Session ID not valid");
                }
            }
            catch (Exception ex)
            {
                Log.Error("Facebook Plugin", "Failed to submit status to Facebook. {0}", ex.Message);
            }
        }